《DSP using MATLAB》示例Example7.10

代码:

ws1 = 0.2*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.8*pi; As = 60; 
tr_width = min((wp1-ws1), (ws2-wp2));
M = ceil(11*pi/tr_width) + 1 

n = [0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;

%wc = (ws + wp)/2,                    % ideal LPF cutoff frequency

hd = ideal_lp(wc2, M) - ideal_lp(wc1, M); 
w_bla = (blackman(M))';  h = hd .* w_bla;
[db, mag, pha, grd, w] = freqz_m(h, [1]);  delta_w = 2*pi/1000;

Rp = -(min(db(wp1/delta_w+1:1:wp2/delta_w)))   % Actual Passband Ripple

As = -round(max(db(ws2/delta_w+1:1:501)))   % Min Stopband attenuation

%Plot

figure('NumberTitle', 'off', 'Name', 'Exameple 7.10')
set(gcf,'Color','white'); 

subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.4 0.5]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response');

subplot(2,2,2); stem(n, w_bla); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Blackman Window');

subplot(2,2,3); stem(n, h); axis([0 M-1 -0.4 0.5]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response');

subplot(2,2,4); plot(w/pi, db); axis([0 1 -150 10]); grid on;
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');

  运行结果:

        Blackman窗函数的长度M=75,实际的阻带衰减As=75dB。

 

posted @ 2017-03-27 10:23  跑啊跑  阅读(205)  评论(0编辑  收藏  举报