ws1 = 0.01; wp1 = 0.1; wp2 = 0.24; ws2 = 0.33; As = 40;
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;
%lowpass2
alpha = (M-1)/2; n = [0:1:(M-1)];
m = n - alpha; fc2 = wc2/pi; hd2 = fc2*sinc(fc2*m);
%lowpass1
fc1 = wc1/pi; hd1 = fc1*sinc(fc1*m);
hd = hd2-hd1;
w_bla = blackman(M)'; h = hd .* w_bla;
[H,w] = freqz(h,[1],1000,'whole');
H = H(1:1:501); w = w(1:1:501);
mag = abs(H); db = 20*log10((mag+eps)/max(mag));
pha = angle(H); grd = grpdelay(h,[1],w);
delta_w = 2*pi/1000;
Rp = -min(db(wp1/delta_w+1:1:wp2/delta_w))
As = -round(max(db(ws2/delta_w+1:1:501)))
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2); stem(n,w_bla);title('Blackman Window')
axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Actual Impulse Response')
axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('h(n)')
subplot(2,2,4);plot(w/pi,db);axis([0 1 -150 10]);
title('Magnitude Response in dB');grid;
xlabel('frequency in pi units'); ylabel('Decibels')