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

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




15 comments:

Anonymous said...

rockinnnnn

Anonymous said...

holy shit its fuckin awsum....

allinone said...

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

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

thanks!!

Anonymous said...

thank you very much....

Kishore Kumar said...

can u plz upload the 2*2 fast fir algorithm

Anonymous said...

thnks

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
b=fir1(n,wn,w);

Anonymous said...

wats that formula for

num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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