Control System Lab Exercise PDF
Control System Lab Exercise PDF
Control in Matlab
This exercise is intended to give a basic introduction to Matlab. The main focus will
be on the use of Control Systems Toolbox for control system analysis and design.
This toolbox will be used extensively during the upcoming exercises and laboratories
in the course. A short Matlab reference guide and a guide to the most commonly
used commands from Control Systems Toolbox can be found at the end of this
exercise.
Getting started
Matlab is started by issuing the command
> matlab
which will bring up a Java-based interface with three different frames showing the
current directory, your defined variables, and the Matlab command window. This
gives a good overview, but may be slow.
An alternative way to start Matlab is by the command
which will only open up the command window. You can then use the commands ls
and whos to examine the current directory and your defined Matlab variables.
All Matlab commands have a help text, which is displayed by typing
>> A = [1 2;3 4]
A =
1 2
3 4
with semi-colons being used to separate the lines of the matrix. The transpose of a
matrix is written as
>> A’
ans =
1 3
2 4
1
Exercise 1
Enter the system matrices A, B, and C in Matlab and use the command
eig to determine the poles of the system.
In Control System Toolbox, the basic data structure is the linear time-invariant
(LTI) model. There is a number of ways to create, manipulate and analyze models
(type, e.g., help ltimodels). Some operations are best done on the LTI system, and
others directly on the matrices of the model.
1.2 Define an LTI model of the pendulum system with the command ss. Use
the command tf to determine the transfer function of the system.
1.3 Zeros, poles and stationary gain of an LTI model is computed with the
command zpkdata. Use this command on the inverted pendulum model.
Compare with 1.1.
The command tf is used to create an LTI model from a transfer function. This is
done by specifying the coefficients of the numerator and denominator polynomials,
e.g.
Another convenient way to create transfer function models is by the following com-
mands
>> s = tf(’s’);
>> P = 1 / (2*s + 1);
To specify a time delay, set the property InputDelay of the LTI model
To display all properties of an LTI model and their respective values, type
>> get(P)
and use the commands step, nyquist, and bode to plot time- and frequency
responses of the system. Is the system stable? Will the closed-loop system
be stable if unit gain negative feedback is applied?
2
Exercise 1
s2 + 1.4s + 1 = 0
1.5 Is the system controllable? Use the command ctrb to compute the controlla-
bility matrix. Then use the command place to determine the state-feedback
vector L.
Connecting systems
LTI systems can be interconnected in a number of ways. For example, you may
add and multiply systems (or constants) to achieve parallel and series connections,
respectively. Assume that the system (1.2) without time delay is controlled by a PD
controller, C(s) = K (1 + sTd ), with K = 0.5 and Td = 4, according to the standard
block diagram to the left in Figure 1.1:
l
uc u y +
Σ C(s) Σ P(s) Σ SYS1
–
−1 SYS2
1.6 Define an LTI model of the controller, C(s). Compute the amplitude margin
and phase margin for the loop transfer function. Use the Matlab command
margin.
There is a function feedback for constructing feedback systems. The block diagram
to the right in Figure 1.1 is obtained by the call feedback(SYS1,SYS2). Note the
sign conventions. To find the transfer function from the set point uc to the output
y, you identify that SYS1 is P(s) C(s) and SYS2 is 1.
1.7 Compute the transfer function for the closed-loop system, both using the
feedback command and by direct computation (use minreal to simplify)
according to the formula
P(s) C(s)
Gcl (s) =
1 + P(s) C(s)
1.8 Plot the step response of the closed-loop system. What is the stationary gain
from uc to y?
3
Exercise 1
1.9 The systems you have seen so far have been SISO (Single-Input, Single-
Output) systems. In this course we will also work with MIMO (Multiple-
Input, Multiple-Output) systems. This problem gives you an example of a
MIMO system.
A rough model for the pitch dynamics of a JAS 39 Gripen is given by
−1 1 0 −1/2 0 0 0
4 −1 0 −25 8
3/2 1/2
ẋ =
0 1 0 0 0
x +
0 0
u
0 0 0 −20 0
20 0
(1.3)
0 0 0 0 −20 0 20
0 1 0 0 0
y= x
0 0 1 0 0
Enter this system into Matlab using the ss command and determine if the
system is stable/controllable/observable? What is your conclusion from this
analysis?
Can you find the transfer function from the second input (the elevator rud-
der command) to the first output (the pitch rate)?
1
G1 (s) =
s3 + 3s2 + 3s + 1
1
G2 (s) =
(s + 1)3
During calculations, numerical round-off errors can arise, which can lead
to changed dynamics of the system. Calculate the poles of the following
systems where one coefficient has been modified.
1
G3 (s) =
s3 + 2.99s2 + 3s + 1
1
G4 (s) =
(s + 0.99)3
In view of your results on the poles of the four systems G1 (s) to G4 (s),
discuss which format that is numerically the best.
4
Exercise 1
1.12 (*) Given a mass-spring system in state-space form without a damper with
m = 0.5 kg and k = 10 N/m, compute the transfer function of the system
using the commands ss and zpk. Design a PID controller such that the
closed loop system gets the characteristic equation
s3 + s2 (2ζ ω + ω ) + s(ω 2 + 2ζ ω 2 ) + ω 3 = 0
dx 0 1 0
= x(t) +
u(t)
dt − k/m 0 1/m (1.5)
y(t) = 1 0 x(t)
3−s
P(s) =
(s + 1)(s + 2)
s2 + 5.6s + 16 = 0
Simulate a step response of the closed-loop system. What is the static gain?
What is the system called when the step response starts “in the wrong
direction”? How can we directly see this property in the transfer function
of the process?
5
Exercise 1
Matrix commands
1 2
[ 1 2; 3 4] create the matrix
.
3 4
zeros(n) creates an nxn matrix whose elements are zero.
zeros(m,n) creates a m-row, n-column matrix of zeros.
ones(n) creates a n x n square matrix whose elements are 1’s
ones(m,n) creates a mxn matrix whose elements are 1’s.
ones(A) creates an m x n matrix of 1’s, where m and n are based on the
size of an existing matrix, A.
zeros(A) creates an mxn matrix of 0’s, where m and n are based on the
size of the existing matrix, A.
eye(n) creates the nxn identity matrix with 1’s on the diagonal.
A’ (complex conjugate) transpose of A
diag(V) creates a matrix with the elements of V on the diagonal.
blkdiag(A,B,C) creates block matrix with the matrices A, B, and C on the di-
agonal
6
Exercise 1
Plotting commands
plot(x,y) creates an Cartesian plot of the vectors x & y.
stairs(x,y) creates a stairstep of the vectors x & y.
semilogx(x,y) plots log(x) vs y.
semilogy(x,y) plots x vs log(y)
loglog(x,y) plots log(x) vs log(y).
grid creates a grid on the graphics plot.
title(’text’) places a title at top of graphics plot.
xlabel(’text’) writes ’text’ beneath the x-axis of a plot.
ylabel(’text’) writes ’text’ beside the y-axis of a plot.
gtext(’text’) writes text according to placement of mouse
hold on maintains the current plot in the graphics window while
executing subsequent plotting commands.
hold off turns off the ’hold on’ option.
print filename -dps writes the contents of current graphics to ’filename’ in
postscript format.
Misc. commands
length(x) returns the number elements in a vector.
size(x) returns the size m(rows) and n(columns) of matrix x.
rand returns a random number between 0 and 1.
randn returns a random number selected from a normal
distribution with a mean of 0 and variance of 1.
rand(A) returns a matrix of size A of random numbers.
fliplr(x) reverses the order of a vector. If x is a matrix,
this reverse the order of the columns in the matrix.
flipud(x) reverses the order of a matrix in the sense of
exchanging or reversing the order of the matrix
rows. This will not reverse a row vector!
reshape(A,m,n) reshapes the matrix A into an mxn matrix
from element (1,1) working column-wise.
squeeze(A) remove empty dimensions from A
A.x access element x in the struct A
7
Exercise 1
Sampling of systems.
c2d - Continuous to discrete conversion.
d2c - Discrete to continuous conversion.
Model dynamics.
pole, eig - System poles.
zero - System zeros.
pzmap - Pole-zero map.
covar - Covariance of response to white noise.
State-space models.
ss2ss - State coordinate transformation.
canon - State-space canonical forms.
ctrb, obsv - Controllability and observability matrices.
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.
Frequency response.
bode - Bode plot of the frequency response.
margin - Bode plot with phase and gain margins.
sigma - Singular value plot.
nyquist - Nyquist plot.
nichols - Nichols plot.
ltiview - Response analysis GUI.
ctrlpref - Open GUI for setting Control System Toolbox Preferences.
System interconnections.
+ and - - Add and subtract systems (parallel connection).
* - Multiplication of systems (series connection).
/ and \ - Division of systems (right and left, respectively).
inv - Inverse of a system.
[ ] - Horizontal/vertical concatenation of systems.
feedback - Feedback connection of two systems.
8
Exercise 2. System Representations and
Stability
ẋ1 = −2x1 + x2 + u1
ẋ2 = −3x2 + u1 + 2u2
y1 = x1 + x2
y2 = 2x1 + u1
y3 = 2x2 + u2
2.2 A system with two inputs and one output is modeled by a differential equa-
tion:
ÿ + a1 ẏ + a2 y = b11 u̇1 + b12 u1 + b21 u̇2 + b22 u2 .
Also, if u(t) = r(t) − y(t), find the closed-loop transfer function Gc (s) such
that
9
Exercise 2
d v
s+1 1
r + 1.4 + + y
s (s + 1)2
C(s) P(s)
+ n
−1
1
10
Magnitude (abs)
0
10
−1
10
−2
10
−1 0 1
10 10 10
1
10
Magnitude (abs)
0
10
−1
10
−2
10
−1 0 1
10 10 10
Frequency (rad/sec)
Figure 2.2
b. Figure 2.2 shows gain curves for the sensitivity function and the comple-
mentary sensitivity function. Which curve represents which function?
2.5 Study the feedback control system in Figure 6.5, where the process, P(s),
is given by
1
P(s) =
(s + 1)(s + 2)
s+1 s + 1 −0.1s
C1 (s) = 10 C2 (s) = 10 C3 (s) = 10 e
s s
10
Exercise 2
d v
r + C(s) + P(s) + y
+ n
−1
Bode Diagram
0
10
−1
10
Magnitude (abs)
−2
10
−3
10
−4
10
0
−45
Phase (deg)
−90
−135
−180
−2 −1 0 1 2
10 10 10 10 10
Frequency (rad/sec)
2.6 Consider a water tank with a separating wall. The wall has a hole at the
bottom, as can be seen in figure 2.7.
The input signals are the inflows of water to the left, u1 , and the right, u2 ,
halves of the tank, measured in cm3 /s. The water levels are denoted by h1
cm and h2 cm, respectively. The outflow y cm3 /s is considered proportional
to the water level in the right half of the tank:
y(t) = α h2 (t)
11
Exercise 2
Bode Diagram
A B C
1
10
Magnitude (abs)
0
10
−1
10 −1 0 1 2 −1 0 1 2 −1 0 1 2
10 10 10 1010 10 10 1010 10 10 10
Frequency (rad/sec)
Step Response
I II III
1.2
0.8
0.6
0.4
Output
0.2
−0.2
−0.4
−0.6
−0.8
0 5 10 0 5 10 0 5 10
Time (sec)
The flow between the tank halves is proportional to the difference in level:
d. It turns out that the L2 -gain is larger than one. How is this possible? Can
there be more water coming out from the tank than what is poured into it?
Have we invented a water-producing device? Explain what’s wrong here!
12
Exercise 2
Figure 2.7
1
Y (s) = U (s) m>0
ms2 + 2s
This problem is about investigating for what values of the mass m the
closed loop system is stable, using the Nyquist criterion. Before we can do
that however, we need to write the system in another form.
a. Find the characteristic polynomial of the closed-loop system. Show that the
same characteristic polynomial can be generated by a feedback loop between
Q ( s)
some system P(s) and d where m = d + 1. See figure 2.8. Determine Q(s)
and P(s) so that they are not dependent on d.
Q(s)
r + d y
P(s)
−1
( s)
b. Use the Nyquist criterion on QP ( s)
to determine the values of d (and hence
m) for which the closed-loop system is stable. Use Matlab.
13
Exercise 2
d. Suppose that the servo instead has some unmodeled dynamics ∆(s)
1
Y (s) = (1 + s∆(s)) U (s)
s2 + 2s
Rewrite the closed-loop system as a feedback loop between ∆(s) and a trans-
fer function H (s). Determine a number γ such that the small gain theorem
guarantees stability for all ∆(s) with q∆q∞ < γ .
14
Exercise 3. Disturbance Models and
Robustness
3.1 a. Analyze the stability of the system to the left in Figure 3.1 using the small
gain theorem.
b. Analyze how the stability of the system to the right in Figure 3.1 depends
on the feedback gain K . If you get different results from a, explain why!
1 1
Σ s+ 1 Σ s+ 1
∆ −K
a) b)
Figure 3.1
v n s
∆
s+2
2s + 2 1
+
s (s + 1)2
C(s) P(s)
−1
b. How large is the gain q Gvn q∞ ? Support the solution by a Matlab plot.
c. Using the small gain theorem, find the largest possible L2 -gain of ∆ for
which the closed loop system is stable.
d. The ∆ block is used to account for uncertainty in the process model. Explain
the role of the factor s+s 2 multiplying ∆ .
a. Compute the poles of the closed loop system. You may use Matlab.
15
Exercise 3
d v
0.81s + 3.6 1
r + + + y
0.225s (s + 2)
C(s) P(s)
+ n
−1
v n s
∆
s+1
0.81s + 3.6 1
+
0.225s (s + 2)
C(s) P(s)
−1
a. What is the largest possible bound on the L2 -gain of ∆ , for which the closed
loop system is stable, by the small gain theorem? Support the solution by
a Matlab plot.
c. What is the difference between the uncertainty model in this problem and
the one in problem 3.2?
16
Exercise 3
a.
a2
Φ u (ω ) =
ω 2 + a2
b.
a2 b2
Φ u (ω ) =
(ω 2 + a2 )(ω 2 + b2 )
f = k1 ⋅ ż + v,
where v are random variations due to wind and pressure changes. Combin-
ing this with Newton’s second law, m z̈ = u − f , where m is the mass of the
missile, gives the input-output relation
k1 1
z̈ + ż = (u − v).
m m
1
Φ v(ω ) = k0 ⋅
ω 2 + a2
Expand your state-space description so that the disturbance input can be
expressed as white noise. What is the new input-output relation?
ω2
Φ n (ω ) = 0.1 .
ω 2 + b2
1
Φ n (ω ) = 0.1 .
ω2 + b2
17
Exercise 3
ẋ = Ax + Bu + Nw
y = Cx + n
3.9 (*) Consider a swing (swe: gunga) that is hanging outside in the wind. The
swing is described by the transfer function
1
Y (s) = U (s)
s2 +s+1
where the output signal y(t) is the angle of the swing (relative to the vertical
axis) and the input signal u(t) is the moment around the pivotal point. The
influence of wind can be described as
u(t) = K v(t)
2α
Φ v(ω ) = , α > 0.
α2 +ω2
K is a measure of the wind strength and α is a measure of the occurrence
of wind gusts (swe: vindbyar).
a. Does α increase or decrease when there are more wind gusts (i.e., when
the wind changes strength and direction more often)?
1
G (s) =
s(s + 1)
18
Exercise 3
In both cases, ẇ(t) = v(t), where v(t) is a unit disturbance, e.g. an impulse.
b. Put both cases in state-space form. It is assumed in the second case that
the disturbance does not give cause to any common states with the engine.
19
Exercise 4. Loop Shaping
Exercises 4.1–4.4 are preparatory exercises for laboratory exercise 1. In these exer-
cises, we will design a controller, step by step, for the process given by the transfer
function
1
P(s) = 2
s + 0.7s + 1
4.1 Create a transfer function object in Matlab, and take a look at the Bode and
Nyquist diagrams of the process. In the following exercises you will use a
number of different controllers to shape the Bode diagram of the open loop
system.
The structure of the control system is given in Figure 4.1. As you may have
already heard, several transfer functions should be studied in a design.
Besides a nice step response from r to y, also a fast recovery from, e.g., load
disturbances, d is required. Furthermore, it is important to see how the
control signal responds to the different input signals.
d n
r u y
F (s) + C(s) + P(s) +
−1
Figure 4.1 Our control loop with reference signal r, load disturbance d, measurement noise
n and output y.
a. We will first try to control the system using a simple P-controller. Simulate
load step responses for K =0.1, 1.0, 5.0, 10.0. Does the output go to zero?
How much stationary error is left for different K ’s?
Tip: Use the Matlab command figure(n) to draw several plots. E.g:
>> figure(1)
>> bode(P*C, P) % Plot both the process and the
>> % compensated open loop process
>> figure(2)
>> step(P/(1+C*P)) % Plot step load disturbance
>> figure(3)
>> bode(P/(1+C*P)) % Bode-plot of closed loop from
>> % load disturbance
20
Exercise 4
4.2 To create a more advanced controller, we need to know the effect of adding
additional poles and zeros to the controller, C(s).
a. Let Ca (s) = s/a1+1 . How are the magnitude and the phase affected by a?.
When and why would we add this kind of system to our controller?
s/b+1
b. Let Cb (s) = 1 . Again, how are magnitude and phase affected by b?
When/why would we add this kind of system to our controller?
(s/b + 1)
C(s) = K
(s/a + 1)
for the process P(s), by adding a pole and a zero to the PI-controller in
Problem 4.1. Note that the added compensator will allow you to adjust the
parameters, K and Ti , of the PI-controller.
Requirements:
• The disturbance step response should settle within about 5 seconds.
Specifically, p y(t)p < 4 ⋅ 10−3 for t > 5.
• No more than 20% overshoot in the step response from r to y.
Hints:
• Faster response is often tightly connected to a higher cut-off frequency
ω c.
• Oscillations are due to bad margins (being close to the −1 point in the
Nichols or Nyquist diagrams).
If needed you can add more poles and zeros to your controller, but make
sure that you keep the number of poles at least as many as the zeros. This
will ensure that the system is proper, i.e. is not containing a pure derivative.
21
Exercise 4
4.4
which must be taken into account in the design. This limits how fast we
can change the process.
Simulate the step response. Is the constraint on u(t) satisfied? Improve
G yr (s) by tuning the prefilter F (s) so that the step response behaves nicely.
How should F (s) compensate G yr (s) in the frequency domain?
2.0
Go (s) =
s(s + 0.5)(s + 3)
The closed system has a step response according to Figure 4.2. It is clear
that the system is poorly damped and has a large overshoot. It is, however,
fast enough. Create a lead controller that stabilizes the system by increasing
the phase margin to φ m = 50○ , without changing the cut-off frequency.
(φ m = 50○ gives a relative damping of ζ ( 0.5 which achieves an overshoot
of M ( 17%). The stationary error for the closed system is 0.75 for a ramp-
shaped input signal. The error for a ramp function at the compensated
system must not exceed 1.5.
Step Response
1.6
1.4
1.2
1
Amplitude
0.8
0.6
0.4
0.2
0
0 5 10 15 20 25 30 35 40 45
Time (sec)
Figure 4.2 Step response from the closed servo system in 4.5.
4.6 (*) Consider the control system in Figure 4.1, where the plant is described
by
1
P(s) =
(s + 1)(s + 0.02)
22
Exercise 4
Bode diagram
4
10
P(s)
C(s)
2
P(s)C(s)
Magnitude
10
0
10
−2
10 −3 −2 −1 0 1
10 10 10 10 10
−50
Phase [deg]
−100
−150
−200 −3 −2 −1 0 1
10 10 10 10 10
Frequency [rad/s]
Figure 4.3 The Bode diagrams of P(s), C (s) and the open loop P(s) C (s) when r = 0.02.
• The range [0, ω b ] where you get good disturbance rejection of d is in-
creased.
• The cross-over frequency of the system is still approximately the same.
Exact proofs are not required; some Bode-diagram reasoning will do.
23
Exercise 5. Multivariable Zeros, Singular
Values and Controllability/Observability
a. Show that the system is neither controllable nor observable. Also determine
the uncontrollable and unobservable modes.
b. Determine the transfer function of the system and the order of a minimal
state space realisation. How can this be related to the controllable and
observable states of the system?
5.2 The following model of a heat exchanger was presented in the course book
(see Example 2.2)
−0.21 0.2 0.01 0
ẋ =
x+
u
0.2 −0.21 0 0.01
1 0
y= x,
0 1
where the first state represents the temperature of the cold water and the
second state is the temperature of the warm water.
5.3 (*) In the first exercise session we were given a rough model of the pitch
dynamics of JAS 39 Gripen
−1 1 0 −1/2 0 0 0
4 −1 0 −25 8
3/2 1/2
ẋ =
0 1 0 0 0
x+
0 0
u. (5.1)
0 0 0 −20 0
20 0
0 0 0 0 −20 0 20
Using Matlab:
a. Show that there is no scalar output signal that makes the system observ-
able.
Hint: Use symbolic toolbox to determine a general C matrix and calculate
the observability matrix. For instance, the following lines of Matlab code
may help you:
24
Exercise 5
>> syms c1 c2 c3 c4 c5
>> C = [c1 c2 c3 c4 c5]
>> Wo = ...
5.4 In Figure 5.1 and Figure 5.2 you see an interconnection of two systems P1 =
s+3 s+1
and P2 = . One can notice that after multiplying
s+2 (s + 3)(s + 4)(s − 2)
the two systems we can cancel a pole and a zero in s0 = −3. Usually it
means that the whole system is not observable, or not controllable. Which
of these two situations are depicted in the Figure 5.1 and Figure 5.2?
P1 P2
P2 P1
a. Determine the pole and zero polynomials for this system. What is the least
order needed to realize the system on state space form?
c. Use Matlab to draw a singular value plot for the system. What is the L 2 -gain
of the system?
25
Exercise 5
b. The derived input directions are complex. What does this mean? Explain
why it’s logical that these received input directions are those giving the
smallest and highest system gains respectively for this particular system.
b. For the frequencies ω = 0, 0.1 rad/s, calculate the gains of the system
in the input directions d1 = [0.6713 0.7412]T and d2 = [1 0]T , i.e. the
amplification of the input di ⋅ sin(ω ) by the transfer matrix G (s).
26
Exercise 6. Fundamental Limitations
6.1 Consider the ball in the hoop in Figure 6.1. This process consists of a cylin-
der rotating with the angular velocity ω . Inside the cylinder, a ball is rolling.
The position of the ball is given by the angle θ and the linearized dynamics
can be written as θ¨ + cθ˙ + kθ = ω̇ . Let k = 1 and c = 2.
b. What limitation on the sensitivity function for a stable closed loop system
is imposed by the process zero?
c. What consequence does the process zero have on the static error when a
reference signal r(t), e.g. a step with the magnitude a, is to be followed. Let
the control signal ω (t) be determined from the error signal r(t) − θ (t) via
the controller transfer function C(s). Give a physical interpretation.
b. What consequence does this give for the control error e, in presence of a
sinusoidal measurement disturbance n with frequency ω p?
e. What consequence does this give for the response x, in presence of a sinu-
soidal measurement disturbance n with a frequency ω z?
27
Exercise 6
4
x 10
3
−1
−2
−3
−15 −10 −5 0 5
4
x 10
d n
r e u x y
F Σ C Σ P Σ
−1
6.3 Consider the setup in Figure 6.3 with P(s) = (3 − s)/(s + 1)2
a. Does there exist a stabilizing controller C(s) such that the transfer function
from n to x becomes 5/(s + 5) ? (Note: All transfer functions in the gang of
four must be stable.)
b. Show that the specification
2ω
p S(iω )p ≤ √ ω ∈ IR
ω 2 + 36
is equivalent to
sup p Wa (iω ) S(iω )p ≤ 1
ω
with a = 6 and
s+a
Wa (s) =
2s
Is this specification possible to satisfy ?
c. Use Matlab to find a stabilizing controller C(s) such that
≤ √ 2ω
1
1 + PC ( iω ) for ω ∈ [0, 2]
ω2 + 1
Hint: Use a PI controller on the form:
s/b + 1
C(s) = K
s
28
Exercise 6
1
10
0
10
−1
10
−2
10 −2 −1 0 1 2
10 10 10 10 10
Figure 6.4 Gain specification for the closed-loop transfer function T in problem 6.4.
6.4 For each of the following three design problems, state if it is possible to con-
struct a controller that can achieve the given specification. Motivate your
answers! (Hint: It is not possible in at least two of the cases.)
System: Specification:
e− 2s
P1 (s) = The step response must reach 0.9 before t = 1.
s+2
(s + 40)(s − 20) The gain curve of the closed-loop transfer func-
P2 (s) = 3 tion T should lie between the two gain curves
s2 (s − 10)
depicted in Figure 6.4.
1 The step response must stay in the interval [0, 2]
P3 (s) =
s−3 for all t.
can be used to make sure that the sensitivity is small in a low frequency
range and measurement noise is rejected in a high frequency range.
and n ≥ 8.
Hint: Use the result of a.
29
Exercise 6
d v
r + C(s) + P(s) + y
+ n
−1
c. (*) Give conditions on the open-loop gain p L(iω )p = p P(iω ) C(iω )p that are
sufficient to fulfill these specifications.
d. (*) What cut-off frequency and what phase margin could have been ex-
pected, following your answer in c, if the system had been SISO? What
lower bound on qT q∞ does this give?
6−s
P(s) =
s2 + 5s + 6
Give an upper bound for how fast the closed loop system can be made. That
is, give a value a such that the following specification is impossible to satisfy
if c > a.
2ω
p S(iω )p ≤ √ ω ∈ IR
ω 2 + c2
30
Exercise 7. Controller Structures and
Preparations for Laboratory Exercise 2
7.1 a. Give the definition of RGA for a complex valued, not necessarily square,
matrix A. How do you apply it to a process G (s) and what information can
be extracted in an automatic control perspective?
b. Let 1 10 !
s+ 2 s+ 1
G (s) = .
1 5
s+ 5 s+ 3
Compute RGA( G (0)).
7.3 Figure 7.1 shows the quadruple-tank process that will be used in Lab 2.
The goal is to control the levels in the lower tanks ( y1 , y2 ) using the pumps
(u1 , u2 ). For each tank i = 1 . . . 4, mass balance and Bernoulli’s law give
that
dhi p
Ai = −ai 2hi + qin (7.1)
dt
where Ai is the cross-section of the tank, hi is the water level, ai is the
cross-section of the outlet hole, is the acceleration of gravity, and qin
is the inflow to the tank. The non-linear equation (7.1) can be linearized
around a stationary point (h0i , q0in ), giving the linear equation
s
d ∆ hi
Ai = − ai ∆ hi + ∆ qin (7.2)
dt 2h0i
31
Exercise 7
Tank 3 Tank 4
Tank 1 Tank 2
Pump 1 y1 y2 Pump 2
u1 u2
where ∆ hi = hi − h0i , and ∆ qin = qin − q0in denote deviations around the
stationary point.
The flows from the pumps are divided according to two parameters γ 1 , γ 2 ∈
(0, 1). The flow to Tank 1 is γ 1 k1 u1 and the flow to Tank 4 is (1 − γ 1 ) k1 u1 .
Symmetrically, the flow to Tank 2 is γ 2 k2 u2 and the flow to Tank 3 is
(1 − γ 2 ) k2 u2 .
32
Exercise 7
33
Exercise 7
7.5 (*) In this exercise we will try to design controllers for a 2x2-process, that
is, a process that has 2 inputs and 2 outputs. The process is described by
the transfer function matrix
4 3
!
s+ 1 3s+1
G (s) = 1 2
.
3s+1 s+0.5
In both cases, use ordinary PI-controllers. Use the step responses to evalu-
ate the performance of the loop.
34
Exercise 8. Linear Quadratic Optimal Control
b. Do the design for different R using Matlab when assuming a = 1, and plot
the position of the closed loop pole as a function of R. Conclusion?
Show that
u(t) = − ( 2 −3 ) x(t)
can not be an optimal state feed-back designed using LQ-technique with the
cost function
Z∞
J = ( x T (t) Q1 x(t) + Q2 u2 (t)) dt
0
where Q1 and Q2 are positive definite matrices.
Hint: Look at the Nyquist plot of the loop gain.
35
Exercise 8
Is it possible to find positive definite weights Q1 and Q2 such that the cost
function V (T ) < ∞ as T → ∞?
8.5 We would like to control the following process with linear quadratic optimal
control, that is, LQ-technique.
1 3 1
ẋ(t) = x(t) + u(t)
4 8 0.1
z(t) = ( 0 1 ) x(t)
a. Determine the cost function matrices for the three different cases.
with
1 0
Q1 =
,
Q2 = 0.1
0 0
The stationary gain from reference r(t) to output z(t) should be equal to 1.
36
Exercise 8
1.5 1.5
1 1
A)
B)
0.5 0.5
0 0
0 2 4 6 8 0 10 20 30 40 50
Time (sec) Time (sec)
Step Response Step Response
1.5 1.5
1 1
C)
D)
0.5 0.5
0 0
0 1 2 3 0 2 4 6
Time (sec) Time (sec)
Figure 8.1 Step responses for LQ-control of the system in Problem 8.6 with different
weights on Q1 , Q2 .
c. The four plots in Figure 8.1 show the step responses of the closed loop system
for four different combinations of weights, Q1 , Q2 . Pair the combinations of
weights given below with the step responses in Figure 8.1.
1.
1 0
Q1 =
,
Q2 = 0.01
0 0
2.
1 0
Q1 =
,
Q2 = 1
0 0
3.
1 0
Q1 =
,
Q2 = 1
0 1
4.
1 0
Q1 =
,
Q2 = 1000
0 0
ξ¨ (t) = u(t).
37
Exercise 8
where y = (ξ (t), ξ˙ (t)), i.e., both states are measured. You would like to
design a controller using the criterion
Z ∞
(ξ 2 (t) + η ⋅ u2 (t)) dt
0
b. What are the closed loop poles of the system when using this optimal state
feedback? What happens with the control signal if η is reduced?
38
Exercise 9. Kalman Filtering/LQG
1
G (s) =
s−1
The noise signals vi (t) are white with intensities R i . We are about to inves-
tigate how the optimal Kalman filter depends on the R i ’s.
a. Show that the optimal Kalman filter only depends on the ratio β = R1 / R2 .
b. Find the error dynamics, i.e., the dynamics of the estimation error e(t) =
x(t) − x̂(t).
9.2 A Kalman filter should be designed for the second order system
0 1 1 1
ẋ(t) = x(t) + u(t) + v1 (t)
1 0 0 1
y(t) = ( 1 0 ) x(t) + v2 (t)
1
G (s) =
s+1
The noise signals vi (t) are white with intensities 1. Often, we have load
disturbances acting on the system, hence there is a need for integral action
39
Exercise 9
In order to model the static error in z and y, w(t) should have large low-
frequncy content. To use a Kalman filter to estimate the error, we need to
find a filter H (s) that generates the signal w from a white noise process n
w = H (s)n.
For true integral action we want H (s) = 1/s, but with this model the noise
state will be neither controllable nor stable, and we will not be able to design
an LQG controller for the extended system. To get around this problem, we
replace the pure integrator by a first order system
1
H (s) =
s+δ
ẋ e = A e x e + Beu e + N ev1e
y = Ce x e + v2
z = Me x e
v1
where v1e =
n
b. Design the full LQG-controller in Matlab using the extended model. Be sure
to have small weight on u(t). Why?
c. Examine the Bode plot of the controller. How does the (almost) integral
action in the controller change when changing δ and the noise variance
corresponding to the added state?
1
G (s) =
s(s + 1)
40
Exercise 9
White process noise is active on both states with intensity 1 and with input
vector ( 0.1 0.1 )T . There is also noise on the output with intensity 0.1. Let
the states be x1 = y, x2 = ẏ. This gives the following state space model
0 1 0 0.1
ẋ(t) = x(t) + u(t) + v1 (t)
0 −1 1 0.1
y(t) = ( 1 0 ) x(t) + v2 (t)
| {z }
C
a. How can you change the model such that the LQG-controller will have good
robustness at this frequency (a small complementary sensitivity function)?
Derive this extended model and determine the intensity matrices needed
to solve for the Kalman filter gain.
b. Compute the Kalman filter using lqe in Matlab. Plot the transfer function
from y(t) to ŷ(t) = C x̂(t). Can you see the implication of the noise modelling?
9.5 Consider the problem of estimating the states of a double integrator where
noise with variance 1 effects the input only and we have measurement noise
of variance 1.
41
Exercise 10. LQG and Preparations for
Laboratory Exercise 3
a. Design an LQG controller for the system, assume initially that process
and measurement noise are independent and have intensity 1, and that
we should weight the control signals u and output z exactly the same.
Useful commands: lqry, kalman
b. Using the states x and x̂, write the closed loop system in state-space form
using letters. Use L for state-feedback gain and K for Kalman filter gain.
c. Simulate the system without noise with the initial state x = ( 1 −1 )T . Plot
both process states and estimated states. The Kalman filter begins with its
estimates in 0. Try different noise intensities, any conclusions?
Useful commands: lqgreg, feedback, initial
where the white noise v1 has intensity I. We can only measure x1 , unfortu-
nately with added white noise also of intensity 1. We want to minimize the
cost
Z∞
J= x12 + x22 + u2 dt.
0
Solve the control problem by hand (not using Matlab) and give the controller
on state-space form.
10.3 Do preparatory exercises for Laboratory 3 – Crane with rotating load. The
lab manual is found on the course homepage.
42
Exercise 11. Youla Parametrization and Dead
Time Compensation
11.1 Consider the control system in Figure 11.1, designed around the SISO sys-
tem P0 .
We first want to rewrite the system to the more general form presented in
Figure 11.2. In this figure: w are the external inputs to the system (e.g.
disturbances and reference), z gathers all signals that we are interested in
controlling, u are the control signals from K , and y contains all signals used
by the controller (e.g. reference and measurements).
a. Choose
d x
w=
, z=
n v
P in Figure 11.2 consists of a number of different subsystems as
Pzw Pzu
P=
Pyw Pyu
shows. Derive P and determine Pzw, Pzu , Pyw and Pyu as transfer function
matrices.
b. Call the closed loop system (from w to z) H. Determine this transfer function
matrix and rewrite it in terms of the sensitivity function S and complemen-
tary sensitivity function T. Use the formula H = Pzw + Pzu C(1− Pyu C)−1 Pyw.
Note that we normally have a −1 in the feedback loop. Here it is assumed
that this sign is part of the controller instead, hence the minus sign in
(1 − Pyu C).
11.2 Note: It is recommended that you solve this problem before you start on Ex-
ercise 12.
y u v x
C Σ P0
n
Σ
Figure 11.1 The block diagram of the closed loop system in 11.1.
43
Exercise 11
w z
u P y
noisy
position sensed
d1 position
d2
spring
k
M
force m
u 20kg
1kg
damping
b
Let us consider the physical system shown in Figure 11.3, showing two
masses, lightly coupled through a spring with spring constant k and damp-
ing b. The only sensor signal we have is the noisy measurement d2 + n of
the position, d2 , for the small mass, m. The purpose of the controller is to
make the position of the large mass, d1 , follow a reference input, r, such
that the control error e becomes small. This is in turn weighted against
controller effort in a quadratic cost function (the objective)
Z ∞
J= γ e2 (t) + ρ u2 (t)dt
0
• maximum magnitude of the control signal qu(t)q < umax (the force
acting on the large mass) during a reference step
• step response overshoot, rise time and settling time from r to the po-
sition d1 (performance constraint)
• the maximum norm of the sensitivity function, q S(iω )q∞ ≤ Ms (ro-
bustness constraint)
The system can be described by the equations of motion
44
Exercise 11
ui
r d1
u uo
C Σ Plant d2
n
Σ
Figure 11.4 The block diagram of the closed loop system in 11.2.
ẋ = Ax + Bu
d1 = C1 x
d2 = C2 x
where
−b/ M − k/ M b/ M k/ M
1
0 0 0
A=
b/m k/m −b/m − k/m
0 0 1 0
1/ M
0
B=
0
0
C1 = 0 1 0 0
C2 = 0 0 0 1
Now, consider the problem to set up this system on a form such that we
can optimize over the Q parametrization. Have Figure 11.4 as a reference.
Then, the exogenous signals, w, of the system are
• the reference r,
• the noise input n,
• a loop input ui (used for the robustness constraint).
The exogenous outputs, z, are
45
Exercise 11
• the reference r,
• the noisy measurement d2 + n.
In other words, we have
r d1
r
w=
n , z=
,
uo y=
.
d2 + n
ui e
With these variables, we can rewrite the system on the more general form
shown in Figure 11.2. On state space form, this becomes
ẋ = Ax + Bww + Bu (11.1)
z = Cz x + D zww + D zu u (11.2)
y = Cy x + D yww + D yu u (11.3)
b. On the next exercise session we will use software that solves the minimiza-
tion problem. This software will need to know the general process P, deter-
mined by (11.1)-(11.3), and the element indices of the closed-loop transfer
function H corresponding to the constraints and cost function specified for
the control design problem. For instance, the step response overshoot, rise
time and settling time will correspond to H d1 r which has index (1, 1). De-
termine the rest of these indices.
c. How many inputs and outputs will the Q parametrization filter have?
11.3 Derive a controller using the IMC method on the following system
6 − 3s
P(s) = .
s2 + 5s + 6
Show that the controller has the form of a PID controller and a first order
filter, i.e.
1 1
K 1+ + Td s
Ti s sT + 1
11.4 Processes in industry often have time delays that give phase lags with the
result of limiting the achievable performance, resulting in a fundamental
46
Exercise 11
limitation. Model based control structures that give good performance for
such processes are available. Consider the simple process
1
P(s) = e−4s ,
s+1
which is clearly delay dominant (time delay larger than time constant). Use
IMC to design a delay compensating controller for this process. Draw the
Nyquist diagram for the loop transfer function and conclude if the closed
loop system is stable.
47
Exercise 12. Synthesis by Convex
Optimization
12.1 Note: It is recommended that you do problem 11.2 before you start this exer-
cise session. If you have done 11.2, but don’t remember it, you should read
through the problem text again.
Last exercise session we were introduced to the mass spring system shown
in Figure 11.3. We will now use the general system we derived there in
order to find an optimal controller based on the Q parametrization. The
Matlab tool we will use to find this controller can be found on
http://www.control.lth.se/course/FRTN10/exercises.html
and was developed here at the department. In short, the tool needs the user
to give it the general system, P (see Figure 11.2) and point at the indices
in the closed loop system to which the constraints and objective function
correspond to (this has already been done in advance this time, so you will
not need to worry about it). The user will also need to specify these con-
straints and objective to the tool. The tool then uses the software packages
yalmip and sedumi in order to carry out the optimization of the specified
problem. By editing the m-file called spring_mass_problem.m, you will be
able to modify the given objective and constraints.
In the course we have only worked in continuous time. The Matlab tool
that we will use does however work in discrete time, but could just as well
have been written for continuous time. This exercise have been written such
that you will get as little contact with discrete time as possible. You should
merely look at the discrete time part of the tool as an approximation of
the continuous time system, which is used in order to solve your optimiza-
tion problem numerically. What you may need to know however, is that
the constraints will be divided into a finite number of points. For instance,
the constraints on the signals (in the time domain) are split into 170 time
points with an interval of 0.2 seconds. These constraints will therefore only
be active from 0 to 34 seconds and it is important that this interval has
been chosen to be wide enough for the system. The Ms -constraint, which is
in the frequency domain, has been divided into a fixed number of frequency
points in a similar manner.
a. Go through spring_mass_problem.m and try to understand it. Fill in the
blanks in the program such that:
• You use the system matrices from the previous exercise session.
• The order of the two Q-filters are 10 each.
• The unit step response in d1 from r has a maximum overshoot of 2 %
from the final value.
• The time constant of step response should not be greater than 3.6
seconds.
• The settling time constraints become active after 19 seconds.
• p = 0.8 (gives the decay rate 20 %). p is related to settling time con-
straints by the functions 1 + kpt and 1 − kpt . k is set automatically by
the program to match the overshoot constraint.
48
Exercise 12
os 1+kpt
1
t
1−kp
0.8
0.63
0.6
Magnitude
0.4
0.2
0
0 t1 5 10 15 t2 20 25 30
Time (s)
Figure 12.1 Constraints on the closed loop step response from the reference, r, to the
position of the first mass, d1 . os is the maximum allowed overshoot.
Run the program, with the given setup, and identify which plots corre-
spond to the nominal and optimal controller respectively. What constraints
are active? A constraint is active if the solution touches this constraint in
any points.
c. Plot the Bode diagram of the controller. Can you recognize any resemblance
with any other type of controller? Can you give some intuition to any of the
dips in the magnitude plot?
49
Exercise 12
d. Every time you run the program you should be given some text similar to
this:
Lets not go into detail what all columns stand for, but rather look only at
the feas one. The number you end up with should ideally be 1, or at least
close by, in order for you to have a fully feasible solution (a solution that
satisfies all constraints you have posed). If you end up with a value of −1,
then you can know for sure that your optimization did not succeed. The
higher you have chosen the order of your Q-filters, the more likely it is that
the optimization problem will succeed if there are any feasible solutions to
be found. If we do not find a feasible solution, even though the order of the
Q-filters is large, this tells us that we should try to loosen our constraints
a bit if we want to find a usable controller.
Take your code and decrease NQ=n_q1=n_q2 until your problem is no longer
feasible. What constraint will fail first? What is the least order NQ you need
your Q-filters to have in order to get feasibility?
f. Change the weights on the objective function and see how this alters the
solution. Also play around with the constraints to see if you can achieve an
extremely fast step response. Explain your results.
h. (*) Take a look in the other m-files and see if you can find the closed loop
transfer function matrix (Note: It will be in discrete time). Plot all 9 (Why
9?) Bode diagrams. Point out at least one of these that you would have
wished had a different appearance. How would you have prefered it to look
and why?
50
Exercise 12
i. (*) Change the system and see how this affects the solution. For instance,
you can try to make both k and b small to see if you can make the system
very hard to control with the constraints we have have. Play around with
different constraints, weights on the objective and order of the Q-filters to
see if you can find a decent controller for the new system.
51
Exercise 13. Controller simplification
13.1 Consider a SISO system for which the pole-zero map is given in figure 13.1.
a. Determine the transfer function of the system. You can assume that the
static gain is G (0) = 1.
b. By studying the pole-zero map, it is possible to get a hint that the system
is a candidate for model order reduction. How?
Pole−Zero Map
1.5
1
Imaginary Axis (seconds−1)
0.5
−0.5
−1
−1.5
−1.4 −1.2 −1 −0.8 −0.6 −0.4 −0.2 0
−1
Real Axis (seconds )
13.3 For the same system and notation as in the previous problem, use a com-
puter for the following:
52
Exercise 13
b. Compare the error maxω p G (iω )− G1 (iω )p with the error bound for balanced
truncation.
d. Compare the error maxω p G (iω )− G2 (iω )p with the error bound for balanced
truncation.
2s2 + 2.99s + 1
s(s + 1)2
53
Exercise 14. Old Exam
14.2 A system has the transfer function G (s) = s+1 a , where a > 0. The input to
the system is white noise with spectral density Φ n = 1. What is the spectral
density of the output?
14.3 Steve is working with a process and he wants to design a controller for it.
After identifying the transfer function P(s) he decides to try a PI-controller
CPI (s) = 0.88(1 + 1s ). With the PI-controller, the disturbance response is
very poorly damped, so he adds a lead filter. The controller is now:
1 s/1.79 + 1
C(s) = 0.88 1 + .
s s/8.94 + 1
The bode diagrams of the controller and the loop transfer function can be
seen in Figure 14.1. The disturbance response is still poorly damped. You
realize that Steve has made a serious mistake when calculating his lead
filter parameters.
b. Can you improve the disturbance response by adjusting the lead filter (in-
cluding the gain K )? You have to follow the specifications:
• The cutoff frequency ω c must not change
• The high frequency gain of the controller must not increase
B1 (s)
C1 (s) = .
A1 (s)
a. Let us now consider design of the cart velocity loop with input r and output
y2 . In order to evaluate different control designs, it is useful to analyze
the loop transfer function, Go (s) = C2 (s) G y2 ,m , where G y2 ,m is the transfer
function from m to y2 . Calculate G y2 ,m .
54
Exercise 14
Bode Diagram
2
10
0
10
Magnitude (abs)
−2
10
−4
10
−6
10
90
0
Phase (deg)
PC
−90 C
−180
−270
−1 0 1 2
10 10 10 10
Frequency (rad/sec)
y2
G 2 ( s)
r e m y1
C2 (s) C1 (s) u G 1 ( s)
G ( s)
−1
−1
Figure 14.2 A block diagram for the inverted pendulum control system.
b. What can be said about performance limitations of the closed loop system
from r to y2 ? Notice: You do not have to design any controllers!
c. Figure 14.3 shows four plots, where one of the plots shows the sensitivity
and complementary sensitivity function of a closed loop system discussed
in problem b, with ω 0 = 1 and a particular choise of C2 (s). Which plot?
55
Exercise 14
A B
1 1
10 10
Magnitude (abs)
Magnitude (abs)
0
10
0
10
−1
10
−1 −2
10 10
−1 0 1 −1 1 3
10 10 10 10 10 10
Frequency (rad/sec) Frequency (rad/sec)
C D
1 1
10 10
Magnitude (abs)
Magnitude (abs)
0 0
10 10
−1 −1
10 10
−2 −2
10 10
−1 1 3 −1 1 3
10 10 10 10 10 10
Frequency (rad/sec) Frequency (rad/sec)
Calculate the poles and zeros of G2 (s). Are there any limitations on the
achievable bandwidth?
14.6 Assume that we can model a physical process with the following transfer
function
( s + a) m
G (s) = ,
(s + b)n
where m = 1 < n and a, b > 0. The IMC method was used to find a
controller for this system, namely a PID controller with a lowpass filter
1
(1 + Ti s + Td s)
C(s) = K .
(s TNd + 1)
56
Exercise 14
14.7 Recall the the quadruple tank system that was examined in Laboratory
Exercise 2. The transfer function from the two inputs (u1 , u2 ) to the two
outputs ( y1 , y2 ) was
γ 1 c1 (1 − γ 2 )c1
1 + sT1 (1 + sT1 )(1 + sT3 )
G (s) =
(1 − γ 1 )c2 γ 2 c2
(1 + sT2 )(1 + sT4 ) 1 + sT2
This time we will approach the problem by use of Q-optimization. The ob-
jective will be to keep the control errors ( e1 = r1 − y1 , e2 = r2 − y2 ) low. For
this reason we will choose r1 as well as r2 to be exogenous inputs w (see
Figure 14.4) while e1 and e2 will be our exogenous outputs z. The signals
r1 , r2 , y1 and y2 will all be given to the controller. Hence
y1
r1 − y1 r1
y2
z= w= y=
r2 − y2 r2 r1
r2
y u
- − C(s)
Pzw Pzu
P=
Pyw Pyu
b. Suppose that we want to control the process by selecting input and output
pairs for two SISO loops. How should we pair the input and outputs ?
57
Exercise 14
4.2
G (s) = .
s2 + 0.12s + 1
Four different cost functions have been used and step responses from r to y
have been plotted for performance comparison. However, the plots have not
come in the correct order. Help the designer by pairing the correct weights
below and step responses in Figure 14.5. A cost function might suit several
step responses, give all alternatives! Motivate!
A. Q1 = 1, Q2 = 10 B. Q1 = 1, Q2 = 0.01
C. Q1 = 100, Q2 = 1000 D. Q1 = 1, Q2 = 100
58
Exercise 14
1.5 1.5
Amplitude
Amplitude
1 1
0.5 0.5
0 0
0 2 4 6 8 0 2 4 6 8
Time (sec) Time (sec)
Step response 3 Step response 4
2 1.5
Amplitude
Amplitude
1.5
1
1
0.5
0.5
0 0
0 5 10 15 20 25 0 0.5 1
Time (sec) Time (sec)
59