利用窗函数法设计一个线性相位FIR带阻滤波器,技术指标为阻带下截止频率fst1=4kHz,阻带上截止频率fst2=6kHz,通带下截止频率为fp1=2kHz,通带上截止频率fp2=8kHz,阻带最小衰减为40dB,抽样频率为fs=20kHz。
绘制实际滤波器的单位抽样响应h(n)、窗函数w(n)及滤波器频响幅度和相位曲线。检验滤波器指标是否满足要求,若不满足,应如何修改设计方案。
代码:
flp=2000;
fhp=8000;
fls=4000;
fhs=6000;
fs=20000;
wlp=2*pi*flp/fs;
whp=2*pi*fhp/fs;
wls=2*pi*fls/fs;
whs=2*pi*fhs/fs;
wc=[(wlp+wls)/(2*pi),(whp+whs)/(2*pi)];
delta1=wls-wlp;
delta2=whp-whs;
delta_w=min(delta1,delta2);
N=ceil(12*pi/delta_w);
n=0:N-1;
window=hamming(N+1);
[h1,w]=freqz(window,1);
subplot(2,2,1)
stem(window,'.');
xlabel('n');
title('haiming窗函数');
subplot(2,2,2)
plot(w*fs/(2*pi),20*log(abs(h1)/abs(h1(1))));
grid;
xlabel('f/Hz');
ylabel('·ù¶È(dB)');
title('haiming窗函数的频谱');
hn=fir1(N,wc,'stop',window);
[h2,w]=freqz(hn,1,512);
subplot(2,2,3)
stem(hn,'.');
xlabel('n');
ylabel('h(n)');
title('hn');
subplot(2,2,4)
plot(w*fs/(2*pi),20*log(abs(h2)/abs(h2(1))));
grid;
xlabel('f/Hz');
ylabel('·ù¶È(dB)');
title('haiming带阻滤波器的幅度特性');