You are on page 1of 3

Exercise 3 Copy the MATLAB program from the handout and then using this function, plot the

sequences for x1[n] = {0, 0, .8, .8, .8, .8, .8, .8, } x2[n] = { 0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7} and their convolution sum x1=[.8 .8 .8 .8 .8 .8];n1=(2:7); x2=[.7 .7 .7 .7 .7 .7 .7 .7 .7 ];n2=(-4:4); convstem(x1,n1,x2,n2) Save t e res!"ts o# Exercise 1, 2 an$ 3 inc"!$in% a screen s ot o# t e o!t&!t #rom Exercise 3. 't s o!"$ "oo( "i(e t e one )e"o* * ic c"ear"+ s o*s +o!r &at containin% +o!r st!$ent ',. Ens!re t at +o! ave si%ne$ o## t is assi%nment.

-onvstem .ro%ram
% convstem.m is for plotting two sequences and their convolution sum such that % all three plots have the same scale of indices and the index scale extends from % the lowest index amongst the three to the highest index among the three function convstem(x1, n1, x2, n2) y=conv(x1,x2); % we now need to find the lowest index kmin of the convolution sum. kmin=n1(1)+n2(1); % We next make the lowest index of the plot equal to the lowest index amongst % x1, x2 and the convolution sum. kmin_plot=min([n1(1) n2(1) kmin]); % We need to find the highest index kmax of the convolution sum kmax=max(n1)+max(n2); % we next make the highest indexof the plot equal to one plus the highest index % amongst x1, x2 and the convolution sum. The one is needed since we shall later % assign the last element of each vector to zero and we must not destro kmax_plot=max([max(n1) max(n2) kmax])+1; % We next generate a vector of indices that is appropriate to plts of x1, x2 and % the convolution sum. k_plot=(kmin_plot:kmax_plot); % !ext come the plots themselves. "ach one must #e padded with zeros outside the % range of the original data. xx1=[ze os(1,n1(1)!kmin_plot) x1]; xx1(len"t#(k_plot))=$; % This extension of the xx1 vector # % assignment command is wh xx2(len"t#(k_plot))=$; yy=[ze os(1,kmin!kmin_plot) y]; yy(len"t#(k_plot))=$; % We now plot xx1 su&plot(',1,1) stem(k_plot,xx1) % We nowset the limits of the horizontal axis of the plots avoiding stems on the % left or right #oundaries #e ond the lowest and % the highest timing index. We also reduce the font size and specif % ever lag defined # the k$plot vector. a tick mark for we extended kmax$plot # one. xx2=[ze os(1,n2(1)!kmin_plot) x2]; meams of this an data.

a=len"t#(k_plot)()$; % *#e #o izontal axis +ill &e exten,e, &y t#is muc# set("ca,-./im-,[kmin_plot ! a kmax_plot + a],-fontsize-,1$,-.*ick-,[k_plot]) xla&el(-n-),yla&el(-x1[n]-) % We now plot xx2 su&plot(',1,2) stem(k_plot,xx2) set("ca,-./im-,[kmin_plot ! a kmax_plot + a],-fontsize-,1$,-.*ick-,[k_plot]) xla&el(-n-),yla&el(-x2[n]-) % %inall we p&lot the convolution sum . su&plot(',1,') stem(k_plot,yy) set("ca,-./im-,[kmin_plot ! a kmax_plot + a],-fontsize-,1$,-.*ick-,[k_plot]) xla&el(-/a" k of x2[!n] yla&el(-x1[n]0x2[n]-) elative to x1[n], o of x1[!n] elative to x2[n]-)

You might also like