fp=2000;
fs=5000;
a=(M-1)/2;
Ap=2;
As=42;
fc=20000;
wp=2*pi*fp/fc;
ws=2*pi*fs/fc;
wc=(ws-wp)/2;
dw=(ws-wp);
dp=((10^(Ap/20)-1)/(10^(Ap/20)+1));
ds=10^-(As/20);
d=min(dp,ds);
A=-20*log10(d);
M=(6.2*pi)/dw
wd1=hamming(M);
disp('Coefficients of Hamming window are:');
disp(wd1);
figure(1);
freqz(wd1);
title('Frequency response of Hamming window');
n=0:M-1;
hd1=sin(wc*(n-a))/(pi*(n-a))
disp('desired filter coeffiients:');
disp(hd1);
hn1=hd1*wd1;
disp('filter coefficients of FIR filter:');
disp(hn1);
figure(2);
freqz(hn1);
title('frequency response of th fir filter');
[N1,w1]=freqz(hn1);
m1=abs(N1);
figure(3)
plot(w1/pi,m1);
title('magnitude response');
n=0:M-1;
wd2=(0.42-0.5*cos((2*pi*n)/(M-1))+0.8*cos((4*pi*n)/(M-1)));
disp('Coefficients of Blackman window are:');
disp(wd2);
figure(4);
freqz(wd2);
title('Frequency response of blackman window');
n=0:M-1;
hd1=sin(wc*(n-a))/(pi*(n-a))
disp('desired filter coeffiients:');
disp(hd1);
hn1=hd1*wd1;
disp('filter coefficients of FIR filter:');
disp(hn1);
figure(5);
freqz(hn1);
title('frequency response of th fir filter');
[N1,w1]=freqz(hn1);
m1=abs(N1);
figure(6)
plot(w1/pi,m1);
title('magnitude response');
wd2=bartlett(M);
disp('Coefficients of triangle window are:');
disp(wd2);
figure(7);
freqz(wd2);
title('Frequency response of triangle window');
n=0:M-1;
hd1=sin(wc*(n-a))/(pi*(n-a))
disp('desired filter coeffiients:');
disp(hd1);
hn1=hd1*wd1;
disp('filter coefficients of FIR filter:');
disp(hn1);
figure(8);
freqz(hn1);
title('frequency response of th fir filter');
[N1,w1]=freqz(hn1);
m1=abs(N1);
figure(9)
plot(w1/pi,m1);
title('magnitude response');