📄 fir_design_win1.m
字号:
% Name:FIR_design_win1.m
clear,close all;
wp=input('Type in the passband edge frequency (in Radian) wp=');
ws=input('Type in the passband edge frequency (in Radian) ws=');
deltaw=input('Type in the width of the transition band =');
wc=(wp+ws)/2;
L=ceil(8*pi/(ws-wp));
if L/2==ceil(L/2);
L=L+1;
else
L=L;
end
a=(L-1)/2;
n=0:L-1;
%w=u(n)-u(n-L);%Rectangle window,
w=0.5*(1-cos(2*pi*n/(L-1))).*(u(n)-u(n-L)); %Hanning window
h=(wc/pi)*sin(wc*(n-a+eps))./(wc*(n-a+eps)).*w;
%=======================================================================
N=2000;
H=fft(h,N);
H=H/max(abs(H));
W=0:2*pi/N:2*pi-2*pi/N;
%=======================================================================
subplot(222)
plot(W/pi,abs(H)),title('The magnitude response of the FIR filter')
axis([0,1,0,max(abs(H))]),grid on;
%=========================================================
subplot(223)
plot(W/pi,angle(H))
axis([0,1,-pi,pi]),grid on;
title('The phase response of the FIR filter'),xlabel('Frequency (*pi)')
%======================================================
subplot(224)
plot(W/pi,20*log10(abs(H)));
axis([0,1,-100,0]),grid on;
title('The frequency response in dB'),
xlabel('Frequency (*pi)')
%======================================================
subplot(221)
stem(n,h,'.'),
axis([0,L-1,min(h),max(h)]),grid on;
title('The impulse response of the FIR filter')
xlabel('Index n')
%=================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -