rp=1;rs=35;
Wc1=4500*pi;Wc2=9000*pi;
Wr1=1500*pi;Wr2=12000*pi;
W0=sqrt(Wc1*Wc2);B=Wc2-Wc1;
nwr1=Wr1/B;nwr2=Wr2/B;nw0=W0/B;
wp=1;%归一化通带截止频率
ws=(nwr2^2-nw0^2)/nwr2;
[N,wc]=buttord(wp,ws,rp,rs,'s')%求滤波器阶数和3dB截止频率
[Z,P,K]=buttap(N)%设计模拟低通滤波器
[Md,Nd]=zp2tf(Z,P,K)%将零极点形式转换为传输函数形式
[M,N]=lp2bp(Md,Nd,W0,B)%对低通滤波器进行频率变换,转换为带通滤波器
[h,w]=freqs(M,N);%模拟带通滤波器的幅频相频响应
figure(1);
subplot(2,1,1);
plot(w/(2*pi),20*log10(abs(h)));
title('模拟带通滤波器幅频响应');grid on;
xlabel('频率/HZ');ylabel('幅度/DB');
subplot(2,1,2);
plot(w/pi,180/pi*angle(h));
title('模拟带通滤波器相频响应');grid on;
xlabel('W/pi');ylabel('相位/度');
[b,a]=impinvar(M,N,fs);
[H,W]=freqz(b,a,fs);%数字带通滤波器的幅频相频响应
figure(2);
subplot(2,1,1);
plot(W/pi,20*log10(abs(H))); axis([0,8000,-40,10]);
title('数字带通滤波器幅频响应');grid on;
xlabel('W/pi');ylabel('幅度/DB');
subplot(2,1,2);
plot(W/pi,180/pi*angle(H)); axis([0,1,-40,10]);
title('数字带通滤波器相频响应');grid on;
xlabel('W/pi');ylabel('相位/度');
%带通滤波器测试程序
n=0:Nn-1;
t=n/fs;
x=2*sin(2*pi*3000*t)+2*sin(2*pi*5500*t)+2*sin(2*pi*500*t);
figure(3);
subplot(2,1,1);
stem(t,x);
title('输入信号');
ylabel('幅度');
g=fft(x,Nn);
f=(0:length(g)-1)'*fs/length(g);
mag=abs(g);
subplot(2,1,2);
stem(f,mag);
axis([0,7500,0,300]);
title('输入信号频谱');
xlabel('频率/Hz');
y=filter(b,a,x);
figure(4);
subplot(2,1,1);
stem(t,y);
title('通过滤波器后的输出信号');
ylabel('幅度');
h=fft(y,Nn);
f=(0:length(h)-1)'*fs/length(h);
mag=abs(h);
subplot(2,1,2);
stem(f,mag);
axis([0,7500,0,300]);
title('输出信号频谱');
xlabel('频率/Hz');下载本文