hw 2 solutions - binghamton university personal page/st… ·  · 2011-09-212.12(b) the signals to...

15
EECE 301 HW #2 Solutions Fall 2009 x=[0 0 1 1 1 0 0]; v=[0 0 1 1 1 1 0 0]; y=conv(x,v); stem(-4:9,y) xlabel('n') ylabel('x[n]*v[n]') n = 0 If you check this conv by hand you’ll see why you need to end at n= 9 for the output. Note: if x “ends” at n = M 1 (4 here) and if v “ends” at n = M 2 (5 here) then y ends at n = M 1 + M 2 1 (9 here) If you check this conv by hand you’ll see why you need to start at n= –4 for the output. Note: if x “begins” at n = –N 1 (–2 here) and if v “begins” at n = –N 2 (–2 here) then y begins at n = –N 1 –N 2 (–4 here) I chose to append 2 zeros here prior to n =0… you could append fewer or more

Upload: truongdung

Post on 13-Apr-2018

217 views

Category:

Documents


4 download

TRANSCRIPT

EECE 301 HW #2 Solutions Fall 2009

x=[0 0 1 1 1 0 0]; v=[0 0 1 1 1 1 0 0]; y=conv(x,v); stem(-4:9,y) xlabel('n') ylabel('x[n]*v[n]')

n = 0

If you check this conv by hand you’ll see why you need to end at n= 9 for the output. Note: if x “ends” at n = M1 (4 here) and if v “ends” at n = M2 (5 here) then y ends at n = M1 + M2 – 1 (9 here)

If you check this conv by hand you’ll see why you need to start at n= –4 for the output. Note: if x “begins” at n = –N1 (–2 here) and if v “begins” at n = –N2 (–2 here) then y begins at n = –N1 –N2 (–4 here)

I chose to append 2 zeros here prior to n =0… you could append fewer or more

x=[0 0 2 1 0 0 0]; v=[0 0 1 1 1 1 0 0]; y=conv(x,v); stem(-4:9,y) xlabel('n') ylabel('x[n]*v[n]')

x=[0 0 2 1 0 0 0]; v=[0 0 0 1 2 0 0 0]; y=conv(x,v); stem(-4:9,y) xlabel('n') ylabel('x[n]*v[n]')

2.12(b) The signals to be convolved are infinite in length but we can only specify them inside matlab over some finite range; I chose 0 to 20 here. Likewise, the output (i.e., the convolution) will be infinite duration but you can only compute it for a finite duration. Using insight from hand-calculated convolution of the infinite duration version versus hand-calculated convolution of the finite duration version it is easy to see the following: If one signal is specified in matlab for n=0:N1 and the other signal is specified for n=0:N2 then the convolution of the these finite versions results in output values defined for index values of n=0:(N1+N2); however, only those over the range n=0:min(N1,N2) are correct. Here is a first stab at the matlab code and its result: n=0:20; h=0.3*(0.7.^n); x=sin(n*pi/8); y=conv(x,h); stem(0:(length(y)-1),y) % plots the full length of the computed y[n] xlabel('n (sample index)') ylabel('y[n] (convolution result)') grid

This part does not occur when doing the true infinite duration convolution by hand… so this must be wrong. This transient decay is due to the fact that we computed this using truncations of the infinite duration signals.

Based on the above we know that we can really only show the output up to index value of n = min(N1,N2) In this case N1 = N2 = 20.... So, here is the correct matlab code: n=0:20; % define the h=0.3*(0.7.^n); x=sin(n*pi/8); y=conv(x,h); stem(n,y(1:21))

Only grab y[n] for n = 0:21, or the first 21 samples.

xlabel('n (sample index)') ylabel('y[n] (convolution result)') grid

2.29 (c)

Matlab code is: t1=0:0.001:2; t2=2.001:0.001:10; y1=2*(exp(-t1)-exp(-2*t1)); y2=2*(1-exp(-2))*exp(-t2); t=[t1 t2]; y=[y1 y2]; plot(t,y) xlabel('t (sec)') ylabel('y(t)')

Because the output is defined piece-wise over two intervals we need to define two different time vectors. The first covers the finite range from 0 to 2 seconds (w/ a spacing of 0.001 which is exceedingly fine enough of a grid!). The second starts at 2.001 (one grid point past where the first stopped) and goes only to 10, even though in theory this goes on to infinity. Note that the two time constants are 1 sec and ½ sec so the 5 tau rule for the largest tau gives 5 seconds past where the decay starts (it starts at 2)… extending from this determined 7 to 10 seconds yields a good view of the “tail”

It is Engineering not Art!!!

Now… fuse the two time vectors onto one long vector that covers the whole range… and do the same for the two y parts

Matlab code: t1=0:0.001:4; t2=4.001:0.001:10; y1=4*exp(-2)*(1-exp(-2*t1)); y2=4*(exp(6)-exp(-2))*exp(-2*t2); t=[t1 t2]; y=[y1 y2]; plot(t,y) xlabel('t (sec)') ylabel('y(t)') grid