ECE438 - Laboratory 2: Discrete-Time Systems
ECE438 - Laboratory 2: Discrete-Time Systems
ECE438 - Laboratory 2:
Discrete-Time Systems
By Prof. Charles Bouman, Prof. Mireille Boutin and Wenwei Zhou
Spring 2017
1 Introduction
A discrete-time system is anything that takes a discrete-time signal as input and generates
a discrete-time signal as output.1 The concept of a system is very general. It may be used
to model the response of an audio equalizer or the performance of the US economy.
In electrical engineering, continuous-time signals are usually processed by electrical cir-
cuits described by differential equations. For example, any circuit of resistors, capacitors and
inductors can be analyzed using mesh analysis to yield a system of differential equations.
The voltages and currents in the circuit may then be computed by solving the equations.
The processing of discrete-time signals is performed by discrete-time systems. Similar
to the continuous-time case, we may represent a discrete-time system either by a set of
difference equations or by a block diagram of its implementation. For example, consider the
following difference equation.
This equation represents a discrete-time system. It operates on the input signal x[n] to
produce the output signal y[n]. This system may also be defined by a system diagram as in
Figure 1.
Mathematically, we use the notation y = S[x] to denote a discrete-time system S with
input signal x[n] and output signal y[n]. Notice that the input and output to the system are
the complete signals for all time n. This is important since the output at a particular time
can be a function of past, present and future values of x[n].
It is usually quite straightforward to write a computer program to implement a discrete-
time system from its difference equation. In fact, programmable computers are one of the
easiest and most cost-effective ways of implementing discrete-time systems.
While Equation (1) is an example of a linear time-invariant system, other discrete-time
systems may be nonlinear and/or time varying. In order to understand discrete-time systems,
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
1
A more general behavioral view of systems is anything that imposes constraints on a set of signals.
Purdue University: ECE438 - Digital Signal Processing with Applications 2
To illustrate how a discrete-time system can be derived from the corresponding continuous-
time system, we will show how the above two continuous-time systems can be formulated
into corresponding discrete-time systems.
Z nT
y(nT ) = x(τ )dτ
−∞
Z (n−1)T Z nT
= x(τ )dτ + x(τ )dτ
−∞ (n−1)T
≈ y ((n − 1)T ) + x(nT ) · T
INLAB REPORT:
i. Draw block diagrams of both the discrete-time differentiator and integrator as in Fig. 1.
ii. Apply both the discrete-time differentiator and integrator to the signal u[n] − u[n −
(N + 1)], with N = 10, for −10 ≤ n ≤ 20. (This assumes a time-step of T = 1)
iii. Use the discrete-time differentiator to numerically evaluate dtd x(t) of x(t) = sin(2πt)
for t ∈ [0, 10], try T = 0.1 and T = 0.001 and compare the results. You can use
SIMULINK if you know how.
3 Difference Equations
In this section, we will study the effect of two discrete-time filters. The first filter, y = S1 [x],
obeys the difference equation
y[n] = x[n] − x[n − 1]
and the second filter, y = S2 [x], obeys the difference equation
1
y[n] = y[n − 1] + x[n]
2
Write Matlab functions to implement each of these filters. Then use these functions to
calculate the impulse response of each of the following 5 systems: S1 , S2 , S1 (S2 ) (i.e., the
series connection with S1 following S2 ), S2 (S1 ) (i.e., the series connection with S2 following
S1 ), and S1 + S2 .
Note: In Matlab, when implementing a difference equation using a loop structure, it is
very good practice to pre-define your output vector before entering into the loop. Otherwise,
Purdue University: ECE438 - Digital Signal Processing with Applications 4
Matlab has to resize the output vector at each iteration. For example, say you are using a
FOR loop to filter the signal x[n], yielding an output y[n]. You can pre-define the output
vector by issuing the command y = zeros(1,N) before entering the loop, where N is the
final length of y. For long signals, this speeds up the computation dramatically.
INLAB REPORT:
For each of the five systems, draw and submit a system diagram (use only delays, multi-
plications and additions as in Fig. 1). Also submit plots of each impulse response. Discuss
your observations.
Download music.au
https://engineering.purdue.edu/VISE/ee438L/lab2/data/music.zip
How to play audio signals
https://engineering.purdue.edu/VISE/ee438L/matlab/help/pdf/audio.pdf
Download the audio file music.au. Use the command auread to load the file into Matlab.
Then use the Matlab function sound to listen to the signal.
Next filter the audio signal with each of the two systems S1 and S2 . Listen to the two
filtered signals.
INLAB REPORT:
How do the filters change the sound of the audio signals? Explain your observations.
4 Inverse Systems
Consider the system y = S2 [x] from Section 3. Find a difference equation for a new system
y = S3 [x] such that δ = S3 [S2 [δ]] where δ denotes the discrete-time impulse function δ(n).
Since both systems S2 and S3 are LTI, the time-invariance and superposition properties can
be used to obtain x = S3 [S2 [x]] for any discrete-time signal x. We say that the systems S3
and S2 are inverse filters because they cancel out the effects of each other.
Hint: The system y = S3 [x] can be described by the difference equation
INLAB REPORT:
Draw a system diagram for the system S3 , and submit plots of the impulse responses for S3
and S3 (S2 ).
Purdue University: ECE438 - Digital Signal Processing with Applications 5
5 System Tests
Download bbox.zip
https://www.projectrhea.org/rhea/images/e/e9/Bbox.zip
INLAB REPORT:
process voltage and current signals, a computer can process discrete-time signals which are
essentially just sequences of numbers. Therefore DSP may be used in a very wide range of
applications. Let’s look at an example.
A stockbroker wants to see whether the average value of a certain stock is increasing or
decreasing. To do this, the daily fluctuations of the stock values must be eliminated. A
popular business magazine recommends three possible methods for computing this average.
1
averagevalue(today) = (value(today)+value(yesterday)+value(2 days ago)) (5)
3
averagevalue(today) = 0.6 ∗ averagevalue(yesterday) + 0.4 ∗ (value(today)) (6)
1
averagevalue(today) = averagevalue(yesterday) + (value(today) - value(3 days ago)) (7)
3
INLAB REPORT:
• For each of these three methods, 1) write a difference equation, 2) draw a system
diagram, and 3) calculate the impulse response.
• Explain why methods (5) and (7) are known as moving averages.
6.2 Application
Download stockrates.mat
https://engineering.purdue.edu/VISE/ee438L/lab2/data/stockrates.zip
Help on loading Matlab files
https://engineering.purdue.edu/VISE/ee438L/matlab/help/pdf/load.pdf
Load the file stockrates.mat into Matlab. This file contains a vector, called rate, of daily
stock market exchange rates for a publicly traded stock.
Apply Filters (6) and (7) from Section 6 of the background exercises to smooth the
stock values. When you apply Filter (6) you will need to initialize the value of aver-
agevalue(yesterday). Use an initial value of 0. Similarly, in Filter (7), set the initial values
of the value vector to 0 (for the days prior to the start of data collection). Use the subplot
command to plot the original stock values, the result of filtering with (6), and the result of
filtering with (7).
INLAB REPORT:
Submit your plots of the original and filtered exchange-rates. Discuss the advantages and
disadvantages of the two filters. Can you suggest a better method for initializing the filter
outputs?