wlp=0.4999*pi;%下通带截止频率
wls=0.5*pi;%阻带下限频率
wus=0.5*pi;%阻带上限频率
wup=0.5*pi;%上通带截止频率
wc=[(wlp+wls)/2/pi,(wus+wup)/2/pi];%截止频率在通带和阻带边界频率的中点
B=wls-wlp;%迁移域
N=ceil(12*pi/B)-1;%正向取整数,根据过渡带宽等于窗函数主瓣宽求窗函数的最小长度
n=0:N-1;
alpha=(N-1)/2;%求滤波器的相位延迟
m=n-alpha+eps;%eps为MATLAB系统的精度
%hd=sin(wc*m)/(m*pi);%求理想滤波器脉冲响应 %维度不同,无法运行
window=hamming(N);
[h1,w]=freqz(window,1)
figure(1);
subplot(2,1,1)
stem(window,'.');
xlabel('n');
title('海明窗函数');
subplot(2,1,2)
plot(w/pi,20*log(abs(h1)/abs(h1)))
grid on;
xlabel('w/pi');
ylabel('幅度(dB)');
title('海明窗函数频谱');
hn=fir1(N-1,wc,'stop');
[h2,w]=freqz(hn,1,512);
figure