📄 fig6_12.m
字号:
echo on
% fig 6-12:
% (a) with remez exchange algorithm (order 20)
% (b) 31 coefficients (order 31) FIR filter with Hanning window
% (c) Comparison of two designs showing passband/stopband
echo off
nr = 19; % coefficient sizes (-1) for remez/Hanning
nf = 30;
% Note: the quoted cutoffs have been manupulated to get
% -3dB cutoffs occuring at actual frequency wn=0.1 (in
% Matlab wn = 1 is at 0.5*ws hence wn = 0.2 or thereabouts
% is used here) - you'll see this in Figure 3
f = [0 0.11 0.36 1.0]; % Remez specification
mag = [100 100 0 0];
wn = 0.23; % Hanning window cutoff
% First process remez design
b = remez(nr,f,mag);
[h,w] = freqz(b,1,256);
m = 20*log10(abs(h));
figure(1)
plot(w/pi/2,m-40,'b');
xlabel('normalised frequency')
ylabel('gain (dB)')
axis([0 0.5 -100 20]);
pause;
% Hanning window design
b1 = fir1(nf,wn,hanning(nf+1));
[h1,w1] = freqz(b1,1,256);
mag1 = 20*log10(abs(h1));
f1 = w1/2/pi;
figure(2)
plot(f1,mag1,'b');
xlabel('normalised frequency')
ylabel('gain (dB)')
axis([0 0.5 -100 20]);
pause;
% finally compare two designs
% green line shows -3dB cutoff
% magenta line defines passband/stopband
figure(3)
f2 = [0 0.1 0.1 0.18 0.18 0.5];
mag2 = [0 0 -100 -100 -44 -44];
plot(f1,mag1,'r',w/pi/2,m-40,'b',w/pi/2,-3*ones(1,256),'g',f2,mag2,'m');
xlabel('normalised frequency')
ylabel('gain (dB)')
axis([0 0.5 -100 20]);
pause;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -