You are on page 1of 7

EXP.

NO:05 FIR FILTER

DATE:

AIM:
To write a matlab program to design a FIR filter in analog and digital form and to plot its
response.

SOFTWARE REQUIRED:
MATLAB Simulator

THEORY:
Filters are used in digital signal processing to remove undesirable parts of the signal, such as
random noise, or to extract useful parts of the signal, such as the parts of the signal
belonging to a particular range. Digital filters can be classified into two groups, FIR (finite-
duration impulse response) and IIR (infinite-duration impulse response) filters.
FIR FILTER:
The finite response filter is a non-recursive filter and it does not have feedback.It is a
all zero filter.FIR filter can be designed using various methods.They are,

• Frequency sampling technique


• Windowing technique
• Fouries series technique

In fourier series technique, h(n)=hd(n).Therefore,oscillations occur in the stopband and


passband due to the slow convergence of fourier series at the point of discontinuous.This
effect is known as “Gibbs phenomenon”.

There are several windowing techniques available such as rectangular,triangular,Hanning


,Hamming,Blackman,Kaiser,etc..

Rectangular window function is given by,


Hamming window function is given by,

Blackmann window function is given by,

To find the equivalent time-domain representation, we calculate the inverse discrete-time


Fourier transform:

The frequency sampling method is of type-I and type II.For linear phase filters, with positive
symmetrical impulse response,

If N=odd ,UL = (N-1)/2 and if N=even ,UL = (N/2)-1


PROGRAM:
clc;
clear all;
close all;
F=input('Enter the sampling frequency');
N=input('Enter the order');
fc=input('Enter the cutoff frequency');
wn=(2*fc)/F;
display('1.LOW 2.High 3.bandpass 4.stop');
ft=input('Enter the filter type');
switch(ft)
case 1
ftype='Low';
case 2
ftype='High';
case 3
ftype='bandpass';
case 4
ftype='stop';
end
display('1.rectwin 2.hann 3.hamming 4.blackman 5.kaiser');
wt=input('Enter the window type');
switch(wt)
case 1
wtype=rectwin(N+1);
case 2
wtype=hann(N+1);
case 3
wtype=hamming(N+1);
case 4
wtype=blackman(N+1);
case 5
wtype=kaiser(N+1,0.5);
end
b=fir1(N,wn,ftype,wtype);
figure(1);
freqz(b,1,F);
title('magnitude response');
fp=input('Enter the passband frequency');
fs=input('Enter the stopband frequency');
n=linspace(0,1,8000);
x=sin(2*pi*fp*n)+sin(2*pi*fs*n);
y=filter(b,1,x);
X=fft(x);
figure(2);
subplot(2,1,1);
stem(0:7999,abs(X));
xlabel('EnterFrequency');
ylabel('magnitude');
title('spectrum of inputsignal');
Y=fft(y);
subplot(2,1,2);
stem(0:7999,abs(Y));
xlabel('frequency');
ylabel('magnitude');
title('spectrum of filtered signal');

RECTANGULAR WINDOW:
Fs = 8000 Hz fp = 1500 Hz fs = 3000 Hz N=2
HANNING WINDOW:
Fs = 8000 Hz fp = 1500 Hz fs = 3000 Hz N=20
HAMMING WINDOW:
Fs = 8000 Hz fp = 2500 Hz fs = 500 Hz N=20
Presentation Uniqueness Punctuality Viva Total

RESULT:
Thus the matlab program to design FIR filter was done and its response was
plotted.

You might also like