Discrete-Time Simulation With Simulink: ECE4560: Digital Control Laboratory
Discrete-Time Simulation With Simulink: ECE4560: Digital Control Laboratory
1–1
1.1 INTRODUCTION
A fundamental aspect of digital control systems is that they operate in discrete time rather than continuous time. In
this lab period you will discover how to implement and simulate discrete-time systems in Simulink. This will be
important as the semester progresses since you will use Simulink to control the Lab’s Magnetic Levitation (MagLev)
systems using digital control methods.
• Orientation: A quick overview of the syllabus and expectations for lab reports.
1.3 ORIENTATION
1.3.1 Prerequisites
The prerequisite for this lab is ECE4510: Feedback Control Systems. This is implied by the corequisite ECE4540:
Digital Control Systems. Specifically, the ECE4530: Feedback Control Laboratory is not a prerequisite for this
lab course. However, if you have not taken ECE4530, you will be at a disadvantage. Please read (very carefully)
Apps. A and B. A thorough understanding of the material in App. B is critical.
This lab reader1 contains eleven labs. The first is a Simulink-only lab. The remaining labs are divided up into four
“units”. The first unit focuses on digital design via emulating a continuous-time design; the second unit addresses
digital effects not present in continuous-time design; the third unit concentrates on control design using transfer-
function methods; and the fourth unit looks at state-space models and design. Each lab has a detailed discussion in
this lab reader, and a consistent format is used throughout:
1 The reader has been entered using the L X document processing systemand typeset with LAT X2 on a Pentium class computer running
Y E ε
the Linux operating system. All original diagrams have been created using either xfig or Matlab. Screen shots were made using xv.
The lab reader has been prepared by Dr. Gregory Plett; however, much has been taken from the manual for the Model 730 Magnetic
Levitation unit by Educational Control Products (ECP), http://www.ecpsystems.com, and the manual for the Real Time Linux Target
(RTLT) by Quality Real Time Systems (QRTS), http://www.qrts.com. Text and diagrams have been copied from these manuals.
Scanned photos from the ECP web site have also been included. All are used with permission of ECP and QRTS.
Lab reader prepared by Dr. Gregory L. Plett, ECE Department, University of Colorado at Colorado Springs
ECE4560, Discrete-Time Simulation with Simulink 1–2
Prelab assignment: An assignment which must be completed and turned in before you will be permitted to start
the lab.
Before you enter the laboratory each week, you are expected to thoroughly read and understand the corresponding
lab writeup in this lab reader. Each lab has a prelab assignment. This assignment must be completed and turned in
to the lab instructor before you will be permitted to start the lab. Each of your prelab assignments must contain:
• Answers to the specific questions given in the “Prelab Assignment” portion of the lab reader for that lab,
A portion of your course grade will be assigned based on your prelab assignments. Furthermore, no grade better
than an “F” is possible for any lab report until an approved prelab assignment has been turned in for that lab.
A syllabus of lab topics is listed on the front page of this lab reader. You will see that the semester is divided into
four main units which each contain a number of labs. The report for Lab 1 is due at the beginning of lab period 2; the
reports for Labs 2 and 3 are due at the beginning of lab period 4; the reports for Labs 4–6 are due at the beginning of
lab period 7; the reports for Labs 7–9 are due at the beginning of lab period 10; the reports for Labs 10–11 are due
before the end of finals week.
The Department requires formal lab reports. The format for formal lab reports must comply to the following:
1. Title page: This must include a title, group member names, course and section name and date.
2. Introduction: Explain the background and objective of the lab indicating requirements and desired results.
3. Discussion: Discuss the underlying applicable theory and concepts that support the measurements. Indicate
and discuss the measurement set-up and equipment used.
4. Measurement data and/or Results: Present measurement results in tabular, graphical or numeric form. Present
results from required lab exercises.
5. Discussion of Measurements: Discuss the measurement data in context of comparison to expectation, accu-
racy, difficulties, etc.
6. Summary and Conclusions: Discuss findings, explain errors and unexpected results and summarize and indi-
cate conclusions.
Lab reader prepared by Dr. Gregory L. Plett, ECE Department, University of Colorado at Colorado Springs
ECE4560, Discrete-Time Simulation with Simulink 1–3
1.4 BACKGROUND
Control systems implemented on a digital computer are called digital control systems (tricky, huh?). Digital control
systems differ from their analog counterparts in two important ways.
1. Digital systems operate in discrete time, not continuous time. That is, control computations do not occur
continuously (as they do using op-amps for analog systems), but occur at discrete instants in time. These
instants are usually regular periodic times, separated by the sampling period T [sec]. The sampling operation
introduces artifacts into the signal which are known as signal aliases. It also introduces delay into the closed-
loop system which tends to destabilize the control.
2. Digital systems do not use infinite-precision mathematics. To store the value of a signal—such as a control
signal—in computer memory, the value must be quantized. This means that the value is rounded to the nearest
number which can be stored. The coefficients of the transfer function of the controller must also be quantized.
These are two separate issues: signal quantization and coefficient quantization.
In this lab period you will implement and simulate a discrete-time system in Simulink.
Consider a continuous-time signal x(t). If we look at the signal at discrete points in time that are separated by a
constant sampling period T , then we have the set of values x(kT ) where k is an integer. To simplify notation, we say
that x[k] = x(kT ) where x[k] is a discrete-time signal (denoted using square brackets) and x(t) is a continuous-time
signal (denoted by parentheses). When you read x[k] you should understand that some sampling period T is implied,
which must be somehow specified elsewhere.
The continuous-time systems you have seen are defined by Linear Constant Coefficient Ordinary Differential Equa-
tions (LCCODEs). Linear, time invariant, lumped discrete-time systems may be defined by Linear Constant Coeffi-
cient Difference Equations (LCCDEs). A controller would be implemented with a LCCDE such as:
X n Xm
ai u[k − i] = bi e[k − i],
i=0 i=0
with input e[k] and output u[k] and ai and bi which determine the transfer function of the controller.
An example discrete-time system is a discrete-time integrator. If the sampling period is T , then the output of an
integrator may be approximated by (rectangular rule)
k
X
y[k] = T x[i],
i=0
Pk−1
where y[k] is the output of the integral and x[k] is the input signal. Note: y[k − 1] = T i=0 x[i] so we can write2
y[k] = y[k − 1] + T x[k].
When we consider implementing the above equation, we find that we need two quantities: x[k] and y[k − 1]. The
input to the system is x[k], and y[k − 1] is a delayed version of the system’s output. Therefore, we can implement
the above equation with a feedback loop which has a delay in it.
2 Notice that this is the same as y[k] − y[k − 1] = T x[k], which is of the LCCDE form. However, the form given in the main text is more
useful for us.
Lab reader prepared by Dr. Gregory L. Plett, ECE Department, University of Colorado at Colorado Springs
ECE4560, Discrete-Time Simulation with Simulink 1–4
Simulink has a number of blocks which will aid you in making discrete-time simulations. These are part of the
Discrete-Time Simulink library, and are shown in Fig. 1.1. The two blocks of interest to us now are the “Zero-Order
Hold” and “Unit Delay” blocks. Over the course of the semester, you will learn to use many of the other blocks as
well. The reason for the label 1/z on the unit-delay will also become apparent.
To continue with the integrator example, consider the block diagram in Fig. 3.1 on page 3–2. A source (in this case
a sine wave) generates an input signal x(t). This signal must be sampled to make x[k]. The Simulink block which
does this function is the “Zero-Order Hold” block. The x[k] signal is scaled by T to produce T x[k]. The output of
the integrator is y[k] which is computed as x[k] + y[k − 1]. The final remaining signal y[k − 1] is computed from
y[k] by passing it through a “Unit Delay” block.
The zero-order hold, amplifier and unit delay blocks require the sampling period T . You will find that it is best to
enter these as symbolic T and define the value of T in the Matlab workspace. This allows easy and consistent change
of sampling rate.
1
Sine Wave Zero−Order Gain Scope
y[k−1] z
Hold
Unit Delay
There are no prelab questions for this lab. You are still expected to submit a prelab containing a paragraph describing
what you are supposed to do during the lab, and a paragraph describing expected results.
A “leaky” integrator is defined by the difference equation y[k] = ay[k − 1] + T x[k], where usually 0 ≤ a < 1. The
system is stable, however, for −1 < a < 1.
1. Implement a leaky integrator in Simulink. Plot the step response of the system for a number of values of
0 ≤ a ≤ 1. Also plot the step response of the system for a number of values −1 ≤ a < 0. Use T = 0.1 sec.
Lab reader prepared by Dr. Gregory L. Plett, ECE Department, University of Colorado at Colorado Springs
ECE4560, Discrete-Time Simulation with Simulink 1–5
2. Plot the response of the system with the input being a sine wave and a = 0.9. Use a sine wave of frequency
1 rad/sec. Use sampling periods T = 0.1, 0.5, 1 sec.
1.7 ASSIGNMENT
Include your Simulink diagram and plots in your report. Comment on the shapes of the output curves. What
prominent features do you see? How do you explain them? Your “leaky integrator” also has another name—suggest
what kind of discrete-time filter it is implementing (Hint: It is either a low-pass, band-pass or high-pass filter).
Note: You have the next lab period free; the report for Lab 1 is due at the beginning of the following lab period.
Lab reader prepared by Dr. Gregory L. Plett, ECE Department, University of Colorado at Colorado Springs