B=blackman(N);
string=['Blackman','N=',num2str(N)]; end end end end
h=hd.*(B)'; %得到FIR数字滤波器
[H,m]=freqz(h,[1],1024,'whole'); % mag=abs(H); %得到幅值 db=20*log10((mag+eps)/max(mag)); pha=angle(H); %得到相位 i=i+1; figure(i) subplot(2,2,1); n=0:N-1; stem(n,h,'.');
axis([0,N-1,-0.1,0.3]); hold on; n=0:N-1; x=zeros(N); plot(n,x,'-'); xlabel('n'); ylabel('h(n)');
title('实际低通滤波器的h(n)'); text((0.3*N),0.27,string); hold off; subplot(2,2,2); plot(m/pi,db); axis([0,1,-100,0]);
求其频率响应 6
xlabel('w/pi'); ylabel('dB');
title('衰减特性(dB)'); grid;
subplot(2,2,3); plot(m,pha); hold on; n=0:7; x=zeros(8); plot(n,x,'-'); title('相频特性'); xlabel('频率(rad)'); ylabel('相位(rad)'); axis([0,3.15,-4,4]); subplot(2,2,4); plot(m,mag); title('频率特性'); xlabel('频率W(rad)'); ylabel('幅值'); axis([0,3.15,0,1.5]); text(0.9,1.2,string);
b=menu('Do You want To Continue ?','Yes','No'); if b==2 b=0; end end
temp=menu('Close All Figure ?','Yes','No'); if temp==1 close all
7
end
程序运行结果:
运行程序,根据实验内容要求和程序提示选择你要进行的实验参数。三个实验参数选定后,程序运行输出用所选窗函数设计的实际FIR低通数字滤波器的单位脉冲响应h(n)、幅频衰减特性(20lg|H(ejw)|)、相频特性及幅频特性|H(ejw)|的波形,h(n)和|H(ejw)|图中标出了所选窗函数类型及其长度N值。对四种窗函数(N=15和N=33)的程序运行结果如图4-2到图4-9所示,由图可以看出用各种窗函数设计的FIR滤波器的阻带最小衰减及过渡带均与教材中一致。在通带内均为严格相位特性。
图6-2 矩形窗(N=15)
8
图6-3 矩形窗(N=33)
图6-4 哈明窗(N=15)
9
图6-5 哈明窗(N=33)
图6-6 汉宁窗(N=15)
10