Sunday, July 3, 2011

MATLAB Programs 10: Design Of FIR filter using windows

Design of FIR filters using windows are very easy in MATLAB. Following functions are used for finding the popular window coefficients.

hann() - for hanning window
hamming() - for hamming window
blackman() - for blackman window
kaiser() - for kaiser window

Here the design of FIR low pass filter using hanning window is demonstrated. The program is given below 

% Program to design a FIR filter using windows.

close all;
clear all;

fp=input('Enter the pass band frequency');
fs=input('Enter the stop band frequency');
rp=input(' Enter the pass band attenuation');
rs=input('Enter the stop band attenuation');
f=input(' Enter the sampling frequency');

%Calculating filter order


% Normalizing the frequencies


%Adjusting the filter order. The order of window must be an odd number 
%and the order of filter must be one less than that of the window 

if (rem(n,2)==0)

%Window sequence calculation


%Calculation of filter coefficients


%Plotting the filter response

TITLE('Magnitude and Phase response');

%Enter the pass band frequency1000
%Enter the stop band frequency1200
%Enter the pass band attenuation.2
%Enter the stop band attenuation45
%Enter the sampling frequency3000

You can change this lowpass filter to high pass filter by changing the option 'low' to 
'high' in the fir1() function. The output is shown below.

%Enter the pass band frequency1200
%Enter the stop band frequency1000
%Enter the pass band attenuation.2
%Enter the stop band attenuation45
%Enter the sampling frequency3000


Anonymous said...


Anonymous said...

holy shit its fuckin awsum....

allinone said...

good site friend providing signal processing ...and this is also one good site

IPhone App Development said...

Excellent pieces. Keep posting such kind of information on your blog. I really impressed by your blog.
Android apps developer| WINDOWS PHONE 7 DEVELOPMENT|

Anonymous said...

helped a lot :)

ank12 said...

hey i want to multiply a function(spline function) with time response of filter....i m not getting correct answer ...plz help me out..........any one working on multirate signal processing

prashant said...

what need to be done for band pass filter

edwina_ms said...


Anonymous said...

thank you very much....

Kishore Kumar said...

can u plz upload the 2*2 fast fir algorithm

Anonymous said...


Mohankumar said...

great .... & God bless you

vignesh waran said...

can u plz help in multirate fir filters!!

kamalakar jyothi said...

for above code it shows below error i.e
??? Attempt to execute SCRIPT fir1 as a function.

Error in ==> fir3 at 41

Anonymous said...

wats that formula for


Anonymous said...

I have done modulo adder I have to do some application of it... Can u help me in doin for filter??

reply at

Asim Khan said...

when i use kaiser function then this error appears...
Attempt to execute SCRIPT kaiser as a function:

pls help

Anonymous said...


Anonymous said...

please upload Down sampling and Up sampling codes

Puneeth raj .k.r said...
This comment has been removed by the author.
Anonymous said...

this site is very helpful for tympass in lab. we can chat with new people and read their comments and have fun....please reply to

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes