Description
In this lab, we will implement convolution on the computer to find responses of an LTI system to
different signals.
In particular, we will look at convolving with a pulse, and we’ll revisit the time
delay system from Lab 2, implemented using LTI systems and impulse responses.
Finally, we
apply our knowledge to another audio signal problem. Important concepts in this lab include
plotting the unit impulse function, describing LTI systems using the impulse response h(t), and
computing output y(t) of an LTI system using convolution.
Lab 3 Turn-in Checklist
• 3 pre-lab exercises
• 3 Assignment check-offs with TA
• Lab report, completed and submitted as a team
◦ Submit as a Jupyter notebook following the format that you used in labs 1 and 2.
◦ Submit the audio file recovered in assignment 3
Note: All assignments except the prelab should be completed in groups of 2-3 people.
The pre-lab exercises are to be completed individually and submitted via Canvas before lab
section.
Pre-lab
Read the Lab 3 Background document, then complete the following exercises.
1. Let x(t)=u(t-1)-u(t-3). Assuming that you have continuous time signals, sketch the result
of convolving x(t) with each of the following signals:
h1(t)=d(t-1) h2(t)=p(t)=u(t)-u(t-1)
2. You need to create signals x and h1 on the computer for the above signals for the time
period [0,4] using sampling rate fs. What python commands would you use to do that?
3. The devious student from Lab 2 has attacked the former TA once again. This time, they
corrupted some signals by dividing them into pieces. The TA deduced that the sound files
had been split into three pieces: the first two are 1-sec long, and the third is 2-sec long.
The second piece (1-sec long) has been attenuated by 10 – the other pieces are
unchanged. The following systems need to be implemented to realign the audio file.
Determine the continuous-time impulse response of each system.
Lab Assignments
This lab has 3 assignments. Each should be given a separate code cell in your Notebook, and
each should be associated with a markdown cell with subtitle and discussion. As in Labs 1 and 2,
your notebook should start with a markdown title and overview cell, which should be followed
by an import cell that has the import statements for all assignments.
For assignment 2, you will use the train signal from Labs 1 & 2. For assignment 3, your TA will
assign you an audio file to upload.
You will again be working with arrays, audio files and plotting, so you may want to refer back to
the Lab 1 background discussion. Be sure to include the necessary import statements. Your input
cell should be similar to that used in lab 2.
Assignment 1: Convolving Signals
We will start by doing some simple convolutions. Create a new cell in your Lab 3 notebook for
Assignment 1. This assignment will have four parts, A-D.
A. Create vectors for the following signals using the time range [0,4] and sampling rate fs =
1000:
a. x(t)=u(t-1)-u(t-3)
b. h1(t)=d(t-1)
c. h2(t)=u(t)-u(t-1) (or, try h2(t)=u(t)-u(t-0.5))
d. h3(t)=1 for [0,0.5); = -1 for [0.5,1); 0 otherwise
(or, try h3(t)=1 for [0,0.25); = -1 for [0.25,0.5); 0 otherwise)
EE 235 Lab 3
University of Washington Electrical Engineering 3
You can use your prelab results for (a) and (b). The solution for (c) and (d) should build
on what you did for (a).
B. Create a time vector th for plotting that covers time range [0,4]. Plot the following on a
3×1 subplot. Use a y-axis between -2 and 2. Label and title the graphs. Verify that the
signals for (a) and (b) match what you expect from your prelab
a. h1 vs. th b. h2 vs. th d. h3 vs. th
C. Use the numpy.convolve() function to find yi(t)=x(t)*hi(t) for i=1, 2, 3. Don’t forget the
amplitude scaling associated with the sampling time.
D. Create a time vector ty for plotting that covers time range [0,8]. Plot the following on a
4×1 subplot. (You may need to add zeros to make sure all signals are defined for this time
range.) Use a y-axis between -2 and 2. Label and title the graphs. Verify that the signals
for y1 and y2 match what you expect from your prelab
a. x vs. ty b. y1 vs. ty c. y2 vs. ty d. y3 vs. ty
Assignment Check-Off #1 of 3: Demonstrate this Assignment to the lab TA
Report discussion: Discuss how the hi plots would change if you used fs = 10, instead of fs =
1000? The systems corresponding to impulse responses h2(t) and h3(t) capture different
information about a signal. If you change the width of the pulse to be half as long, then it is
easier to see the effect. Comment on what aspects of the input signal correspond to the largest
values of y2(t) and y3(t).
Assignment 2: Revisiting Time Delay Transformation
In this exercise, we will revisit the time delay transformation from lab 2 with a real signal. To
implement it here, we will use convolution and the impulse response of an LTI system. Start a
new cell in your Lab 3 notebook for Assignment 2. This assignment will have four parts, A-D.
A. Read in train32.wav, saving its signal x and sampling rate fs. Create a time samples
vector t_x for vector x.
B. Implement the impulse response hd of the LTI system that delays a signal by to = 1 sec
as in assignment 1 but using fs from the train signal and defining the signal only for the
time range [0,2). Create t_h as the time samples vector corresponding to hd.
C. Use numpy.convolve() to compute y as x convolved with hd and scale the amplitude
according to the sampling time. Create t_y as the time samples vector corresponding to y.
D. Plot the following on a 3×1 subplot. Use an x-axis between 0 and 4. Label and title
completely. Verify that your delay matches to.
a. x vs. t_x b. hd vs. t_h c. y vs. t_y
EE 235 Lab 3
University of Washington Electrical Engineering 4
Assignment Check-Off #2 of 3: Demonstrate this Assignment to the lab TA
Report discussion: Suppose we modify (C) by not scaling according to the sampling time.
Describe (in words) what would happen to output signal y(t) if you used this h(t) instead. How
will the graph of y(t) differ from the original and how will the sound differ?
Assignment 3: Audio File Realignment
In this section, we will perform a simple speech realignment task from a set of three signals, our
understanding of unit impulses, impulse responses, and LTI systems. You will use the result of
problem 3 in your pre-lab to design impulse responses, then implement the systems with
convolution and sum the resulting signals to recover the original audio file:
y(t) = y1(t) + y2(t) + y3(t)
Download (from Canvas) the three audio files associated with either s1, s2, or s3, depending on
which is assigned to you by your TA. Start a new cell for this Assignment 3.
A. Load the three audio files and name them x1, x2 and x3. They should all have the
same sampling rate fs.
B. Create discrete versions of the impulse responses for the three filters that you
designed in the prelab using the sampling rate of the signals you loaded and a time
window of [0,3) sec. Use the same approach as in assignments 1 and 2.
C. Use numpy.convolve() to obtain y1, y2, and y3. Make sure to scale the output if you
have used the scaled version of the unit impulse.
D. Add zeros to the ends of the resulting signals so that they are all the same length and
add them. Play the resulting file – you should get a recognizable soundbite if you
implemented it correctly. Save the result as a wav file, which you will include with
your report.
Assignment Check-Off #3 of 3: Play your recovered sound file for the TA.
Report discussion: What would the result sound like if you accidentally put x2(t) into all three
filters?
Can you name the character or TV show for your selected sound file? Here are some hints:
• S1: This space ranger action figure is one of the main characters in the first computer animated
film released by Pixar Studios. This character has appeared in multiple feature films, along with
his own spinoff film and TV show. The inspiration for this character is said to be astronaut Buzz
Aldrin.
• S2: This quote comes from a 1980 space opera film, often cited as the best film in the entire
franchise. One of the most well-known quotes of that film comes from this pivotal antagonist
and warrior of the dark side.
EE 235 Lab 3
University of Washington Electrical Engineering 5
• S3: This animated TV character has been on the air for a very long time, probably longer than
most of you have been alive! This family patriarch has been described by some as the “the
greatest comic creation of all time” and one of the greatest cartoon characters “of the last 20
years.”
Team Report
When you’ve tested and cleaned up all your code (remember, you should only submit code for
the Assignments, each in their own cell), go to ‘File’ then ‘Download as’, then select ‘.ipynb’. The
file you download is a Notebook that your TA will be able to open and grade for you, once you
submit it on Canvas. Remember, only one notebook per team! Make sure that your notebook is
titled Lab2-XYZ.ipynb, where XYZ are the initials of the lab partners. You may want to also
download the file as pdf to have a nicer documentation of your records.
Submit via Canvas: i) the .ipynb file, and ii) the recovered audio file from assignment 3.