说明 1:由于用Matlab设计出系数之后,要在实验板上面跑,所以取两个正弦信号。
一巴特沃斯低通滤波器
fs=1000000;
N=1024;
n=0:N-1;
t=0:1/fs:1;
f=n*fs/N;
x1=sin(2*pi*22500*t);
x2=sin(2*pi*45000*t);
x=x1+x2;
y=fft(x,N);
subplot(221);
plot(t,x);title('原始信号');grid on;
subplot(222);
plot(f,abs(y));title('原始信号FFT');
Wc=2*30000/fs;
[b,a]=butter(2,Wc);
% y2=filter(b,a,x);
y2=filtfilt(b,a,x);
Ps=sum(x1.^2);
Pu=sum((y2-x1).^2);
SNR=10*log10(Ps/Pu);
y3=fft(y2,N);
subplot(223);
plot(f,abs(y3));xlabel('频率/Hz');
ylabel('振幅');title('滤波后信号FFT');
[H,F]=freqz(b,a,512);
subplot(224);
plot(F/pi,abs(H));xlabel('归一化频率');
ylabel('幅度');
title(['Order=',int2str(2),'
set(gcf, 'color', 'white');
二,巴特沃斯带通滤波器的设计
fs=1000000;
N=1024;
n=0:N-1;
t=0:1/fs:1;
f=n*fs/N;
x1=sin(2*pi*22500*t);
x2=sin(2*pi*45000*t);
x=x1+x2;
y=fft(x,N);
subplot(221)
plot(t,x);title('原始信号');grid on;
subplot(222);
plot(f,abs(y));title('原始信号FFT');
%
%
%
%
Wn=[43000*247000*2]/fs;
[b,a]=butter(1,Wn);
%y2=filter(b,a,x);
y2=filtfilt(b,a,x);
Ps=sum(x2.^2);
Pu=sum((y2-x2).^2);
SNR=10*log10(Ps/Pu);
y3=fft(y2,N);
subplot(223);
plot(f,abs(y3));
xlabel('频率/Hz');
ylabel('振幅');
title('滤波后信号FFT');grid on;
[H,F]=freqz(b,a,512);
subplot(224);
plot(F/pi,abs(H));
xlabel('归一化频率');
ylabel('幅度');
title(['Order=',int2str(1),'
set(gcf, 'color', 'white');
% figure;
% freqz(b,a,512);
% figure;
% plot(t,y2);
三,巴特沃斯带阻滤波器
fs=1000000;
N=1024;
n=0:N-1;
t=0:1/fs:1;
f=n*fs/N;
x1=sin(2*pi*22500*t);
x2=sin(2*pi*45000*t);
x=x1+x2;
y=fft(x,N);
subplot(221)
plot(t,x);title('原始信号');
subplot(222);
plot(f,abs(y));title('原始信号FFT');
%
%
%
%
Wn=[20000*225000*2]/fs;
[b,a]=butter(2,Wn,'stop');
%y2=filter(b,a,x);
y2=filtfilt(b,a,x);
Ps=sum(x2.^2);
Pu=sum((y2-x2).^2);
SNR=10*log10(Ps/Pu);
y3=fft(y2,N);
subplot(223);
plot(f,abs(y3));
xlabel('频率/Hz');
ylabel('振幅');
title('滤波后信号FFT');grid on;
[H,F]=freqz(b,a,512);
subplot(224);
plot(F/pi,abs(H));
xlabel('归一化频率');
ylabel('幅度');
title(['Order=',int2str(2),'
set(gcf, 'color', 'white');
四,巴特沃斯高通滤波器
fs=1000000;
N=1024;
n=0:N-1;
t=0:1/fs:1;
f=n*fs/N;
x1=sin(2*pi*22500*t);
x2=sin(2*pi*45000*t);
x=x1+x2;
y=fft(x,N);
subplot(221)
plot(t,x);title('原始信号');
subplot(222);
plot(f,abs(y));title('原始信号FFT');
%
%
%
%
[b,a]=butter(2,32000*2/fs,'high');
% y2=filter(b,a,x);
y2=filtfilt(b,a,x);
Ps=sum(x2.^2);
Pu=sum((y2-x2).^2);
SNR=10*log10(Ps/Pu);
y3=fft(y2,N);
subplot(223);
plot(f,abs(y3));xlabel('频率/Hz');
ylabel('振幅');title('滤波后信号FFT');grid on;
[H,F]=freqz(b,a,512);
subplot(224);
plot(F/pi,abs(H));xlabel('归一化频率');
ylabel('幅度');title(['Order=',int2str(2),'
set(gcf, 'color', 'white');
% figure;
% % freqz(b,a,512);
% plot(t,y2);
联系客服