在設計FIR濾波器時遇到點問題,

題目:

在設計FIR濾波器時遇到點問題,
clear all;
wlp=0.2*pi;wls=0.35*pi;wus=0.65*pi;wup=0.8*pi;
B=wls-wlp;
M=ceil(12*pi/B)-1;
wp=[(wls+wlp)/2/pi,(wus+wup)/2/pi];
hn=fir1(M,wp,'stop',blackman(M+1));
運行該程序會顯示如下錯誤:
Error using ==> fir1 at 92
The window length must be the same as the filter length.
具體該怎麼解決那?
運行了還是一樣的!
Error using ==> fir1 at 92
The window length must be the same as the filter length.
Error in ==> ex723 at 6
hn=fir1(M,wp,'stop',blackman(M));

解答:

先看下fir1中的一段解釋
For filters with a gain other than zero at Fs/2, e.g., highpass
and bandstop filters, N must be even. Otherwise, N will be
incremented by one. In this case the window length should be
specified as N+2.
即高通、帶阻濾波器的階數應該控制爲奇數,因爲如果階數爲偶數,則在π點必有一零點,這對於高通帶阻來說是不允許的,故取階數爲奇數,而你FIR1濾波器階數爲M+1階,所以你的M必須爲偶數,所以可以將程序改爲
clear all;
clc
wlp=0.2*pi;wls=0.35*pi;wus=0.65*pi;wup=0.8*pi;
B=wls-wlp;
M=ceil(12*pi/B);
M=M+mod(M,2);
wp=[(wls+wlp)/2/pi,(wus+wup)/2/pi];
hn=fir1(M,wp,'stop',blackman(M+1));
freqz(hn)

添加新評論

暱稱
郵箱
網站