EE325 Signals & Systems II Lab #1 Filtering Report Due: M1B: Tuesday, January 25 3:45pm M1D: Thursday, January 27 3:45pm Via Gradescope

You might also like

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

EE325 Signals & Systems II

Lab #1 Filtering

Report due:
M1B: Tuesday, January 25 3:45pm1
M1D: Thursday, January 27 3:45pm
via gradescope

Portions of this lab were adapted/taken from “Computer Explorations in Signals and Systems
Using Matlab” second edition, by Buck, Daniel, and Singer.

Introduction
This lab will introduce you to some of the basic commands for filtering discrete-time signals in
Matlab, as well as give you some exposure to how digital signal processing can be used to
process an audio signal. In both parts of this lab, it is important to note that the audio signals are
discrete-time signals acquired through the process of sampling a continuous-time audio signal,
the filtering operation takes place in the discrete-time domain, and the discrete-time audio signal
is being reconstructed to a continuous-time audio signal when you play the file on your speakers.
We are thus implementing a discrete-time processing of a continuous-time signal as discussed in
Section 7.4 of the textbook.

Before Lab
It would strongly behoove you to have completed the tutorials in the handout included with this
lab on the Matlab commands filter (Section 2.2) and freqz (Section 3.2) if you are not
familiar with those functions. You do not need to submit your solutions to those tutorials, but
you will need to use those two functions to complete the remainder of this lab.

This lab will require the use of Matlab and the Signal Processing Toolbox. You can manage
add-ons by Clicking on the Add-Ons button on the Home tab in the Matlab Command window.
Search for Signal Processing Toolbox and follow the instructions to install it.

Lab
Complete the following problems and write up your individual solutions in the prescribed lab
format. You may include your code in line to your report or you may submit your Matlab code
as a .pdf with comments clearly indicating which portion of the lab the code corresponds to.

Part I: Echo cancellation using filter

Part Ia: Read in Audio Files


Download Happy.wav and Happy_echo.wav from the Lab #1 assignment on Canvas.

1 For consistency in canvas and gradescope, a single due date and time will be specified as the later of the two lab
sections, i.e., Thursday at 3:45pm. It is the students’ responsibility to submit their lab reports by the beginning
of their registered lab section. Tuesday lab section students are still expected to submit their lab reports by
Tuesday at 3:45pm.

1
Read Happy.wav into variable x and Happy_echo.wav into variable x_echo using the
Matlab command audioread. When reading in these two wave files, also read in the sample
frequency into variables fs1 and fs2. As an example, this can be done as shown below:

[x, fs] = audioread('file.wav');

What is the sampling frequency of each signal? What is the length of each signal in samples and
seconds? Include answers to these questions in your lab report.

To listen to these signals, you can use the Matlab command sound as shown below:

sound(x,fs1);
sound(x_echo,fs2);

If the sound command does not work, you can alternatively use the Matlab command
audiowrite as shown below:

audiowrite('sound1.wav', x, fs);

Then you can listen to the sound file sound1.wav in another audio player on your computer.

Part Ib: Define Echo System


The echo signal can be modeled as x ec h o [ n ] =x [ n ] +αx [ n − N ] where x ec h o [ n ] is the signal with the
echo, x [ n ] is the original non-echoed signal, α is the attenuation of the echo, and N is the time-
delay of the echo in samples. For this example, Happy_echo.wav corresponds to α =0.75
and N=5499 , which corresponds to a delay of approximately 0.25 seconds (since f s=22050

X ec h o ( e )
Hz). Given this information, find the transfer function . Show your work and include
X ( e j Ω)
this in your lab report. Note—we are using Ω here as the discrete-time frequency variable to
be consistent with the material in textbook section 7.4. You have seen this variable before as
ω .

Part Ic: Define Echo Cancellation System


An echo cancellation system can be implemented as y [ n ] =x ec h o [ n ] − αy [ n− N ] where y [ n ] is the
output of the echo cancellation and x ec h o [ n ] is given as above. Is this system FIR or IIR? How do
Y (e j Ω)
you know? Find the transfer function . Show your work and include this in your lab
X ec h o ( e j Ω )
report.

Part Id: Define Full Transfer Function (Echo and Echo Cancellation)
Y (e j Ω)
Next find the full transfer function . Show your work and include this in your lab report.
X (e j Ω)

2

Y (e ) X ech o ( e j Ω ) Y ( e j Ω )
*** Note that jΩ
= jΩ jΩ .
X (e ) X (e ) X ec h o ( e )

Is this transfer function equivalent to the echo cancellation that is claimed? Note that if we
successfully canceled the echo, we would expect y [ n ] =x [ n ]. Show your work and include this in
your lab report.

Part Ie: Implement Echo Cancellation System


We now want to define the coefficients for the echo cancellation system to compute the output of

Y (e )
our LCCDE. Please take careful note that you are going to be implementing j Ω here.
X echo ( e )

X echo ( e ) Y (e j Ω)
Our analytical computations with and were to demonstrate that the proposed
X (e )

X (e j Ω)
echo cancellation filter does indeed cancel the echo.

Y (e )
Using your transfer function j Ω from part Ic, construct feedback vector a and feedforward
X echo ( e )
vector b. Be very careful about a: remember that the first index in a corresponds to a delay of
zero samples.

After constructing the feedback and feedforward vectors, filter x_echo through the echo
cancellation filter defined by filter coefficient vectors a and b using the command filter.

Listen to output. Comment on what you hear. If you have implemented the echo cancellation
filter correctly, the output should be a very clear signal almost identical to the clean signal x. If
that is not the case, you have not defined vectors a and/or b correctly.

What happens if don’t get the delay quite right? e.g., even off by one sample. Discuss your
results and include your answers in your lab report.

Part II: Lowpass Filtering and Highpass Filtering

Part IIa: Define Butterworth Filters


A Butterworth filter is a specific non-ideal filter. You can define lowpass and highpass
Butterworth filters using the Matlab command butter using the code below as an example.

[b, a] = butter(n, Wn, type);

Here b and a are the feedforward and feedback coefficients, respectively, that define the
Butterworth filter. The parameter n is the order of the filter, Wn specifies the normalized cutoff
frequency, and ftype specifies the type of filter you want to design. The default is lowpass, so
you could either specify 'low' or leave the type blank, but for a highpass filter, you would
specify 'high' (with the apostrophes).

3
In this lab, use an order n of 9, and choose a cutoff frequency Wn of 0.1 (corresponding to a
cutoff frequency of Ωc =0.1 π ) for the lowpass filter and Wn of 0.3 (corresponding to a cutoff
frequency of Ωc =0.3 π ) for the highpass filter. In order to avoid confusion, call the coefficients
of your lowpass filter a_lp and b_lp and call the coefficients of your highpass filter a_hp and
b_hp.

Now that we have created the lowpass and highpass filter coefficients, use these as input to the
freqz command to plot the frequency response for each of the filters. Be sure to title your
plots. Do these filters have a frequency response consistent with what you expect for a lowpass
and highpass filter? Do these filters appear to have their cutoff frequency in the specified
location ( Ωc =0.1 π for the lowpass and Ωc =0.3 π for the highpass)? Be careful about
units on both axes when interpreting the frequency responses. Include the frequency response
plots in your report.

Part IIb: Filter Audio Signal through Butterworth Filters


Filter the original Happy.wav signal (variable x) filter (for both the lowpass and highpass).
Listen to the output and comment on the effects of both filters. What do you notice?

Now vary the cutoff frequencies of each Butterworth filter and comment on what you notice.
Discuss your results and include your answers in your lab report.

You might also like