Question

a. In this exercise we will look at how to convolve a signal with a system's impulse response function. Given an impulse response h[n] = u[n+ 1] – u[n –

3] and a signal ¤[n] = 2(u[n] – u[n – 11]) lets use MATLAB to convolve them and display the resulting signal y[n] = [n] * h[n]. To do so enter the following lines of code into MATLAB: >> n = [– 20:201: >> X = 0*n: >> x ([0:10] + 21) = 2; >> h = 0*n; >> h([-1:2] + 21) = 1; >> y = conv(h,x,'same '); b. Let's plot the resulting sequences: >> figure ( 2); >> subplot (3,1,1); >> stem (n,x,’filled '); >> axis ([-20 20 0 3]); >> xlabel('$$n$$ ' , 'interpreter ','latex '); >> title ('$$x [n]$$ ' , 'interpreter ','latex '); >> subplot (3,1,2); >> stem (n, h,'filled '); >> axis([– 20 20 0 3]); >> xlabel ('$$n$$ ' , 'interpreter ','latex '); >> title ('$$h[n] $$ ' , 'interpreter ',' latex '); >> subplot (3,1,3); >> stem (n,y,'filled '); >> axis ([-20 20 0 10]); >> xlabel('$$n$$ ' , 'interpreter ','latex '); >> title ('$$y [n]x[n]*h[n] $$ ', 'interpreter ','latex '); Notice that we create the discrete time vector n to have a range from [-20, 20]. We then create x[n] to be the same length as n and set each element to zero. Since MATLAB has a 1-based indexing convention notice that for creation of x[n] we need to set the elements corresponding to n e [0, 10] to 2, but we have to offset the index value by 21 since our n vector begins at -20. We do similar steps to define the impulse response h[n]. Then, we use the conv function to perform the convolution. Note that we use the parameter 'same'. This truncates the convolution to have the same number of samples as the longest input sequence. Normally a convolution results in a sequence of length (M +N – 1) (length of first sequence plus length of second sequence - 1). We also padour sequences with sufficient zeros in order to ensure that the full convolution results are properly captured in our truncated (due to ʻsame'), convolved sequence.

Question image 1Question image 2Question image 3Question image 4Question image 5Question image 6Question image 7Question image 8Question image 9Question image 10Question image 11Question image 12Question image 13Question image 14Question image 15Question image 16Question image 17Question image 18Question image 19Question image 20Question image 21Question image 22Question image 23Question image 24Question image 25