0% found this document useful (0 votes)
14 views

Window Function

The document describes a program to design and implement FIR filters using different window functions. It prompts the user to enter the length of the window, lower cutoff frequency, and higher cutoff frequency. It then designs low pass, high pass, band stop, and band pass filters using rectangular, Hann, and Hamming window functions and plots the frequency responses of the different filters.

Uploaded by

Deepak Adhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Window Function

The document describes a program to design and implement FIR filters using different window functions. It prompts the user to enter the length of the window, lower cutoff frequency, and higher cutoff frequency. It then designs low pass, high pass, band stop, and band pass filters using rectangular, Hann, and Hamming window functions and plots the frequency responses of the different filters.

Uploaded by

Deepak Adhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Program to design and implement FIR filter using window functions.

clc;
clear all;
close all;
N=input('Enter length of window=');
w1=input('Enter lower cutoff frequency=');
w2=input('Enter higher cutoff frequency=');
wh=rectwin(N);
%wh=hann(N);
%wh=hamming(N);

b=fir1(N-1,w1,'low',wh);
[h,omega]=freqz(b,1,256);
mag=20*log10(abs(h));
subplot(2,2,1)
plot(omega/pi,mag);
grid on;
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Low pass filter');

b=fir1(N-1,w1,'high',wh);
[h,omega]=freqz(b,1,256);
mag=20*log10(abs(h));
subplot(2,2,2)
plot(omega/pi,mag);
grid on;
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('High pass filter');

b=fir1(N-1,[w1,w2],'stop',wh);
[h,omega]=freqz(b,1,256);
mag=20*log10(abs(h));
subplot(2,2,3);
plot(omega/pi,mag);
grid on;
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('band stop filter');

b=fir1(N-1,[w1,w2],wh);
[h,omega]=freqz(b,1,256);
mag=20*log10(abs(h));
subplot(2,2,4);
plot(omega/pi,mag);
grid on;
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Band pass filter');

Input:

Enter length of window=25

Enter lower cutoff frequency=0.2

Enter higher cutoff frequency=0.4


Rectangular window:

Low pass filter High pass filter


50 20
Gain in dB

Gain in dB
0
0
-20
-50
-40

-100 -60
0 0.2 0.4 0.6 0.8 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency Normalized frequency
band stop filter Band pass filter
20 0
Gain in dB

0 -20

Gain in dB
-20 -40

-40 -60

-60 -80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency Normalized frequency

Hann window:

Low pass filter High pass filter


50 50
Gain in dB

Gain in dB

0
0
-50
-50
-100

-150 -100
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalized frequency Normalized frequency
band stop filter Band pass filter
10 0
Gain in dB

Gain in dB

0
-50
-10
-100
-20

-30 -150
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalized frequency Normalized frequency
Hamming window:

Low pass filter High pass filter


50 50
Gain in dB

Gain in dB
0
0
-50
-50
-100

-150 -100
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalized frequency Normalized frequency
band stop filter Band pass filter
10 0
Gain in dB

Gain in dB
0

-10 -50
-20

-30 -100
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalized frequency Normalized frequency

You might also like