Lab_2_FIR___IIR_Filter_GNU_Radio
Lab_2_FIR___IIR_Filter_GNU_Radio
their comparison
Lab Goals
The purpose of this lab is to build the framework for real-time filtering of an incoming signal in GNU Radio.
We will learn to implement an FIR Filter and Direct-form I IIR Filter in embedded python block of GNU
Radio. We will also learn about the advantages of one over another.
• Implementation of FIR Filter using linear buffer
• Direct form I implementation of an IIR filter
• FIR vs IIR implementation of a system
1 Introduction to FIR
1.1 Convolution
The convolution operation which is the fundamental operation in realizing a finite impulse response (FIR)
filter, is given by,
N −1
def X
y[n] = h[m]x[n − m] (1)
m=0
where h[n] is the impulse response (N length FIR Filter) of the filter, x[n] is the input signal and y[n] is the
filtered output signal. In non-real-time processing, the entire input data and the impulse response samples
are stored in the memory, and the processing is carried out on the stored data. But in real-time processing,
we are interested in acquisition and processing of samples simultaneously, which means that the processing
delay per input sample must be bounded even if the processing continues overall for an unlimited time. So it
can be said that the mean processing time per sample should not be greater than the sampling period. More
generally, the number of input samples entering the DSP in a particular time interval is same as the number
of processed samples delivered as output in the same time interval. As we are doing this lab in software we do
not need to worry about the time intervals. But while implementing on hardware one should always keep that
in mind.
1
Figure 1: Linear buffer (a) new sample is put in position 0, (b) before the next sample comes, elements of the
buffer have to be shifted by one step and the latest sample needs to be accommodated in position 0.
h[n] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
Now obtain the magnitude frequency response of the filter by varying the input sine wave frequency from
0Hz to 4000Hz. What type of filter is it ? Is it High-Pass, Band-Pass, Low-Pass or Band-stop ?
4. Find the 3 dB cutoff frequency from the magnitude frequency response plotted.
5. Next you will be using the files in the ‘Noise Filtering’ Folder. Copy paste your FIR filter implementation
code from the previous implementation in the current Embedded python block. Here you will use a FIR
filter to filter a noisy sine wave corrupted by white Gaussian noise. Observe the noisy input signal and
the filtered noise free signal.
6. Using the freqz function provided by Matlab/Octave, plot the frequency response of the filter used in
the above checkpoint and identify the type of the filter (Lowpass / Highpass / Bandpass / Notch) and
note down the cutoff frequency. Verify the cutoff frequency with that obtained in GNU Radio.
7. Next we will be using GNU radio to filter an audio file saved in .wav format sampled at 22050Hz with a
Low pass and High pass Filter. We will be using files in the ‘Audio Filtering’ folder.
• Low pass Filter coefficients containing 51 elements are denoted by the list coeff on line 31.
• High pass Filter coefficients containing 62 elements are denoted by the list coeff on line 36.
2 of 4
• Comment one while using the other. Filter the audio signal first using the Low pass filter and later
using the High pass filter. Observe the effect on the original signal by listening to the .wav file.
8. You need to Estimate the number of Operations required for calculation of one output sample. Fill them
in Table 1 for both the FIR High pass and the Low pass Filter:
N
X M
X
ai y[n − i] = bj x[n − j] (2)
i=0 j=0
The transfer function H(z) obtained by applying Z transform on both sides of equation (2) is as follows:
PM −j
j=0 bj z
H(z) = PN (3)
−i
i=0 ai z
Time domain impulse response h[n] obtained by applying inverse Z transform to equation 3 is of infinitely long
duration. Such a filter is therefore called an Infinite Impulse Response (IIR) filter.
The techniques to implement a FIR digital filter is not applicable to IIR filter due to the feedback component.
Thus, we need to implement IIR filters differently. Assuming a0 = 1, an IIR filter can be described using the
difference equation
XN M
X
y[n] = − ai y[n − i] + bj x[n − j] (4)
i=1 j=0
This form can be exploited to implement the filter by defining two buffers of lengths M and N , for holding past
values of output and input, respectively. Thereby, performing finite multiplication and addition operations, an
IIR filter can be easily realized.
The difference equation 4 can be rearranged in different ways thereby obtaining different structures. One
such class of structures referred to as direct form structures is introduced in this lab. Other known forms are
cascaded sections, parallel sections, lattice structures and state-space structures.
3 of 4
6. Continue steps 3 to 5 till the input data-flow continues.
7. Note: Equation 4 assumes a0 to be equal to 1, in otherwise case you have to consider a0 as well.
Figure 2: Block diagram for direct-form I structure for the IIR filter given by eq 4
3 Learning checkpoint
All the following tasks need to be shown to your TA to get full credit for this lab session.
1. Here, you will be removing Gaussian Noise of amplitude 1 from Cosine wave, Consider the IIR filter given
by eq 5.
0.0230184 + 0.0460368z −1 + 0.0230184z −2
H1 (z) = (5)
1 − 1.6185196z −1 + 0.7105934z −2
(a) Using the freqz function provided by Matlab/Octave, plot the frequency response of the filter and
identify the type of the filter (Lowpass / Highpass / Bandpass / Notch) and note down the cutoff
frequency.
(b) Use the provided IIR noise. file to open python script in GNU radio’s ‘Python Embedded Block’
to implement the filtering. You have to complete the python script by writing suitable code at the
place indicated in the python script of embedded block to realize the direct form I implementation
of the above filter (5).
(c) Verify the working of your filter by using ‘QT GUI Time Sink’ for both input noise and output
signal.
(d) Also compare the freqz plots obtained in Matlab/Octave for filtering of Gaussian noise using FIR
and IIR Filters. What can you comment on the magnitude and phase of the two filters ?
2. Now, when you have successfully implemented IIR filter, let’s move forward to understand the effect of
Low Pass Filter and High Pass Filter on audio.
(a) You are provided with an audio(.wav) file, use this file as input to your Python block using ‘QT
GUI Wav File Source’ and store the filtered response as wav file using ‘QT GUI Wav File Sink’.
Open the ‘ReadMe.txt’ file provided to access LPF (Low Pass Filter) and HPF (High Pass Filter)
coefficients for IIR filter.
(b) Implement IIR filter with these coefficients and notice the change in the audio. What is getting
filtered out from the audio when you use LPF & HPF ?
(c) Now you need to Estimate the number of Operations required for calculation of one output sample.
Fill them in Table 1 for both the IIR High pass and the Low pass Filter. Compare the results with
that of the FIR Filter.
4 of 4