基于MATLAB的Filter使用,低通、带通和高通滤波器的MATLAB程序分享
完整程序如下:
clear all
close all
clc
%% Parameter Interface
Frequence0 = 60; %单位:Hz
Frequence1 = 130; %单位:Hz
Frequence2 = 1e3; %单位:Hz
SampleFre = 4e3; %单位:Hz
SampleLen = SampleFre; %采样点数
%% Main
%-------------------产生三路信号
t = 0:1/SampleLen:1/SampleFre*(SampleLen-1);
SignalData0 = sin(2*pi*Frequence0*t);
SignalData1 = sin(2*pi*Frequence1*t);
SignalData2 = sin(2*pi*Frequence2*t);
SignalData3 = SignalData0+SignalData1+SignalData2;
figure;hold on
plot(t(1:150),SignalData0(1:150),'b')
plot(t(1:150),SignalData1(1:150),'r')
plot(t(1:150),SignalData2(1:150),'k')
hold off
figure;plot(t(1:150),SignalData3(1:150))
title('三路信号求和')
%-------------------频谱分析
FFT_Data = fft(SignalData3);
Amplitude = abs(FFT_Data);
Amplitude = Amplitude/length(Amplitude);
Amplitude(2:end) = 2*Amplitude(2:end);
Frequence = (0:(length(Amplitude)/2-1))/length(Amplitude)*SampleFre;
figure;plot(Frequence,Amplitude(1:length(Frequence)))
title('三路信号叠加频谱')
%-------------------低通滤波
LPF_Coe = load('LPF_60M.mat');
LPF_Data = filter(LPF_Coe.LPF_60M,1,SignalData3);
figure;plot(t,LPF_Data)
title('低通滤波之后的波形')
%-------------------低通滤波之后频谱分析
FFT_LPF_Data = fft(LPF_Data);
Amplitude_LPF = abs(FFT_LPF_Data);
Amplitude_LPF = Amplitude_LPF/length(Amplitude_LPF);
Amplitude_LPF(2:end) = 2*Amplitude_LPF(2:end);
Frequence = (0:(length(Amplitude_LPF)/2-1))/length(Amplitude_LPF)*SampleFre;
figure;plot(Frequence,Amplitude_LPF(1:length(Frequence)))
title('低通滤波之后的频谱')
%-------------------带通滤波
BPF_Coe = load('BPF_130M.mat');
BPF_Data = filter(BPF_Coe.BPF_130M,1,SignalData3);
figure;plot(t,BPF_Data)
title('带通滤波之后的波形')
%-------------------带通滤波之后频谱分析
FFT_BPF_Data = fft(BPF_Data);
Amplitude_BPF = abs(FFT_BPF_Data);
Amplitude_BPF = Amplitude_BPF/length(Amplitude_BPF);
Amplitude_BPF(2:end) = 2*Amplitude_BPF(2:end);
Frequence = (0:(length(Amplitude_BPF)/2-1))/length(Amplitude_BPF)*SampleFre;
figure;plot(Frequence,Amplitude_BPF(1:length(Frequence)))
title('带通滤波之后的频谱')