Exp.
No:
FIR FILTER DESIGN AND ITS ANALYSIS USING WINDOWING METHOD
Date:
Aim:
To design FIR filters and analyze it using the different windowing methods
Software Required:
MATLAB R2022a
Code
A) Low pass filter:
n1=input("Enter the order of Filter SMALL:");
n2=input("Enter the order of Filter LARGE:");
nor=input("Enter the normalized frequency:");
b=fir1(n1,nor,'low',rectwin(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,1);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'low',hanning(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,2);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'low',hamming(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,3);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'low',blackman(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,4);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
b=fir1(n2,nor,'low',rectwin(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,5);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'low',hanning(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,6);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'low',hamming(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,7);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'low',blackman(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,8);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
ylabel('magnitude');
Output:
Enter the order of Filter SMALL:5
Enter the order of Filter LARGE:50
Enter the normalized frequency:0.5
B) High pass filter:
n1=input("Enter the order of Filter SMALL:");
n2=input("Enter the order of Filter LARGE:");
nor=input("Enter the normalized frequency:");
b=fir1(n1,nor,'low',rectwin(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,1);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'low',hanning(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,2);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'low',hamming(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,3);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'low',blackman(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,4);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
b=fir1(n2,nor,'low',rectwin(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,5);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'low',hanning(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,6);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'high',hamming(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,7);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'low',blackman(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,8);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
ylabel('magnitude');
Output:
Enter the order of Filter SMALL:6
Enter the order of Filter LARGE:50
Enter the normalized frequency:0.7
C) Band Pass Filter:
n1=input("Enter the order of Filter SMALL:");
n2=input("Enter the order of Filter LARGE:");
nor=input("Enter the normalized frequency:");
b=fir1(n1,nor,'bandpass',rectwin(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,1);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'bandpass',hanning(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,2);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'bandpass',hamming(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,3);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'bandpass',blackman(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,4);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
b=fir1(n2,nor,'bandpass',rectwin(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,5);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'bandpass',hanning(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,6);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'bandpass',hamming(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,7);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'bandpass',blackman(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,8);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
ylabel('magnitude');
Output:
Enter the order of Filter SMALL:5
Enter the order of Filter LARGE:50
Enter the normalized frequency:[0.2 0.7]
D) Band Stop Filter:
n1=input("Enter the order of Filter SMALL:");
n2=input("Enter the order of Filter LARGE:");
nor=input("Enter the normalized frequency:");
b=fir1(n1,nor,'stop',rectwin(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,1);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'stop',hanning(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,2);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'stop',hamming(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,3);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n1,nor,'stop',blackman(n1+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,4);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
b=fir1(n2,nor,'stop',rectwin(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,5);
plot(w/pi,20*log(abs(h)));
title('rectangle windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'stop',hanning(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,6);
plot(w/pi,20*log(abs(h)));
title('hanning windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'stop',hamming(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,7);
plot(w/pi,20*log(abs(h)));
title('hamming windowing');
xlabel('freq');
ylabel('magnitude');
b=fir1(n2,nor,'stop',blackman(n2+1));
[h,w]=freqz(b,1,1024);
subplot(4,2,8);
plot(w/pi,20*log(abs(h)));
title('blackmann windowing');
xlabel('freq');
ylabel('magnitude');
Output:
Enter the order of Filter SMALL:6
Enter the order of Filter LARGE:50
Enter the normalized frequency:[0.2 0.8]
Result:
Thus, FIR filter is designed and analyzed using different windowing methods.