LAB # 12 Fir Filters: 1. Objective

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

LAB # 12

FIR FILTERS

1. OBJECTIVE: Object of this lab is introduction to digital filters and its types, design FIR
filter and study how it performs filtering on a signal. Further truncate different types of FIR filter
like Low Pass, High Pass, Band Pass using different windows like rectangular, Kaiser Etc. and
compare the results obtained from different windows.

2. FIR FILTER DESIGN USING WINDOW TECHNIQUES

The different types of Window techniques based FIR filters are listed as follows:
1. Rectangular windows.
2. Hamming window.
3. Hanning window.
4. Blackman window.
5. Barlett window.
6. Kaiser window.

Following points are usually considered to design FIR filter other the window type.

INPUT
• Window Type
• Passband and stopband ripples
• Passband and stopband edge frequencies
• Sampling frequency
• order of the filter
• window coefficients

OUTPUT
• magnitude and phase responses

In the design of FIR filters using any window technique, the order can be calculated using the
formula given by

−𝟐𝟎𝒍𝒐𝒈(√𝜹𝒑𝜹𝒔 −𝟏𝟑
N= 𝟏𝟒.𝟔 (𝒇𝒔−𝒇𝒑)/𝒇

where 𝜹p is the passband ripple, 𝜹s is the stopband ripple, fp is the passband frequency, fs is the
stopband frequency and f is the sampling frequency.
Example-1

1. Create a signal vector containing two frequencies as: i) 100 Hz. and ii) 150 Hz. with Fs = 1000
Hz.
2. Design two band pass FIR filters with 64 coefficients and with pass bands as i) 125 to 175 Hz.
and ii) 75 to 125 Hz.
3. Use both filters on the created signal and observe their outputs.
4. Plot frequency responses and pole-zero constellations of both filters and note observations.

clc
clear all
close all
f1=100; f2=150; fs=1000;
t=0:1/fs:1;
f=fs*[0:length(t)-1]/length(t);
x=exp(i*2*pi*f1*t) + exp(i*2*pi*f2*t);
b=fir1(64,[125 175]/500);
b1=fir1(64,[75 125]/500);
[h,w]=freqz(b,1,length(t))
[h1,w1]=freqz(b1,1,length(t))
y=filtfilt(b,1,x)
y1=filtfilt(b1,1,x)
subplot(511)
plot(f,abs(fft(x))) %fft of orignal signal
subplot(512)
plot(f,abs(h)) % freq res of filter
subplot(513)
plot(f,abs(fft(y))) %fft of filtered signal
subplot(514)
plot(f,abs(h1)) % freq response if filtered signal
subplot(515)
plot(f,y1) %fft of filtered signal

Example-2
Write a program to design a FIR filter using Rectangular window?
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the window coefficients
6. Draw the magnitude and phase responses.
clc
clear all
close all

N=128; rp=0.05; rs=0.04; wp=1500; ws=2000; fs= 9000;


w1=2*wp/fs ; w2= 2*ws/fs ; wn= 0.2 * pi ;
r=boxcar(N)
subplot(221)
plot(r)
x=fir1(N-1,wn,'low',r)
[a,b]= freqz(x,1,N)
m=20 *log10(abs(a))
subplot(222)
plot(b/pi,m)

p=unwrap(angle(a))*180/pi;
subplot(223)
plot(b/pi,p)
ACTIVITY:
Q1. Run the codes described in above examples?
Q2. Make low pass and band stop filter using Hamming window technique?

You might also like