21.03.2013 Views

EECE 359 MATLAB Exercise 2 1 Introduction 2 Discrete-time ...

EECE 359 MATLAB Exercise 2 1 Introduction 2 Discrete-time ...

EECE 359 MATLAB Exercise 2 1 Introduction 2 Discrete-time ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>EECE</strong><strong>359</strong>: Matlab <strong>Exercise</strong> 2 2<br />

2.2 Convolution of an impulse and a square wave<br />

In this section, we will examine the result of a convolution y[n] = δ[n − 1]∗xs[n], were<br />

xs[n] =<br />

Enter the following code to create this signals<br />

>> x = [0 1 0 0 0 0];<br />

>> xs = [1 1 1 1 1 1];<br />

<br />

1, 0 ≤ n ≤ 5<br />

0, otherwise<br />

Now, convolve the signals and create a <strong>time</strong> vector:<br />

>> y = conv(x,xs);<br />

>> t = 0:length(y)-1;<br />

Try plotting the output of the system using stem. What can you observe about the output?<br />

Try shifting the <strong>time</strong> square wave and/or the impulse. How does this change the<br />

convolution output?<br />

2.3 Convolution of two square waves<br />

In this section, we will try convolving two square waves together. We use again the<br />

function xs[n] defined in Equation 1, and look at the convolution y[n] = xs[n]∗xs[n].<br />

Create xs as we did above. Now, we can perform the convolution:<br />

>> y = conv(xs,xs);<br />

>> t = 0:length(y)-1;<br />

Plot the output using thestem function as we did before. What can you observe about the<br />

convolution of two square waves?<br />

3 Animated <strong>Discrete</strong>-Time Convolution<br />

In this section, you will learn to create Matlab script files (called M-files), and you will write<br />

a Matlab script which shows an animation of the convolution process. The signals we are<br />

convolving are from page 36 of the Lecture Notes.<br />

3.1 Creating an M-file<br />

Create a new M-file (“File” → “New” → “M-File”), and enter the following code into it (the<br />

line numbers at the left margin are only for reference, and should not be entered in the<br />

file):<br />

(1)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!