Lab 1
Lab 1
1.1 Introduction
The purpose of this lab is to illustrate the properties of continuous and discrete-time signals using
digital computers and the Matlab software environment. A continuous-time signal takes on a value at
every point in time, whereas a discrete-time signal is only defined at integer values of the “time”
variable. However, while discrete-time signals can be easily stored and processed on a computer, it is
impossible to store the values of a continuous-time signal for all points along a segment of the real
line. In later labs, we will see that digital computers are actually restricted to the storage of quantized
discrete-time signals. Such signals are appropriately known as digital signals.
How then do we process continuous-time signals? In this lab, we will show that continuous-time
signals may be processed by first approximating them by discrete-time signals using a process known
as sampling. We will see that proper selection of the spacing between samples is crucial for an efficient
and accurate approximation of a continuous-time signal. Excessively close spacing will lead to too
much data, whereas excessively distant spacing will lead to a poor approximation of the continuous-
time signal. Sampling will be an important topic in future labs, but for now we will use sampling to
approximately compute some simple attributes of both real and synthetic signals.
In the following sections, we will illustrate the process of sampling, and demonstrate the
importance of the sampling interval to the precision of numerical computations.
on your desktop. After starting up, you will get a Matlab window. To get help on any specific
command, such as “plot”, you can type the following
help plot
in the “Command Window” portion of the Matlab window. You can do a keyword search for
commands related to a topic by using the following.
lookfor topic
EE323 Digital Signal Processing - Laboratory Manuals
execution of the script-file, you can access its variables at the Matlab prompt. For more help on scripts,
see script.pdf.
To create a function nameed func, you first create a text file named func.m. The first line of the
file must be
function output = func(input)
where input designates the set of input variables, and output are your output variables. The rest of
the function file then contains the desired operations. All variables within the function are local; that
means the function cannot access Matlab workspace variables that you don't pass as inputs. After the
execution of the function, you cannot access internal variables of the function. For more help on
functions see function.pdf.
INLAB REPORT: Hand in your calculations of these two integrals. Show all work.
This plot shows the discrete-time signal formed by computing the values of the function sin(t/6) at
points which are uniformly spaced at intervals of size 2. Notice that while sin(t/6) is a continuous-
time function, the sampled version of the signal, sin(n/6), is a discrete-time function.
A digital computer cannot store all points of a continuous-time signal since this would require an
infinite amount of memory. It is, however, possible to plot a signal which looks like a continuous-
time signal, by computing the value of the signal at closely spaced points in time, and then
connecting the plotted points with lines. The Matlab plot function may be used to generate such
plots. Use the following sequence of commands to generate two continuous-time plots of the signal
sin(t/6).
n1 = 0:2:60;
z = sin(n1/6);
subplot(3,1,2)
plot(n1,z)
n2 = 0:10:60;
w = sin(n2/6);
subplot(3,1,3)
plot(n2,w)
As you can see, it is important to have many points to make the signal appear smooth. But how
many points are enough for numerical calculations? In the following sections we will examine the
effect of the sampling interval on the accuracy of computations.
INLAB REPORT: Submit a hard copy of the plots of the discrete-time function and two
continuous-time functions. Label them with the title command, and include your names.
Comment on the accuracy of each of the continuous time plots.
NOTE: Since Matlab is an interpreted language, for loops are relatively slow. Therefore, we will
avoid using loops whenever possible.
Next write an m-file script that evaluates I (N) for 1 N 100, store the result in a vector and plot the
resulting vector as a function of N. This m-file script may contain for loops.
Repeat this procedure for a second function J = integ2(N) which numerically computes the integral
of
exp (t) on the interval [0; 1].
INLAB REPORT: Submit plots of I (N) and J (N) versus N. Use the subplot command to put both
plots on a single sheet of paper. Also submit your Matlab code for each function. Compare your
results to the analytical solutions from the "Analytical Calculation" (Section 2.1: Analytical
Calculation) section. Explain why I (5) = I (10) = 0.
First download the speech audio file speech.au, and then do the following:
1. Use the audioread command to load the file speech.au into Matlab.
2. Plot the signal on the screen as if it were a continuous-time signal (i.e. use the plot command).
3. Play the signal via the digital-to-analog converter in your computer with the Matlab sound
function.
files if you prefer. Use the subplot command to put both plots in a single figure, and be sure to label
the time axes.
sinc (t) for t in [10, 10]
rect (t) for t in [2, 2]
HINT: The function rect(t) may be computed in Matlab by using a Boolean expression. For
example, if t = 10:0.1:10, then y = rect(t) may be computed using the Matlab command
y=(abs(t)<=0.5).
Write an .m-script file to stem the following discrete-time function for a = 0.8, a = 1.0 and a = 1.5.
Use the subplot command to put all three plots in a single figure. Issue the command orient('tall')
just prior to printing to prevent crowding of the subplots.
an (u [n] u [n 10]) for n in [20, 20]
Repeat this procedure for the function
cos(n) an u[n] for = /4, and n in [1, 10]
HINT: The unit step function y = u [n] may be computed in Matlab using the command
y = (n>=0) ,
where n is a vector of time indices.
INLAB REPORT: Submit all three figures, for a total of 8 plots. Also submit the copies of
your Matlab .m-files.
1.6 Sampling
The word sampling refers to the conversion of a continuous-time signal into a discrete-time
signal. The signal is converted by taking its value, or sample, at uniformly spaced points in time. The
time between two consecutive samples is called the sampling period. For example, a sampling period
of 0.1 seconds implies that the value of the signal is stored every 0.1 seconds.
Consider the signal f (t) = sin(2 t). We may form a discrete-time signal, x[n], by sampling this
signal with a period of Ts. In this case,
x[n] = f (Tsn) = sin (2Tsn).
Use the stem command to plot the function f (Tsn) defined above for the following values of Ts
and n. Use the subplot command to put all the plots in a single figure, and scale the plots properly
with the axis command.
1. Ts = 1/10, 0 n 100; axis([0,100,1,1])
2. Ts = 1/3, 0 n 30; axis([0,30,1,1])
3. Ts = 1/2, 0 n 20; axis([0,20,1,1])
4. Ts = 10/9, 0 n 9; axis([0,9,1,1])
INLAB REPORT: Submit a copy of the figure containing all four subplots. Discuss your results.
How does the sampled version of the signal with Ts = 1/10 compare to those with Ts = 1/3, Ts =
1/2 and Ts = 10/9?
INLAB REPORT: Submit your plot of the two signals “sig1” and “sig2”. Also submit your plot of
the two signals “ave1” and “ave2”. Comment on how the average values changes with n. Also
comment on how the average values can be used to distinguish between random noise with
different means.
INLAB REPORT: Hand in softcopies of your mesh plot and image. For which applications do you
think the surface plot works better? When would you prefer the image?