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**

**num=-20*log10(sqrt(rp*rs))-13;**

**dem=14.6*(fs-fp)/f;**

**n=ceil(num/dem);**

**n=abs(n);**

**% Normalizing the frequencies**

**wp=2*fp/f;**

**ws=2*fs/f;**

**wn=(ws+wp)/2;**

**%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)**

**m=n+1;**

**else**

**m=n;**

**n=n-1;**

**end**

**%Window sequence calculation**

**w=hann(m);**

**%Calculation of filter coefficients**

**b=fir1(n,wn,'low',w);**

**%Plotting the filter response**

**freqz(b,1,500,3000);**

**TITLE('Magnitude and Phase response');**

%output

%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.

%output

%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

## 16 comments:

rockinnnnn

holy shit its fuckin awsum....

good site friend ...in providing signal processing ...and this is also one good site www.allinonestudentscorner.blogspot.com

Excellent pieces. Keep posting such kind of information on your blog. I really impressed by your blog.

Android apps developer| WINDOWS PHONE 7 DEVELOPMENT|

helped a lot :)

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

what need to be done for band pass filter

thanks!!

thank you very much....

can u plz upload the 2*2 fast fir algorithm

thnks

great .... & God bless you

can u plz help in multirate fir filters!!

for above code it shows below error i.e

??? Attempt to execute SCRIPT fir1 as a function.

Error in ==> fir3 at 41

b=fir1(n,wn,w);

wats that formula for

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

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

reply at tifa.thaseen@gmail.com

## Post a Comment