<< Chapter < Page | Chapter >> Page > |
In this lab, we will explore convolution and how it can be used with signals such as audio.
Since we are working on a computer, we are working with finite-length, discrete-time versions of signals. It is important to note that convolution in continuous-time systems cannot be exactly replicated in a discrete-time system, but using MATLAB's
conv
function for convolution, we can explore the basic effects and gain insight into what is going on. (You can learn more about discrete-time convolution in the UW EE 341 class.)
When you are explicitly working with discrete-time signals, you would plot them with
stem
. However, since we want to think of these as continuous time, we'll still use the
plot
command. An artifact that you may notice is that discontinuities (as in a step function) are not instantaneous -- they have a small slope in the plot. In addition, you need to represent impulses with the height in discrete time equal to the area in continuous time.
When you want to play or plot the discrete-time signal, you need to specify the time increment Ts between samples. As you found in the previous lab, when playing a sound you specify Fs=1/Ts. (Fs is set for you when you load a sound.) When plotting, you need to define a time vector, e.g. t=[0:Ts:end] where end=(length-1)*Ts.
whos
, list all variables and their sizes.clear
, clears all variables.zeros
, creates a vector (or matrix) of zeros.ones
, creates a vector (or matrix) of ones.conv
, convolves two signals.soundsc
, plays an audio signal, normalizing if the values are greater than +/-1. Requires the sampling rate.MATLAB has a function called
conv(x,h)
that you can use to convolve two discrete-time functions
x(n)
and
h(n)
. It assumes that the time steps are the same in both cases. The input signals must be finite length, and the result of the convolution has a length that is the sum of the lengths of the two signals you are convolving (actually L1+L2-1).
h = [1 zeros(1,20) .5 zeros(1,10)];
Plot the impulse response using the
plot
command.x = [0 1:10 ones(1,5)*5 zeros(1,40)];
Plot the input with the
plot
command.conv
to convolve
x
and
h
like this,
y = conv(x, h);
Use subplot to show the impulse response, input, and output of the convolution. Note that you need to add zeros to the end of x and h (to make them the same length as y) or define a time vector for each signal in order to make the timing comparable in the different subplots.h
, acts as an echo. When you convolve the input
x
and impulse response
h
, you add up all the time-shifted and scaled echoes. Try making the second coefficient negative. How does this change the final result?Notification Switch
Would you like to follow the 'Continuous time linear systems laboratory (ee 235)' conversation and receive update notifications?