Continuous & Discreate Control Systems
Continuous & Discreate Control Systems
Control Systems
John Dorsey
Chapter 1
Preliminaries
1.1 Overview
The opening chapter of the book doesn't require the use of Matlab, but we can take a
preliminary look at Matlab and some of its basic commands.
Matlab is, to me, just a versatile, on-line calculator, with some some limited graphical
capabilities that are not user friendly. I use it in preference to a hand held calculator, but if
I want to do some serious number crunching I turn to a real programming language.
Matlab is an interpreted language. That is, it runs along executing each instruction as it
comes to it. In normal use there is no compilation of the code. The latest releases do include
a compiler, however. In normal use, without compilation, `for' loops and `while' loops don't
run extremely fast. However, if we put a semicolon behind each command inside such a loop
things speed up considerably. It is then possible to run simple iterative routines in a couple
of seconds on the current generation of desktop computers. This is plenty fast enough for
the kinds of programs we generally write with Matlab. On average, the specialized programs
you nd in subsequent chapters have fewer than thirty statements. Thus, Matlab serves as
a `quick and dirty' super calculator.
To illustrate the basic commands I will use what I refer to as `in line Matlab dialogues.'
When I type something, Matlab then responds. Hence the dialogue.
To multiply to numbers together we type
EDU>2 * 4
ans =
EDU>
We can assign names to numbers and then compute with them as follows.
2 CHAPTER 1. PRELIMINARIES
EDU>a = 2
a =
EDU>b = 4
b =
EDU>c = a*b
c =
EDU>
EDU>a = [1 2]
a =
1 2
EDU>b = [ 1 ; 2 ]
b =
1
2
EDU>c = a*b
c =
EDU>
Note that the semicolon separates rows in forming the column vector b.
For the two arrays a and b, if we can also type
1.2. THE BASIC COMMANDS 3
EDU>c = b*a
c =
1 2
2 4
EDU>
Matlab also contains all the usual mathematical functions. For instance,
EDU>y = cos(pi)
y =
-1
EDU>x = atan(0.5)
x =
4.636476090008061e-01
EDU>
Note that the angle x is in radians. If we want to plot the function cos t over two periods we
can do so using program chap1cda, repeated below for convenience.
t1 = 0
t2 = 4*pi
x = linspace(t1,t2)
y = cos(x)
plot(x,y)
print -deps cosx.eps
The resulting plot is shown in Figure 1.1
The Matlab command linspace creates 100 equally spaced points between 0 and 4 . If
we want more, or less, than 100 points we can type
linspace(x,y,npts),
where npts is the number of points desired.
We could also generate this plot using the program chap1cdb, repeated below for conve-
nience.
t1 = 0
t2 = 4*pi
npts = 200
t = t1
4 CHAPTER 1. PRELIMINARIES
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 2 4 6 8 10 12 14
dt = (t2 - t1)/npts
for i = 1:npts
y(i) = cos(t);
x(i) = t;
t = t + dt;
end
plot(x,y)
print -deps cosx.eps
The commands inside the `for' loop are terminated with a semicolon. This suppresses Mat-
lab's print function and drastically speeds up the execution of the program.
We have given an idea of how to use Matlab. To see all the possible Matlab commands
pull down the Help menu in the Matlab command window and select Help Window. To see
all the commands in the Control Toolbox type
help control
In the Matlab command window. Matlab will respond with
EDU>help control
Data extraction.
ssdata - Extract state-space matrices.
zpkdata - Extract zero/pole/gain data.
tfdata - Extract numerator(s) and denominator(s).
dssdata - Descriptor version of SSDATA.
get - Access values of LTI model properties.
Model characteristics.
class - Model type ('ss', 'zpk', or 'tf').
size - Input/output dimensions.
isempty - True for empty LTI models.
isct - True for continuous-time models.
isdt - True for discrete-time models.
isproper - True for proper LTI models.
issiso - True for single-input/single-output systems.
isa - Test if LTI model is of given type.
Conversions.
ss - Conversion to state space.
zpk - Conversion to zero/pole/gain.
tf - Conversion to transfer function.
c2d - Continuous to discrete conversion.
d2c - Discrete to continuous conversion.
d2d - Resample discrete system or add input delay(s).
Model dynamics.
pole, eig - System poles.
tzero - System transmission zeros.
6 CHAPTER 1. PRELIMINARIES
State-space models.
rss,drss - Random stable state-space models.
ss2ss - State coordinate transformation.
canon - State-space canonical forms.
ctrb, obsv - Controllability and observability matrices.
gram - Controllability and observability gramians.
ssbal - Diagonal balancing of state-space realizations.
balreal - Gramian-based input/output balancing.
modred - Model state reduction.
minreal - Minimal realization and pole/zero cancellation.
augstate - Augment output by appending states.
Time response.
step - Step response.
impulse - Impulse response.
initial - Response of state-space system with given initial state.
lsim - Response to arbitrary inputs.
ltiview - Response analysis GUI.
gensig - Generate input signal for LSIM.
stepfun - Generate unit-step input.
Frequency response.
bode - Bode plot of the frequency response.
sigma - Singular value frequency plot.
nyquist - Nyquist plot.
nichols - Nichols chart.
ltiview - Response analysis GUI.
evalfr - Evaluate frequency response at given frequency.
freqresp - Frequency response over a frequency grid.
margin - Gain and phase margins.
System interconnections.
append - Group LTI systems by appending inputs and outputs.
parallel - Generalized parallel connection (see also overloaded +).
series - Generalized series connection (see also overloaded *).
feedback - Feedback connection of two systems.
1.2. THE BASIC COMMANDS 7
Demonstrations.
ctrldemo - Introduction to the Control System Toolbox.
jetdemo - Classical design of jet transport yaw damper.
diskdemo - Digital design of hard-disk-drive controller.
milldemo - SISO and MIMO LQG control of steel rolling mill.
kalmdemo - Kalman filter design and simulation.
EDU>
All the commands that we have discussed, plus many, many more are listed. Note that there
are also ve demonstration programs that can be run.
Chapter 2
p s ( ) = s2 + 2s + 1:
( ) = s3 + 2s2 + 3s + 1
q s
by typing
q = [1 2 3 1]
What this would like if you were in the Matlab command window is:
1
2 CHAPTER 2. THE LAPLACE TRANSFORM
EDU>p = [1 2 1]
p =
1 2 1
EDU>q = [1 2 3 1]
q =
1 2 3 1
EDU>r = conv(p,q)
r =
1 4 8 9 5 1
EDU>
Thus
( ) = p(s)q (s) = s5 + 4s4 + 8s3 + 9s2 + 5s + 1:
r s
The roots command can be used to nd the roots of a polynomial. For instance, suppose
we type:
a = [1 2]
b = [1 4]
c = [1 8]
p = conv{a,b}
p = conv(p,c)
roots(p)
What we have done is create the polynomials
s +2 ; s +4 ; and s + 8;
and then multiply them together to create the polynomial p(s). We then use the Matlab
command roots to nd roots nd the roots ( which we already know). If we typed these
commands in the Matlab command window we would get:
EDU>a = [1 2]
a =
1 2
2.1. IMPORTANT COMMANDS 3
EDU>b = [1,4]
b =
1 4
EDU>c = [1,8]
c =
1 8
EDU>p = conv(a,b)
p =
1 6 8
EDU>p= conv(p,c)
p =
1 14 56 64
EDU>roots(p)
ans =
-7.99999999999998
-4.00000000000002
-2.00000000000000
EDU>
Note that we put commas between the entries in `b.' They aren't required, but they
sometimes are helpful. Note also that we have some round-o error when we compute the
roots.
The residue command enables us to quickly nd the residues in a partial fraction ex-
pansion. For instance, suppose we have
10(s + 4)
Y (s) =
s(s + 10)(s + 20)
4 CHAPTER 2. THE LAPLACE TRANSFORM
() =
b s ( + 10)(s + 20);
s s
a =
1 4
EDU>a = 10*a
a =
10 40
EDU>c = [1 0]
c =
1 0
EDU>d = [1 10]
d =
1 10
EDU>e = [1 20]
e =
2.1. IMPORTANT COMMANDS 5
1 20
EDU>b = conv(c,d)
b =
1 10 0
EDU>b = conv(b,e)
b =
1 30 200 0
EDU>[R,P,K] = residue(a,b)
R =
-0.80000000000000
0.60000000000000
0.20000000000000
P =
-20
-10
0
K =
[ ]
EDU>
Thus, the partial fraction expansion is
10(s + 4) 0:2 0:6 0:8
= + :
s(s + 10)(s + 20) s s + 10 s + 20
Chapter 3
1
2 CHAPTER 3. THE TRANSFER FUNCTION
in the approprtiate vectors, then two commands mesh and view are used.
The command mesh draws the three dimensional plot. The command view
determines the angle at which you view the plot. The command has two
arguments, so that when we use it we tupe
view(AZ,EL),
where the rst argument is the azimuth from which the plot is viewed and
second argument is the elevation from which the plot is viewed.
The azimuth and elevation chosen, combined with the order in which
the data was stored in the vectors X, Y, and Z, yields what I consider the
`natural' view of the plot, with values on the x-axis increasing from right
to left and values on the y -axis increasing from front to back. If you don't
view this as `natural,' type:
help view
EDU>a = 10*[1 1]
a =
10 10
EDU>c = [1 0]
c =
1 0
EDU>d = [1 2]
d =
1 2
EDU>e = [1 10]
e =
1 10
EDU>b = conv(c,d)
b =
1 2 0
EDU>b = conv(b,e)
b =
1 12 20 0
EDU>g = tf(a,b)
Transfer function:
10 s + 10
3.1. USEFUL COMMANDS 5
-------------------
s^3 + 12 s^2 + 20 s
Chapter 4
Introducing Feedback
4.1 Useful Commands
Typing
help control
will generate all the commands in the Matlab control tool box. There are a
great many commands. Several that are worth introducing at this juncture
are:
1. pole
2. damp
3. pzmap
4. step
The command \verb+pole+ finds the poles of a transfer function. For instance,
consider the following Matlab dialogue.
EDU>a = [5 1]
a =
5 1
1
2 CHAPTER 4. INTRODUCING FEEDBACK
b =
1 13 44 32
EDU>g = tf(a,b)
Transfer function:
5 s + 1
------------------------
s^3 + 13 s^2 + 44 s + 32
EDU>pole(g)
ans =
-7.999999999999991e+00
-4.000000000000006e+00
-9.999999999999998e-01
EDU>
a =
18
EDU>b = [1 7 24 18]
b =
1 7 24 18
4.1. USEFUL COMMANDS 3
EDU>g = tf(a,b)
Transfer function:
18
-----------------------
s^3 + 7 s^2 + 24 s + 18
EDU>damp(g)
EDU>
Matlab uses the term eigenvalue for poles of the transfer function. We will
encounter the terminology eigenvalue in Chapter 18. when we begin talking
about state models. We will see there that the eigenvalues of a state model
correspond to the poles of a transfer function.
The command pzmap plots the poles of a transfer function. For
18
g = ;
s
3 + 7s2 + 24s + 18
typing
pzmap(g)
yields Figure 4.1
The command step generates the unit step response of a transfer func-
tion. The following Matlab dialogue generates the step response of the sim-
ple transfer function and saves the reponse as an encapsulated postscript
le.
5
G(s) = :
s+ 5
EDU>a = 5
a =
5
4 CHAPTER 4. INTRODUCING FEEDBACK
Pole-zero map
3
1
Imag Axis
-1
-2
-3
-3.5 -3 -2.5 -2 -1.5 -1 -0.5 0
Real Axis
EDU>b = [1 5]
b =
1 5
EDU>g = tf(a,b)
Transfer function:
5
-----
s + 5
EDU>step(g)
EDU>print -deps stepg.eps
EDU>
The response is shown in Figure 4.2
There are many more commands in the Matlab controls toolbox worth
investigating. We will discuss some of these in subsequent chapters, but the
student is encouraged to investigate these commands.
6 CHAPTER 4. INTRODUCING FEEDBACK
Step Response
0.9
0.8
0.7
0.6
Amplitude
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1 1.2
Time (sec.)
1
2 CHAPTER 4. ROOT LOCUS ANALYSIS
1.5
0.5
Imag Axis
-0.5
-1
-1.5
-15 -10 -5 0 5
Real Axis
2
Imag Axis
-2
-4
-6
-8
-18 -16 -14 -12 -10 -8 -6 -4 -2 0
Real Axis
%
a = [1 3]
b = [1 19 18 0]
g = tf(a,b)
%
% generate root locus
%
rlocus(g,gain)
print -deps chap5rla.eps
The command
rlocus(g,gain)
prints an x at each point of the root locus. Figure 4.2 the x's are so close together they form
a thick solid line. We can spread the x's out by plotting fewer points.
We can also write our own root locus program. Suppose for unity feedback we have
and
160(s + 1)2
( )=
Gc s
s(s + 24:71)
Then the Matlab program chap5rl.m listed below will plot the root locus for 0 < K < 160
%Root Locus Program chap5rl.m
gaininc = 0.25
gainmin = 0
gainmax = 160
gain = gainmin;
kount = 1;
while (gain <= gainmax);
a = [1,2,1];
b= [1,12,72];
top = conv(a,b);
c = [1,0];
d = [1,24.71];
e =[1,10,50];
f = [1,2,2];
bot = conv(c,d);
bot = conv(bot,e);
bot = conv(bot,f);
roots(top);
roots(bot);
top = top * gain;
top=[0,0,top];
p= bot + top;
x = roots(p);
a1(kount) = real ( x(1) );
b1(kount) = imag ( x(1) );
c1(kount) = real( x(2) );
d1(kount) = imag ( x(2) );
e1(kount) = real( x(3) );
f1(kount) = imag( x(3) );
g1(kount) = real( x(4) );
h1(kount) = imag( x(4) );
i1(kount) = real( x(5) );
j1(kount) = imag( x(5) );
k1(kount) = real( x(6) );
l1(kount) = imag( x(6) );
gain = gain + gaininc;
kount = kount + 1;
end
save real1.dat a1 -ascii
4.1. USEFUL COMMANDS 5
-2
-4
-6
-8
-25 -20 -15 -10 -5 0
EDU>[K,poles]=rlocfind(g)
Select a point in the graphics window
selected_point =
-6.146464646464647e+00 + 3.820512820512819e+00i
K =
1.167208589859281e+02
poles =
-6.160840653110633e+00 + 3.804837293076535e+00i
-6.160840653110633e+00 - 3.804837293076535e+00i
-6.678318693778726e+00
2
Imag Axis
-2
-4
-6
-8
-18 -16 -14 -12 -10 -8 -6 -4 -2 0
Real Axis
Specifying Performance
6.1 Useful Commands
Some useful commands that we can use with this chapter are
1. damp
2. pole
3. zpk
4. zpkdata
5. tfdata
6. ltiview
The Matlab command damp nds the natural frequency !n and the damping ratio for
all the poles of transfer function. For instance, let
250
Tc(s) =
(s + 4 j 3)(s + 4 + j 3)(s + 10)
The following Matlab dialogue shows how to use zpk and damp.
EDU>g = zpk([],[-4+j*3,-4-j*3,-10],250)
Zero/pole/gain:
250
----------------------
(s+10) (s^2 + 8s + 25)
EDU>damp(g)
1
2 CHAPTER 6. SPECIFYING PERFORMANCE
EDU>
The arguments of the command zpk are:
1. [ ] indicating there are no zeros in the transfer function
2. [-4j*3,-4-j*3,-10]+ dening the poles of the system
3. 250 dening the gain of the system.
The command
damp(g)
6.1. USEFUL COMMANDS 3
The extracts the damping ratio and naturalfrequency of all poles of the system.
The matlab command tfdata returns the zeros, poles and gain of the system. For
instance, for the system we just dened we have
EDU>[Z,P,K] = zpkdata(g,'v')
Z =
P =
-4.000000000000000e+00 + 3.000000000000000e+00i
-4.000000000000000e+00 - 3.000000000000000e+00i
-1.000000000000000e+01
K =
250
EDU>
The Matlab command tfdata works in a similar way, as demonstrated by the following
Matlab dialogue.
EDU>num = 250
num =
250
EDU>p1 = [1 4-j*3]
p1 =
Column 1
1.000000000000000e+00
Column 2
4.000000000000000e+00 - 3.000000000000000e+00i
4 CHAPTER 6. SPECIFYING PERFORMANCE
EDU>p2 = [1 4+j*3]
p2 =
Column 1
1.000000000000000e+00
Column 2
4.000000000000000e+00 + 3.000000000000000e+00i
EDU>p3 = [1 10]
p3 =
1 10
EDU>den = conv(p1,p2)
den =
1 8 25
EDU>den = conv(den,p3)
den =
1 18 105 250
EDU>g1 = tf(num,den)
Transfer function:
250
--------------------------
s^3 + 18 s^2 + 105 s + 250
EDU>[n,d] = tfdata(g1,'v')
n =
0 0 0 250
6.1. USEFUL COMMANDS 5
d =
1 18 105 250
EDU>
One additional command of some use is ltiview. This command opens a graphical user
interface (GUI) window that allows the user to select any system currently dened in the
workspace and make various plots, such as the step response, Bode magnitude and phase
plot, nyquist plots, and so on. At this juncture in the book the only plots that the reader
`oÆcially' knows about are the step and impulse responses. One of the features of this GUI
window is that the reader can select various characterstics of the plot and have them appear
on the plot. Of course, this could be done almost as easily using the command plot, and
each user has to decide which display method is best. It is really a matter of taste. This
command is probably best used in the early stages of a design process to compare two or
three preliminary designs.
Chapter 7
Most of the commands that pertain to root locus design were discussed in Chapters 5 and 6.
One command of great use is the command
feedback.
The following Matlab dialogue shows how it is used.
1
2 CHAPTER 7. ROOT LOCUS DESIGN
EDU>clear all
EDU>g = zpk([-3],[0 -1 -18], 78)
Zero/pole/gain:
78 (s+3)
--------------
s (s+1) (s+18)
EDU>h = 1
h =
EDU>tc = feedback(g,h)
Zero/pole/gain:
78 (s+3)
----------------------
(s+13) (s^2 + 6s + 18)
EDU>step(tc,3)
EDU>print -deps stepresp.eps
The feedback command lets us determine the closed loop transfer function for output
feedback. Here we have chosen unity feedback with the command
h = 1
We can then nd the unit step response, shown in Figure 7.1, with the command
step(tc,3)
One additional command is of some use, namely ltiview. This command opens a graphical
user interface (GUI) window that allows the user to select any system currently dened in
the workspace and make various plots, such as the step response, Bode magnitude and phase
plots, Nyquist plots, and so on. At this juncture in the book the only plots that the reader
`oÆcially' knows about are the step and impulse responses.
One of the features of this GUI window is that the reader can select various characteristics
of the plot and have them appear on the plot. Of course, this could be done almost as easily
using the command plot, and each user has to decide which display method is best. It is
really a matter of taste. This command is probably best used in the early stages of a design
process to compare two or three preliminary designs.
7.1. USEFUL COMMANDS 3
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3
Time (sec.)
Speed Control
8.1 Data Description
All the data les in this chapter are in column form with the rst column
being the time and the second column being the system step respoonse. For
the step responses of the d c motors the armature voltage response is also
given.
The motor data is contained in a folder called Motordata. The data
for transfer function identication in problems 8,9, and 10 is contained in a
folder called xferid. For problems 8,9, and 10, the inputis a unit step.
1
Chapter 9
Frequency Response
9.1 Useful Commands
The disadvantage of this plot is that I would prefer to have the scaling of the magnitude
plot be in increments of 20 dB because in the transfer indentication process we look for
slopes of 20, 40 and 60 db/dec.
We can write our own program to compute the Bode magnitude and phase plots. An
example is program bodeplot.m, listed below for convenience.
1
2 CHAPTER 9. FREQUENCY RESPONSE
Bode Diagrams
100
50
Phase (deg); Magnitude (dB)
-50
-80
-100
-120
-140
-160
-180
-2 -1 0 1 2
10 10 10 10 10
Frequency (rad/sec)
fmin =0.01
fmax = 1000
ftop = log10(fmax)
fbot = log10(fmin)
npts = 100
dw = ( ftop - fbot) / npts
for i = 1:npts
w = fmin*( 10^(i*dw) );
s = j* w;
mag(i) = 20*log10(abs(100*(s + 3)/( s * (s + 10)*(s + 100))));
phase(i) =( atan(w/3)-pi/2 -atan(w/10) -atan(w/100) )*180/pi;
radfreq(i) = w;
end
subplot(2,1,1),semilogx(radfreq,mag)
grid on
axis([0.1 1000 -100 20])
subplot(2,1,2), semilogx(radfreq,phase)
grid on
axis([0.1 1000 -180 0])
print -deps chap9bode2.eps
The result is shown in Figure 9.2 Note we have used the subplot command here to get both
9.1. USEFUL COMMANDS 3
20
-20
-40
-60
-80
-100
-1 0 1 2 3
10 10 10 10 10
-50
-100
-150
-1 0 1 2 3
10 10 10 10 10
1
2 CHAPTER 9. THE NYQUIST CRITERION
Chapter 11
Bode Design
11.1 Useful Commands
We have already discussed the basic command for frequency response analysis, namely bode.
Three other closely related commands are
1. evalfr,
2. freqresp,
3. margin
The rst two are very minor variations of bode. The third is not much more than that, but we
illustrate it with the short Matlab program chap11margin.m, repeated below for convenience.
This program creates the Bode magnitude and phase plots shown in Figure 11.1.
a = 100000*[1 5]
c = [1 0]
d = [1 1]
e = [1 50]
f = [1 100]
b = conv(c,d)
b = conv(b,e)
b = conv(b,f)
g = tf(a,b)
grid on
margin(g)
print -deps chap11mar.eps
As usual Matlab has chosen very inconvenient scaling for the Bode magnitude plot. This
command to me is only of marginal worth, as are evalfr and freqresp.
1
2 CHAPTER 11. BODE DESIGN
Bode Diagrams
50
0
Phase (deg); Magnitude (dB)
-50
-100
-50
-100
-150
-200
-250
-300
-2 -1 0 1 2 3
10 10 10 10 10 10
Frequency (rad/sec)
Robust Control
There is a robust control tool box, but it is devoted to multi-input, multi-output models. A
useful exercise is to write a program to nd the line of closest approach to the point 1 in
the GH -plane.
1
Chapter 13
Position Control
13.1 Impulse Data
The data is stored in column form. The rst column is the time in seconds the second column
the impulse response of the postioning table. The armature voltage is also provided for each
turntable. The lename
ptkixx
is decoded as: postioning table `k' impulse of xx miliseconds. The armature voltage lename
is similar but with the suÆx `av.'
1
Chapter 14
Discrete Systems
14.1 Useful Commands
z =
[ ]
EDU>p = -5
1
2 CHAPTER 14. DISCRETE SYSTEMS
p =
-5
EDU>K = 5
K =
EDU>g = zpk(z,p,K)
Zero/pole/gain:
5
-----
(s+5)
EDU>gz = c2d(g,0.1)
Zero/pole/gain:
0.39347
----------
(z-0.6065)
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5 4
Time (sec.)
Zero/pole/gain:
2
-------
(z+0.5)
Step Response
2.5
1.5
Amplitude
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4
Time (sec.)
EDU>step(gz1,4)
EDU>print -deps dstepgz1.eps
EDU>
Note that we did not have to specify the sampling rate since when we created
gz1 we specied the sampling rate of 10 hz. The step response is shown in
Figure 14.2.
The command bode can be used for discrete systems as well. In the
following Matlab dialogue we nd the frequency response of
0:39347
G(z ) = :
z 0:6065
EDU>bode(gz)
EDU>print -deps dbode.eps
EDU>
The Bode phase and magnitude plots are shown in Figure 14.3 In this par-
14.1. USEFUL COMMANDS 5
Bode Diagrams
-5
Phase (deg); Magnitude (dB)
-10
-15
-50
-100
-150
-200
0 1 2
10 10 10
Frequency (rad/sec)
ticular case the sampling rate is 10 Hz so that the maximum frequency that
can be sampled without aliasing is
Digital Control
15.1 Useful Commands
In Chapter 14 we discussed most of the commands of use in analyzing digital control systems.
The command c2d discussed in chapter 14 has several alternative modes. Two of importance
to us are the bilinear and ad hoc mappings, both of which can be done with c2d. In addition
the commands
1. d2d
2. damp, and
3. filt
4. ltiview
are also of some use.
The command c2d rst discussed in Chapter 14, can be used to determine the bilinear
and ad hoc digital equivalents of continuous transfer functions.
Consider the transfer function
10(s + 2)
G(s) = ;
(s + 1)(s + 4)
discussed in Sections 15.2.3 and 15.2.4 of the text. Then the following Matlab dialogue
creates the equivalent discrete transfer function under the bilinear (Tustin's) mapping.
EDU>g = zpk(-2,[-1 -4],10)
Zero/pole/gain:
10 (s+2)
-----------
(s+1) (s+4)
1
2 CHAPTER 15. DIGITAL CONTROL
EDU>gz = c2d(g,0.1,'tustin')
Zero/pole/gain:
0.43651 (z-0.8182) (z+1)
------------------------
(z-0.9048) (z-0.6667)
EDU>gzah = c2d(g,0.1,'matched')
Zero/pole/gain:
0.86538 (z-0.8187)
---------------------
(z-0.9048) (z-0.6703)
Zero/pole/gain:
0.43651 (z+0.0758) (z-0.9046)
-----------------------------
(z-0.9512) (z-0.8165)
nds the discrete, zero order hold equivalent, and then uses damp to nd !n and .
15.1. USEFUL COMMANDS 3
EDU>gs = zpk([],[-4+j*3,-4-j*3],25)
Zero/pole/gain:
25
---------------
(s^2 + 8s + 25)
EDU>gzc = c2d(gs,0.1,'zoh')
Zero/pole/gain:
0.095495 (z+0.7652)
-----------------------
(z^2 - 1.281z + 0.4493)
The matlab command filt creates a digital lter using the digital signal processing
preference for powers of z 1 . The followng Matlab dialogue creates such a lter.
EDU>a = [1 2 2 1]
a =
1 2 2 1
EDU>b = [1 2 4 2 ]
b =
1 2 4 2
EDU>gdsp = filt(a,b)
Transfer function:
1 + 2 z^-1 + 2 z^-2 + z^-3
----------------------------
1 + 2 z^-1 + 4 z^-2 + 2 z^-3
4 CHAPTER 15. DIGITAL CONTROL
Transfer function:
1 + 2 z^-1 + 2 z^-2 + z^-3
----------------------------
1 + 2 z^-1 + 4 z^-2 + 2 z^-3
The data is stored in column form. The rst column is the time in seconds the second column
the impulse response of the postioning table. The armature voltage is also provided for each
turntable. The lename
ptkixx
is decoded as: postioning table `k' impulse of xx miliseconds. The armature voltage lename
is similar but with the suÆx `av.'
1
Chapter 17
There is not much in the Matlab tool boxes that will help us with a system that has a
transportation lag. You can either use Simulink or one of the two Matlab programs ufeedbak
or ufeedbakd.
The program ufeedbak is an interactive program that requires you to enter the data from
the keyboard. It simulates the response of a continuous system to inputs of the form
( ) = at3 + bt2 + ct + d:
u t
The program ufeedbakd does the same thing for sampled data systems.
If you do not like the interactive nature of these programs, then I encourage you to modify
them to your own satisfaction. The program rwtest.m that uses the data le called data is
short introduction to how to read and write data in Matlab.
1
Chapter 18
Several useful Matlab commands related to the analysis of state models. Five are listed
below.
1. ss,
2. ss2ss,
3. canon
4. eig
5. inv
The Matlab program chap18ss, repeated below for convenience, creates the state space model
called stmod
A = [0 1 0;0 0 1;0 -2 -3]
B = [0;0;1]
C = [1 0 0]
D = 0
stmod = ss(A,B,C,D)
The output generated in the Matlab command window by executing this program is
A =
0 1 0
0 0 1
0 -2 -3
1
2 CHAPTER 18. THE STATE MODEL
B =
0
0
1
C =
1 0 0
D =
a =
x1 x2 x3
x1 0 1.00000 0
x2 0 0 1.00000
x3 0 -2.00000 -3.00000
b =
u1
x1 0
x2 0
x3 1.00000
c =
x1 x2 x3
y1 1.00000 0 0
d =
u1
y1 0
Continuous-time system.
The system stmod can then be used as an argument for many of the Matlab commands
we have already discussed. For instance, the command
18.1. USEFUL COMMANDS 3
Step Response
2.5
1.5
Amplitude
0.5
0
0 1 2 3 4 5 6
Time (sec.)
step(stmod)
creates the step response shown in Figure 18.1
As another example, typing
eig(stmod)
in the command window produces the dialogue
EDU>eig(stmod)
ans =
0
-1
-2
EDU>
Thus the eigenvalues of the plant matrix A are
= 0 : = 1 ; and = 2:
If we type
[T,F] = eig(A)
4 CHAPTER 18. THE STATE MODEL
we obtain
T =
F =
0 0 0
0 -1 0
0 0 -2
If we then type
tinv = inv(T)
we obtain
tinv =
If we next type
cstmod = ss2ss(stmod,tinv)
we obtain
a =
x1 x2 x3
x1 1.82407e-33 -6.40988e-17 1.93816e-16
x2 2.16731e-16 -1.00000 3.05716e-16
x3 0 0 -2.00000
b =
u1
x1 0.50000
x2 1.73205
x3 2.29129
c =
18.1. USEFUL COMMANDS 5
x1 x2 x3
y1 1.00000 -0.57735 0.21822
d =
u1
y1 0
Continuous-time system.
Except for the round o error, we now have the original system stmod in Jordan canonical
form.
We can accomplish the same thing with the canon command. That is, if we type
cstmod = canon(stmod)
we obtain
a =
x1 x2 x3
x1 0 0 0
x2 0 -1.00000 0
x3 0 0 -2.00000
b =
u1
x1 0.50000
x2 1.73205
x3 2.29129
c =
x1 x2 x3
y1 1.00000 -0.57735 0.21822
d =
u1
y1 0
Continuous-time system.
This is the same model, sans the round o error.
Chapter 19
The following commands are of use in studying controllability and observability, and in
converting continuous transfer functions to both continuous and discrete state models.
1. ctrb
2. obsv
The Matlab program dialogue below forms the matrices A and b for the system
x_ ( ) = Ax( ) + b
t t ()
u t ;
and then uses the Matlab commands ctrb and rank to from the controllability matrix and
nd its rank.
EDU>A = [0 1; 0 0]
A =
0 1
0 0
EDU>b = [0;1]
b =
0
1
EDU>co = ctrb(A,b)
1
2 CHAPTER 19. OBSERVABILITY AND CONTROLLABILITY
co =
0 1
1 0
EDU>rank(co)
ans =
EDU>
A
Thus, we see that even though does not have full rank the system is controllable.
A c
The Matlab dialogue below forms the matrices and for the system
x_ ( )
t = Ax( )
t
y (t) = cT x
and then forms the observability matrix and checks its rank.
A = [0 1;-2 -3]
A =
0 1
-2 -3
EDU>c = [0 1]
c =
0 1
EDU>ob = obsv(A,c)
ob =
0 1
-2 -3
EDU>rank(ob)
ans =
19.1. USEFUL COMMANDS 3
EDU>
The command c2d can be useful here in nding the discrete state model equivalent of a
transfer function, or continuous state model. For instance, the following dialogue shows how
we can turn a transfer function rst into a continuous state model and then into the step
invariant discrete state model.
Zero/pole/gain:
2
-------
s (s+2)
EDU>stmod = ss(g)
a =
x1 x2
x1 -2.00000 0
x2 1.00000 0
b =
u1
x1 1.41421
x2 0
c =
x1 x2
y1 0 1.41421
d =
u1
y1 0
Continuous-time system.
EDU>stmodd = c2d(stmod,0.1,'zoh')
a =
4 CHAPTER 19. OBSERVABILITY AND CONTROLLABILITY
x1 x2
x1 0.81873 0
x2 0.09063 1.00000
b =
u1
x1 0.12818
x2 0.00662
c =
x1 x2
y1 0 1.41421
d =
u1
y1 0
The Controller/Observer
I do not nd much in the Matlab control toolbox that will help you with the design of
controller/observers. I have included some programs that I have written to support this
activity. They are a start. They are by no means everything you would want. and that is
intentional. These programs are crude and cumbersome, but with some work you can turn
them into useful tools. The programs that begin with `build' compute the controller/observer
matrices for some useful choices of dominant poles. The programs that begin with `sim' are
simulation routines. These routines are far from perfect, but they work, and by studying
them you should be able to improve them and make them your own. Good Luck.