代码:
wp = 0.2*pi; ws = 0.3*pi; As = 50; tr_width = ws - wp;
M = ceil((As-7.95)/(2.285*tr_width) + 1 ) + 1
n = [0:1:M-1]; beta = 0.1102*(As-8.7)
wc = (ws + wp)/2; % ideal LPF cutoff frequency
hd = ideal_lp(wc, M);
w_kai = (kaiser(M, beta))'; h = hd .* w_kai;
[db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
% Rp = -(min(db(1:1:wp/delta_w+1))); % Actual Passband Ripple
As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband attenuation
%Plot
figure('NumberTitle', 'off', 'Name', 'Exameple 7.9')
set(gcf,'Color','white');
subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.1 0.3]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response');
subplot(2,2,2); stem(n, w_kai); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Kaiser Window');
subplot(2,2,3); stem(n, h); axis([0 M-1 -0.1 0.3]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response');
subplot(2,2,4); plot(w/pi, db); axis([0 1 -100 10]); grid on;
xlabel('frequency in pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
运行结果:
我们注意到,Kaiser窗函数的特征,长度M=61,β =4.5513,滤波器Rp=0.0442dB,阻带衰减As=52dB,满足设计要求。