Description
Objectives
The objectives of this lab are to observe the characteristics of the frequency response of
finite impulse response (FIR) digital filters and to understand the main elements involved
in their design by using GNURadio.
Background
The background material for this Lab is presented in Appendix A and relevant code is in
Appendix B.
Procedure
1. Use the previously posted instruction on Brightspace to install GNURadio. Once
Installation is finished. Open “GNURadio Companion”. It will open an initial screen
of GNURadio as illustrated in Fig. 1.
2. When the initial splash screen appears, choose “FileOpen”. Navigate to the
downloaded file directory and choose “FIR_filter_design.grc”, it should bring the
screen shown in the Fig. 2 and run the program by going into “RunExecute” or
press F6. The screen showed in Fig.4 should appear with the default configuration.
3. Refer Fig. 3 which illustrate the different blocks of the Flow Chart.
– 0 –
ECED4502 Lab 3
Fig.1. Initial GNURadio welcome screen
Fig.2. GNURadio Screen with the FIR filter design experiment setup
– 1 –
ECED4502 Lab 3
Fig.3. Introduction to Flow Graph
Fig.4. GNURadio Output QT GUI
– 2 –
ECED4502 Lab 3
a. Low pass filter block configuration b. High pass filter block configuration
c. Band pass filter block configuration d. Band reject filter block configuration
Fig.5. Filter design block configuration
4. Figure 3 shows the filter design blocks with the parameter tabs needed to design an
FIR filter. Figure 4 shows the frequency response plots for all four filters: low-pass,
high-pass, band-pass and band-stop. The filter parameters are given in “FIR Filter
Settings” which you can open by double clicking on the respective filter, see figure 5.
As a part of the screen (figure 4) where you can select (i) the filter type – you should
try first the low-pass filter; (ii) the number of coefficients (taps) in your filter (the
more taps, the better approximation of the ideal filter you will get) and (iii) the cut-off
frequency of your filter – the cut-off frequency should be always smaller than fs/2
with fs selected either through sliders or counter shown in the upper part of the GUI.
You could try to design your filter using different windows, number of taps, and by
using different configuration setting, you could observe better distinction from the QT
GUI Label shown in the lower part of the GUI which displays the length of the
window in number of taps, a.k.a the number of filter coefficients.
– 3 –
ECED4502 Lab 3
The coefficients in your design are printed in the “command prompt of GNURadio”
see figure 6 below. The number of filter coefficients, obtained by adjusting various
parameters in the GUI such as transition band width, LP and HP cut off (passband
corner) frequencies, can be seen at any time at the bottom of the GUI.
• Enable/Disable the filter response by clicking on the name of the filter type in
the GUI buttons for Low-pass, High-pass, Band-pass & Band-reject;
• Change the transition bandwidth, observe the filter frequency response, the
number of taps needed for the filter designed and compare the effect of
different windows on the number of taps and relative gain.
• Change the number of taps (length of your filer) from 77 to 39 to 9 and 5 taps
and observe different filter responses.
• Record your filter frequency responses for the number of taps given in the
table below for different windows Rectangular, Hann, Hamming & Blackman.
Complete the table below including the transition band width, the cut-off
frequency and window type used.
No. of Taps Transition band width Cut-off
frequency
Window type
77
51
39
25
19
11
09
05
• Comment on which of the parameters above; transition band width, cut-off
frequency and/or window type affect the number of taps needed.
• What is the effect different parameter values have on the number of taps. Are
there any consistent trends?
• Record filter coefficients as you can also implement the same filters using
MatLab or Python (refer to Appendix B for more details).
– 4 –
ECED4502 Lab 3
Fig.6. Filter taps (coefficients) and number of taps displayed in GNURadio command
prompt
5. Change the window type in the Filter design block configuration (see figure 5) to
Hamming, Rectangular and Blackman to each filter and compare the frequency
response of all four filters.
Comment on your observations how different windows affect the stopband attenuation,
and how the transition band width affects the number of filter taps (or coefficients) for
different windows.
6. In your lab report you should comment on the following:
• How does the number of taps affect the frequency response of your FIR
filters? Is the number of taps related to the window length?
• How does the window type affect the frequency response of your FIR
filter?
• What is the name of the separation between the passband and stopband in your
designs?
• How far does this transition extend? What are its limits? Explain in terms of the
error, or maximum ripple, introduced by using practical filters vs ideal filters,
and the type of window used.
ECED4502 Lab5
– 5 –
Appendix A FIR Digital Filters
Introduction
A digital filter is a basic building block in any Digital Signal Processing (DSP) system. The frequency
response of the filter depends on the value of its coefficients, or taps. Many software programs can compute
the values of the coefficients based on the desired frequency response. In our course, the students are using
Labview programs to obtain the filter coefficients. These values are typically floating point numbers and
they are represented with a fairly high degree of precision. However, when a digital filter is implemented in
hardware, such as the TI TMS320C26 boards as it is a case in the second part of this laboratory experiment,
the designer wants to represent the coefficients (and also the data) with the smallest number of bits that still
gives acceptable resolution for the numbers. This is because representing a number with excess bits
increases the size of the registers, buses, adders, multipliers and other hardware used to process that signal.
The bigger sizes result in a chip with a larger die size, which translates into increased power consumption
and a higher chip price. Thus, the bit precisions used to represent numbers are important in the performance
of real-world signal processing designs.
Filtering with FIR systems
A Finite Impulse Response (FIR) digital filter is one whose impulse response is of finite duration. This can
be stated mathematically as
h[n] = 0 Þ n < 0 or n > N
where h[n] denotes the impulse response of the digital filter, n is the
discrete time index, and N is the length of the filter. A difference equation is the discrete time equivalent of
a continuous time differential equation. The general difference equation for a FIR digital filter is
å=
= × –
N
k
y n h k x n k
0
[ ] [ ] [ ]
where y(n) is the filter output at discrete time instance n, h[k] is the k-th feedforward tap, or filter
coefficient, and x[n-k] is the filter input delayed by k samples. The å =
N
k 0
denotes summation from k = 0
to k = N where N is the number of feedforward taps in the FIR filter. The calculations of the output sample
in terms of the input samples and the h[k] coefficients are represented in the figure below with the
-1
z representing the delays (of one sampling period):
Figure 3: FIR structure
Note that the FIR filter output depends only on the previous N inputs. This feature is why the impulse
response for a FIR filter is finite.
When the input to a FIR filter is the unit impulse d[n], the output of the filter is the impulse response h[n].
ECED4502 Lab5
– 6 –
Advantages of FIR filters
FIR filters are simple to design and they are guaranteed to be bounded input-bounded output (BIBO) stable.
By designing the filter taps to be sym-metrical about the center tap position, a FIR filter can be guaranteed
to have linear phase. This is a desirable property for many applications such as music and video processing.
FIR filters also have a low sensitivity to filter coefficient unitization errors. This is an important property to
have when implementing a filter on a DSP processor or on an integrated circuit.
FIR Filter Design by Windowing
The most commonly used techniques for design of infinite impulse response (IIR) filters are based on
transformations of continuous-time systems into discrete-time IIR systems. This is partly because
continuous-time filter design was a highly advanced art before discrete-time filters were of interest and
partly because of the difficulty of implementing a noniterative direct design method for IIR filters.
In contrast, FIR filters are almost entirely restricted to discrete-time implementations. Consequently the
design techniques for FIR filters are based on directly approximating the desired frequency response of the
discrete-time ssystem. Furthermore, most techniques for approximating the magnitude response of an FIR
system assume a linear phase constraint, thereby avoiding the problem of
spectrum factorization that comp licates the direct design of IIR filters.
The simplest method of FIR filter design is called the window method. This method generally begins with
an ideal desired frequency response that can be represented as
w jw
n
d
j
d H e åh n e
+¥
=-¥
( ) = [ ]× (0)
where h [n]
d
is the corresponding impulse response sequence, which can be expressed in terms of
( )
jw
d H e as
w
p
w w
p
p
h n H e e d
j j
d d
× ×
×
= ò
–
( )
2
1
[ ] (1)
Many idealized systems are defined by piecewise-constant or piecewise-functional frequency responses
with discontinuities at the boundaries between bands. As a result, they have impulse responses that are
noncausal and infinitely long. The most straightforward approach to obtaining a causal FIR approximation
to such systems is to truncate the ideal response. Equation (1) can be thought of as a Fourier series
representation of the periodic frequency response ( )
jw
d H e , with the sequence h [n]
d
playing the role of
the Fourier coefficients. Thus, the approximation of an ideal filter by truncation of the ideal impulse
response is identical to the issue of the convergence of Fourier series, a subject that has received a great
deal of study. A particularly important concept from this theory is the Gibbs phenomenon, which will be
covered in the example with this Appendix.
The simplest way to obtain a causal FIR filter from h [n]
d
is to define a new system with impulse response
h[n] given by
{
otherwise
h n n M
h n
d
K
L
0,
[ ], 0
[ ]
£ £
= (2)
More generally, we can represent h[n] as the product of the desired impulse response and a finite-duration
“window” w[n]; i.e.,
h[n] h [n] w[n]
d = × (3)
where for simple truncation as in Eq. (2), the window is the rectangular window
ECED4502 Lab5
– 7 –
{
otherwise
n M
w n
K
L
0,
1, 0
[ ]
£ £
= (4)
It follows from the windowing theorem that
w
p
q w q
p
p
w H e H e W e d
j j
d
j
( ) ( )
2
1
( )
( – )
–
× ×
×
= ò
(5)
That is, ( )
jw H e is the periodic convolution of the desired ideal frequency response with the Fourier
transform of the window. Thus, the frequency response ( )
jw H e will be a “smeared” version of the desired
response ( )
jw
d H e . Figure 2(a) depicts typical functions ( )
jw
d H e and ( )
jw W e as required in Eq.(5).
If w[n] = 1 for all n (i.e., we do not truncate at all), ( )
jw W e is a periodic impulse train with
period 2 ×p , and therefore ( ) ( )
jw jw
d H e = H e .
This interpretation suggests that if w[n] is chosen so that ( )
jw W e is concentrated in a narrow band of
frequencies around w= 0, then ( )
jw H e will “look like ( )
jw
d H e except where ( )
jw
d H e changes
very abruptly. Thus, the choice of window is governed by the desire to have w[n] as short as possible in
duration so as to minimize computation in the implementation of the filter while having ( )
jw W e
approximate an impulse; that is, we want ( )
jw W e to be highly concentrated in frequency so that the
convolution of Eq. (5) faithfully reproduces the desired frequency response. These are conflicting
requirements, as can be seen in the case of the rectangular window of Eq. (4), where
sin( / 2)
sin( ( 1) / 2)
1
1
( )
/ 2
( 1)
0 w
w w
w
w
w w × +
= ×
–
–
= =
– ×
– ×
– × +
– ×
=
å
M
e
e
e
W e h e
j M
j
j M
j n
M
n
d
j
(6)
The magnitude of ( )
jw W e is plotted in Fig. 8 for the case M = 7. Note that ( )
jw W e for the rectangular
window has generalized linear phase. As M increases, the width of the “main lobe” decreases. The main
lobe is usually defined as the region between the first zero crossings on either side of the
origin. For the rectangular window, the mainlobe width is
1
4
+
×
D =
M
m
p
w . However, for the rectangular
window, the sidelobes are significantly large andin fact, as M increases, the peak amplitudes of the
mainlobe and the sidelobes grow in a manner such that the area under each lobe is a constant while the
width of each lobe decreases with M. Consequently, as ( )
j(w -q ) W e “slides by” a discontinuity of
( )
jw
d H e with increasing w, the integral of ( ) ( )
(w q ) jw
d
j W e × H e
– will oscillate as each sidelobe of
( )
j(w -q ) W e moves past the discontinuity. This result is depicted in Fig.7(b). Since the area under each
lobe remains constant with increasing M, the oscillations occur more rapidly but do not decrease in
amplitude as M increases.
In the theory of Fourier series, it is well known that this nonuniform convergence, the Gibbs
phenomenon, can be moderated through the use of a less abrupt truncation of the Fourier series by tapering
the window smoothly to zero.
Figure 7 (a) Convolution process implied by truncation of the ideal impulse response.
(b) Typical approximation resulting from windowing the ideal impulse response.
ECED4502 Lab5
– 8 –
Figure 8 Magnitude of the Fourier transform of a rectangular window (M = 7).
Design Example
The desired frequency response is defined as
{
0, | | | | | |
, | | | |
( )
/ 2
w w p
w w
w
w
< £
£
=
– ×
c
c
j M
j
lp
e
H e K
L (86)
where the generalized linear phase factor has been incorporated into the definition of the ideal lowpass
filter. The corresponding ideal impulse response is
( / 2)
sin( ( / 2))
2
1
[ ]
/ 2
n M
n M
h n e e d
n c
j M j
lp
× –
× –
× × =
×
=
– × ×
–
ò
p
w
w
p
w w
p
p
(87)
ECED4502 Lab5
– 9 –
for – ¥ < n < +¥ . It is easily shown that h [M n] h [n]
lp – = lp , so
if we use a symmetric window in the equation
[ ]
( / 2)
sin( ( / 2)) [ ] w n
n M
n M
h n
c
×
× –
× –
=
p
w
(88)
then a linear phase system will result.
The upper part of Fig. 31 depicts the character of the amplitude response that would result for the typical
windows used in your design. Figure 31 displays the important properties of window method
approximations to desired frequency responses that have step discontinuities. It applies accurately when
wc
is not close to zero or to p and when the width of the mainlobe is smaller than wc 2 × . At the bottom
of the figure is a typical Fourier transform for a symmetric window. This function should be visualized in
different positions as an aid in understanding the shape of the approximation ( )
jw H e in the vicinity of
wc
.
Figure 31 Illustration of type of approximation obtained at a discontinuity of the ideal frequency response.
– 10
ECED4502 – Lab 3
Appendix B FIR Digital Filters design using Matlab / Python
Using MATLAB :
After designing a FIR filter with N=5 taps in GNURadio with = 10 and cut off
frequency of your choice, you will verify your design in Matlab using the following steps:
• If your coefficients were [0.15 0.19 0.20 0.19 0.15], define in Matlab the
impulse response vector h as:
1. h=[0.15 0.19 0.20 0.19 0.15];and get the frequency response of your filter as
2. hf=fft(h);
3. plot(abs(hf));
• Now try to do zero padding on your impulse response as to get
1. h1=[h zeros(1,100)];
2. hf1=fft(h1);
3. plot(abs(hf1));
4. plot(20*log10(abs(hf1)));
• Comment on your observations in these two steps and compare the last results
to the frequency response of the filter displayed in GNURadio.
• In the Matlab code provided, describe what each line does and how it affects
the graphs.
• Design your own low-pass FIR filter with impulse response myh in Matlab by
using the following sample statements:
1. myt=-4:4;
2. myh=sinc(0.2*t);
• Filter sinusoidal signals x[n] = sin(wOn) with different wO using a filter
having the impulse response ℎ[n] from your design using Matlab command
filter:
1. t=1:200;
2. x=sin(0.25*t);
3. y=filter(h,1,x);
4. plot(y);
5. plot(abs(fft(y)));



