Thursday, September 15, 2011

Finite Impulse Response FIR FILTER (FIR)


5. FIR FILTER.


AIM: To verify FIR filters.

EQUIPMENTS:
Constructor –MATLAB Software

Learning Objectives: To make the students familiar with designing concepts of FIR filter
with the use of MATLAB.

THEORY:
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose
output is based on the weighted summation of a finite number of past inputs. An FIR transversal
filter structure can be obtained directly from the equation for discrete-time convolution.
In this equation, x(k) and y(n) represent the input to and output from the filter at time n.
h(n-k) is the transversal filter coefficients at time n. These coefficients are generated by using
FDS (Filter Design Software or Digital filter design package).
FIR – filter is a finite impulse response filter. Order of the filter should be specified.
Infinite response is truncated to get finite impulse response. placing a window of finite length
does this. Types of windows available are Rectangular, Barlett, Hamming, Hanning, Blackmann
window etc. This FIR filter is an all zero filter.

PROGRAM:
%fir filt design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end

%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
%HPF

b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
%BPF

wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
xlabel('(d) Normalized frequency-->')

No comments:

Post a Comment