Example: bachelor of science

Discrete Time Signals & Matlab

Discrete Time Signals & MatlabA Discrete -time signalxis a bi-in nite sequence,fxkg1k= an integer and is called thediscrete time. An equivalent way to thinkaboutxis that it is a function that assigns toksome real (or complex) graph called a time severalways of plotting time series, or Discrete data. The simplest is the stem let the Discrete signal bex=( 0 123 2010 );(1)where the rst non-zero entry corresponds tok=0andthelasttok= values ofklarger than 5 or less than 0,xk=0. Toplotxkfork= 2tok= 7, which will include some zeros, we use these commands. (See Figure 1.)x=[00-123-20100];dtx= -2:7;( Discrete time for x)stem(dtx,x) 202468 3 2 101234 Figure 1: A stem plot convolution of two Discrete -time signalsxandyisx y,whichisde ned by(x y)n:=1Xk= 1xn kyk:(2)As is the case with the continuous-time convolution,x y=y is of interest in Discrete -time signal processing because of itsconnection with linear, time-invariant lters.

Discrete Time Signals & Matlab A discrete-time signal x is a bi-in nite sequence, fx kg1 k=−1.Thevariable kis an integer and is called the discrete time.An equivalent way to think about x is that it is a function that assigns to k some real (or complex) number x k. The graph of x k vs. k is called a time series. Matlab provides several

Tags:

  Discrete

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Discrete Time Signals & Matlab

1 Discrete Time Signals & MatlabA Discrete -time signalxis a bi-in nite sequence,fxkg1k= an integer and is called thediscrete time. An equivalent way to thinkaboutxis that it is a function that assigns toksome real (or complex) graph called a time severalways of plotting time series, or Discrete data. The simplest is the stem let the Discrete signal bex=( 0 123 2010 );(1)where the rst non-zero entry corresponds tok=0andthelasttok= values ofklarger than 5 or less than 0,xk=0. Toplotxkfork= 2tok= 7, which will include some zeros, we use these commands. (See Figure 1.)x=[00-123-20100];dtx= -2:7;( Discrete time for x)stem(dtx,x) 202468 3 2 101234 Figure 1: A stem plot convolution of two Discrete -time signalsxandyisx y,whichisde ned by(x y)n:=1Xk= 1xn kyk:(2)As is the case with the continuous-time convolution,x y=y is of interest in Discrete -time signal processing because of itsconnection with linear, time-invariant lters.

2 IfHis such a lter, than thereis a sequencefhkg1k= 1such thatH[x]=h x;his called theimpulseresponse(IR) of the lterH. When the IRhhas only a nite number ofnon-zerohk's, we say thatHhas nite impulse response(FIR). Otherwise,it hasin nite impulse response(IIR).In practical situations, we will work only with nite sequences, but thesesequences may be arbitrarily large. To compute convolutions of such se-quences, we need to discuss indexing of sequences. For a nite sequencexwewill letsxbe the starting value ofkconsidered. We thus assume thatxk=0ifk<sx. In addition, we let`xbe the last value ofkwe consider; again, weassume thatxk=0ifk>`x. Also, we will letnxbe the length of the stretchbetween the starting and lastxk's, sonx=`x sx+ 1. For example, if weonly wish to work with nonzeroxk's in the sequencexde ned previously in(1), thensx=0,`x=5,andnx= goal is to useMatlab's functionconvto computex ywhenxandyare nite.

3 To do this, we rst need to look at what the indexing of theconvolutionx yis. That is, we want to know whatsx y,`x y,andnx yare, given the corresponding quantities for nitexandy. Whenyis nite,equation (2) has the form(x y)n:=`yXk=syxn kyk=`y syXk=0xn k syyk+sy;(3)where the second equality follows from a change of index. Since 0 k `y sy, the indexn k sysatis esn sy n k sy n `yIfn `y>`x,allthexn k sy=0,and(x y)n= 0. Similarly, ifn sy<sx,wehave(x y)n= 0. In addition, by direct substitution we see that(x y)sy+sx=xsxysyand (x y)`y+`x=x`xy`y. It follows that the startingindex forx yissx y=sx+sy, that the last index is`x y=`x+`y,andthat2the number of terms we need to compute isnx y=`x+`y sx sy+1=nx 1+ny 1+1=nx+ny 1. We list these y=sx+sy`x y=`x+`ynx y=nx+ny 19>=>;(4)Matlabstores a nite sequence in a row or column vector, depending onthe user's choice. Such vectors are always indexed starting with 1 and goingup to the number of entries in the vector.

4 Let's look at our earlier example,whereweletx=[0 0 -1 2 3 -2 0 1 0 0]. To access the fourth entry, wetype inx(4). When we hit theENTERkey, we would getans= ,asasequence,xis a function the Discrete time,k. In the entries given above,kruns fromk= 2 throughk= 7. For plotting purposes and other reasons,we de ne a Discrete time vector to carry this information,dtx=-2 , to nd the Discrete time that corresponds to the fourth entry inx,we type indtx(4)and hitENTERto getans= 's use this to ndingx y. Again, takex=[00-123-20100]anddtx=-2:7. Also, lety=[1 -1 2 4]anddty=8:11. To nd the convolu-tion of these two and plot the result, we use these commands:x=[00-123-20100];dtx= -2:7;y=[1 -1 2 4];dty=8:11;z=conv(x,y);dtz=6:18;stem(dt z,z)The result of this is thatz=[0 0 -1 3 -1 -5 16 9 -9 2 4 0 0].Apartfrom these entries, which are for Discrete timesk= 6 throughk= 18, theother entries inz=x yare all 0.

5 So, for example,z 20=0andz5=0. Toinclude more entries on the plot, say fork= 5tok= 27, one needs to padthe row vectorzwith zeros. There are many ways to do this. Here is one :27;stem(dtz,[zeros(size(-2:5)) z zeros(size(19:27))]) exercises requireMatlab. A basic introduction may befound online Clickon theMatlabandSimulinkTutorials to get Do each of the sets of commands listed in the discussion. Print theresulting Find the convolution of thexandy. Here,xk= 0 fork>3andk< 4, andxk= 1 for 4 k 3. Foryk, assume thatyk=0fork> 2 and fork< 8. When 8 k 2,yk=k+2. Findx yand determine the Discrete time index. Plot the result withstem,again using the correct time index. Put a title on your plot by usingthe commandtitle('Convolution of x*y'). Print the Taket=linspace(0,2*pi,20), x=sin(t). Do the plotsstem(t,x),stem(t,x,':r','fill'),and stem(t,x,' ','fill').Putthemall in one plot with the commands below and print the (1,3,1), stem(t,x)title('Default Stem Plot')subplot(1,3,2), stem(t,x,':r','fill')title('Filled Stem Plot')subplot(1,3,3), stem(t,x,'sk')title('Square Marker Stem Plot')4.

6 This exercise illustrates the use of another plotting tool,stairs. Startwith the following (-pi,pi,20); x=sin(t);stairs(t,x)Next, change the plot by using a \dash-dot" line instead of a solid will also change the color to red:stairs(t,x,' '). We will nowcombinestairs,stemandplot. Title the plot and print the (-pi,pi,20); x=sin(t);tt=linspace(-pi,pi,600); xx=sin(tt);stairs(t,x,' '), hold onstem(t,x,':sb','fill')(Dotted stems & lled circles)plot(tt,xx,'k'), hold off45. Thestairsplots are well suited to doing plots involving the Haarscaling function and wavelet. Recall that the Haar scaling function isde ned by'(x):=(1;if 0 t<1;0;otherwise:Usestairsto plotf(x)=3'(x+1) 2'(x)+'(x 1) +'(x 2)on the interval 3 x 4. On the same interval, plotg(x)='(2x+3) '(2x+2)+2'(2x) '(2x 3). Forg, use a dash-dot pattern (-.)and make the color red. (Hint: to plot two functions, you will need tousehold on.))

7 6. This problem pertains to the Z-transform. Lethbe a nite Discrete -time signal. If we letz=ei!, then the Z-transform is^h(!)=`hXk=shhkz k:We want to illustrate how to numerically compute and plot^ , we will work with anhfor whichsh= n,`=n,andhk=1=nfor n k n. We will do the (-pi,pi,600); z=exp(i*w);(Initializez.)n=2; h=ones(1,2*n+1)/(2*n+1);H=z.^ n.*polyval(h, );(Compute the Z-transform.)norm(imag(H))(This should be small; if not, H is wrong.)plot(w,real(H))In addition ton= 2, do this forn=4,andn= 5. Title, and thenprint, each


Related search queries