Summary: Approximating continuous time on a computer. Creating signals, doing things to them like convolution, and plotting them. This development of these labs was supported by the National Science Foundation under Grant No. DUE-0511635. Any opinions, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.
In MATLAB, we have so far been representing time functions for plotting purposes by storing time samples in a vector. For example, in the Introduction to Matlab lab, we used
t = -10:0.1:10;
xo = t .* exp(-abs(t));
plot(t,xo);
When we use a fine-grained time vector, then the plot looks continuous to our eyes. If the time samples are spaced too far apart, then the signal will look choppy. You can control the time granularity by the step size in defining your time vector. Try plotting the time function above using different time granularities, e.g., time steps of 0.05, 0.1, 0.5, 1. At what step size does the plotted signal start looking choppy?
unitstep function in matlab. The function should have two parameters, a time vector and a time shift value.
unitstep([time],td) should be equivalent to u(t + td)unitstep function to create a box-shaped time signal. Write a new function called boxt.m that creates a box with specified start and end times t1 and t2. In other words, your function should take three inputs: scalers t1 and t2, and a time vector t, and should output a vector of the same size as t, which contains the values of u(t-t1)-u(t-t2) evaluated at each point in t.
boxtscript.m that uses the function to create a box that starts at time -1 and ends at time 1, given an input time vector that spans the time window [-3,3]. Generate 3 different versions of this box using 3 different time granularities, where the finest granularity has very sharp edges similar to the ideal box and the coarsest granularity has a step size of 0.5.
boxtscript.tif.
boxt.m.
unitstep.m
boxt.m
boxtscript.m
boxtscript.tif
MATLAB has a function conv(u,v) that you can use to convolve
two discrete time functions
u is a vector of length n with time span tu=t1:del:t2 and v is a vector of length m with time span tv=t3:del:t4, and both have the same time step del =
res=conv(u,v)will be a vector of length n + m - 1 with a time span tc=(t1+t3):del:(t2+t4). Using the box function that you wrote above with a sufficiently fine grained step size, find and plot the result of the convolution of box(0,2) and box(-1,1). Include your name in the title of the plot and save as convplot.tif. Verify that the timing of signal rising and falling matches what you expect in theory.
n rather n
scaled.tif
convplot.tif
scaled.tif
For this problem, create a script file called cosines.m to write your commands in and do the following.
dampedCosine.m from the Introduction to Matlab lab as a reference to generate a cosine at a given frequency. Your cosines will not be damped, so remember to remove the exponential. Generate a time index in increments of Ts = 1/8000 second using
Ts = 1/8000;
timeIndex = 0:Ts:(100*Ts);
k multiples of this fundamental frequency, for k = 2, 3, 4. These are called the harmonics of the fundamental frequency.
signalsAdded = signal1 + signal2.
cosines.tif.
cossums.m
cosines.tif
Show the TA ALL m-files that you created or edited and the files below.
unitstep.m
boxt.m
boxtscript.m
boxtscript.tif
convplot.tif
scaled.tif
cosines.m
cosines.tif