Exploring Digital Filters: Linear Systems, FIR and IIR Filters, Lab Reports of Digital Signal Processing

A lab guide for students in ece 158 on digital filtering. It covers the concepts of linear systems, finite impulse response (fir) filters, and infinite impulse response (iir) filters. Students will learn about the impulse response, frequency response, and group delay of filters. They will also get hands-on experience in finding and plotting the frequency response and group delay of fir and iir filters.

Typology: Lab Reports

Pre 2010

Uploaded on 08/30/2009

koofers-user-xoj-1
koofers-user-xoj-1 🇺🇸

10 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Copyright 2006 Bob L. Sturm
Lab 4
Linear Systems and Digital Filtering
0. Preface
Any operation on a digital signal can be described as a filtering operation. In the
first lab you explored the moving average. This is in fact a digital filter! In the third
lab you saw that in order to properly change the sampling rate of a digital signal,
with either upsampling or downsampling, and where the word “properly” signifies
not only politeness but also the absence of aliasing, a digital lowpass filter is
necessary. In this lab you will explore digital filters in the time and frequency
domains. You will learn about linear systems, and finite and infinite impulse
response filters.
Really, in constructing a lab on digital filters, it is difficult to limit the subject
material. So vast is the subject that one could take several courses on it and still
have more to learn. Even so, we hope the sampling provided below will interest
you in at least devoting a few hours to completing this lab satisfactorily.
Your lab report should answer all questions in all sections. Good luck with that.
1. Linear Systems, Linear Filters
As we all know, the eigenfunctions of linear systems are complex exponentials.
This means that if we excite a linear system with the signal
x(t)=ej
ω
0t
, the output
of the system is guaranteed to be
y(t)=H(
ω
0)ej
ω
0t=H(
ω
0)ej(
ω
0t+
φ
(
ω
0))
. The
frequency of the excitation is carried over to the output—i.e., it does not
change—but its amplitude and phase are changed by
H(
ω
0)
and
φ
(
ω
0)=angle(H(
ω
0))
, respectively. Furthermore, by the definition of a linear
system, the same principle can be applied to any linear combination of any
number of these eigenfunctions. Now if you are unsure about what you just read,
just smile, nod, and assume you will see the light in the next part of the lab.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Exploring Digital Filters: Linear Systems, FIR and IIR Filters and more Lab Reports Digital Signal Processing in PDF only on Docsity!

Lab 4

Linear Systems and Digital Filtering

0. Preface

Any operation on a digital signal can be described as a filtering operation. In the first lab you explored the moving average. This is in fact a digital filter! In the third lab you saw that in order to properly change the sampling rate of a digital signal, with either upsampling or downsampling, and where the word “properly” signifies not only politeness but also the absence of aliasing, a digital lowpass filter is necessary. In this lab you will explore digital filters in the time and frequency domains. You will learn about linear systems, and finite and infinite impulse response filters. Really, in constructing a lab on digital filters, it is difficult to limit the subject material. So vast is the subject that one could take several courses on it and still have more to learn. Even so, we hope the sampling provided below will interest you in at least devoting a few hours to completing this lab satisfactorily. Your lab report should answer all questions in all sections. Good luck with that.

1. Linear Systems, Linear Filters

As we all know, the eigenfunctions of linear systems are complex exponentials. This means that if we excite a linear system with the signal € x ( t ) = e j ω 0 t , the output of the system is guaranteed to be € y ( t ) = H ( ω 0 ) e j^ ω^0 t^ = H ( ω 0 ) e j (^ ω^0 t^ +^ φ^ (^ ω^0 )). The frequency of the excitation is carried over to the output—i.e., it does not change—but its amplitude and phase are changed by € H ( ω 0 ) and € φ( ω 0 ) = angle( H ( ω 0 )) , respectively. Furthermore, by the definition of a linear system, the same principle can be applied to any linear combination of any number of these eigenfunctions. Now if you are unsure about what you just read, just smile, nod, and assume you will see the light in the next part of the lab.

Recall from the very first lab, the definition of an € M -point moving average filter: € y [ n ] =

M

x [ nk ] k = 0 M − 1 ∑ ,^ (1) where the integer € M is usually odd. Indeed, this system so described is a linear system. In fact, it couldn’t be otherwise because this section is titled “Linear Systems, Linear Filters.” What you (should have) observed in the first lab is that the moving average acts like a lowpass filter. More formally, a lowpass filter suppresses high frequencies and passes low ones. Let’s prove this by plotting the frequency response of an € M -point moving averager. 1.1 Knowing that an M-point averager has an impulse response of ones(1,M)./M, you can find its frequency response. I know you can. For M=[5, 21, 51] plot (using plot and not s t e m) on the same figure (hold on) the magnitude response versus the normalized frequency domain [0:0.5]. Evaluate the FFT using 1024 points, i.e., fft(h,1024). (“Normalized frequency” means that a value of 1 is the sampling rate; and a value of 0.5 is the Nyquist frequency.) Use gtext to label each curve. Include you figure and code. It should look something like Figure 1, but of course not nearly as moving. Figure 1: Magnitude responses of moving average filters of different M, labeled

Given the frequency response of a linear system, € H ( ω) , the phase delay of the system is given by € τ (^) p ( ω) = −angle( H ( ω)) ω , which is equivalent to a time-delay. This can be seen in the following example. Consider exciting a linear system by € x ( t ) = e j ω 0 t

. Then the response of the system is expressed as € y ( t ) = H ( ω 0 ) exp[ j ω 0 ( t − − φ( ω 0 ) ω 0 )] = H ( ω 0 ) exp( j ω 0 [ t − τ (^) p ( ω 0 )]). Thus phase delay is a measure of the time-shift of a particular component. The group delay of the system, given by € τ (^) g ( ω) = −

ω d φ( ω) d ω , is a measure of the change in phase with respect to frequency. Stated in a less abstract manner, the group delay describes the time-delay of the envelope of a signal. In many applications, for instance AM radio, it is desirable to use filters with constant group delay so that the amplitude envelope of a signal, i.e., the information, is preserved. 1.6 For each M above, plot on one figure the group delay of the moving average filter by using the g r p d e l a y routine. In this case you will say: g = grpdelay(ones(1,M)./M, 1, 1024, ‘whole’). Plot the group delay as a function of normalized frequency, and include your plot. Your plot of group delay shows that for the moving average filter, its group delay is constant over all frequencies. Furthermore, the delay introduced into the data is (M-1)/2 samples. Indeed, looking back to lab #1, you observed this exact amount of delay in the envelope of the signals you averaged with the causal moving average filter. Finally, any linear system is completely described by its impulse response. That is a wonderful property. Take for example the linear system given by Killaloe Cathedral in County Clare, Ireland (Figure 2).

Figure 2: Killaloe Cathedral, County Clare, Ireland, linear system from the 13 th century. The outside is shown on the left; the inside is shown on the right, looking toward the sanctuary This ancient linear system is completely 1 described by its impulse response. You can listen to its long characteristic impulse response by downloading the file “KillaloeCathedral.wav” from the class website. While you are at it, download the file “PDQBach.wav” as well. You are going to perform some DSP magic and make that music sound reverberate like it is being played in Killaloe Cathedral. Reverberation is basically the natural diffusion of sound energy by an elastic environment. For instance, a person yelling in a canyon will hear echoes when the sound waves bounce off the canyon walls and rosy-hued bluffs peppered with fossil relics millions of years old—themselves echoes of a primitive past. 1.7 Load both of these sound files into MATLAB. Zeropad each one of them to the sum of their lengths minus one. (For instance, if L1 is the length of one, and L2 is the length of the other, zeropad both of the signals so that they have the same length L1+L2-1.) Evaluate the FFT of each one and then pointwise multiply both transforms. Evaluate the inverse FFT of the result. Listen to the result using soundsc at the appropriate sampling rate. Include your code. 1 Though not completely true, this is added to be dramatic and awe inspiring.

2.1 Consider the following impulse response of a 10-order, length-11 FIR system, as described by (2): € h [ n ]={0.00506, 0, -0.04194, 0, 0.28848, 0.49679, 0.28848, 0, -0.04194, 0, 0.00506} for € 0 ≤ n ≤ 10. Plot this impulse response with stem. Include your figure with appropriately labeled axes. 2.2 Find and plot the frequency response (magnitude and phase), and the group delay, of this system as functions of normalized frequency (between 0 and 0.5). Evaluate the FFT using 1,024 points, i.e., fft(h,1024). (This essentially zeropads the signal with enough zeros until its length is 1,024 samples, and then evaluates the FFT. Zeropadding is not always a good thing though, so get that out of your head!) Plot the magnitude response in dB. (This means something like 20*log10(abs(H)./max(abs(H))).) Make sure you unwrap the phase, i.e., unwrap(angle(H)). Include your figures and your code. 2.3 What kind of filter is this? Find the “3 dB” point, or the normalized frequency above which the attenuation is greater than 3 dB. This is also called the cut- off frequency. (Hint: it should be a number between 0 and 0.5.) Physically, an attenuation of 3 dB corresponds to a reduction of the power by two, approximately. 2.4 What is the group delay of this filter in samples for all frequencies? Would it destroy information contained in the envelope of a signal? 2.5 For the € h [ n ] given in 2.1, multiply it by a series of alternating positive and negative ones, or {1, -1, 1, -1, …}. Now € h [ n ]={0.00506, 0, -0.04194, 0, 0.28848, -0.49679, 0.28848, 0, -0.04194, 0, 0.00506}. Find and plot the frequency response (magnitude and phase), and the group delay, of this system as functions of normalized frequency (between 0 and 0.5). Evaluate the FFT using 1,024 points, i.e., fft(h,1024). Plot the magnitude response in dB. Make sure you unwrap the phase, i.e., unwrap(angle(H)). Include your figures, but not you code since it will basically be the same as 2.2. 2.6 What kind of filter is this? What is the cut-off frequency now? You only changed the sign of one value in the impulse response of a system and this is what happens! The former lowpass filter starts attenuating the lows and

Copyright 2006 Bob L. Sturm passing the highs. Its magnitude and phase responses appear to be mirror images of those of the original lowpass filter, found in 2.2. Its group delay remains the same however. 2.7 Why is this happening? Explain why multiplying the impulse response of the lowpass FIR filter by a series of alternating positive and negative 1’s, turns it into a highpass FIR filter. 2.8 Apply the filters described in 2.2 and 2.5 to the sound “drumloop2.wav”, (which can be acquired from the class website) in the time-domain using convolution (2). This can be done using the conv routine. Listen to each of the results and describe what you hear. 2.9 For each of these outputs, what band of frequencies is above the cut-off frequency? That means, after applying the lowpass filter described in 2.2, what band of frequencies are “preserved” from the original drum signal? Calculate the region for the highpass filter described in 2.5 as well.

3. Infinite Impulse Response Filters

Any linear system that has an infinite-length non-zero response to any finite- length input is an infinite impulse response (IIR) system. (Notice how skillfully I once again interchange the terms “system” and “filter”; not to mention my adorable use of italics.) Essentially, an IIR filter is a linear recursive system. The most general form of an IIR filter is given by: € y [ n ] = b [ k ] x [ nk ] + a [ l ] y [ nl ] l = 1 L − 1 ∑ k = 0 M − 1 ∑ (3) One can immediately intuit that the inclusion of past output will make a more “responsive” filter, but could also lead to instability if the output is amplified at each step. Consider the following IIR system: € y [ n ] = 0.206572 x [ n ] + 0.413144 x [ n − 1 ] + 0.206572 x [ n − 2 ]

  • 0.369527 y [ n − 1 ] − 0.195816 y [ n − 2]

the group delay of another filter to become constant in the passband. In this way the information in an amplitude modulated signal can be preserved even after distortion by some filters, for instance. Figure 4: “Two allpass filters, in parallel, in the z-domain (untitled #7)” by Bob L. Sturm, 2006. 3.5 Now for our last trick, we will make something from nothing. Consider the two allpass filters in parallel artfully shown in Figure 4. With A 0 (z) described by (5) with α = -0.15, and A 1 (z) = 1, plot the frequency response and group delay of this system, just like you did in 2.2 and 3.2. Make sure your magnitude plot is in dB this time. Include your code and plot. 3.6 How does this lowpass filter compare with those created in 2.2 and 3.2? (Hint: if you are not getting a lowpass filter, again, seek professional help.) For instance, how do the cut-off frequencies compare? What is different about the group delay? How does the computational complexity of this filter compare to the other two? And now you see another use of allpass filters: they can be combined in parallel to make filters of any kind! If you are like me though, the idea of putting two allpass filters in parallel and not getting an allpass filter as a result makes your tummy hurt. The same frequency component is passed through both filters individually with no change in amplitude! How then can the sum produce a lower amplitude component?

The answer is, of course, described in the Book of Mitra, chapter seven, verse twenty-three: “Forgeteth not the importance of phase and group delay; for an allpasseth filter may not changeth an amplitude, but verily it changeth a phase.” 3.7 In your own words, interpret this verse from the Book of Mitra to explain why two allpass filters in parallel may not an allpass filter make. 3.8 Take a moment to reminisce with friends (Figure 5) about that crazy experience. This includes looking back at your answers while sipping tea and confirming that you understand now what was happening. Figure 5: Two former DSP students reminisce about the crazy times they didn’t realize the significance of group delay, and all that The Book of Mitra also prophesizes, “One day there will come unto you a masterful assistant of teachers who rides a mighty wheeled board named Gretchen,” but we will save that for another discussion.