Lab 1
Lab 1
ECE438 - Laboratory 1:
Discrete and Continuous-Time Signals
By Prof. Charles Bouman and Prof. Mireille Boutin
Fall 2016
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.
2 Laboratory Ethics
Students are expected to behave ethically both in and out of the lab. Unethical behavior
includes, but is not limited to, the following:
• Possession of another person’s laboratory solutions from the current or previous years.
• Reference to, or use of another person’s laboratory solutions from the current or pre-
vious years.
Questions or comments concerning this laboratory should be directed to Prof. Mireille Boutin, School
of Electrical and Computer Engineering, Purdue University, West Lafayette IN 47907
Purdue University: ECE438 - Digital Signal Processing with Applications 2
• Cheating on quizzes.
The ECE438 laboratory experience is meant to strengthen and deepen the student’s
understanding of basic concepts taught in the ECE438 lectures and to help the student
develop practical skills in applying the concepts taught in the ECE438 course. The rules
of laboratory ethics are designed to facilitate these goals. We emphasize that laboratory
teaching assistants are available throughout the week to help the student both understand
the basic concepts and answer the questions being asked in the laboratory exercises. By
performing the laboratories independently, students will likely learn more and improve their
performance in the course as a whole.
Please note that it is the responsibility of the student to make sure that the content of
their graded laboratories is not distributed to other students. If there is any question as to
whether a given action might be considered unethical, please see the professor or the TA
before you engage in such actions.
INLAB REPORT:
Each student on the team must write by hand the following statement in the lab report,
sign and date.
“I have read and understood the Laboratory Ethics section (Section 2) of Laboratory 1. I
pledge to behave ethically and with honesty in ECE438 this semester. The reports I will
hand in will be the product of original work by myself and my teammate, and no one else. I
will not look at other people’s laboratory. I will not use other people’s code. I will not make
my labs available to other students beyond my teammates, even after the semester is over. In
particular, I will not post my labs on the Internet or make my files available to other people.
I will not be a cheater. ” Name, Signature, Date.
3 Matlab Review
Practically all lab tasks in the ECE438 lab will be performed using Matlab. Matlab (MATrix
LABoratory) is a technical computing environment for numerical analysis, matrix compu-
tation, signal processing, and graphics. In this section, we will review some of its basic
functions. For a short tutorial and some Matlab examples see
https://engineering.purdue.edu/ECN/Support/KB/Docs/MatlabCharlesBoumans/index_html
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
You can get an interactive help window using the function
helpdesk
or by following the Help menu near the top of the Matlab window.
prompt. Within the script-file, you can access variables you defined earlier in Matlab. All
variables in the script-file are global, i.e. after the execution of the script-file, you can access
its variables at the Matlab prompt. For more help on scripts, please refer to the following
file
https://engineering.purdue.edu/VISE/ee438L/matlab/help/pdf/script.pdf
To create a function call “func”, you first create a file called “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 in 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 please refer to the following file
https://engineering.purdue.edu/VISE/ee438L/matlab/help/pdf/function.pdf
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
“looking” functions. Label them with the title command, and include your names. Comment
on the accuracy of each of the continuous time plots.
1
If you have trouble printing, make sure LPDEST is defined. Refer to the printing information on the
VISE home page.
Purdue University: ECE438 - Digital Signal Processing with Applications 6
subplot(3,1,1)
plot(x)
subplot(3,1,2)
plot(t1,x)
subplot(3,1,3)
t2=0:0.1:20;
plot(t2,x)
INLAB REPORT:
Print the three subplots and explain the difference between the three signals represented.
Write Matlab command(s) that would print the graph of sin(t) for the values of t on the
interval [3.5,4.5]. (Pick a suitable increment for t.)
1. Z 2π
sin2 (7t)dt (1)
0
2. Z 1
et dt (2)
0
INLAB REPORT:
Hand in your calculations of these two integrals. Show all work.
func(t)
N
1 2 ..
t
0 ∆t N∆t
Next write an m-file script that evaluates I(N) for 1 ≤ N ≤ 100, stores the result in a
vector and plots 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 Section 4.3. Explain why I(7) = I(14) = 0.
Digital signal processing is widely used in speech processing for applications ranging from
speech compression and transmission, to speech recognition and speaker identification. This
exercise will introduce the process of reading and manipulating a speech signal.
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.
Purdue University: ECE438 - Digital Signal Processing with Applications 8
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 workstation with the Matlab
sound function.
INLAB REPORT:
Submit your plot of the speech signal.
6 Special Functions
Plot the following two continuous-time functions over the specified intervals. Write separate
script files if you prefer. Use the subplot command to put both plots in a single figure, and
be sure to label the time axes.
(
sin πt
, t 6= 0
• πt for t ∈ [−10π, 10π]
1. t=0
Hint: The function rect(t) may be computed in Matlab by using a Boolean expres-
sion. 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.
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 values of time indices.
INLAB REPORT:
Submit all three figures, for a total of 8 plots. Also submit the printouts of your Matlab
.m-files.
Purdue University: ECE438 - Digital Signal Processing with Applications 9
7 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 sam-
pling this signal with a period of Ts . In this case,
x(n) = f (Ts n) = sin(2πTs n) .
Use the stem command to plot the function f (Ts n) 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 hardcopy 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?
8 2-D Signals
So far we have only considered 1-D signals such as speech signals. However, 2-D signals are
also very important in digital signal processing. For example, the elevation at each point on
a map, or the color at each point on a photograph are examples of important 2-D signals.
As in the 1-D case, we may distinguish between continuous-space and discrete-space signals.
However in this section, we will restrict attention to discrete-space 2-D signals.
When working with 2-D signals, we may choose to visualize them as images or as 2-D
surfaces in a 3-D space. To demonstrate the differences between these two approaches, we
will use two different display techniques in Matlab. Do the following:
3. Display the signal as an image. Use the command colormap(gray(256)) just after
issuing the image command to obtain a grayscale image. Read the help on image
for more information.
INLAB REPORT:
Hand in hardcopies of your mesh plot and image. For which applications do you think the
surface plot works better? When would you prefer the image?
The objective of this section is to show how to recover a signal from noisy observations
of that signal.
Generate one 100x100 image with a 10x10 white square in the middle (pixel value 110)
on a black background (pixel value 100). Add a random number to each pixel value of the
image. The random number for each pixel should be generated independently following a
uniform distribution on the interval [−100, 100]. Use the Matlab command rand to generate
these random numbers. Hint: While the command rand generates a sample of a uniform
random variable on the interval [0,1], the command rand-3 will generate a sample from
uniform random variable on the interval [-3,-2], and the command 7*rand will generate a
sample from uniform random variable on the interval [0,7].
Having added a random number to each pixel of the square image, you have created a
“noisy observation” of the square image. Display the resulting 2D signal (the noisy obser-
vation) as an image using the command imshow (e.g., imshow(X, [])). Can you distinguish
the square in the center of the noisy image?
Repeat this procedure to generate 99 additional (different) noisy observations of the
image of the square. Can you distinguish the square in any of these noisy images?
Obtain a new image by averaging the pixel values of each of these 100 images. Plot the
resulting new image. Can you distinguish the square in the center of the new image?