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 l... 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.
具体该怎么解决那?
先看下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)