Topics in Undergraduate Control Systems Designhespanha/published/allugtopics.pdf · Topics in...

137
T U C S D João P. Hespanha March 31, 2014 Disclaimer: This is an early draft and probably contains many typos. Comments and information about typos are welcome. Please contact the author at (hespanha@ece. ucsb.edu). c Copyright to João Hespanha. Please do not distribute this document without the author’s consent.

Transcript of Topics in Undergraduate Control Systems Designhespanha/published/allugtopics.pdf · Topics in...

Topics in UndergraduateControl Systems Design

João P. Hespanha

March 31, 2014

Disclaimer: This is an early draft and probably contains many typos.

Comments and information about typos are welcome. Please contact the author at ([email protected]).

c© Copyright to João Hespanha. Please do not distribute this document without the author’s consent.

Contents

I System Identification 1

1 Computer-Controlled Systems 51.1 Computer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2 Continuous-time Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.3 Discrete-time Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.4 Discrete- vs. Continuous-time Transfer Functions . . . . . . . . . . . . . . . . . . . . 101.5 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.6 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.7 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2 Nonparametric Identification 152.1 Nonparametric Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.2 Time-domain Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.3 Frequency Response Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3 Parametric Identification using Least-squares 233.1 Parametric Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.2 Least-squares Line Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.3 Vector Least-squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4 Parametric Identification of an ARX Model 314.1 ARX Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.2 Identification of an ARX Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.3 Dealing with Known Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

5 Practical Considerations in Parametric Identification 375.1 Choice of Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375.2 Signal Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.3 Choice of Sampling Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.4 Choice of Model Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455.5 Combination of Multiple Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.6 Closed-loop Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.7 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

i

ii João P. Hespanha

II Robust Control 53

6 Robust stability 576.1 Model Uncertainty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576.2 Nyquist Stability Criterion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606.3 Small Gain Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

7 Control design by loop shaping 677.1 The Loop-shaping Design Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677.2 Open-loop vs. closed-loop specifications . . . . . . . . . . . . . . . . . . . . . . . . . 677.3 Open-loop Gain Shaping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

III LQG/LQR Controller Design 75

8 Review of State-space models 798.1 State-space Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798.2 Input-output Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808.3 Realizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818.4 Controllability and Observability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818.5 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828.6 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

9 Linear Quadratic Regulation (LQR) 859.1 Feedback Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859.2 Optimal Regulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869.3 State-Feedback LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879.4 Stability and Robustness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 889.5 Loop-shaping Control using LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909.6 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929.7 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

10 LQG/LQR Output Feedback 9510.1 Output Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9510.2 Full-order Observers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9510.3 LQG Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9610.4 LQG/LQR Output Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9710.5 Separation Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9810.6 Loop-gain Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9810.7 Loop Shaping using LQR/LQG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10010.8 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10010.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

11 Set-point control 10311.1 Nonzero Equilibrium State and Input . . . . . . . . . . . . . . . . . . . . . . . . . . . 10311.2 State feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10411.3 Output feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10511.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10511.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

Control Systems Design iii

IV Nonlinear Control 107

12 Feedback linearization controllers 11312.1 Feedback Linearization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11312.2 Generalized Model for Mechanical Systems . . . . . . . . . . . . . . . . . . . . . . . . 11412.3 Feedback Linearization of Mechanical Systems . . . . . . . . . . . . . . . . . . . . . . 11612.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

13 Lyapunov Stability 11913.1 Lyapunov Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11913.2 Lyapunov Stability Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12113.3 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12213.4 LaSalle’s Invariance Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12213.5 Liénard Equation and Generalizations . . . . . . . . . . . . . . . . . . . . . . . . . . . 12313.6 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12513.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

14 Lyapunov-based Designs 12714.1 Lyapunov-based Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12714.2 Application to Mechanical Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12814.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Attention! When a marginal note finishes with “ p. XXX,” more information about that topic can befound on page XXX.

iv João P. Hespanha

Part I

System Identification

1

Introduction to System Identification

The goal of system identification is to utilize input/output experimental data to determine a system’smodel. For example, one may apply to the system a specific input u, measure the observed discrete-time output y an try to determine the system’s transfer function (cf. Figure 1).

u y?

Figure 1. System identification from input/output experimental data

Pre-requisites

1. Laplace transform, continuous-time transfer functions, stability, and frequency response (brieflyreviewed here).

2. z-transform, discrete-time transfer functions, stability, and impulse/step/frequency responses(briefly reviewed here).

3. Computer-control system design (briefly reviewed here).

4. Familiarity with basic vector and matrix operations.

5. Knowledge of MATLAB R©/Simulink.

Further reading A more extensive coverage of system identification can be found, e.g., in [10].

3

4 João P. Hespanha

Chapter 1

Computer-Controlled Systems

Contents1.1 Computer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2 Continuous-time Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.3 Discrete-time Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.4 Discrete- vs. Continuous-time Transfer Functions . . . . . . . . . . . . . . . . . . . . 101.5 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.6 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.7 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

1.1 Computer ControlFigure 1.1 show the typical block diagram of a control system implemented using a digital computer.Although the output ycptq of most physical systems vary continuously as a function of time, it can

computer process

sample

hold

rptq ucptq ycptqudpkq

ydpkq

Figure 1.1. Computer control architecture. The components in the dashed boxed can be regarded as a discrete-time process to be controlled.

only be measured at discrete time instants. Typically, it is sampled periodically as shown in the leftplot of Figure 1.2. Moreover, the control signal ucptq cannot be changed continuously and typicallyis held constant between sampling times as shown in the right plot of Figure 1.2:

ucptq “ udpkq, @t P rkTs, pk ` 1qTsq.

5

6 João P. Hespanha

Ts

Ts 2Ts 3Ts

ydp1q

ydp2q ydp3qycptq

. . .

Ts

Ts 2Ts 3Ts

udp1q

udp2q udp3q

ucptq

. . .

Figure 1.2. Sampling (left) and holding (right)

It is therefore sometimes convenient to regard the process to be controlled as a discrete-time systemwhose inputs and outputs are the discrete-time signals

ydpkq “ ycpkTsq, udpkq “ ucpkTsq, k P t0, 1, 2, . . . u.

The identification techniques that we will study allow us to estimate the transfer function of thisdiscrete-time system. We can then use standard techniques from digital control to (approximately)recover the underlying continuous-time transfer function. This is discussed in Section 1.4 below.

1.2 Continuous-time Systems

ucptq ycptq

Hcpsq “?

Figure 1.3. Continuous-time system

Consider the continuous-time system in Figure 1.3 and assume that the input and output signalssatisfy the following differential equation:

Notation 1. We denote by 9ycptqand :ycptq the first and sec-ond time derivatives of the signalycptq. Higher-order derivatives oforder k ě 3 are denoted by de-note by ypkqptq.

ypnqc ` βn´1ypn´1qc ` ¨ ¨ ¨ ` β2:yc ` β1 9yc ` β0yc

“ αmupmqc ` αm´1upm´1qc ` ¨ ¨ ¨ ` α2:uc ` α1 9uc ` α0uc. (1.1)

We recall that, given a signal xptq with Laplace transform X psq, the Laplace transform of the `thNote 1. The (unilateral) Laplacetransform of a signal xptq is givenby

Xpsq–ż 8

0e´stxptqdt.

See [5, Appendix A] for a review ofLaplace transforms.

derivative of xptq is given by

s`X psq ´ s`´1xp0q ´ s`´2 9xp0q ´ ¨ ¨ ¨ ´ xp`´1qp0q.

In particular, when x and all its derivatives are zero at time t “ 0, the Laplace transform of the `thderivative xp`qptq simplifies to

s`X psq.

Taking Laplace transforms to both sides of (1.1) and assuming that both y and u are zero at timezero (as well as all their derivatives), we obtain

snYcpsq ` βn´1sn´1Ycpsq ` ¨ ¨ ¨ ` β2s2Ycpsq ` β1sYcpsq ` β0Ycpsq“ αmsmUcpsq ` αm´1sm´1Ucpsq ` ¨ ¨ ¨ ` α2s2Ucpsq ` α1sUcpsq ` α0Ucpsq.

System Identification 7

This leads toMATLAB R© Hint 1.tf(num,den) creates acontinuous-time transfer functionwith numerator and denominatorspecified by num, den. . . p. 12

MATLAB R© Hint 2. zpk(z,p,k)creates a continuous-time transferfunction with zeros, poles, andgain specified by z, p, k. . . p. 12

MATLAB R© Hint 3. pole(sys)and zero(sys) compute thepoles and zeros of a system,respectively.

Ycpsq “ HcpsqUcpsq,

where

Hcpsq–αmsm ` αm´1sm´1 ` ¨ ¨ ¨ ` α1s` α0sn ` βn´1sn´1 ` ¨ ¨ ¨ ` β1s` β0

, (1.2)

the (continuous-time) transfer function of the system. The roots of the denominator are called thepoles of the system and the roots of the numerator are called the zeros of the system.

The system is (BIBO) stable if all poles have negative real part. In this case, for every input

Note 2. Since there are other no-tions of stability, one should usethe term BIBO stable to clarifythat it refers to the property thatBounded-Inputs lead to Bounded-Outputs.

bounded signal ucptq, the output ycptq remains bounded.

1.2.1 Steady-state Response to Sine WavesSuppose that we apply a sinusoidal input with amplitude A and angular frequency ω, given by

Note 3. The angular frequency ωis measured in radian per second,and is related to the (regular) fre-quency f by the formula ω “ 2πf ,where f is given in Hertz or cyclesper second.

ucptq “ A cospωtq, @t ě 0,

to the system (1.1) with transfer function (1.2). Assuming that the system is BIBO stable, thecorresponding output is of the form

ycptq “ gA cospωt ` φqlooooooomooooooon

steady-state

` εptqloomoon

transient

, @t ě 0, (1.3)

where the gain g and the phase φ are given by the following formulas

g– |Hcpjωq|, φ – =Hcpjωq, (1.4)

and εptq is a transient signal that decays to zero at t Ñ8 (cf. Figure 1.4).

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5−1

−0.5

0

0.5

1

t (sec)

u

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5−0.2

−0.1

0

0.1

0.2

t (sec)

y

Figure 1.4. Response to a sinusoidal input with frequency f “ 1Hz, corresponding to ω “ 2π rad/sec. TheBode plot of the system is shown in Figure 1.5.

The Bode plot of a transfer function Hcpsq depictsMATLAB R© Hint 4. bode(sys)draws the Bode plot of the systemsys. . . p. 13

1. the norm of Hcpjωq in decibels [dB], which is given by 20 log10ˇ

ˇHcpjωqˇ

ˇ; and

2. the phase of Hcpjωqboth as a function of the angular frequency ω (in a logarithmic scale). In view of (1.3)–(1.4), theBode plot provides information about how much a sinusoidal signal is amplified and by how much itsphase is changed.

8 João P. Hespanha

−40

−30

−20

−10

0From: u To: y

Mag

nitu

de (

dB)

10−2

10−1

100

101

102

−90

−45

0

Pha

se (

deg)

Bode Diagram

Frequency (rad/sec)

Figure 1.5. Bode plot of a system with transfer function Hcpsq “ 1s`1 .

1.3 Discrete-time Systems

process SHucptq ycptq

udpkq “ ucpkTsq ydpkq “ ycpkTsq

Hcpsq

Hdpzq

Figure 1.6. Discrete-time system

Consider now the discrete-time system in Figure 1.6 and assume that the output can be computedNote 4. Since the output cannotdepend on future inputs, we musthave n ě m for (1.5) to be physi-cally realizable.

recursively by the following difference equation:

ydpk ` nq “ ´βn´1ydpk ` n´ 1q ´ ¨ ¨ ¨ ´ β2ydpk ` 2q ´ β1ydpk ` 1q ´ β0ydpkq` αmudpk ` mq ` αm´1udpk ` m´ 1q ` ¨ ¨ ¨ ` α2udpk ` 2q ` α1udpk ` 1q ` α0udpkq. (1.5)

To obtain an equation that mimics (1.1), we can re-write (1.5) as

ydpk ` nq ` βn´1ydpk ` n´ 1q ` ¨ ¨ ¨ ` β2ydpk ` 2q ` β1ydpk ` 1q ` β0ydpkq“ αmudpk ` mq ` αm´1udpk ` m´ 1q ` ¨ ¨ ¨ ` α2udpk ` 2q ` α1udpk ` 1q ` α0udpkq. (1.6)

We recall that, given a signal xpkq with z-transform X pzq, the z-transform of xpk ` `q is given byNote 5. The (unilateral) z-transform of a signal xpkq is givenby

Xpzq–8ÿ

k“0z´k xpkq.

See [5, Section 8.2] for a review ofLaplace z-transforms.

z`X pzq ´ z`xp0q ´ z`´1xp1q ´ ¨ ¨ ¨ ´ zxp` ´ 1q.

In particular, when x is equal to zero before time k “ ` , the z-transform of xpk ` `q simplifies to

z`X pzq.

System Identification 9

Taking z-transforms to both sides of (1.6) and assuming that both yd and ud are zero before timen ě m, we obtain

znYdpzq ` βn´1zn´1Ydpzq ` ¨ ¨ ¨ ` β2z2Ydpzq ` β1zYdpzq ` β0Ydpzq“ αmzmUdpzq ` αm´1zm´1Udpzq ` ¨ ¨ ¨ ` α2z2Udpzq ` α1zUdpzq ` α0Udpzq.

This leads toMATLAB R© Hint 5.tf(num,den,Ts) creates adiscrete-time transfer functionwith sampling time Ts and numer-ator and denominator specified bynum, den. . . p. 12

MATLAB R© Hint 6.zpk(z,p,k,Ts) creates atransfer function with samplingtime Ts zeros, poles, and gainspecified by z, p, k. . . p. 12

Ydpzq “ HdpzqUdpzq,

where

Hdpzq–αmzm ` αm´1zm´1 ` ¨ ¨ ¨ ` α1z ` α0zn ` βn´1zn´1 ` ¨ ¨ ¨ ` β1z ` β0

, (1.7)

is called the (discrete-time) transfer function of the system. The roots of the denominator are calledthe poles of the system and the roots of the numerator are called the zeros of the system.

The system is (BIBO) stable if all poles have magnitude strictly smaller than one. In this case,Note 6. Since there are other no-tions of stability, one should usethe term BIBO stable to clarifythat it refers to the property thatBounded-Inputs lead to Bounded-Outputs.

for every input bounded signal upkq, the output ypkq remains bounded.

1.3.1 Steady-state Response to Sine WavesSuppose that we apply a sinusoidal input with amplitude A and discrete-time angular frequencyΩ P r0, πs, given by

Note 7. Discrete-time angularfrequencies take values from0 to π. In particular, Ω “ πcorresponds to the “fastest”discrete-time signal:

udpkq “ A cospπkq “ Ap´1qk .

. . . p. 13

udpkq “ A cospΩkq, @k P t0, 1, 2 . . . u,

to the system (1.1) with transfer function (1.2). Assuming that the system is BIBO stable, thecorresponding output is of the form

ydpkq “ gA cospΩk ` φqloooooooomoooooooon

steady-state

` εpkqloomoon

transient

, @k P t0, 1, 2 . . . u, (1.8)

where the gain g and phase φ are given by Attention! For discrete-time sys-tems the argument to H is ejΩ andnot just jΩ, as in continuous-timesystems. This means that Hpzqwill be evaluated over the unit cir-cle, instead of the imaginary axis.

g– |HdpejΩq|, φ – =HdpejΩq, (1.9)

and εptq is a transient signal that decays to zero at k Ñ8 (cf. Figure 1.4).

The Bode plot of a transfer function Hdpzq depictsMATLAB R© Hint 7. bode(sys)draws the Bode plot of the systemsys. . . p. 13

1. the norm of HdpejΩq in decibels [dB], which is given by 20 log10ˇ

ˇHdpejΩqˇ

ˇ; and

2. the phase of HdpejΩq

as a function of the angular frequency Ω (in a logarithmic scale). In view of (1.8)–(1.9), the Bodeplot provides information about how much a sinusoidal signal is amplified (magnitude) and by howmuch its phase is changed.

1.3.2 Step and Impulse ResponsesSuppose that we apply a discrete-time impulse, given by

upkq “ δpkq–#

1 k “ 00 k ‰ 0

10 João P. Hespanha

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5−1

−0.5

0

0.5

1

t (sec)

u

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5−1

−0.5

0

0.5

1

t (sec)y

Figure 1.7. Response to a sinusoidal input with frequency f “ 1Hz, ω “ 2π rad/sec sampled with a periodequal to Ts “ .01 sec. The corresponding discrete-time frequency is given by Ω “ .02π and the Bode plot ofthe system is shown in Figure 1.8.

to the system (1.1) with transfer function (1.2). The corresponding output hpkq is called the impulseresponse and its z-transform is precisely the system’s transfer function:

Hdpzq “8ÿ

k“0z´khpkq.

Consider now an input equal to a discrete-time step with magnitude α , i.e.,

upkq “ spkq–#

0 k ă 0α k ě 0,

and let ypkq be the corresponding output, which is called the step response. Since the impulse δpkqcan be obtained from the step spkq by

δpkq “ spkq ´ spk ´ 1qα , @k P t0, 1, 2 . . . u,

the impulse response hpkq (which is the output to δpkq) can be obtained from the output ypkq tospkq by

hpkq “ ypkq ´ ypk ´ 1qα , @k P t0, 1, 2 . . . u.

This is a consequence of linearity (cf. Figure 1.9).

1.4 Discrete- vs. Continuous-time Transfer FunctionsWhen the sampling time Ts is small, one can easily go from continuous- to discrete-time transferfunctions shown in Figure 1.10. To understand how this can be done, consider a continuous-timeintegrator

9yc “ uc (1.10)

with transfer function

Hcpsq “YcpsqUcpsq

“1s . (1.11)

System Identification 11

−40

−30

−20

−10

0From: u To: y

Mag

nitu

de (

dB)

10−2

10−1

100

101

102

−90

−45

0

Pha

se (

deg)

Bode Diagram

Frequency (rad/sec)

Figure 1.8. Bode plot of a system with transfer function Hdpsq “ .05z´.95 .

sptq yptqHdpzq

(a) step response

δpkq “ spkq´spk´1qα hpkq “ ypkq´ypk´1q

αHdpzq

(b) impulse response

Figure 1.9. Impulse versus step responses

Suppose that the signals y and u are sampled every Ts time units as shown in Figure 1.2 and thatwe define the discrete-time signals

ydpkq “ ycpkTsq, udpkq “ ucpkTsq, k P t0, 1, 2, . . . u.

Assuming that ucptq is approximately constant over an interval of length Ts, we can take a finitedifferences approximation to the derivative in (1.10), which leads to

ycpt ` Tsq ´ ycptqTs

“ ucptq.

In particular, for t “ kTs we obtain

ydpk ` 1q ´ ydpkqTs

“ udpkq. (1.12)

process SHucptq ycptq

udpkq ydpkq

Hcpsq

Hdpzq

Figure 1.10. Discrete vs. continuous-time transfer functions

12 João P. Hespanha

Taking the z-transform we conclude thatNote 8. In discrete-time, an in-tegrator has a pole at z “ 1,whereas in continuous-time thepole is at s “ 0.

zYdpzq ´ YdpzqTs

“ Udpzq ô Hdpzq “YdpzqUdpzq

“1z´1Ts. (1.13)

Comparing (1.11) with (1.13), we observe that we can go directly from a continuous-time transferfunction to the discrete-time one using the so called Euler transformations:

MATLAB R© Hint 8. c2d and d2cconvert transfer functions fromcontinuous- to discrete-time andvice-versa. . . p. 13

s ÞÑ z ´ 1Ts

ô z ÞÑ 1` sTs.

In general, a somewhat better approximation is obtained by taking the right-hand-side of (1.12) tobe the average of udpkq and udpk ` 1q. This leads to the so called Tustin or bilinear transformation:

Note 9. Why?. . . p. 14Note 10. The Euler transforma-tion preserves the number of polesand the number of zeros since itreplaces a polynomial of degreen in s by a polynomial of thesame degree in z and vice-versa.However, the Tustin transformationonly preserves the number of polesand can make discrete-time zerosappear, for systems that did nothave continuous-time zeros. E.g.,the integrator system 1

s becomesTspz`1q2pz´1q . . . p. 14

s ÞÑ 2pz ´ 1qTspz ` 1q ô z ÞÑ 2` sTs

2´ sTs.

1.5 MATLAB R© HintsMATLAB R© Hint 1, 5 (tf). The command sys_tf=tf(num,den) assigns to sys_tf a MATLAB R©

continuous-time transfer function. num is a vector with the coefficients of the numerator of the system’stransfer function and den a vector with the coefficients of the denominator. The last coefficient mustalways be the zero-order one. E.g., to get 2s

s2`3 one should use num=[2 0];den=[1 0 3];

The command sys_tf=tf(num,den,Ts) assigns to sys_tf a MATLAB R© discrete-time transferfunction, with sampling time equal to Ts.

For transfer matrices, num and den are cell arrays. Type help tf for examples.

Optionally, one can specify the names of the inputs, outputs, and state to be used in subsequentplots as follows:

sys_tf=tf(num,den,...’InputName’,’input1’,’input2’,...,...’OutputName’,’output1’,’output2’,...,...’StateName’,’input1’,’input2’,...)

The number of elements in the bracketed lists must match the number of inputs,outputs, and statevariables. 2

MATLAB R© Hint 2, 6 (zpk). The command sys_tf=zpk(z,p,k) assigns to sys_tf a MATLAB R©

continuous-time transfer function. z is a vector with the zeros of the system, p a vector with itspoles, and k the gain. E.g., to get 2s

ps`1qps`3q one should use z=0;p=[1,3];k=2;

The command sys_tf=zpk(z,p,k,Ts) assigns to sys_tf a MATLAB R© discrete-time transfer func-tion, with sampling time equal to Ts.

For transfer matrices, z and p are cell arrays and k a regular array. Type help zpk for examples.

Optionally, one can specify the names of the inputs, outputs, and state to be used in subsequentplots as follows:

sys_tf=zpk(z,p,k,...’InputName’,’input1’,’input2’,...,...’OutputName’,’output1’,’output2’,...,...’StateName’,’input1’,’input2’,...)

The number of elements in the bracketed lists must match the number of inputs,outputs, and statevariables. 2

System Identification 13

MATLAB R© Hint 4, 7, 23 (bode). The command bode(sys) draws the Bode plot of the system sys.To specify the system one can use:

1. sys=tf(num,den), where num is a vector with the coefficients of the numerator of the system’stransfer function and den a vector with the coefficients of the denominator. The last coefficientmust always be the zero-order one. E.g., to get 2s

s2`3 one should use num=[2 0];den=[1 03];

2. sys=zpk(z,p,k), where z is a vector with the zeros of the system, p a vector with its poles,and k the gain. E.g., to get 2s

ps`1qps`3q one should use z=0;p=[1,3];k=2;

3. sys=ss(A,B,C,D), where A,B,C,D are a realization of the system. 2

MATLAB R© Hint 8 (c2d and d2c). The command c2d(sysc,Ts,’tustin’) converts the continuous-time LTI model sysc to a discrete-time model with sampling time Ts using the Tustin transformation.To specify the continuous-time system sysc one can use:

1. sysc=tf(num,den), where num is a vector with the coefficients of the numerator of thesystem’s transfer function and den a vector with the coefficients of the denominator. Thelast coefficient must always be the zero-order one. E.g., to get 2s

s2`3 one should use num=[20];den=[1 0 3];

2. sysc=zpk(z,p,k), where z is a vector with the zeros of the system, p a vector with its poles,and k the gain. E.g., to get 2s

ps`1qps`3q one should use z=0;p=[1,3];k=2;

3. sysc=ss(A,B,C,D), where A,B,C,D are a realization of the system.

The command d2c(sysd,’tustin’) converts the discrete-time LTI model sysd to a continuous-time model, using the Tustin transformation. To specify the discrete-time system sysd one canuse:

1. sysd=tf(num,den,Ts), where Ts is the sampling time, num is a vector with the coefficientsof the numerator of the system’s transfer function and den a vector with the coefficients of thedenominator. The last coefficient must always be the zero-order one. E.g., to get 2s

s2`3 oneshould use num=[2 0];den=[1 0 3];

2. sysd=zpk(z,p,k,Ts), where Ts is the sampling time, z is a vector with the zeros of thesystem, p a vector with its poles, and k the gain. E.g., to get 2s

ps`1qps`3q one should usez=0;p=[1,3];k=2;

3. sysd=ss(A,B,C,D,Ts), where Ts is the sampling time, A,B,C,D are a realization of thesystem. 2

1.6 To Probe FurtherNote 7 (Discrete- vs. continuous-time frequencies). When operating with a sample period Ts, togenerate a discrete-time signal udpkq that corresponds to the sampled version of the continuous-time signal

ucptq “ A cospωtq, @t ě 0

we must have

udpkq “ ucpkTsq “ A cospωkTsq “ A cospΩkq,

where the last equality holds as long as we select Ω “ ωTs “ 2πfTs.

14 João P. Hespanha

Discrete-time angular frequencies take values from 0 to π. In particular, Ω “ π results in the“fastest” discrete-time signal:

udpkq “ A cospπkq “ Ap´1qk ,

which corresponds to a continuous-time frequency f “ 12T s equal to half the sampling rate, also

known as the Nyquist frequency. 2

Note 9 (Tustin transformation). Consider a continuous-time integrator in (1.10) and assume that uptqis approximately linear on the interval rkTs, pk ` 1qTss, i.e.,

uptq “ pk ` 1qTs ´ tTs

udpkq `t ´ kTsTs

udpk ` 1q, @t P rkTs, pk ` 1qTss.

Then, for ydpk ` 1q to be exactly equal to the integral of uptq at time t “ pk ` 1qTs, we need tohave

ydpk ` 1q “ ydpkq `ż pk`1qTs

kTs

´

pk ` 1qTs ´ tTs

udpkq `t ´ kTsTs

udpk ` 1q¯

dt

“ ydpkq `Ts2 udpkq `

Ts2 udpk ` 1q.

Taking the z-transform we conclude that

zYdpzq ´ YdpzqTs

“Udpzq ` zUdpzq

2 ô Hdpzq “YdpzqUdpzq

“Tsp1` zq2pz ´ 1q .

Comparing this with (1.11), we observe that we can go directly from a continuous-time transferfunction to the discrete-time one using the so called Tustin or bilinear transformation:

s ÞÑ 2pz ´ 1qTspz ` 1q ô z ÞÑ 2` sTs

2´ sTs. 2

Note 10 (Number of poles and zeros). The Euler transformation preserves the number of poles andthe number of zeros since the rule

s ÞÑ z ´ 1Ts

replaces a polynomial of degree n in s by a polynomial of the same degree in z and vice-versa.However, the Tustin transformation

s ÞÑ 2pz ´ 1qTspz ` 1q

replaces a polynomial of degree n in s by a ratio of polynomials of the same degree in z . This meansthat it preserves the number of poles, but it can make discrete-time zeros appear, for systems thatdid not have continuous-time zeros. E.g., the integrator system 1

s becomes

Tspz ` 1q2pz ´ 1q ,

which has a pole at z “ 1 (as expected), but also a zero at z “ ´1. 2

1.7 Exercise1.1. Suppose that you sample at 1KHz a unit-amplitude continuous-time sinusoid ucptq with fre-quency 10Hz. Write the expression for the corresponding discrete-time sinusoid udpkq.

Chapter 2

Nonparametric Identification

Contents2.1 Nonparametric Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.2 Time-domain Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.3 Frequency Response Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.1 Nonparametric MethodsNonparametric identification attempts to directly determine the model of a system, without assumingthat its transfer function is rational and that we known the number of poles or zeros. The followingare typical problems in this class:Problem 2.1 (Nonparametric time response identification). Determine the impulse response hpkqfrom time k “ 0 to k “ N .

orProblem 2.2 (Nonparametric frequency response identification). Determine the frequency responseHpejΩq over a range of frequencies Ω P rΩmin,Ωmaxs.

Problem 2.1 is useful for controller design based on the Ziegler-Nichols rules to tune PIDcontrollers [5], whereas Problem 2.2 is useful for controller design based on loop-shaping or theNyquist criterion. For N large, one can also recover the transfer function from the impulse responseby taking the z-transform:

MATLAB R© Hint 9. fft(h) com-putes the values of Hpzq for z “ejΩ . p. 19Hpzq “ Zrhpkqs “

8ÿ

k“0hpkqz´k «

Nÿ

k“0hpkqz´k ,

assuming that N is large enough so that hpkq « 0 for k ą N .Throughout this chapter we will assume that the system is BIBO stable, i.e., that all poles of the Attention! Systems with an inte-

grator (i.e., a discrete-time poleat z “ 1) are not BIBO sta-ble. However, if all other discrete-time poles have magnitude strictlysmaller than one, this difficultycan be overcome using a tech-nique that will be discussed inSection 4.3. p. 33

transfer function Hpzq have magnitude smaller than one or equivalently that hpkq converges to zeroexponentially fast.

A detailed treatment of this subject can be found, e.g., in [10, Chapter 7].

2.2 Time-domain IdentificationWe start by discussing a few methods used to solve the time response identification Problem 2.1.

15

16 João P. Hespanha

2.2.1 Impulse Response MethodNote 11. The main weakness ofthe impulse-response method isthat impulses are rarely represen-tative of typical inputs that ap-pear in closed loop so, especiallyfor nonlinear systems, we estimatea regimen that may be far fromthe dynamics that will appear inclosed loop.

The impulse response of a system can be determines directly by starting with the system at rest andapplying an impulse at the input :

upkq “#

α k “ 00 k ­“ 0.

The output will be a (scaled) version of the impulse response, possibly corrupted by some measurementnoise npkq:

ypkq “ αhpkq ` npkq.

Therefore

hpkq “ ypkqα ´

npkqα

Hopefully the noise term npkqα is small when compared to hpkq and one can use the followingestimate for the impulse response:

hpkq “ ypkqα , k P t0, 1, . . . , Nu.

Attention! The choice of α is generally critical to obtain a good estimate for the impulse response:

(i) |α | should be large to make sure that npkqα is indeed negligible when compared to hpkq;Note 12. Note that the estimatehpkq differs from the true valuehpkq, precisely by:

hpkq “ hpkq ` npkqα .

(ii) |α | should be small to make sure that the process does not leave the region where a linearmodel is valid and where it is safe to operate it open-loop.

As one increases α , a simple practical test to check if one is leaving the linear region of operationis to do identification both with some α ą 0 and ´α ă 0. In the linear region of operation, theidentified impulse-response does not change. See also the discussion in Section 5.1. 2

2.2.2 Step ResponseNote 13. In general, steps aremore representative than pulsesin feedback loops so, in that re-spect, the step response is a bettermethod than the impulse response.

The impulse response of a system can also be determined by starting with the system at rest andapplying an step at the input :

upkq “#

α k ě 00 k ă 0.

The z-transform of the output will be given by

Y pzq “ HpzqUpzq ` Npzq “ Hpzq α1´ z´1 ` Npzq,

where Npzq denotes the z-transform of measurement noise. Solving for Hpzq we obtain:

Hpzq “ Y pzq ´ z´1Y pzqα ´

Npzq ´ z´1Npzqα

Taking inverse z-transforms, we conclude that

hpkq “ ypkq ´ ypk ´ 1qα ´

npkq ´ npk ´ 1qα .

Hopefully the noise term npkq´npk´1qα is small when compared to hpkq, and we can use following

estimate for the impulse response:

hpkq “ ypkq ´ ypk ´ 1qα , k P t0, 1, . . . , Nu.

System Identification 17

Attention! The main weakness of the step-response method is that it can amplify noise because inthe worst case npkq´npk´1q

α can be twice as large as npkqα (when npk ´ 1q “ ´npkq). Although this

may seem unlikely, it is not unlikely to have all the npkq independent and identically distributedwith zero mean and standard deviation σ . In this case,

Note 14. Why?. . . p. 19

StdDev”npkqα

ı

“σα , StdDev

”npkq ´ npk ´ 1qα

ı

“1.41 σα ,

which means that the noise is amplified by approximately 41%. 2

2.2.3 Other InputsOne can determine the impulse response of a system using any input and not just a pulse- or step-input. Take an arbitrary input upkq, with z-transform Upzq. The z-transform of the output will begiven by

Y pzq “ HpzqUpzq ` Npzq,

where Npzq denotes the z-transform of measurement noise. Solving for Hpzq we obtain:

Hpzq “ U´1pzq`

Y pzq ´ Npzq˘

Taking inverse z-transforms, we conclude thatNote 15. The inverse z-transformof the product of two z-transformsis equal to the convolution of theinverse z-transforms of the fac-tors. . . p. 17

hpkq “ Z´1rU´1pzqs ‹ Z´1“Y pzq ´ Npzq‰

“ Z´1rU´1pzqs ‹`

ypkq ´ npkq˘

,

where the ‹ denotes the (discrete-time) convolution operation. Hopefully the noise term is small

MATLAB R© Hint 10. The identifi-cation toolbox command impulseperforms impulse response estima-tion for arbitrary inputs. . . p. 19

when compared to hpkq, and we can use following estimate for the impulse response:

hpkq “ Z´1rU´1pzqs ˚ ypkq, k P t0, 1, . . . , Nu.

Note 15 (Discrete-time convolution and z-transform). Given two discrete-time signals x1pkq, x2pkq,k P t0, 1, 2, . . . u, their (discrete-time) convolution is a third discrete-time signal defined by

px1 ‹ x2qpkq–8ÿ

k“0x1pkqx2pn´ kq, @k P t0, 1, 2, . . . u.

It turns out that the z-transform of the convolution of two signals can be easily computed by takingthe product of the z-transforms of the original signals. Specifically,

Zrx1 ‹ x2s “ X1pzqX2pzq, (2.1)

where X1pzq and X2pzq denote the z-transforms of x1pkq and x2pkq, respectively.

Applying the inverse z-transform to both sides of (2.1), we also conclude that

Z´1“X1pzqX2pzq‰

“ x1 ‹ x2,

which shows that we can obtain the inverse z-transform of the product of two z-transforms by doingthe convolution of the inverse z-transforms of the factors. 2

2.3 Frequency Response IdentificationWe now consider a couple of methods used to solve the frequency response identification Problem 2.2.

18 João P. Hespanha

2.3.1 Sine-wave TestingSuppose that one applies an sinusoidal input of the form,

Note 7. Discrete-time angularfrequencies Ω take values from0 to π. When operating with asample period Ts , to generatea discrete-time signal udpkqthat corresponds to the sampledversion of the continuous-timesignal ucptq “ A cospωtq,@t ě 0, we should selectΩ “ ωTs “ 2πfTs . . . p. 13

upkq “ α cospΩkq, @k P t1, 2, . . . , Nu. (2.2)

Since we are assuming that Hpzq is BIBO stable, the measured output is given by

ypkq “ α AΩ cos`

Ωk ` φΩ˘

` εpkq ` npkq, (2.3)

where

1. AΩ – |HpejΩ| and φΩ – =HpejΩq are the magnitude and phase of the transfer function Hpzqat z “ ejΩ;

2. εpkq is a transient signal that converges to zero as fast as cγk , where γ is the magnitude ofthe pole of Hpzq with largest magnitude and c some constant; and

3. npkq corresponds to measurement noise.Note 16. To minimize the errorscaused by noise, the amplitudeα should be large. However, itshould still be sufficiently small sothat the process does not leave thelinear regime.

When npkq is much smaller than αAΩ and for k sufficiently large so that εpkq is negligible, we have

ypkq « αAΩ cos`

Ωk ` φΩ˘

.

This allows us to recover both AΩ – |HpejΩ| and φΩ – =HpejΩq from the magnitude and phaseof ypkq. Repeating this experiment for several inputs (2.3) with distinct frequencies Ω, one obtainsseveral points in the Bode plot of Hpzq and, eventually, one estimates the frequency response HpejΩqover the range of frequencies of interest.

2.3.2 Correlation MethodEspecially when there is noise, it may be difficult to determine the amplitude and phase of ypkq byinspection. The correlation method aims at accomplishing this task.

Suppose that the input upkq in (2.2) was applied, resulting in the measured output ypkq givenby (2.3). In the correlation method we compute

KΩ –1T

Tÿ

k“1e´jΩkypkq “ 1

T

Tÿ

k“1

´

cospΩkq ´ j sinpΩkq¯

ypkq.

Using the expression for ypkq in (2.3), we conclude after fairly straightforward algebraic manipulationsthat

Note 17. Why?. . . p. 20

KΩ “α2Hpe

jΩq `α2T H

˚pejΩqe´2jΩ´e´2jΩpT`1q

1´ e´2jΩ `1T

Tÿ

k“1e´jΩk

`

εpkq ` npkq˘

.

As T Ñ 8, the second term converges to zero and the summation at the end converges to theNote 18. Since the process isbounded, εpkq converges to zeroand therefore it has no pure sinu-soids. However, a periodic noiseterm with frequency exactly equalto Ω would lead to trouble.Note 19. Even though the termdue to εpkq does not lead to trou-ble as T Ñ 8, it is still a goodidea to start collecting data onlyafter the time at which ypkq ap-pears to have stabilized into apure sinusoid.

z-transform of εpkq ` npkq at the point z “ e´jΩ. We thus conclude that

KΩ Ñα2Hpe

jΩq ` limTÑ8

1T`

Epe´jΩq ` Npe´jΩq˘

,

where Epzq and Npzq denote the z-transforms of epkq and npkq, respectively. As long as npkq andepkq do not contain pure sinusoidal terms of frequency Ω, the z-transforms are finite and thereforethe limit is equal to zero. This leads to the following estimate for HpejΩq

Note 20. KΩ is a complex numberso we get estimates for the ampli-tude and phase of HpejΩq.

HpejΩq “ 2α KΩ,

which is valid for large T .

System Identification 19

Attention! The main weaknesses of the frequency response methods are:

(i) To estimate HpejΩq at a single frequency, one still needs a long input (i.e., T large). In practice,this leads to a long experimentation period to obtain the Bode plot over a wide range offrequencies.

(ii) It requires that we apply very specific inputs (sinusoids) to the process. This may not be possible(or safe) in certain applications. Especially for processes that are open-loop unstable.

(iii) We do not get a parametric form of the transfer function; and, instead, we get the Bode plotdirectly. This prevent the use of control design methods that are not directly based on theprocess’ Bode plot.

Note 21. For simple systems, itmay be possible to estimate thelocations of poles and zeros, di-rectly from the Bode plot. Thispermits the use of many other con-trol design methods.

Its key strengths are

(i) It is typically very robust with respect to measurement noise since it uses a large amount ofdata to estimate a single point in the Bode plot.

(ii) It requires very few assumptions on the transfer function, which may not even by rational. 2

2.4 MATLAB R© HintsMATLAB R© Hint 9 (fft). The command fft(h) computes the fast-Fourier-transform (FFT) of thesignal hpkq, k P t1, 2, . . . , Nu, which provides the values of HpejΩq for equally spaced frequenciesΩ “ 2πk

N , k P t0, 1, . . . , N ´ 1u. However, since we only care for values of Ω in the interval r0, πs,we should discard the second half of fft’s output. 2

MATLAB R© Hint 10 (impulse). The command impulse from the identification toolbox performsimpulse response estimation from data collected with arbitrary inputs. To use this command onemust

1. Create a data object that encapsulates the input/output data using:

data=iddata(y,u),

where u and y are vectors with the input and output data.

2. Plot the estimated impulse response using:

impulse(dat),

or compute the response using

model=impulse(data),

where m is a MATLAB R© object with an impulse-response model. The impulse response is givenby model.b. 2

2.5 To Probe FurtherNote 14 (Noise in step-response method). When npkq and npk ´ 1q are independent, we have

Varrnpkq ´ npk ´ 1qs “ Varrnpkqs ` Varrnpk ´ 1qs.

Therefore

StdDev”npkq ´ npk ´ 1q

α

ı

c

Var”npkq ´ npk ´ 1q

α

ı

c

Varrnpkqs ` Varrnpk ´ 1qsα2

20 João P. Hespanha

When, both variables have the same standard deviation σ , we obtain

StdDev”npkq ´ npk ´ 1q

α

ı

c

2σ 2

α2 “

?2 σα . 2

Note 17 (Correlation method). In the correlation method one computes

KΩ –1T

Tÿ

k“1e´jΩkypkq “ 1

T

Tÿ

k“1

`

cospΩkq ´ j sinpΩkq˘

ypkq

Using the expression for ypkq in (2.3), we conclude that

KΩ “αT AΩ

Tÿ

k“1

´

cospΩkq cospΩk ` φΩq ´ j sinpΩkq cospΩk ` φΩq¯

`1T

Tÿ

k“1e´jΩk

`

εpkq ` npkq˘

.

Applying the trigonometric formulas cosa cos b “ 12 pcospa ´ bq ` cospa ` bqq and sina cos b “

12 psinpa´ bq ` sinpa` bqq, we further conclude that

KΩ “αAΩ2T

Tÿ

k“1

´

cosφΩ ` cos`

2Ωk ` φΩ˘

` j sinφΩ ´ j sin`

2Ωk ` φΩ˘

¯

`1T

Tÿ

k“1ejΩk

`

εpkq ` npkq˘

“αAΩ2T

Tÿ

k“1ejφΩ `

αAΩ2T

Tÿ

k“1e´2jΩk´jφΩ `

1T

Tÿ

k“1e´jΩk

`

εpkq ` npkq˘

“α2Hpe

jΩq `α2T H

˚pejΩqTÿ

k“1e´2jΩk `

1T

Tÿ

k“1e´jΩk

`

εpkq ` npkq˘

,

where we used the fact that AΩejφΩ is equal to the value HpejΩq of the transfer function at z “ ejΩand AΩe´jφΩ is equal to its complex conjugate H˚pejΩq. By noticing that the second term is thesummation of a geometric series, we can simplify this expression to

Note 22. Recall that the sum of ageometric series is given by

Tÿ

k“1rk “ r ´ rT`1

1´ r.

KΩ “α2Hpe

jΩq `α2T H

˚pejΩqe´2jΩ´e´2jΩpT`1q

1´ e´2jΩ `1T

Tÿ

k“1e´jΩk

`

εpkq ` npkq˘

2

2.6 Exercises2.1 (Step response). A Simulink block that models a pendulum with viscous friction is provided.

1. Use the Simulink block (without noise) to estimate the system’s impulse response hpkq usingboth the impulse and step response methods.What is the largest value α of the input magnitude for which the system still remains withinthe approximately linear region of operation?Hint: to make sure that the estimate is good you can compare the impulses response fromsteps and impulses.

2. Turn on the noise in the Simulink block and repeat the identification procedure above for arange of values for α . For both methods, plot the error

ř

k hαpkq´hpkq vs. α , where hαpkqdenotes the estimate obtained for an input with magnitude α . What is your conclusion?Take the estimate hpkq determined in 1 for the noise-free case as the ground truth hpkq. 2

2.2 (Correlation method). Modify the Simulink block provided for Exercise 2.1 to accept a sinusoidalinput.

System Identification 21

1. Estimate the system’s frequency response HpejΩq at a representative set of (log-spaced)frequencies Ωi using the correlation method.Select an input amplitude α for which the system remains within the approximately linearregion of operation.Important: Write MATLAB R© scripts to automate the procedure of taking as inputs the simula-tion data upkq, ypkq (from a set of .mat files in a given folder) and producing the Bode plotof the system.

2. Turn on the noise in the Simulink block and repeat the identification procedure above for arange of values for α . Plot the error

ř

i HαpejΩiq ´ HpejΩiq vs. α , where HαpejΩiq denotes

the estimate obtained for an input with magnitude α . What is your conclusion?

Take the estimate HpejΩq determined in 1 for the noise-free case as the ground truth HpejΩq.

3. Compare your best frequency response estimate HpejΩq, with the frequency responses thatyou would obtain by taking the Fourier transform of the best impulse response hpkq that youobtained in Exercise 2.1.Hint: Use the MATLAB R© command fft to compute the Fourier transform. This command givesyou HpejΩq from Ω “ 0 to Ω “ 2π so you should discard the second half of the Fouriertransform (corresponding to Ω ą π). 2

22 João P. Hespanha

Chapter 3

Parametric Identification usingLeast-squares

Contents3.1 Parametric Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.2 Least-squares Line Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.3 Vector Least-squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.1 Parametric IdentificationIn parametric identification one attempts to determine a finite number of unknown parameters thatcharacterize the model of the system. The following is a typical problem in this class:

Problem 3.1 (Parametric transfer function identification). Determine the coefficients αi and βi of thesystem’s rational transfer function

Hpzq “ αmzm ` αm´1zm´1 ` ¨ ¨ ¨ ` α1z ` α0zn ` βn´1zn´1 ` ¨ ¨ ¨ ` β1z ` β0

.

The number of poles n and the number of zeros m are assumed known.

This can be done using the method of least-squares, which we introduce next, starting from asimple line fitting problem and eventually building up to Problem 3.1 in Chapter 4.

The methods of least-squares is generally attributed to Gauss [6] but the American mathematicianAdrain [1] seems to have arrived at the same results independently [7]. A detailed treatment of least-squares estimation can be found, e.g., in [10, Chapter 7].

3.2 Least-squares Line FittingSuppose that we have reasons to believe that two physical scalar variables x and y are approximatelyrelated by a linear equation of the form

y “ ax ` b, (3.1)

23

24 João P. Hespanha

y “ voltage

x “ current

R

(a) Voltage vs. current

R

y “ pressure

x “ height

(b) Pressure vs. height

Figure 3.1. Linear models

but we do not know the value of the constants a and b. The variables y and x could be, e.g., avoltage and a current in a simple electric circuit, or the height of a fluid in a tank and the pressureat the bottom of the tank (cf. Figure 3.1).

Numerical values for a and b can be determined by conducting several experiments and measuringthe values obtained for x and y. We will denote by pxi, yiq the measurements obtained on the ithexperiment of a total of N experiments. As illustrated in Figure 3.2, it is unlikely that we have exactly

yi “ axi ` b, @i P t1, 2, . . . , Nu, (3.2)

because of measurement errors and also because often the model (3.1) is only approximate.

x

y

y “ ax ` b

pxi, yiq

(a) Measurement noisex

y

y “ ax ` b

pxi, yiq

(b) Nonlinearity

Figure 3.2. Main causes for discrepancy between experimental data and linear model

Least-squares identification attempts to find values for a and b for which the left- and the right-hand-sides of (3.2) differ by the smallest possible error. More precisely, the values of a and b leadingto the smallest possible sum of squares for the errors over the N experiments. This motivates thefollowing problem:

Problem 3.2 (Basic Least-Squares). Find values for a and b that minimize the following Sum-of-Squares Error (SSE):

SSE –

Nÿ

i“1paxi ` b´ yiq2.

Solution to Problem 3.2. This problem can be solved using standard calculus. All we need to do issolve

$

&

%

BSSEBa “

Nÿ

i“12xipaxi ` b´ yiq “ 0

BSSEBb “

Nÿ

i“12paxi ` b´ yiq “ 0

System Identification 25

for the unknowns a and b. This is a simple task because it amounts to solving a system of linearequations:

$

&

%

2`

Nÿ

i“1x2i˘

a` 2`

Nÿ

i“1xi˘

b “ 2Nÿ

i“1xiyi

2`

Nÿ

i“1xi˘

a` 2Nb “ 2Nÿ

i“1yi

ô

$

&

%

a “ Npř

i xiyiq ´ př

i xiqpř

i yiqNp

ř

i x2i q ´ p

ř

i xiq2

b “ př

i x2i qp

ř

i yiq ´ př

i xiyiqpř

i xiqNp

ř

i x2i q ´ p

ř

i xiq2

In the above expressions, we used a and b to denote the solution to the least-squares minimization.These are called the least-squares estimates of a and b, respectively. 2

Note 23. Statistical interpreta-tion of least-squares. . . p. 27Attention! The above estimates for a and b are not valid when

Npÿ

ix2i q ´ p

ÿ

ixiq2 “ 0, (3.3)

because this would lead to a division by zero. It turns out that (3.3) only holds when the xi obtainedNote 24. Why does (3.3) only holdwhen all the xi are equal to eachother? . . . p. 28

in all experiments are exactly the same, as shown in Figure 3.3. Such set of measurements does not

x

y

yiq

Figure 3.3. Singularity in least-squares line fitting due to poor data.

provide enough information to estimate the parameter a and b that characterize the line defined by(3.1). 2

3.3 Vector Least-squaresThe least-square problem defined in Section 3.2 can be extended to a more general linear model,where y is a scalar, z –

z1 z2 ¨ ¨ ¨ zm‰

an m-vector, and these variables are related by alinear equation of the form

Notation 2. a¨b denotes the innerproduct of a and b. . . p. 27

Note 25. The line fitting problemis a special case of this one forz “ rx 1s and θ “ ra bs.

y “mÿ

j“1zjθj “ z ¨ θ, (3.4)

where θ –“

θ1 θ2 ¨ ¨ ¨ θm‰

is an m-vector with parameters whose values we would like todetermine.

To determine the parameter vector θ, we conduct N experiments from which we obtain measure- Attention! We are now using piqto denote the ith experiment sincethe subscript in zj is needed todenotes the jth entry of the vectorz .

ments`

zpiq, ypiq˘

, i P t1, 2, . . . , Nu, where each zpiq denotes one m-vector and each ypiq a scalar.The least-squares problem is now formulated as follows:

Problem 3.3 (Vector Least-Squares). Find values for θ –“

θ1 θ2 ¨ ¨ ¨ θm‰

that minimize thefollowing Sum-of-Squares Error (SSE):

SSE –

Nÿ

i“1

`

zpiq ¨ θ ´ ypiq˘2.

26 João P. Hespanha

Solution to Problem 3.3. This problem can also be solved using standard calculus. Essentially wehave to solve

BSSEBθ1

“BSSEBθ2

“ ¨ ¨ ¨ “BSSEBθm

“ 0,

for the unknown θi . The equation above can also be re-written asNotation 3. ∇x fpxq denotes thegradient of fpxq. . . p. 27 ∇θSSE “

BSSEBθ1

BSSEBθ2

¨ ¨ ¨ BSSEBθm

ı

“ 0.

However, to simplify the computation it is convenient to write the SSE in vector notation. DefiningNote 26. Vector notation is con-venient both for algebraic manipu-lations and for efficient MATLAB R©

computations.

E to be an N-vector obtained by stacking all the errors zpiq ¨ θ ´ ypiq on top of each other, i.e.,

E –

»

zp1q ¨ θ ´ yp1qzp2q ¨ θ ´ yp2q

...zpNq ¨ θ ´ ypNq

fi

ffi

ffi

ffi

fl

Nˆ1

,

we can writeNotation 4. Given a matrix M , wedenote the transpose of M by M1 . SSE “ E2 “ E 1E.

Moreover, by viewing θ as a column vector, we can write

E “ Zθ ´ Y ,

where Z denotes a N ˆm matrix obtained by stacking all the row vectors zpiq on top of each other,and Y an m-vector obtained by stacking all the ypiq on top of each other, i.e.,

Z “

»

zp1qzp2q

...zpNq

fi

ffi

ffi

ffi

fl

Nˆm

, Y “

»

yp1qyp2q

...ypNq

fi

ffi

ffi

ffi

fl

Nˆ1

.

Therefore

SSE “ pθ1Z 1 ´ Y 1qpZθ ´ Y q “ θ1Z 1Zθ ´ 2Y 1Zθ ` Y 1Y . (3.5)

It is now straightforward to compute the gradient of the SSE and find the solution to ∇θSSE “ 0:Note 27. The gradientof a quadratic functionfpxq “ x1Qx ` cx ` d,is given by ∇x fpxq “

x1pQ ` Q1q ` c. . . p. 28

MATLAB R© Hint 11. ZzY com-putes directly pZ1Zq´1Z1Y in avery efficient way, which avoidsinverting Z1Z by solving directlythe linear system of equationsin (3.6). This is desirable, be-cause this operation is oftenill-conditioned.

∇θSSE “ 2θ1Z 1Z ´ 2Y 1Z “ 0 ô θ1 “ Y 1Z pZ 1Z q´1, (3.6)

which yields the following least-squares estimate for θ:

θ “ pZ 1Z q´1Z 1Y . (3.7)

Since Z 1Z “ř

i zpiq1zpiq and Z 1Y “ř

i zpiq1ypiq, we can re-write the above formula as

θ “ R´1f, R –

Nÿ

i“1zpiq1zpiq, f –

Nÿ

i“1zpiq1ypiq.

One can gauge the quality of the fit by computing the SSE achieved by the estimate (i.e., theminimum achievable squared-error). Replacing the estimate (3.7) in (3.5) we obtain

SSEY 2 “

Z θ ´ Y 2Y 2 “ 1´ Y 1Z pZ 1Z q´1Z 1Y

Y 1Y “ 1´ Y 1Z θY 1Y . (3.8)

When this error-to-signal ratio is much smaller than one, the mismatch between the left- and right-hand-sides of (3.4) has been made significantly smaller than the output. 2

Attention! The above estimate for θ is not valid when the mˆm matrix R is not invertible. SingularityMATLAB R© Hint 12. svd(A)provides a measure of how closeA is to being singular. . . p. 27

of R is a situation similar to (3.3) in line fitting and it means that the zpiq are not sufficiently richto estimate θ. In practice, even when R is invertible, poor estimates are obtained if R is close to asingular matrix. 2

System Identification 27

3.4 MATLAB R© HintsMATLAB R© Hint 12 (svd). The command svd(A) computes the singular values of the matrix A. Thesingular values of a matrix A are the square-roots of the eigenvalues of A1A. Singular values arealways real and nonnegative.

1. The largest singular value (written σmaxrAs) provides a measure of how much a matrix canamplify a vector. In particular,

Ax ď σmaxrAsx.

2. The smallest singular value (written σminrAs) provides a measure of how little a matrix canamplify a vector. In particular,

Ax ě σminrAsx.

For singular matrices σminrAs “ 0.

3. The ratio between the largest and smallest singular values is called the condition number ofa matrix:

ρrAs– σmaxrAsσminrAs

.

For singular matrices, the condition number is equal to 8. Finite but large condition numberscorrespond to matrices that are nonsingular but “close” to being singular, in the sense thatthey can become singular by making small changes in their entries. Because of this property,the condition number provides a measure of how close a matrix is to being singular.Inverting matrices with large condition numbers is very difficult and often results in largenumerical errors due to round-off. 2

3.5 To Probe FurtherNotation 2 (Inner product). Given two m-vectors, a “

a1 a2 ¨ ¨ ¨ am‰

and a ““

a1 a2 ¨ ¨ ¨ am‰

,a ¨ b denotes the inner product of a and b, i.e.,

a ¨ b “mÿ

i“1aibi.

2

Notation 3 (Gradient). Given a scalar function of n variables fpx1, . . . , xmq,∇x f denotes the gradientof f , i.e.,

∇x fpx1, x2, . . . , xmq “”

BfBx1

BfBx2 ¨ ¨ ¨ Bf

Bxm

ı

. 2

Note 23 (Statistical interpretation of least-squares). Suppose that the mismatch between left- andthe right-hand sides of (3.2) is due to uncorrelated zero-mean noise. In particular, that

yi “ axi ` b` ni, @i P t1, 2, . . . , nu,

where all the ni are uncorrelated zero-mean random variables with the same variance σ 2, i.e.,

Ernis “ 0, Ern2i s “ σ 2, Erni nj s “ 0,@i, j ‰ i.

The Gauss-Markov Theorem stated below justifies the wide use of least-squares estimation.

28 João P. Hespanha

Theorem 3.1 (Gauss-Markov). The best linear unbiased estimator (BLUE) for the parameters a andb is the least-squares estimator.

Some clarification is needed to understand this theorem

1. The Gauss-Markov Theorem 3.1 compares all linear estimators, i.e., all estimators of the form

a “ α1y1 ` ¨ ¨ ¨ ` αnyn, b “ β1y1 ` ¨ ¨ ¨ ` βnyn,

where the αi, βi are coefficients that may depend on the xi .

2. It then asks what is the choice for the αi, βi that lead to an estimator that is “best” in thesense that it is (i) unbiased, i.e., for which

Eras “ a, Erbs “ b,

and (ii) results in the smallest possible variance for the estimation error, i.e., that minimizes

Erpa´ aq2 ` pb´ bq2s.

The conclusion is that the least-squares estimator satisfies these requirements.

Unbiasedness, means that when we repeat the identification procedure many time, although we maynever get a “ a and b “ b, the estimates obtained will be clustered around the true values.Minimum variance, means that the clusters so obtained will be as “narrow” as possible. 2

Note 24 (Singularity of line fit). The estimates for a and b are not valid when

Npÿ

ix2i q ´ p

ÿ

ixiq2 “ 0.

To understand when this can happen let us compute

Nÿ

ipxi ´ µq2 “ N

ÿ

ix2i ´ 2Nµ

ÿ

ixi ` n2µ2

but Nµ “ř

i xi , so

Nÿ

ipxi ´ µq2 “ N

ÿ

ix2i ´ p

ÿ

ixiq2.

This means that we run into trouble whenÿ

ipxi ´ µq2 “ 0,

which can only occur when all the xi are the same and equal to µ. 2

Note 27 (Gradient of a quadratic function). Given a m ˆ m matrix Q and a m-row vector c, thegradient of the quadratic function

fpxq “ x 1Qx ` cx “mÿ

i“1

mÿ

j“1qijxixj `

mÿ

i“1cixi.

To determine the gradient of f , we need to compute:

BfpxqBxk

mÿ

i“1

mÿ

j“1qijxi

BxjBxk

`

mÿ

i“1

mÿ

j“1qijxj

BxiBxk

`

mÿ

i“1ciBxiBxk

.

System Identification 29

However, BxiBxk and Bxj

Bxk are zero whenever i ‰ k and j ‰ k , respectively, and 1 otherwise. Therefore,the summations above can be simplified to

BfpxqBxk

mÿ

i“1qikxi `

mÿ

j“1qkjxj ` ck “

mÿ

i“1pqik ` qkiqxi ` ck .

Therefore

∇x fpxq “”

BfpxqBx1

BfpxqBx2 ¨ ¨ ¨

BfpxqBxm

ı

““řmi“1pqi1 ` q1iqxi ` c1 ¨ ¨ ¨

řmi“1pqim ` qmiqxi ` cm

“ x 1pQ ` Q1q ` c. 2

3.6 Exercises3.1 (Electrical circuit). Consider the electrical circuit in Figure 3.4, where the voltage U across thesource and the resistor R are unknown. To determine the values of U and R you place several test

+

−U

RA

B

ri

Ii

Vi

Figure 3.4. Electrical circuit

resistors ri between the terminals A, B and measure the voltages Vi and currents Ii across them.

1. Write a MATLAB R© script to compute the voltages Vi and currents Ii that would be obtainedwhen U “ 10V , R “ 1kΩ, and the ri are equally spaced in the interval r100Ω, 10kΩs. Add tothe “correct” voltage and current values measurement noise. Use for the currents and for thevoltages Gaussian distributed noise with zero mean and standard deviation .1mA and 10mV ,respectively.The script should take as input the number N of test resistors.

2. Use least-squares to determine the values of R and U from the measurements for N P

t5, 10, 50, 100, 1000u. Repeat each procedure 5 times and plot the average error that youobtained in your estimates versus N . Use a logarithmic scale. What do you conclude? 2

3.2 (Nonlinear spring). Consider a nonlinear spring with restoring force

F “ ´px ` x3q,

where x denotes the spring displacement. Use least-squares to determine linear models for thespring of the form

F “ ax ` b.

Compute values for the parameters a and b for

1. forces evenly distributed in the interval r´.1, .1s,

2. forces evenly distributed in the interval r´.5, .5s, and

30 João P. Hespanha

3. forces evenly distributed in the interval r´1, 1s.

For each case

1. calculate the SSE ,

2. plot the actual and estimated forces vs. x , and

3. plot the estimation error vs. x . 2

Chapter 4

Parametric Identification of an ARXModel

Contents4.1 ARX Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.2 Identification of an ARX Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.3 Dealing with Known Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

4.1 ARX ModelSuppose that we want to determine the transfer function Hpzq of the discrete-time system in Fig-ure 4.1. In least-squares identification, one converts the problem of estimating Hpzq into the vector

upkq ypkqHpzq “ ?

Figure 4.1. System identification from input/output experimental data

least-squares problem considered in Section 3.3. This is done using the ARX model that will beconstructed below.

The z-transforms of the input and output of the system in Figure 4.1 are related by

Y pzqUpzq “ Hpzq “ αmzm ` αm´1zm´1 ` ¨ ¨ ¨ ` α1z ` α0

zn ` βn´1zn´1 ` ¨ ¨ ¨ ` β1z ` β0, (4.1)

where the αi and the βi denote the coefficients of the numerator and denominator polynomials ofHpzq. Multiplying the numerator and denominator of Hpzq by z´n, we obtain the transfer functionexpressed in negative powers of z:

Y pzqUpzq “

αmz´n`m ` αm´1z´n`m´1 ` ¨ ¨ ¨ ` α1z´n`1 ` α0z´n1` βn´1z´1 ` ¨ ¨ ¨ ` β1z´n`1 ` β0z´n

“ z´pn´mq αm ` αm´1z´1 ` ¨ ¨ ¨ ` α1z´m`1 ` α0z´m1` βn´1z´1 ` ¨ ¨ ¨ ` β1z´n`1 ` β0z´n

31

32 João P. Hespanha

and therefore

Y pzq ` βn´1z´1Y pzq ` ¨ ¨ ¨ ` β1z´n`1Y pzq ` β0z´nY pzq “αmz´n`mUpzq ` αm´1z´n`m´1Upzq ` ¨ ¨ ¨ ` α1z´n`1Upzq ` α0z´nUpzq.

Taking inverse z-transforms we obtainNote 28. We can view the differ-ence n´m between the degrees ofthe denominator and numerator of(4.1) as a delay, because the out-put ypkq at time k in (4.2) onlydepends on the value of the inputu`

k´pn´mq˘

at time k´pn´mqand on previous values of the in-put.

ypkq ` βn´1ypk ´ 1q ` ¨ ¨ ¨ ` β1ypk ´ n` 1q ` β0ypk ´ nq “αmupk ´ n` mq ` αm´1upk ´ n` m´ 1q ` ¨ ¨ ¨ ` α1upk ´ n` 1q ` α0upk ´ nq. (4.2)

This can be re-written compactly as

ypkq “ φpkq ¨ θ (4.3)

where the pn`m` 1q-vector θ contains the coefficient of the transfer function and the vector φpkqthe past inputs and outputs, i.e.,

θ –“

´βn´1 ¨ ¨ ¨ ´β1 ´β0 αm αm´1 ¨ ¨ ¨ α1 α0‰

φpkq–“

ypk ´ 1q ¨ ¨ ¨ ypk ´ nq upk ´ n` mq ¨ ¨ ¨ upk ´ nq‰

.

The vector φpkq is called the regression vector and the equation (4.3) is called an ARX model, ashort form of Auto-Regression model with eXogeneous inputs.

4.2 Identification of an ARX ModelWe are now ready to solve the system identification Problem 3.1 introduced in Chapter 3, by applyingthe least-squares method to the ARX model:

Solution to Problem 3.1.

1. Apply a probe input signal upkq, k P t1, 2, . . . , Nu to the system.

2. Measure the corresponding output ypkq, k P t1, 2, . . . , Nu.

3. Determine the values for the parameter θ that minimize the discrepancy between the left- andthe right-hand-sides of (4.3) in a least-squares sense.

According to Section 3.3, the least-squares estimate of θ is given byMATLAB R© Hint 13. PHIzY com-putes θ directly, from the matrixPHI“ Φ and the vector Y“ Y .

θ “ pΦ1Φq´1Φ1Y , (4.4)

whereAttention! When the system is atrest before k “ 1, upkq “

ypkq “ 0 @k ď 0. Otherwise, ifthe past inputs are unknown, oneneeds to remove from Φ and Y allrows with unknown data.

Φ –

»

φp1qφp2q

...φpNq

fi

ffi

fl

»

yp0q ¨¨¨ yp1´nq up1´n`mq ¨¨¨ up1´nqyp1q ¨¨¨ yp2´nq up2´n`mq ¨¨¨ up2´nq

......

......

ypN´1q ¨¨¨ ypN´nq upN´n`mq ¨¨¨ upN´nq

fi

ffi

fl

, Y –

»

yp1qyp2q

...ypNq

fi

ffi

fl

,

or equivalently

θ “ R´1f, R – Φ1Φ “Nÿ

k“1φpkq1φpkq, f – Φ1Y “

Nÿ

k“1φpkq1ypkq.

The quality of the fit can be assessed by computing the error-to-signal ratio

SSEY 2 “ 1´ Y 1Φθ

Y 1Y .

When this quantity is much smaller than one, the mismatch between the left- and right-hand-sidesof (4.3) has been made significantly smaller than the output. 2

System Identification 33

MATLAB R© Hint 14. arx is con-venient to perform ARX modelsidentification because it does notrequire the construction of the ma-trix Φ and the vector Y . . . p. 33

MATLAB R© Hint 15. compare isuseful to determine the quality offit. . . p. 35

Attention! Two common causes for errors in least-squares identifications of ARX models are:

1. incorrect construction of the matrix Φ and/or vector Y ;2. incorrect construction of the identified transfer function from the entries in the least-squares

estimate θ.

Both errors can be avoided using the MATLAB R© command arx.

4.3 Dealing with Known ParametersDue to physical considerations, one often knows one or more poles/zeros of the process. For example:

1. one may know that the process has an integrator, which corresponds to a continuous-time poleat s “ 0 and consequently to a discrete-time pole at z “ 1; or

2. that the process has a differentiator, which corresponds to a continuous-time zero at s “ 0and consequently to a discrete-time zero at z “ 1.

In this case, it suffices to identify the remaining poles/zeros, which can be done as follows: Supposethat it is known that the transfer function Hpzq has a pole at z “ λ, i.e.,

Hpzq “ 1z ´ λHpzq,

where Hpzq corresponds to the unknown portion of the transfer function. In this case, the z-transformsNote 29. The transfer functionHpzq is proper only if Hpzq isstrictly proper. However, even ifHpzq happens not to be proper,this introduces no difficulties forthis method of system identifica-tion.

of the input and output of the system are related by

Y pzqUpzq “

1z ´ λHpzq,

and therefore

Y pzqUpzq “ Hpzq,

where

Y pzq– pz ´ λqY pzq ñ ypkq “ ypk ` 1q ´ λypkq. (4.5)

This means that we can directly estimate Hpzq by computing ypkq prior to identification and thenNote 30. The new output ypkq isnot a causal function of the orig-inal output ypkq, but this is ofno consequence since we have thewhole ypkq available when wecarry out identification.

MATLAB R© Hint 16. One must becareful in constructing the vector yin (4.5) to be used by the functionarx. . . p. 34

regarding this variable as the output, instead of ypkq.

Attention! To obtain the original transfer function Hpzq, one needs to multiply the identified functionHpzq by the term 1

z´λ . 2

4.4 MATLAB R© HintsMATLAB R© Hint 14 (arx). The command arx from the identification toolbox performs least-squaresidentification of ARX models. To use this command one must

1. Create a data object that encapsulates the input/output data using:

data=iddata(y,u,Ts);

where u and y are vectors with the input and output data, respectively, and Ts is the samplinginterval.

Data from multiple experiments can be combined using the command merge as follows:

34 João P. Hespanha

dat1=iddata(y1,u1,Ts);dat2=iddata(y1,u1,Ts);data=merge(dat1,dat2);

2. Compute the estimated model using:

model=arx(data,[na,nb,nk])

where data is the object with input/output data; na, nb, nk are integers that define theNote 31. MATLAB R© is an objectoriented language and model.ais the property a of the objectmodel.

degrees of the numerator and denominator of the transfer function (see below); and model aMATLAB R© object with the coefficients of the transfer function. The coefficient are returned fornegative powers of z . In particular, the estimated transfer function is given by

Note 32. Typically, one choosesna equal to the (expected) num-ber of poles, nk equal to the (ex-pected) input delay, and nb “

na ´ nk ` 1, which would bethe corresponding number of ze-ros. In this case, ypkq is a func-tion of ypk ´ 1q, . . . , ypk ´ naqand of upk´nkq, . . . , upk´nk´nb ` 1q. See equations (4.1)–(4.2). . . p. 31

Y pzqUpzq “

model.bp1q ` model.bp2qz´1 ` ¨ ¨ ¨ ` model.bpnk` nbqz´nk´nb`1˘

model.ap1q ` model.ap2qz´1 ` ¨ ¨ ¨ ` model.apna` 1qz´na , (4.6)

with the first coefficient of model.a equal to 1 and the first nk coefficients of model.b equalto 0.

For processes with nu inputs and ny outputs, na should be an ny ˆ ny square matrix andboth nb and nk should be ny ˆ nu rectangular matrices. In general, all entries of na shouldbe equal to the number of poles of each transfer function, whereas the entries of nk and nbshould reflect the (possibly different) delays and number of zeros, respectively, for each transferfunction.

The estimated discrete-time transfer function can be recovered using the MATLAB R© command

sysd=tf(model,’Measured’)

The object model contains a lot more information about the estimated transfer function, whichincludes

1. model.da and model.db give the standard deviations associated with the estimates of thecoefficient.

Note 33. Obtaining a standarddeviation for one parameter that iscomparable or larger than its esti-mated value typically arises in oneof three situations. . . p. 35

One should compare the value of each parameter with its standard deviation. A large value inone or more of the standard deviations indicates that the matrix R – Φ1Φ is close to singularand points to little confidence on the estimated value of that parameter.

2. model.noise provides a measure of the quality of fit and is essentially the value of SSEdivided by the number of samples. However, this measure is not normalized by the norm-squareof Y , opposite to (3.8).

One can type idprops idpoly at the MATLAB R© prompt to obtain more information about otherinformation that is available in model.The MATLAB R© command arx uses a more sophisticated algorithm than the one described in thesenotes so the results obtained using arx may not match exactly the ones obtained using the formula(4.4). 2

MATLAB R© Hint 16 (Dealing with known parameters). One must be careful in constructing the vectory in (4.5) to be used by the function arx. In particular, its first element must be equal to

yp2q ´ λyp1q,

as suggested by (4.5). Moreover, if we had values of ypkq and upkq for k P t1, 2, . . . , Nu, thenypkq will only have values for k P t1, 2, . . . , N ´ 1u, because the last element of ypkq that we canconstruct is

ypN ´ 1q “ ypNq ´ ypN ´ 1q.

Since the function iddata only takes input/output pairs of the same length, this means that we needto discard the last input data upNq. The following MATLAB R© commands could be used construct yfrom y and also to discard the last element of u:

System Identification 35

bary=y(2:end)-lambda*y(1:end-1); u=u(1:end-1); 2

MATLAB R© Hint 15 (compare). The command compare from the identification toolbox allows oneto compare experimental outputs with simulated values from an estimated model. This is useful tovalidate model identification. The command

compare(data,model)

plots the measured output from the input/output data object data and the predictions obtained fromthe estimated model model. See MATLAB R© hints 14, 10 for details on these objects. 2

4.5 To Probe FurtherNote 33 (Large standard deviations for the parameter estimates). Obtaining a standard deviation forone parameter that is comparable or larger than its estimated value typically arises in one of threesituations:

1. The data collected is not sufficiently rich. This issue is discussed in detail in Section 5.1. It cangenerally be resolved by choosing a different input signal u for the identification procedure.

2. One has hypothesized an incorrect value for the number of poles, the number of zeros, of thesystem delay. This issue is discussed in detail in Section 5.4. It can generally be resolved byone of three options:

• When encounters small estimated value for parameters corresponding to the terms inthe denominator of (4.6) with the most negative powers in z , this may be resolved byselecting a smaller value for nb;

• When encounters small estimated value for parameters corresponding to the terms in thenumerator of (4.6) with the most negative powers in z , this may be resolved by selectinga smaller value for na;

• When encounters small estimated value for parameters corresponding to the terms in thenumerator of (4.6) with the least negative powers in z , this may be resolved by selectinga large value for nk.

3. One is trying to identify a parameter whose value is actually zero or very small.When the parameter is one of the leading/trailing coefficients of the numerator/denominatorpolynomials, this is can be addressed as discussed in the previous bullet. Otherwise, generallythere is not much one can do about it during system identification. However, since there is afair chance that the value of this parameter has a large percentage error (perhaps even thewrong sign), we must make sure that whatever controller we design for this system is robustwith respect to errors in such parameter. This issue is addressed in Chapters 6–7. 2

4.6 Exercises4.1 (Known zero). Suppose that the process is known to have a zero at z “ γ , i.e., that

Hpzq “ pz ´ γqHpzq,

where Hpzq corresponds to the unknown portion of the transfer function. How would you estimateHpzq? What if you known that the process has both a zero at γ and a pole at λ? 2

4.2 (Selected parameters). The data provided was obtained from a system with transfer function

Hpzq “ z ´ .5pz ´ .3qpz ´ pq ,

where p is unknown. Use the least-squares method to determine the value of p. 2

36 João P. Hespanha

Chapter 5

Practical Considerations in ParametricIdentification

Contents5.1 Choice of Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375.2 Signal Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.3 Choice of Sampling Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.4 Choice of Model Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455.5 Combination of Multiple Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.6 Closed-loop Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.7 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

5.1 Choice of InputsThe quality of least-squares estimates depends significantly on the input upkq used. The choice ofinputs should take into account the following requirements:

1. The input should be sufficiently rich so that the matrix R is nonsingular (and is well condi-tioned).

(a) Single sinusoids should be avoided because a sinusoid of frequency Ω will not allow usNote 34. Why? H1pzq “ 1

z´1and H2pzq “ z`2

z´3 have the samevalue for z “ ejπ2 “ j . Thereforethey will lead to the same ypkqwhen upkq is a sinusoid with fre-quency π2. This input will not al-low us to distinguish between H1and H2 .

to distinguish between different transfer functions with exactly the same value at thepoint z “ ejΩ.

(b) Good inputs include: square-waves, the sum of many sinusoids, or a chirp signal (i.e., asignal with time-varying frequency).

Note 35. Combining multiple ex-periments (see Section 5.5), eachusing a sinusoid of a different fre-quency is typically better than us-ing a chirp signal since one hasbetter control of the duration ofthe input signals at the differentfrequencies.

2. The amplitude of the resulting output ypkq should be much larger than the measurement noise.In particular, large inputs are needed when one wants to probe the system at frequencies forwhich the noise is large.However, when the process is nonlinear but is being approximated by a linear model, largeinputs may be problematic because the linearization may not be valid. As shown in Figure 5.1,there is usually an “optimal” input level that needs to be determined by trial-and-error. 2

3. The input should be representative of the class of inputs that are expected to appear in thefeedback loop.

(a) The input should have strong components in the range of frequencies at which the systemwill operate.

37

38 João P. Hespanha

noise

dominates

optimal

nonlinear

behavior

SSEy2

input magnitude

Figure 5.1. Optimal choice of input magnitude

(b) The magnitude of the input should be representative of the magnitudes that are expectedin the closed loop.

Validation. The choice of input is perhaps the most critical aspect in good system identification.After any identification procedure the following steps should be followed to make sure that the datacollected is adequate:

1. Check if the matrix R is far from singular. If not a different “richer” input should be used.MATLAB R© Hint 14. When usingthe arx command, the singular-ity of the matrix R can be inferredfrom the standard deviations as-sociated with the parameter esti-mates. . . p. 33,35

2. Check the quality of fit by computing SSEY 2 . If this quantity is not small, one of the following

MATLAB R© Hint 14. When usingthe arx command, the qual-ity of fit can be inferred fromthe noise field in the estimatedmodel. . . p. 33

is probably occurring:

(a) There is too much noise and the input magnitude needs to be increased.(b) The inputs are outside the range for which the process is approximately linear and the

input magnitude needs to be decreased.(c) The assumed degrees for the numerator and denominator are incorrect (see Section 5.4).

3. After an input signal upkq passed the checks above, repeat the identification experimentwith the input αupkq with α “ ´1, α “ .5. If the process is in the linear region, themeasured outputs should roughly by equal to αypkq and the two additional experimentsshould approximately result in the same transfer function. When one obtains larger gains inthe experiment with α “ .5, this typically means that the process is saturating and one needsto decrease the magnitude of the input.

Example 5.1 (Two-cart with spring). To make these concepts concrete, we will use as a runningexample the identification of the two-carts with spring apparatus shown in Figure 5.2. From Newton’s

m1 m2

x1 x2

F

Figure 5.2. Two-mass with spring

law one concludes that

m1:x1 “ kpx2 ´ x1q ` f, m2:x2 “ kpx1 ´ x2q, (5.1)

where x1 and x2 are the positions of both carts, m1 and m2 the masses of the carts, and k the springconstant. The force f is produced by an electrical motor driven by an applied voltage v according to

f “KmKgRmr

´

v ´KmKgr

9x1¯

, (5.2)

where Km, Kg, Rm, and r are the motor parameters.

System Identification 39

For this system, we are interested in taken the control input to be the applied voltage u – vand the measured output to be the position y – x2 of the second cart. To determine the system’stransfer function, we replace f from (5.2) into (5.1) and take Laplace transforms to conclude that

#

m1s2X1psq “ k`

Y psq ´ X1psq˘

`KmKgRmr

´

Upsq ´ KmKgr sX1psq

¯

m2 s2Y psq “ k`

X1psq ´ Y psq˘

ñ

#

´

m1s2 `K 2mK 2

gRmr2 s` k

¯

X1psq “ kY psq ` KmKgRmr Upsq

`

m2 s2 ` k˘

Y psq “ kX1psq

ñ`

m2 s2 ` k˘

´

m1s2 `K 2mK 2

g

Rmr2s` k

¯

Y psq “ k2Y psq `kKmKgRmr

Upsq

Y psqUpsq “

kKmKgRmr

`

m2 s2 ` k˘

´

m1s2 `K 2mK 2

gRmr2 s` k

¯

´ k2(5.3)

where the large caps signals denote the Laplace transforms of the corresponding small caps signals.

From the first principles model derived above, we expect this continuous-time system to have 4poles and no zero. Moreover, a close look at the denominator of the transfer function in (5.3) reveals

Note 36. We can make use of theknowledge that the continuous-time system has 4 poles, be-cause the corresponding discrete-time transfer function will havethe same number of poles. How-ever, the absence of zeros inthe continuous-time transfer func-tions tell us little about the num-ber of zeros in the correspond-ing discrete-time transfer functionbecause the Tustin transformationdoes not preserve the number ofzeros (cf. Note 10). . . p. 14

that there is no term of order zero, since the denominator is equal to

`

m2 s2 ` k˘

´

m1s2 `K 2mK 2

g

Rmr2s` k

¯

´ k2 “ m2 s2´

m1s2 `K 2mK 2

g

Rmr2s` k

¯

` km1s2 `kK 2

mK 2g

Rmr2s

and therefore the system should have one pole at zero, i.e., it should contain one pure integrator.

Our goal now is to determine the system’s transfer function (5.3) using system identification frominput/output measurements. The need for this typically stems from the fact that

1. we may not know the values of the system parameters m1, m2, k , km, Kg, Rm, and r; and

2. the first-principles model (5.1)–(5.2) may be ignoring factors that turn out to be important, e.g.,the mass of the spring itself, friction between the masses and whatever platform is supportingthem, the fact that the track where the masses move may not be perfectly horizontal, etc.

Figure 5.3(a) shows four sets of input/output data and four discrete-time transfer functions iden-tified from these data sets.

Key observations. A careful examination of the outputs of the arx command and the plots inFigure 5.3 reveals the following:

1. The quality of fit appears to be very good since arx reports a very small value for the noiseparameter (around 10´10). But this value is suspiciously small when compared to the averagevalue of y2 (around 10´2).

2. The standard deviations associated with the denominator parameters are small when comparedto the parameter estimates (ranging from 2 to 100 times smaller than the estimates).

3. The standard deviations associated with the numerator parameters appear to be worse, oftenexceeding the estimate, which indicate problems in the estimated transfer functions.

4. While difficult to see in Figure 5.3(a), it turns out that the data collected with similar inputsignals (square wave with a period of 2Hz) but 2 different amplitudes (2v and 4v) resulted inroughly the same shape of the output, but scaled appropriately. However, the fact that this isdifficult to see in Figure 5.3(a) because of scaling is actually an indication of trouble, as weshall discuss shortly.

40 João P. Hespanha

0.5 1 1.5

−2

−1

0

1

2

square_a2_f0.5.mat

input [v]output [m]

0.5 1 1.5

−2

−1

0

1

2

square_a2_f1.mat

input [v]output [m]

0.5 1 1.5

−2

−1

0

1

2

square_a2_f2.mat

input [v]output [m]

0.5 1 1.5

−4

−2

0

2

4

square_a4_f2.mat

input [v]output [m]

(a) Four sets of input/output data used to estimate the two-mass system in Figure 5.2. In allexperiments the input signal u is a square wave with frequencies .5Hz, 1Hz, 2Hz, and 2Hz,respectively, from left to right and top to bottom. In the first three plots the square waveswitches from -2v to +2v, whereas in the last plot it switches from -4v to +4v. All signalswere sampled at 1KHz.

10−3

10−2

10−1

100

101

102

103

−140

−120

−100

−80

−60

−40

−20

0

f [Hz]

mag

nitu

de [d

B]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

10−3

10−2

10−1

100

101

102

103

−400

−300

−200

−100

0

f [Hz]

phas

e [d

eg]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

(b) Four discrete-time transfer functions estimated from the four sets of input/output data in(a), sampled at 1KHz. The transfer functions were obtained using the MATLAB R© commandarx with na “ 4, nb “ 4, and nk “ 1, which reflects an expectation of 4 poles and a delay ofone sampling period. The one period delay from upkq to ypkq is natural since a signal appliedat the sampling time k will not affect the output at the same sampling time k (See Note 32,p. 34). The labels in the transfer functions refer to the titles of the four sets of input/outputdata in (a).

Figure 5.3. Initial attempt to estimate the discrete-time transfer function for the two-mass system in Figure 5.2.

System Identification 41

5. The integrator that we were expecting in the transfer functions is not there.

6. The four sets of data input/output data resulted in dramatically different identified transferfunctions.

The last three items are, of course, of great concern, and a clear indication that we are not gettinga good transfer function.

Fixes. The fact that we are not seeing an integrator in the identified transfer functions is nottoo surprising, since our probe input signals are periodic square waves, which has no componentat the zero frequency. The input that has the most zero-frequency component is the square wavewith frequency .5Hz (cf. top-left plot in Figure 5.3(a)), for which less than a full period of data wasapplied to the system. Not surprisingly, that data resulted in the transfer function that is closer toan integrator (i.e., it is larger at low frequencies).

Since we know that the system has a structural pole at z “ 1, we should force it into the modelusing the technique seen in Section 4.3. Figure 5.4(a) shows the same four sets of input/output dataused to estimate the discrete-time transfer function, but the signal labeled “output” now correspondsto the signal y that we encountered in Section 4.3. The new identified transfer functions that appearin Figure 5.4(b) are now much more consistent, mostly exhibiting differences in phase equal to 360deg. However, the standard deviations associated with the numerator parameters continue to belarge, often exceeding the estimate. 2

5.2 Signal ScalingFor the computation of the least-squares estimate to be numerically well conditioned, it is importantthat the numerical values of both the inputs and the outputs have roughly the same order of magnitude.Because the units of these variable are generally quite different, this often requires scaling of thesevariables. It is good practice to scale both inputs and outputs so that all variable take “normal”values in the same range, e.g., the interval r´1, 1s.

Attention! After identification, one must then adjust the system gain to reflect the scaling performedon the signals used for identification: Suppose that one takes the original input/output data set u, yand constructs a new scaled data set u, y, using

upkq “ αuupkq, ypkq “ αyypkq, @k.

If one then uses u and y to identify the transfer function

Hpzq “ UpzqY pzq

“αuαyUpzqY pzq ,

in order to obtain the original transfer function Hpzq from u to y, one need to reverse the scaling:

Hpzq “ UpzqY pzq “

αyαuHpzq. 2

Example 5.2 (Two-cart with spring (cont.)). We can see in Figure 5.4(a), that the input and outputsignals used for identification exhibit vastly different scales. In fact, when drawn in the same axis,the output signals appears to be identically zero.

Fix. To minimize numerical errors, one can scale the output signal by multiplying it by a sufficientlylarge number so that it becomes comparable with the input. Figure 5.4(a) shows the same four setsof input/output data used to estimate the discrete-time transfer function, but the signal labeled“output” now corresponds to a scaled version of the signal y that we encountered in Section 4.3.

42 João P. Hespanha

0.5 1 1.5

−2

−1

0

1

2

square_a2_f0.5.mat

input [v]output [m]

0.5 1 1.5

−2

−1

0

1

2

square_a2_f1.mat

input [v]output [m]

0.5 1 1.5

−2

−1

0

1

2

square_a2_f2.mat

input [v]output [m]

0.5 1 1.5

−4

−2

0

2

4

square_a4_f2.mat

input [v]output [m]

(a) Four sets of input/output data used to estimate the two-mass system in Figure 5.2. In allexperiments the input signal u is a square wave with frequencies .5Hz, 1Hz, 2Hz, and 2Hz,respectively, from left to right and top to bottom. In the first three plots the square waveswitches from -2v to +2v, whereas in the last plot it switches from -4v to +4v. The signallabeled “output” now corresponds to the signal y that we encountered in Section 4.3. Allsignals were sampled at 1KHz.

10−3

10−2

10−1

100

101

102

103

−150

−100

−50

0

50

f [Hz]

mag

nitu

de [d

B]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

10−3

10−2

10−1

100

101

102

103

−200

−100

0

100

200

300

f [Hz]

phas

e [d

eg]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

(b) Four discrete-time transfer functions estimated from the four sets of input/output data in(a), sampled at 1KHz. The transfer functions were obtained using the MATLAB R© commandarx with na “ 3, nb “ 4, and nk “ 0, which reflects an expectation of 3 poles in additionto the one at z “ 1 and no delay from u to y. No delay should now be expected since upkqcan affect ypk ` 1q, which appears directly in ypkq (See Note 32, p. 34). A pole at z “ 1was inserted manually into the transfer function returned by arx. The labels in the transferfunctions refer to the titles of the four sets of input/output data in (a).

Figure 5.4. Attempt to estimate the discrete-time transfer function for the two-mass system in Figure 5.2, forcinga pole at z “ 1.

System Identification 43

0.5 1 1.5

−2

−1

0

1

2

square_a2_f0.5.mat

input [v]output [m*5000]

0.5 1 1.5

−2

−1

0

1

2

square_a2_f1.mat

input [v]output [m*5000]

0.5 1 1.5

−2

−1

0

1

2

square_a2_f2.mat

input [v]output [m*5000]

0.5 1 1.5

−4

−2

0

2

4

square_a4_f2.mat

input [v]output [m*5000]

(a) Four sets of input/output data used to estimate the two-mass system in Figure 5.2. In allexperiments the input signal u is a square wave with frequencies .5Hz, 1Hz, 2Hz, and 2Hz,respectively, from left to right and top to bottom. In the first three plots the square waveswitches from -2v to +2v, whereas in the last plot it switches from -4v to +4v. The signallabeled “output” now corresponds to a scaled version of the signal y that we encountered inSection 4.3. All signals were sampled at 1KHz.

10−3

10−2

10−1

100

101

102

103

−150

−100

−50

0

50

f [Hz]

mag

nitu

de [d

B]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

10−3

10−2

10−1

100

101

102

103

−200

−100

0

100

200

300

f [Hz]

phas

e [d

eg]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

(b) Four discrete-time transfer functions estimated from the four sets of input/output data in(a), sampled at 1KHz. The transfer functions were obtained using the MATLAB R© commandarx with na “ 3, nb “ 4, and nk “ 0, which reflects an expectation of 3 poles in additionto the one at z “ 1 and no delay from u to y. A pole at z “ 1 was inserted manually intothe transfer function returned by arx and the output scaling was reversed back to the originalunits. The labels in the transfer functions refer to the titles of the four sets of input/outputdata in (a).

Figure 5.5. Attempt to estimate the discrete-time transfer function for the two-mass system in Figure 5.2, forcinga pole at z “ 1 and with appropriate output scaling.

44 João P. Hespanha

Key observation. While the transfer functions identified do not show a significant improvements andthe standard deviations associated with the numerator parameters continue to be large, Figure 5.4(a)now shows a clue to further problems: the output signals exhibits significant quantization noise.

2

5.3 Choice of Sampling FrequencyFor a discrete-time model to accurately capture the process’ continuous-time dynamics, the sam-pling frequency should be as large as possible. However, this often leads to difficulties in systemidentification.

As we have seen before, least-squares ARX identification amounts to finding the values for theparameters that minimize the sum of squares difference between the two sides of the followingequation:

ypkq “ ´βn´1ypk ´ 1q ´ ¨ ¨ ¨ ´ β1ypk ´ n` 1q ` β0ypk ´ nq`` αmupk ´ n` mq ` αm´1upk ´ n` m´ 1q ` ¨ ¨ ¨ ` α1upk ´ n` 1q ` α0upk ´ nq. (5.4)

In particular, one is looking for values of the parameters that are optimal at predicting ypkq basedon inputs and outputs from time k ´ 1 back to time k ´ n.

When the sampling period is very short, all the output values

ypkq, ypk ´ 1q, . . . , ypk ´ nq

that appear in (5.4) are very close to each other and often their difference is smaller than onequantization interval of the analogue-to-digital converter (ADC). As shown in Figure 5.6, in this casethe pattern of output values that appear in (5.4) is mostly determined by the dynamics of the ADCconverter and the least-squares ARX model will contain little information about the process transferfunction.

0.96 0.98 1 1.02 1.04

−1.6

−1.5

−1.4

−1.3

−1.2

−1.1

−1

square_a2_f0.5.mat

input [v]output [m*5000]

0.96 0.98 1 1.02 1.04

1

1.2

1.4

1.6

1.8

2

square_a2_f1.mat

input [v]output [m*5000]

0.96 0.98 1 1.02 1.04

0.8

1

1.2

1.4

1.6

square_a2_f2.mat

input [v]output [m*5000]

0.96 0.98 1 1.02 1.04

2

2.5

3

3.5

square_a4_f2.mat

input [v]output [m*5000]

Figure 5.6. Magnified version of the four plots in Figure 5.5(a) showing the input and output signals around timet “ 1s. The patterns seen in the output signals are mostly determined by the dynamics of the ADC converter.

As we increase the sampling time, the difference between the consecutive output values increasesand eventually dominates the quantization noise. In practice, one wants to chose a sampling rate

System Identification 45

that is large enough so that the Tustin transformation is valid but sufficiently small so that thequantization noise does not dominate. A good rule of thumb is to sample the system at a frequency20-40 times larger than the desired closed-loop bandwidth for the system.

Down-SamplingIt sometimes happens that the hardware used to collect data allow us to sample the system atfrequencies much larger than what is needed for identification—oversampling. In this case, onegenerally needs to down-sample the signals but this actually provides an opportunity to removemeasurement noise from the signals.

Suppose that ypkq and upkq have been sampled with a period Tlow but one wants to obtainMATLAB R© Hint 17. A signaly can by down-sampled as in(5.5) using bary=y(1:L:end).Down-sampling can also beachieved with the commandbary=downsample(y,L). Thiscommand requires MATLAB R©’ssignal processing toolbox.

signals ypkq and upkq sampled with period Thigh – L Tlow where L is some integer larger than one.The simplest method to obtain ypkq and upkq consists of extracting only one out of each L

samples of the original signals:

ypkq “ ypLkq, upkq “ upLkq. (5.5)

Instead of discarding all the remaining samples, one can achieve some noise reduction by averaging,MATLAB R© Hint 18. A signal ycan by down-sampled as in (5.6)using bary=(y(1:L:end-2)+ y(2:L:end-1) +y(3:L:end))/3.

as in

ypkq “ ypLk ´ 1q ` ypLkq ` ypLk ` 1q3 , (5.6)

upkq “ upLk ´ 1q ` upLkq ` upLk ` 1q3 , (5.7)

or even longer averaging. The down-sampled signals obtained in this way exhibit lower noise thanMATLAB R© Hint 19. Down-sampling with more sophis-ticated (and longer) filteringcan be achieved with thecommand resample, e.g.,bary=resample(y,1,L,1).This command requiresMATLAB R©’s signal process-ing toolbox. . . p. 50

the original ones because noise is being “averaged out.”

Example 5.3 (Two-cart with spring (cont.)). We can see, e.g., in Figure 5.4(b) that the system appearsto have an “interesting” dynamical behavior in the range of frequencies from .1 to 10Hz. “Interesting,”in the sense that the phase varies and the magnitude bode plot is not just a line. Since the samplingfrequency of 1kHz lies far above this range, we have the opportunity to down-sample the measuredsignals and remove some of the measurement noise that was evident in Figure 5.4(a).

Fix. To remove some noise quantization noise, we down-sampled the input and output signalsby a factor of 10 with the MATLAB R© resample command. The new discrete-time frequency istherefore now sampled only at 100Hz, but this still appears to be sufficiently large. Figure 5.7(a)shows the same four sets of input/output data used to estimate the discrete-time transfer function,down-sampled from the original 1KHz to 100Hz. By comparing this figure with Figure 5.5(a), we canobserve a significant reduction in the output noise level.

Key observation. The transfer functions identified show some improvement, especially because weare now starting to see some resonance, which would be expected in a system like this. Moreimportantly, now all the standard deviations associated with the numerator and denominator param-eters are reasonably small when compared to the parameter estimates (ranging from 2.5 to 30 timessmaller than the estimates). 2

5.4 Choice of Model OrderA significant difficulty in parametric identification of ARX models is that to construct the regressionvector φpkq, one needs to know the degree n of the denominator. In fact, an incorrect choice for nwill generally lead to difficulties.

1. Selecting a value for n too small will lead to mismatch between the measured data and themodel and the SSE will be large.

46 João P. Hespanha

0.6 0.8 1 1.2 1.4 1.6−2

−1

0

1

2square_a2_f0.5.mat

input [v]output [m*500]

0.6 0.8 1 1.2 1.4 1.6−2

−1

0

1

2square_a2_f1.mat

input [v]output [m*500]

0.6 0.8 1 1.2 1.4 1.6−2

−1

0

1

2square_a2_f2.mat

input [v]output [m*500]

0.6 0.8 1 1.2 1.4 1.6−4

−2

0

2

4square_a4_f2.mat

input [v]output [m*500]

(a) Four sets of input/output data used to estimate the two-mass system in Figure 5.2. Inall experiments the input signal u is a square wave with frequencies .5Hz, 1Hz, 2Hz, and2Hz, respectively, from left to right and top to bottom. In the first three plots the squarewave switches from -2v to +2v, whereas in the last plot it switches from -4v to +4v. Thesignal labeled “output” corresponds to a scaled version of the signal y that we encounteredin Section 4.3. All signals were down-sampled from 1 KHz to 100Hz.

10−2

10−1

100

101

102

−120

−100

−80

−60

−40

−20

0

20

f [Hz]

mag

nitu

de [d

B]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

10−2

10−1

100

101

102

−200

−100

0

100

200

300

f [Hz]

phas

e [d

eg]

square_a2_f0.5.matsquare_a2_f1.matsquare_a2_f2.matsquare_a4_f2.mat

(b) Four discrete-time transfer functions estimated from the four sets of input/output data in(a), sampled at 1KHz. The transfer functions were obtained using the MATLAB R© commandarx with na “ 3, nb “ 4, and nk “ 0, which reflects an expectation of 3 poles in additionto the one at z “ 1 and no delay from u to y. A pole at z “ 1 was inserted manually intothe transfer function returned by arx and the output scaling was reversed back to the originalunits. The labels in the transfer functions refer to the titles of the four sets of input/outputdata in (a).

Figure 5.7. Attempt to estimate the discrete-time transfer function for the two-mass system in Figure 5.2, forcinga pole at z “ 1, with appropriate output scaling, and with the signals down-sampled to 100Hz.

System Identification 47

2. Selecting a value for n too large is called over-parameterization and it generally leads to Rbeing close to singular. To understand why, suppose we have a transfer function

Hpzq “ 1z ´ 1 ,

but for estimation purposes we assumed that n “ 2 and therefore attempted to determineconstants αi , βi such that

Hpzq “ α2z2 ` α1z ` α0z2 ` β1z ` β0

.

If the model was perfect, it should be possible to match the data with any αi , βi such that

α2z2 ` α1z ` α0z2 ` β1z ` β0

“z ´ p

pz ´ 1qpz ´ pq ô

#

α2 “ 0, α1 “ 1, α0 “ ´p,β1 “ ´1´ p, β0 “ p,

(5.8)

where p can be any number. This means that the data is not sufficient to determine the valuesof the parameters α0, β0, β1, which translates into R being singular.

MATLAB R© Hint 20. When usingthe arx MATLAB R© command, sin-gularity of R can be inferred fromstandard deviations for the param-eters that are large when com-pared with the estimated param-eter values. . . p. 35

When there is noise, it will never be possible to perfectly explain the data and the smallestSSE will always be positive (either with n “ 1 or n “ 2). However, in general, differentvalues of p will result in different values for SSE . In this case, least-squares estimation willproduce the specific value of p that is better at “explaining the noise,” which is not physicallymeaningful.

When one is uncertain about which values to choose for m and n, the following procedure should beNote 37. When the number ofpoles n is chosen correctly, a num-ber of zeros m too large will gen-erally not lead to trouble so onemay as well chose the largest onethat is physically meaningful. If itis known that there is a delay ofat least d, one should make m “n´d [cf. equation (4.2)]. . . p. 32

followed:

1. Select for n the smallest possible integer that is physically meaningful (conceivably 0).

2. Do least-square estimation with m “ n.

(a) If the SSE is large and R is far from singular increase n and repeat the identification.(b) If R is close to singular or the SSE did not decrease significantly, then n got too large,

go back to the previous n and stop.Note. Identifying a process trans-fer function with a pole-zero can-cellation, like in (5.8), will makecontrol extremely difficult sincefeedback will not be able to movethat “phantom” zero/pole. Thisis especially problematic if the“phantom” pole is unstable or veryslow.

One needs to exercise judgment in deciding when “the SSE is large” or when “R is far/close tosingular.” Physical knowledge about the model should play a major role in deciding model orders.Moreover, one should always be very concerned about identifying noise, as opposed to actuallyidentifying the process model.

Example 5.4 (Two-cart with spring (cont.)). Figure 5.8 shows results obtained for the input/outputdata set shown in the bottom-right plot of Figure 5.7(a). The procedure to estimate the discrete-time transfer functions was similar to that used to obtain the those in Figure 5.7(b), but we let theparameter na “ nb´ 1 that defines the number of poles (excluding the integrator at z “ 1) rangefrom 1 to 12. The delay parameter nk was kept equal to 0.

As expected, the SSE error decreases as we increase na, but the standard deviation of thecoefficients generally increases as we increase na, and rapidly becomes unacceptably large. Theplot indicates that for na between 3 and 6 the parameter estimates exhibit relatively low variance.For larger values of na the decrease in SSE does not appear to be justify the increase in standarddeviation.

Key observation. While the results improved dramatically with respect to the original ones, thestandard deviations for the parameter estimates are still relatively high. We can see from Fig-ure 5.8(a) that even for na “ 4, at least one standard deviation is still above 20% of the value ofthe corresponding parameter. This means that the data used is still not sufficiently rich to achievea reliable estimate for the transfer function. 2

48 João P. Hespanha

0 2 4 6 8 10 1210

−5

10−4

10−3

10−2

10−1

mea

n S

SE

per

sam

ple

poin

t

number of poles (excluding pole at z=1)

0 2 4 6 8 10 1210

−1

100

101

102

number of poles (excluding pole at z=1)

max

(std

dev

/est

imat

e)

(a) The y-axis of the top plot shows the average SSE error per sample and the y-axis of thebottom plot shows the highest (worst) ratio between a parameter standard deviation and itsvalue. Each point in the plots corresponds to the results obtained for a particular choice ofthe model order. In particular, to obtain these two plots we varied from 1 to 12 the parameterna=nb (shown in the x-axis) that defines the number of poles (excluding the integrator atz “ 1). The delay parameter nk was kept the same equal to 0.

10−2

10−1

100

101

102

−120

−100

−80

−60

−40

−20

0

f [Hz]

mag

nitu

de [d

B]

2345

10−2

10−1

100

101

102

−200

−100

0

100

200

300

f [Hz]

phas

e [d

eg]

2345

(b) Transfer functions corresponding to the identification experiments in (a). Each plot islabeled with the corresponding number of poles (excluding the integrator at z “ 1).

Figure 5.8. Choice of model order. All results in this figure refer to the estimation of the discrete-time transferfunction for the two-mass system in Figure 5.2, using the set of input/output data shown in the bottom-right plotof Figure 5.7(a), forcing a pole at z “ 1, with appropriate output scaling, and with the signals down-sampledto 100Hz.

System Identification 49

5.5 Combination of Multiple ExperimentsAs discussed in Section 5.1, the input used for system identification should be sufficiently rich tomake sure that the matrix R is nonsingular and also somewhat representative of the class of allinputs that are likely to appear in the feedback loop. To achieve this, one could use a single verylong input signal upkq that contains a large number of frequencies, steps, chirp signals, etc. Inpractice, this is often difficult so an easier approach is to conduct multiple identification experiments,each with a different input signal uipkq. These experiments result in multiple sets of input/outputdata that can then be combined to identify a single ARX model.

MATLAB R© Hint 14. mergeallows one to combine datafor this type of multi-inputprocessing. . . p. 33

Suppose, for example, that one wants to identify the following ARX model with two poles andtwo zeros

Y pzqUpzq “

α2z2 ` α1z ` α0z2 ` β1z ` β0

,

and that we want to accomplish this using on an input/output pair `

u1pkq, y1pkq˘

: k “ 1, 2, . . . , N1(

of length N1 and another input/output pair `

u2pkq, y2pkq˘

: k “ 1, 2, . . . , N2(

of length N2. One would construct

Φ “

»

y1p2q y1p1q u1p3q u1p2q u1p1qy1p3q y1p2q u1p4q u1p3q u1p2q

......

......

...y1pN1 ´ 1q y1pN1 ´ 2q u1pN1q u1pN1 ´ 1q u1pN1 ´ 2qy2p2q y2p1q u2p3q u2p2q u2p1qy2p3q y2p2q u2p4q u2p3q u2p2q

......

......

...y2pN2 ´ 1q y2pN2 ´ 2q u2pN2q u2pN2 ´ 1q u2pN2 ´ 2q

fi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

fl

, Y “

»

y1p3qy1p4q

...y1pN1qy2p3qy2p4q

...y2pN1q

fi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

ffi

fl

and, according to Section 4.2, the least-squares estimate of

θ –“

´β1 ´β0 αm α2 α1 α0‰

using all the available data is still given byMATLAB R© Hint 21. PHIzY com-putes θ directly, from the matrixPHI“ Φ and the vector Y“ Y .

θ “ pΦ1Φq´1Φ1Y .

Example 5.5 (Two-cart with spring (cont.)). As noted before, we can see in Figure 5.8 that evenfor na “ 4, at least one standard deviation is still above 20% of the value of the correspondingparameter. This is likely caused by the fact that the all the results in this figure were obtained forthe input/output data set shown in the bottom-right plot of Figure 5.7(a). This input data will beexcellent to infer the response of the system to square waves of 2Hz, and possibly to other periodicinputs in this frequency range. However, this data set is relatively poor in providing information onthe system dynamics below and above this frequency.

Fix. By combining the data from the four sets of input/output data shown in Figure 5.7(a), weshould be able to decrease the uncertainty regarding the model parameters.

Figure 5.9 shows results obtained by combining all four sets of input/output data shown inFigure 5.7(a). Aside from this change, the results shown follow from the same procedure used toconstruct the plots in Figure 5.8.

50 João P. Hespanha

Key Observation. As expected, the standard deviations for the parameter estimates decreased and,for na ď 4, all standard deviations are now below 15% of the values of the corresponding parameter.However, one still needs to combine more inputs to obtain a high-confidence model. In particular,the inputs considered provide relatively little data on the system dynamics above 2-4Hz since the2Hz square wave contains very little energy above its 2nd harmonic. One may also want to use alonger time horizon to get inputs with more energy at low frequencies.

Regarding the choice of the system order, we are obtaining fairly consistent Bode plots for 2-5poles (excluding the integrator at z “ 1), at least up to frequencies around 10Hz. If the systemis expected to operate below this frequency, then one should choose the simplest model, whichwould correspond to 2 poles (excluding the integrator at z “ 1). Otherwise richer input signals aredefinitely needed and will hopefully shed further light into the choice of the number of poles. 2

5.6 Closed-loop IdentificationWhen the process is unstable, one cannot simply apply input probing signals to the open-loopsystems. In this case, a stabilizing controller C must be available to collect the identification data.Typically, this is a low performance controller that was designed using only a coarse process model.

One effective method commonly used to identify processes that cannot be probed in open-loopconsists of injecting an artificial disturbance d and estimating the closed-loop transfer function fromthis disturbance to the control input u and the process output y, as in Figure 5.10.

In this feedback configuration, the transfer functions from d to u and y are, respectively, givenby

Note 38. Why? Denoting by Uand D the Laplace transforms of uand d, respectively, we have thatU “ D ´ CPU , and thereforepI ` CPqU “ D, from which oneconcludes that U “ pI`CPq´1D.To obtain the transfer function toy, one simply needs to multiplythis by P . These formulas arevalid, even if the signals are vec-tors and the transfer functions arematrices.

Attention! There is a directfeedthrough term from d to u,which means that the transferfunction Tupsq will have no delayand therefore it will have thesame number of poles and zeros.

Tupsq “`

I ` C psqPpsq˘´1, Typsq “ Ppsq

`

I ` C psqPpsq˘´1.

Therefore, we can recover Ppsq from these two closed-loop transfer functions, by computing

MATLAB R© Hint 22. The systemPpsq in (5.9) can be computed us-ing Ty*inv(Tu).

Ppsq “ TypsqTupsq´1. (5.9)

This formula can then be used to estimate the process transfer function from estimates of the twoclosed-loop transfer functions Typsq and Tupsq.

In closed-loop identification, if the controller is very good the disturbance will be mostly rejectedfrom the output and Typsq can become very small, leading to numerical errors and poor identification.For identification purposes a sluggish controller that does not do a good job at disturbance rejectionis desirable.

5.7 MATLAB R© HintsMATLAB R© Hint 19 (resample). The command resample from the signal processing toolbox re-samples a signal at a different sampling rate and simultaneously performs lowpass filtering to removealiasing and noise. In particular,

bary=resample(y,M,L,F)

produces a signal bary with a sampling period that is L/M times that of y. Therefore, to reduce thesampling frequency one chooses L>M and the length of the signal ybar will be L/M times smallerthan that of y.In computing each entry of bary, this function averages the values of F*L/M entries of y forwardsand backwards in time. In particular, selecting

bary=resample(y,1,L,1)

the signal bary will be a subsampled version of y with one sample of ybar for each L samples ofy and each sample of ybar will be computed using a weighted average of the 2L samples of y (Lforwards in time and another L backwards in time). 2

System Identification 51

0 2 4 6 8 10 1210

−5

10−4

10−3

10−2

mea

n S

SE

per

sam

ple

poin

t

number of poles (excluding pole at z=1)

0 2 4 6 8 10 1210

−1

100

101

102

103

number of poles (excluding pole at z=1)

max

(std

dev

/est

imat

e)

(a) The y-axis of the top plot shows the average SSE error per sample and the y-axis of thebottom plot shows the highest (worst) ratio between a parameter standard deviation and itsvalue. Each point in the plots corresponds to the results obtained for a particular choice ofthe model order. In particular, to obtain these two plots we varied from 1 to 12 the parameterna=nb (shown in the x-axis) that defines the number of poles (excluding the integrator atz “ 1). The delay parameter nk was kept the same equal to 0.

10−2

10−1

100

101

102

−100

−80

−60

−40

−20

0

20

f [Hz]

mag

nitu

de [d

B]

2345

10−2

10−1

100

101

102

−200

−100

0

100

200

300

f [Hz]

phas

e [d

eg]

2345

(b) Transfer functions corresponding to the identification experiments in (a). Each plot islabeled with the corresponding number of poles (excluding the integrator at z “ 1).

Figure 5.9. Choice of model order. All results in this figure refer to the estimation of the discrete-time transferfunction for the two-mass system in Figure 5.2, using all four sets of input/output data shown in Figure 5.7,forcing a pole at z “ 1, with appropriate output scaling, and with the signals down-sampled to 100Hz.

52 João P. Hespanha

yu

d

´

PpsqC psq

Figure 5.10. Closed-loop system

5.8 Exercises5.1 (Input magnitude). A Simulink block that models a nonlinear spring-mass-damper system isprovided.

1. Use the Simulink block to generate the system’s response to step inputs with amplitude 0.25and 1.0 and no measurement noise.

2. For each set of data, use the least-squares method to estimate the systems transfer function.Try a few values for the degrees of the numerator and denominator polynomials m and n.Check the quality of the model by following the validation procedure outlines above.Important: write MATLAB R© scripts to automate these procedures. These scripts should takeas inputs the simulation data upkq, ypkq, and the integers m, n.

3. Use the Simulink block to generate the system’s response to step inputs and measurementnoise with intensity 0.01.For the best values of m and n determined above, plot the SSE vs. the step size. Whichstep-size leads to the best model? 2

5.2 (Model order). Use the data provided to identify the transfer function of the system. Use theprocedure outlined above to determine the order of the numerator and denominator polynomials. Plotthe largest and smallest singular value of R and the SSE as a function of n.Important: write MATLAB R© scripts to automate this procedure. These scripts should take as inputsthe simulation data upkq, ypkq, and the integers m, n. 2

5.3 (Sampling frequency). Consider a continuous-time system with transfer function

Ppsq “ 4π2

s2 ` πs` 4π2 .

1. Build a Simulink model for this system and collect input/output data for an input squarewave with frequency .25Hz and unit amplitude for two sampling frequencies Ts “ .25sec andTs “ .0005sec.

2. Identify the system’s transfer function without down-sampling.

3. Identify the system’s transfer function using the data collected with Ts “ .0005sec but down-sampled.Important: write MATLAB R© scripts to automate this procedure. These scripts should take asinputs the simulation data upkq, ypkq, the integers m, n, and the down-sampling period L.

4. Briefly comment on the results. 2

Part II

Robust Control

53

Introduction to Robust Control

For controller design purposes it is convenient to imagine that we know an accurate model for theprocess, e.g., its transfer function. In practice, this is hardly ever the case:

1. When process models are derived from first principles, they always exhibit parameters that canonly be determined up to some error.E.g., the precise values of masses, moments of inertia, and friction coefficients in models derivedfrom Newton’s laws; or resistances, capacitances, and gains, in electrical circuits.

2. When one identifies a model experimentally, noise and disturbances generally lead to differentresults as the identification experiment is repeated multiple times. Which experiment gave thetrue model? The short answer is none, all models obtained have some error.

3. Processes change due to wear and tear so even if a process was perfectly identified beforestarting operation, its model will soon exhibit some mismatch with respect to the real process.

The goal of this chapter is to learn how to take process model uncertainty into account, whiledesigning a feedback controller.

Pre-requisites

1. Laplace transform, continuous-time transfer functions, frequency responses, and stability.

2. Classical continuous-time feedback control design using loop-shaping.

3. Knowledge of MATLAB/Simulink.

Further reading A more extensive coverage of robust control can be found, e.g., in [4].

55

56 João P. Hespanha

Chapter 6

Robust stability

Contents6.1 Model Uncertainty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576.2 Nyquist Stability Criterion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606.3 Small Gain Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

6.1 Model UncertaintySuppose we want to control the spring-mass-damper system in Figure 6.1, which has the following

ym

k

u

bMeasuring the mass’ vertical position y withrespect to the rest position of the spring, weobtain from Newton’s law:

m:y “ ´b 9y´ ky` u

Figure 6.1. Spring-mass-damper system.

transfer function from the applied force u to the spring position y

Ppsq “ 1ms2 ` bs` k . (6.1)

Typically, the mass m, the friction coefficient b, and the spring constant k would be identifiedexperimentally (or taken from some specifications sheet) leading to confidence intervals for theseparameters and not just a single value:

m P rm0 ´ δ1, m0 ` δ1s, b P rb0 ´ δ2, b0 ` δ2s, k P rk0 ´ δ3, k0 ` δ3s.

The values with subscript 0 are called the nominal values for the parameters and the δi are calledthe maximum deviations from the nominal value.

In practice, this means that there are many admissible transfer functions for the process—onefor each possible combination of m, b, and k in the given intervals. Figure 6.2 shows the Bode plot

MATLAB R© Hint 23. bode(sys)draws the Bode plot of the systemsys. . . p. 13

of (6.1) for different values of the parameters m, b, and k . The idea behind robust control is to designa single controllers that achieves acceptable performance (or at least stability) for every admissibleprocess transfer function.

57

58 João P. Hespanha

−60

−50

−40

−30

−20

−10

0

10

20

Mag

nitu

de (

dB)

10−1

100

101

−180

−135

−90

−45

0

Pha

se (

deg)

Bode Diagram

Frequency (rad/sec)

Figure 6.2. Bode plot of Ppsq “ 1ms2`bs`k , for different values of m P r.9, 1.1s, b P r.1, .2s, and k P r2, 3s. Note

how the different values of the parameters lead to different values for the resonance frequency. One can seein the phase plot that it may be dangerous to have the cross-over frequency near the “uncertain” resonancefrequency since the phase margin may very a lot depending on the system parameters. In particular, one processtransfer function may lead to a large phase margin, whereas another one to an unstable closed-loop system.

6.1.1 Additive UncertaintyIn robust control one starts by characterizing the uncertainty in terms of the process’ frequencyresponse. To this effect on selects a nominal process transfer function P0psq and, for each admissibleprocess transfer function Ppsq, one defines:

∆apsq– Ppsq ´ P0psq, (6.2)

which measures how much Ppsq deviates from P0psq. This allows us to express any admissibletransfer function Ppsq as in Figure 6.3. Motivated by the diagram in Figure 6.3, ∆apsq is called anadditive uncertainty block. P0psq should correspond to the “most likely” transfer function, so that

+

+

yu

∆apsq

P0psq

Ppsq

∆apsq– Ppsq ´ P0psqõ

Ppsq “ P0psq ` ∆apsq

Figure 6.3. Additive uncertainty

the additive uncertainty block is as small as possible. In the example above, one would typicallychoose the transfer function corresponding to the nominal parameter values:

P0psq “1

m0s2 ` b0s` k0.

To obtain a characterization of the uncertainty purely in the frequency domain, one needs to specifyhow large ∆apjωq may be for each frequency ω. This is done by determining a function `apωqsufficiently large so that for every admissible process transfer function Ppsq we have

|∆apjωq| “ |Ppjωq ´ P0pjωq| ď `apωq, @ω.

Robust Control 59

When one has available all the admissible Ppsq (or a representative set of them—such as in Fig-ure 6.2), one can determine `apωq by simply plotting |Ppjωq ´ P0pjωq| vs. ω for all the Ppsq andchoosing for `apωq a function larger than all the plots. Since in general it is not feasible to plot all|Ppjωq´P0pjωq|, one should provide some “safety-cushion” when selecting `apωq. Figure 6.4 shows`apωq for the Bode plots in Figure 6.2.

10−1

100

101

−100

−80

−60

−40

−20

0

20

Magnitude (dB)

Freq

uenc

y (rad

/sec)

Figure 6.4. Additive uncertainty bounds for the process Bode plots in Figure 6.2 with P0psq – 1m0s2`b0s`k0

,m0 “ 1, b0 “ 1.5, k0 “ 2.5. The solid lines represent possible plots for |Ppjωq ´ P0pjωq| and the dashed onerepresents the uncertainty bound `apωq. Note the large uncertainty bound near the resonance frequency. Weshall show shortly how to design a controller that stabilizes all processes for which the additive uncertaintyfalls below the dashed line.

6.1.2 Multiplicative UncertaintyThe additive uncertainty in (6.2) measures the difference between Ppsq and P0psq in absolute termsand may seem misleadingly large when both Ppsq and P0psq are large—e.g., at low frequencieswhen the process has a pole at the origin. To overcome this difficulty one often defines instead

∆mpsq–Ppsq ´ P0psq

P0psq, (6.3)

which measures how much Ppsq deviates from P0psq, relative to the size of Popsq. We can now expressany admissible transfer function Ppsq as in Figure 6.5, which motivates calling ∆mpsq a multiplicativeuncertainty block. To characterize a multiplicative uncertainty one determines a function `mpωq

+

+

yu

∆mpsq

P0psq

Ppsq∆mpsq–

Ppsq ´ P0psqP0psq

õ

Ppsq “ P0psq`

1` ∆mpsq˘

Figure 6.5. Multiplicative uncertainty

sufficiently large so that for every admissible process transfer function Ppsq we have

|∆mpjωq| “|Ppsq ´ P0psq|

|P0psq|ď `mpωq, @ω.

One can determine `mpωq by plotting |Ppsq´P0psq||P0psq| vs. ω for all admissible Ppsq (or a representative

set of them) and choosing `mpωq to be larger than all the plots. Figure 6.6 shows `mpωq for the Bodeplots in Figure 6.2.

60 João P. Hespanha

10−1

100

101

−100

−80

−60

−40

−20

0

20

Magnitude (dB)

Freq

uenc

y (rad

/sec)

Figure 6.6. Multiplicative uncertainty bounds for the process Bode plots in Figure 6.2 with P0psq– 1m0s2`b0s`k0

,m0 “ 1, b0 “ 1.5, k0 “ 2.5. The solid lines represent possible plots for |Ppjωq´P0pjωq|

|P0pjωq|and the dashed one

represents the uncertainty bound `mpωq. Note the large uncertainty bound near the resonance frequency. Weshall show shortly how to design a controller that stabilizes all processes for which the multiplicative uncertaintyfalls below the dashed line.

6.2 Nyquist Stability CriterionThe first question we address is: Given a specific feedback controller C psq, how can we verify that itstabilizes every admissible process Ppsq. When the admissible processes are described in terms of amultiplicative uncertainty block, this amounts to verifying that the closed-loop system in Figure 6.7 isstable for every ∆mpjωq with norm smaller than `mpωq. This can be done using the Nyquist stability

+

+

+

yur

∆mpsq

P0psqs

C psq

|∆mpjωq| ď ℓmpωq, @ω

Figure 6.7. Unity feedback configuration with multiplicative uncertainty

criterion, which we review next.

The Nyquist criterion is used to investigate the stability of the negative feedback connection inNote. Figure 6.8 can representthe closed-loop system in Fig-ure 6.7 if we choose Gpsq–

`

1`∆mpsq

˘

PpsqCpsq.

Figure 6.8. We briefly summarize it here. The textbook [5, Section 6.3] provides a more detailed

+

y

u

rGpsq

Figure 6.8. Negative feedback

description of it with several examples.

6.2.1 The Nyquist PlotThe first step consists of drawing the Nyquist plot, which is done by evaluating Gpjωq from ω “ ´8

MATLAB R© Hint 24.nyquist(sys) draws theNyquist plot of the systemsys. . . p. 64

to ω “ `8 and plotting it in the complex plane. This leads to a closed-curve that is alwayssymmetric with respect to the real axis. This curve should be annotated with arrows indicating thedirection corresponding to increasing ω.

Robust Control 61

6.2.2 The Nyquist CriterionCount the number #ENC of clockwise encirclements by the Nyquist plot of the point ´1. To do this,we draw a ray from ´1 to 8 in any direction and add one each time the Nyquist plot crosses theray in the clockwise direction (with respect to the origin of the ray) and subtract one each time itcrosses the ray in the counter-clockwise direction. The final count gives #ENC.

Nyquist Stability Criterion. The total number of closed-loop unstable (i.e., in the right-hand-sideplane) poles (#CUP) is given by

#CUP “ #ENC`#OUP,

where #OUP denotes the number of (open-loop) unstable poles of Gpsq. To have a stable closed-loopone thus needs

#ENC “ ´#OUP. 2

Attention! Any poles of Gpsq on the imaginary axis should be moved slightly to the left of the axisto avoid divisions by zero. E.g.,

Gpsq “ s` 1sps´ 3q ÝÑ Gεpsq «

s` 1ps` εqps´ 3q

Gpsq “ ss2 ` 4 “

sps` 2jqps´ 2jq ÝÑ Gεpsq «

sps` ε ` 2jqps` ε ´ 2jq “

sps` εq2 ` 4 ,

for a small ε ą 0. The criterion should then be applied to the “perturbed” transfer function Gεpsq.If we conclude that the closed-loop is stable for Gεpsq with very small ε, then the closed-loop withGpsq will also be stable and vice-versa. 2

Example 6.1 (Spring-mass-damper system (cont.)). Figure 6.9 shows the Nyquist plot of

G0psq “ C psqP0psq, (6.4)

for the nominal process model

P0psq–1

m0s2 ` b0s` k0, m0 “ 1, b0 “ 1.5, k0 “ 2.5, (6.5)

(used in Figures 6.4 and 6.6) and a PID controller

C psq– 10s ` 15` 5s, (6.6)

To obtain this plot, we moved the single controller pole on the imaginary axis to the left-hand sideof the complex plane. Since this led to an open loop gain with no unstable poles (#OUP “ 0) andthere are no encirclements of ´1 (#ENC “ 0), we conclude that the closed-loop system is stable.This means that the given PID controller C psq stabilizes, at least, the nominal process P0psq. Itremains to check if it also stabilizes every admissible process model with multiplicative uncertainty.

2

6.3 Small Gain ConditionConsider the closed-loop system in Figure 6.7 and suppose that we are given a controller C psq thatstabilizes the nominal process P0psq, i.e., the closed-loop is stable when ∆mpsq “ 0. Our goal is tofind out if the closed-loop remains stable for every ∆mpjωq with norm smaller than `mpωq.

62 João P. Hespanha

−50 0 50 100 150 200 250 300 350 400−200

−150

−100

−50

0

50

100

150

200Nyquist Diagram

Real Axis

Imag

inar

y A

xis

−20 −15 −10 −5 0 5 10 15 20 25 30−20

−15

−10

−5

0

5

10

15

20Nyquist plot for 1st controller

Real Axis

Imag

inar

y A

xis

Figure 6.9. Nyquist plot for the (open-loop) transfer function in (6.4). The right figure shows a zoomed view ofthe origin. To avoid a pole over the imaginary axis, in these plots we moved the pole of the controller from 0 to´.01.

Since C psq stabilizes P0psq, we know that the Nyquist plot of the nominal (open-loop) transferfunction

G0psq “ C psqP0psq,

has the “right” number of encirclements (#ENC “ ´#OUP, where #OUP is the number of unstablepoles of G0psq. To check is the closed-loop is stable from some admissible process transfer function

Ppsq “ P0psq`

1` ∆mpsq˘

,

we need to draw the Nyquist plot ofNote. We are assuming that Gpsqand G0psq have the same num-ber of unstable poles #OUP andtherefore stability is achieved forthe same number of encirclements#ENC “ ´#OUP. In practicethis means that the uncertaintyshould not change the stability ofany pole.

Gpsq “ C psqPpsq “ C psqP0psq`

1` ∆mpsq˘

“ G0psq ` G0psq∆mpsq

and verify that we still get the same number of encirclements.

GpjωqG0pjωq

|Gpjωq ´ G0pjωq|

|1 ` G0pjωq|

´1

Figure 6.10. Nyquist plot derivation of the small-gain conditions

The Nyquist plots of Gpsq and G0psq differ by

|Gpjωq ´ G0pjωq| “ |G0pjωq∆mpjωq| ď |G0pjωq| `mpωq,

A simple way to make sure that Gpjωq and G0pjωq have the same number of encirclements is to askthat the maximum difference between the two be smaller than the distance from G0pjωq to the point´1, i.e.,

|G0pjωq| `mpωq ă |1` G0pjωq| ô|G0pjωq|

|1` G0pjωq|ă

1`mpωq

@ω.

This leads to the so called small-gain condition:

Robust Control 63

Small-gain Condition. The closed-loop system in Figure 6.7 is stable for every ∆mpjωq with norm Note. A mnemonic to remember(6.7) is that the transfer func-tion whose norm needs to besmall is precisely the transferfunction “seen” by the ∆m blockin Figure 6.7. This mnemonicalso “works” for additive uncer-tainty. . . p. 65

MATLAB R© Hint 25. To check if(6.7) holds for a specific sys-tem, draw 20 log10

1`mpωq “

´20 log10 `mpωq on top of themagnitude Bode plot of thecomplementary sensitivity functionand see if the latter always liesbelow the former.

smaller than `mpωq, provided thatˇ

ˇ

ˇ

C pjωqP0pjωq1` C pjωqP0pjωq

ˇ

ˇ

ˇă

1`mpωq

, @ω. (6.7)

The transfer function on the left-hand-side of (6.7) is precisely the complementary sensitivity function:

T0psq– 1´ S0psq, S0psq–1

1` C psqP0psq

for the nominal process. So (6.7) can be interpreted as requiring the norm of the nominal complemen-tary sensitivity function to be smaller than 1`mpωq, @ω. For this reason (6.7) is called a small-gaincondition.

Example 6.2 (Spring-mass-damper system (cont.)). Figure 6.11 shows the Bode plot of the com-plementary sensitivity function for the nominal process in (6.5) and the PID controller in (6.6). In

10−1

100

101

102

−90

−45

0

Pha

se (

deg)

−30

−25

−20

−15

−10

−5

0

5

10

Mag

nitu

de (

dB)

Bode Diagram

Frequency (rad/sec) .Figure 6.11. Verification of the small gain condition for the nominal process (6.5), the multiplicative uncertaintyin Figure 6.6, and the PID controller (6.6). The solid line corresponds to the Bode plot of the complementarysensitivity function T0psq and the dashed line to 1

`mpωq (both in dB).

the same plot we can see the 20 log101

`mpωq “ ´20 log10 `mpωq, for the `mpωq in Figure 6.6. Sincethe magnitude plot of T0pjωq is not always below that of 1

`mpωq , we conclude that the system maybe unstable for some admissible processes. However, if we redesign our controller to consist of anintegrator with two lags

C psq “ .005ps` 5q2sps` .5q2 , (6.8)

the magnitude plot of T0pjωq is now always below that of 1`mpωq and we can conclude from Figure 6.12

that we have stability for every admissible process. In this case, the price to pay was a lowbandwidth. This example illustrates a common problem in the control of systems with uncertainty: Note. Recall that the complemen-

tary sensitivity function is alsothe closed-loop transfer functionfor the reference r to the outputy. Therefore good tracking re-quires this function to be close to1, whereas to reject large uncer-tainty we need this function to bemuch smaller than 1.

it is not possible to get good reference tracking over ranges of frequencies for which there is largeuncertainty. 2

64 João P. Hespanha

10−2

10−1

100

101

102

103

−450

−360

−270

−180

−90

0

Pha

se (

deg)

−60

−40

−20

0

20

40

Mag

nitu

de (

dB)

Bode Diagram

Frequency (rad/sec) .Figure 6.12. Verification of the small gain condition for the nominal process (6.5), the multiplicative uncertaintyin Figure 6.6, and the integrator with 2 lags controller (6.8). The solid line corresponds to the Bode plot of thecomplementary sensitivity function T0psq and the dashed line to 1

`mpωq (both in dBs).

6.4 MATLAB R© HintsMATLAB R© Hint 24 (nyquist). The command nyquist(sys) draws the Nyquist plot of the systemsys. To specify the system you can use any of the commands in Matlab hint 23.Especially when there are poles very close to the imaginary axis (e.g., because they were actuallyon the axis and you moved them slightly to the left), the automatic scale may not be very goodbecause it may be hard to distinguish the point ´1 from the origin. In this case, you can use thenzoom features of MATLAB to see what is going on near ´1: Try clicking on the magnifying glassand selecting a region of interest; or try left-clicking on the mouse and selecting “zoom on (-1,0)”(without the magnifying glass selected.) 2

6.5 Exercises6.1 (Unknown parameters). Suppose one want to control the orientation of a satellite with respectto its orbital plane by applying a thruster’s generated torque. The system’s transfer function is giveby

Ppsq– 10pbs` kqs2ps2 ` 11pbs` kqq ,

where the values of the parameters b and k are not exactly known, but it is known that

.09 ď k ď .4 .006 ď b ď .03.

Find a nominal model and compute the corresponding additive and multiplicative uncertainty bounds. 2

6.2 (Noisy identification). The Simulink block provided corresponds to a discrete-time system withtransfer function

Hpzq “ α1z ` α0z2 ` β1z ` β0

.

1. Use least-squares to estimate the 4 coefficients of the transfer function. Repeat the identifi-cation experiment 25 times to obtain 25 estimates of the system’s transfer functions.

Robust Control 65

2. Convert the discrete-time transfer functions so obtained to continuous-time using the Tustintransformation.Hint: Use the MATLAB command d2c.

3. Select a nominal model and compute the corresponding additive and multiplicative uncertaintybounds. 2

6.3 (Small gain). For the nominal process model and multiplicative uncertainty that you obtained inExercise 6.2, use the small gain condition to verify if the following controllers achieve stability forall admissible process models:

C1psq “ .3 C2psq “2

s` .1 C3psq “20

s´ 30 C4psq “5ps` 1q

ps` 2qps` 3q C5psq “2ps` 1qps` .3q2

Justify your answers with appropriate Bode plots. 2

6.4 (Robustness vs. performance). Justify the statement: “It is not possible to get good referencetracking over ranges of frequencies for which there is large uncertainty.” 2

6.5 (Additive uncertainty). Derive a small-gain condition similar to (6.7) for additive uncertainty.Check if the mnemonic in Sidebar 6.3 still applies.

Hint: With additive uncertainty, the open-loop gain is given by

Gpsq “ C psqPpsq “ C psq`

P0psq ` ∆apsq˘

“ G0psq ` C psq∆apsq,

which differs from G0psq by C psq∆apsq. 2

66 João P. Hespanha

Chapter 7

Control design by loop shaping

Contents7.1 The Loop-shaping Design Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677.2 Open-loop vs. closed-loop specifications . . . . . . . . . . . . . . . . . . . . . . . . . 677.3 Open-loop Gain Shaping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

7.1 The Loop-shaping Design MethodThe goal of this chapter is to briefly review the loop-shaping control design method for SISO systems. Note. The loop-shaping design

method is covered extensively, e.g.,in [5].

The basic idea behind loop shaping is to convert the desired specifications on the closed-loop system

yur

d

n

e

´

`

`

`PpsqCpsq

Figure 7.1. Closed-loop system

in Figure 7.1 into constraints on the open-loop gain

Lpsq– C psqP0psq.

The controller C psq is then designed so that the open-loop gain Lpsq satisfies these constraints.The shaping of Lpsq can be done using the classical methods briefly mentioned in Section 7.3 andexplained in much greater detail in [5, Chapter 6.7]. However, it can also be done using LQR statefeedback, as discussed in Section 10.7, or using LQG/LQR output feedback controllers, as we shallsee in Section 10.6.

7.2 Open-loop vs. closed-loop specificationsWe start by discussing how several closed-loop specifications can be converted into constraints onthe open-loop gain Lpsq.

67

68 João P. Hespanha

Stability. Assuming that the open-loop gain has no unstable poles, the stability of the closed-loopsystem is guaranteed as long as the phase of the open-loop gain is above ´180˝ at the cross-overfrequency ωc , i.e., at the frequency for whichNotation. The distance between

the phase of Lpjωcq and ´180˝is called the phase margin. SeeFigure 7.2.

|Lpjωcq| “ 1.

´1

PM

Lpjωq

Im

Re

Figure 7.2. Phase margin (PM).

Overshoot. Larger phase margins generally correspond to a smaller overshoot for the step responseof the closed-loop system. The following rules of thumb work well when the open-loop gain Lpsq hasa pole at the origin, an additional real pole, and no zeros:Note. Additional zeros and poles

at frequencies significantly abovethe cross over generally have lit-tle effect and can be ignored.However, additional dynamics be-low or around the cross-over fre-quency typically affect the over-shoot; and make determining theneeded phase margin to achieve adesired overshoot a trial and errorprocess.

Lpsq “ ksps` pq , p ą 0.

They are useful to determine the value of the phase margin needed to obtain the desired overshoot:Phase margin overshoot

65˝ ď 5%60˝ ď 10%45˝ ď 15%

Reference tracking. Suppose that one wants the tracking error to be at least kT ! 1 times smallerthan the reference, over the range of frequencies r0, ωT s. In the frequency domain, this can beNote. Typically one wants to track

low frequency references, whichjustifies the requirement for equa-tion (7.1) to hold in an interval ofthe form r0, ωT s.

expressed by|Epjωq||Rpjωq| ď kT , @ω P r0, ωT s, (7.1)

where Epsq and Rpsq denote the Laplace transforms of the tracking error e – r ´ y and thereference signal r , respectively, in the absence of noise and disturbances. For the closed-loopsystem in Figure 7.1,

Epsq “ 11` LpsqRpsq.

Therefore (7.1) is equivalent to1

|1` Lpjωq| ď kT , @ω P r0, ωT s ô |1` Lpjωq| ě 1kT, @ω P r0, ωT s. (7.2)

This condition is guaranteed to hold by requiring thatNote 39. Why? . . . p. 68

|Lpjωq| ě 1kT` 1, @ω P r0, ωT s. (7.3)

Note 39 (Condition (7.3)). For (7.2) to hold, we need the distance from Lpjωq to the point ´1 toalways exceed 1kT . As one can see in Figure 7.3, this always hold if Lpjωq remains outside a circleof radius 1` 1kT . 2

Robust Control 69

´11kT

1kT

` 1

Im

Re

Figure 7.3. Justification for why (7.3) guarantees that (7.2) holds.

Disturbance rejection. Suppose that one wants input disturbances to appear in the output atten-uated at least kD ! 1 times, over the range of frequencies rωD1 , ωD2s. In the frequency domain, this Note. Typically one wants to re-

ject low-frequency disturbancesand therefore ωD1 and ωD2 in (7.4)generally take low values.

can be expressed by

|Y pjωq||Dpjωq| ď kD , @ω P rωD1 , ωD2s, (7.4)

where Y psq and Dpsq denote the Laplace transforms of the output y and the input disturbance d,respectively, in the absence of reference and measurement noise. For the closed-loop system inFigure 7.1,

Y psq “ P0psq1` LpsqDpsq,

and therefore (7.4) is equivalent to

|P0pjωq||1` Lpjωq| ď kD , @ω P rωD1 , ωD2s ô |1` Lpjωq| ě |P0pjωq|

kD, @ω P rωD1 , ωD2s.

This condition is guaranteed to hold as long as one requires that Note. The reasoning needed tounderstand (7.5) is basically thesame as for (7.3) but with |P0pjωq|

kDinstead of 1

kT .|Lpjωq| ě |P0pjωq|kD

` 1, @ω P rωD1 , ωD2s. (7.5)

Noise rejection. Suppose that one wants measurement noise to appear in the output attenuatedat least kN ! 1 times, over the range of frequencies rωN ,8q. In the frequency domain, this can be Note. Typically one needs to re-

ject high frequencies noise, whichjustifies the requirement for equa-tion (7.6) to hold in an interval ofthe form rωN ,8q.

expressed by

|Y pjωq||Npjωq| ď kN , @ω P rωN ,8q, (7.6)

where Y psq and Npsq denote the Laplace transforms of the output y and the measurement noise n,respectively, in the absence of reference and disturbances. For the closed-loop system in Figure 7.1,

Y psq “ ´ Lpsq1` LpsqNpsq, (7.7)

and therefore (7.6) is equivalent to

|Lpjωq||1` Lpjωq| ď kN , @ω P rωN ,8q ô

ˇ

ˇ

ˇ1` 1

Lpjωq

ˇ

ˇ

ˇě

1kN, @ω P rωN ,8q.

70 João P. Hespanha

This condition is guaranteed to hold as long as one requires thatNote. The reasoning needed tounderstand (7.8) is basically thesame as for (7.3) but with 1

Lpjωqinstead of Lpjωq.

ˇ

ˇ

ˇ

1Lpjωq

ˇ

ˇ

ˇě

1kN` 1, @ω P rωN ,8q ô |Lpjωq| ď kN

1` kN, @ω P rωN ,8q. (7.8)

Robustness with respect to multiplicative uncertainty Suppose that one wants the closed-loop toremain stable for every multiplicative uncertainty ∆mpjωq with norm smaller than `mpωq. This canbe expressed by

|Lpjωq||1` Lpjωq| ď

1`mpωq

, @ω, (7.9)

which is equivalent toNote. While this condition is sim-ilar to the one appearing in (7.7),we now need it to hold for ev-ery frequency and we no longerhave the “luxury” of simply requir-ing |Lpjωq| to be small for everyfrequency.

ˇ

ˇ

ˇ1` 1

Lpjωq

ˇ

ˇ

ˇě `mpωq, @ω. (7.10)

We have two options to make sure that (7.10) hold:

1. As in the discussion for noise rejection, we can require |Lpjωq| to be small. In particular,reasoning as before we may require that

ˇ

ˇ

ˇ

1Lpjωq

ˇ

ˇ

ˇě `mpωq ` 1, ô |Lpjωq| ď 1

1` `mpωq(7.11)

This condition will hold for frequencies for which we can make |Lpjωq| small, typically highfrequencies.

2. Alternatively, (7.10) may hold even when |Lpjωq| large, provided that `mpωq is small. Inparticular, sinceNote. Why does (7.12) hold? Be-

cause of the triangular inequal-ity: 1 “

ˇ

ˇ

ˇ1 ` 1

Lpjωq ´1

Lpjωq

ˇ

ˇ

ˇď

ˇ

ˇ

ˇ1 ` 1

Lpjωq

ˇ

ˇ

ˇ`

ˇ

ˇ

ˇ

1Lpjωq

ˇ

ˇ

ˇform which

(7.12) follows.

ˇ

ˇ

ˇ1` 1

Lpjωq

ˇ

ˇ

ˇě 1´

ˇ

ˇ

ˇ

1Lpjωq

ˇ

ˇ

ˇ, (7.12)

the condition (7.10) holds, provided that we require that

1´ˇ

ˇ

ˇ

1Lpjωq

ˇ

ˇ

ˇě `mpωq ô |Lpjωq| ě 1

1´ `mpωq(7.13)

This condition will hold for frequencies for which |Lpjωq| is large, typically low frequencies.

From the two conditions (7.11)–(7.13), one generally needs to be mostly concerned about (7.11). Thisis because when `mpωq is small, (7.10) will generally hold. However, when `mpωq is large for (7.10)to hold we need Lpjωq to be small, which corresponds to the condition (7.11). Hopefully, `mpωq willonly be large at high frequencies, for which we do not need (7.3) or (7.5) to hold.

Table 7.1 and Figure 7.4 summarize the constraints on the open-loop gain Lpjωq discussed above.

Attention! The conditions derived above for the open-loop gain Lpjωq are sufficient for the originalclosed-loop specifications to hold, but they are not necessary. When the open-loop gain “almost”verifies the conditions derived, it may be worth it to check directly if it verifies the original closed-loopconditions.

This is actually crucial for the conditions (7.11)–(7.13) that arise from robustness with respect tomultiplicative uncertainty, because around the crossover frequency |Lpjωcq| « 1 will not satisfyeither of these conditions, but it will generally satisfy the original condition (7.9) (as long as `mpωqis not too large). 2

Robust Control 71

closed-loop specification open-loop constraintovershoot ď 10% (ď 5%) phase margin ě 60 deg (ě 65 deg)|Epjωq||Rpjωq| ď kT , @ω P r0, ωT s |Lpjωq| ě 1

kT` 1, @ω P r0, ωT s

|Y pjωq||Dpjωq| ď kD , @ω P rωD1 , ωD2s |Lpjωq| ě |P0pjωq|

kD` 1, @ω P rωD1 , ωD2s

|Y pjωq||Npjωq| ď kN , @ω P rωN ,8q |Lpjωq| ď kN

1` kN, @ω P rωN ,8q

|Lpjωq||1` Lpjωq| ď

1`mpωq

, @ω |Lpjωq| ď 11` `mpωq

´

or |Lpjωq| ě 11´ `mpωq

¯

Table 7.1. Summary of the relationship between closed-loop specifications and open-loop constraints for theloop shaping design method

|Lpjωq|

ω

ωT

1

kT` 1

ωD2

|P0pjωq|

kD` 1

ωN

kN

1 ` kN

1

1 ´ ℓmpωq

1

1 ` ℓmpωq

Figure 7.4. Typical open-loop specifications for the loop shaping design method

7.3 Open-loop Gain ShapingIn classical lead/lag compensation, one starts with a basic unit-gain controller

C psq “ 1

and “adds” to it appropriate blocks to shape the desired open-loop gain Note. One actually does not “add”to the controller. To be precise,one multiplies the controller byappropriate gain, lead, and lagblocks. However, this does cor-respond to additions in the mag-nitude (in dBs) and phase Bodeplots.

Lpsq– C psqP0psq,

so that it satisfies the appropriate open-loop constraints. This shaping can be achieved using threebasic tools.

1. Proportional gain. Multiplying the controller by a constant k moves the magnitude Bode plotup and down, without changing its phase.

2. Lead compensation. Multiplying the controller by a lead block with transfer function

Cleadpsq “T s` 1αT s` 1 , α ă 1

increases the phase margin when placed at the cross-over frequency. Figure 7.5(a) shows theBode plot of a lead compensator. Note. A lead compensator also in-

creases the cross-over frequency,so it may require some trial anderror to get the peak of the phaseright at the cross-over frequency.

3. Lag compensation. Multiplying the controller by a lag block with transfer function

Clagpsq “sz ` 1sp` 1 , p ă z

decreases the high-frequency gain. Figure 7.5(b) shows the Bode plot of a lag compensator. Note. A lag compensator also in-creases the phase, so it can de-crease the phase margin. To avoidthis, one should only introducelag compensation away from thecross-over frequency.

72 João P. Hespanha

7.4 Exercises7.1 (Loop-shape 1). Consider again the nominal process model and multiplicative uncertainty thatyou obtained in Exercise 6.2. Design a controller for this process that achieves stability for alladmissible process models and that exhibits:

1. zero steady-state error to a step input,

2. Phase Margin no smaller then 60degrees,

3. steady-state error for sinusoidal inputs with frequencies ω ă 0.1rad/sec smaller than 1/50(´34dB), and

4. Rise time no slower than .3sec. 2

7.2 (Loop-shape 2). Consider the following nominal transfer function ans uncertainty bound:

P0psq “1

sp1` s5qp1` s20q , `mpωq “ |Lpjωq|,

where

Lpsq– 2.5p1` s20q2 .

Use loop shaping to design a controller that achieves stability for all admissible process models andthat exhibits:

1. steady-state error to a ramp input no larger than .01,

2. Phase Margin no smaller then 45degrees,

3. steady-state error for sinusoidal inputs with frequencies ω ă 0.2rad/sec smaller than 1/250(´50dB), and

4. attenuation of measurement noise by at least a factor of 100 (´40dB) for frequencies greaterthan 200rad/sec. 2

Robust Control 73

1

1

α

1

T

1

αT

ωmax “1

?αT

φmax

(a) Lead

1

p

zp z

ωmax “?

pz

(b) Lag

Figure 7.5. Bode plots of lead/lag compensators. The maximum lead phase angle is given by φmax “ arcsin 1´α1`α ;

therefore, to obtain a desired given lead angle φmax one sets α “ 1´sinφmax1`sinφmax

.

74 João P. Hespanha

Part III

LQG/LQR Controller Design

75

Introduction to LQG/LQR ControllerDesign

In optimal control one attempts to find a controller that provides the best possible performance withrespect to some given measure of performance. E.g., the controller that uses the least amount ofcontrol-signal energy to take the output to zero. In this case the measure of performance (also calledthe optimality criterion) would be the control-signal energy.

In general, optimality with respect to some criterion is not the only desirable property for acontroller. One would also like stability of the closed-loop system, good gain and phase margins,robustness with respect to unmodeled dynamics, etc.

In this section we study controllers that are optimal with respect to energy-like criteria. Theseare particularly interesting because the minimization procedure automatically produces controllersthat are stable and somewhat robust. In fact, the controllers obtained through this procedure aregenerally so good that we often use them even when we do not necessarily care about optimizingfor energy. Moreover, this procedure is applicable to multiple-input/multiple-output processes forwhich classical designs are difficult to apply.

Pre-requisites

1. Basic knowledge of state-space models (briefly reviewed here)

2. Familiarity with basic vector and matrix operations.

3. Knowledge of MATLAB/Simulink.

Further reading A more extensive coverage of LQG/LQR controller design can be found, e.g., in [8].

77

78 João P. Hespanha

Chapter 8

Review of State-space models

Contents8.1 State-space Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798.2 Input-output Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808.3 Realizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818.4 Controllability and Observability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818.5 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828.6 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

8.1 State-space ModelsConsider the system in Figure 8.1 with m inputs and k outputs. A state-space model for this system

uptq P Rm

yptq P Rk

9x “ fpx, uq

y “ gpx, uq

Figure 8.1. System with m inputs and k outputs

relates the input and output of a system using the following first-order vector ordinary differentialequation

9x “ fpx, uq, y “ gpx, uq. (8.1)

where x P Rn is called the state of system. In this Chapter we restrict our attention to lineartime-invariant (LTI) systems for which the functions fp¨, ¨q and gp¨, ¨q are linear. In this case, (8.1)

MATLAB R© Hint 26.ss(A,B,C,D) creates a LTIstate-space model with realiza-tion (8.2). . . p. 82

has the special form

9x “ Ax ` Bu, y “ Cx ` Du, (8.2)

where A is a nˆ n matrix, B a nˆ m matrix, C a k ˆ n matrix, and D a k ˆ m matrix.

Example 8.1 (Aircraft roll-dynamics). Figure 8.2 shows the roll-angle dynamics of an aircraft [12,p. 381]. Defining

x –“

θ ω τ‰1

we conclude that

9x “ Ax ` Bu

79

80 João P. Hespanha

roll-angle

roll-rate= ˙

applied torque

replacements

roll-angle

9θ “ ω9ω “ ´.875ω ´ 20τ9τ “ ´50τ ` 50u

Figure 8.2. Aircraft roll-angle dynamics

with

A –

»

0 1 00 ´.875 ´200 0 ´50

fi

fl , B –

»

0050

fi

fl .

If we have both θ and ω available for control, we can define

y–“

θ ω‰1“ Cx ` Du

with

C –

1 0 00 1 0

, D –

00

. 2

8.2 Input-output RelationsNote 1. The (unilateral) Laplacetransform of a signal xptq is givenby

Xpsq–ż 8

0e´stxptqdt.

See [5, Appendix A] for a review ofLaplace transforms.

The transfer-function of this system can be found by taking Laplace transforms of (8.2):#

9x “ Ax ` Bu,y “ Cx ` Du,

LÝÝÝÝÝÑ

#

sX psq “ AX psq ` BUpsq,Y psq “ CX psq ` DUpsq,

where X psq, Upsq, and Y psq denote the Laplace transforms of xptq, uptq, and yptq. Solving for X psq,we get

psI ´ AqX psq “ BUpsq ô X psq “ psI ´ Aq´1BUpsq

and therefore

Y psq “ C psI ´ Aq´1BUpsq ` DUpsq “`

C psI ´ Aq´1B ` D˘

Upsq.

DefiningMATLAB R© Hint 1.tf(num,den) creates a transfer-function with numerator anddenominator specified by num,den. . . p. 12

MATLAB R© Hint 2. zpk(z,p,k)creates a transfer-function withzeros, poles, and gain specified byz, p, k. . . p. 12

MATLAB R© Hint 27.tf(sys_ss) and zpk(sys_ss)compute the transfer-functionof the state-space modelsys_ss. . . p. 82

T psq– C psI ´ Aq´1B ` D,

we conclude that

Y psq “ T psqUpsq. (8.3)

To emphasize the fact that T psq is a k ˆm matrix, we call it the transfer-matrix of the system (8.2).The relation (8.3) between the Laplace transforms of the input and the output of the system is

only valid for zero initial conditions, i.e., when xp0q “ 0. The general solution to the system (8.2) inthe time domain is given by

xptq “ eAtxp0q `ż t

0eApt´sqBupsqds, (8.4)

yptq “ CeAtxp0q `ż t

0CeApt´sqBupsqds` Duptq, @t ě 0. (8.5)

LQG/LQR Controller Design 81

Equation (8.4) is called the variation of constants formula.MATLAB R© Hint 28. expm com-putes the exponential of a ma-trix. . . p. 82

Example 8.2 (Aircraft roll-dynamics). The transfer-function for the state-space model in Example 8.1is given by:

T psq “«

´1000sps`.875qps`50q

´1000ps`.875qps`50q

ff

2

8.3 RealizationsConsider a transfer-matrix

T psq “

»

T11psq T12psq ¨ ¨ ¨ T1mpsqT21psq T22psq ¨ ¨ ¨ T2mpsq

......

. . ....

Tk1psq Tk2psq ¨ ¨ ¨ Tkmpsq

fi

ffi

ffi

ffi

fl

,

where all the Tijpsq are given by a ratio of polynomials with the degree of the numerator smallerthan or equal to the degree of the denominator. It is always possible to find matrices A, B, C , D such

MATLAB R© Hint 29.ss(sys_tf) computes a re-alization of the transfer-functionsys_tf. . . p. 82

thatT psq “ C psI ´ Aq´1B ` D.

This means that it is always possible to find a state-space model like (8.2) whose transfer-matrix isprecisely T psq. The model (8.2) is called a realization of T psq. Attention! Realizations are not

unique, i.e., several state-spacemodels may have the same trans-fer function.8.4 Controllability and Observability

The system (8.2) is said to be controllable when given any initial state xi P Rn, any final statexf P Rn, and any finite time T , one can find an input signal uptq that takes the state of (8.2) fromxi to xf in the interval of time 0 ď t ď T , i.e., when there exists an input uptq such that

xf “ eAT xi `ż T

0eApT´sqBupsqds.

To determine if a system is controllable, one can compute the controllability matrix, which is definedMATLAB R© Hint 30. ctrb(sys)computes the controllabilitymatrix of the state-space systemsys. Alternatively, one can usedirectly ctrb(A,B). . . p. 83

MATLAB R© Hint 31. rank(M)computes the rank of a matrix M.

byC –

B AB A2B ¨ ¨ ¨ An´1B‰

.The system is controllable if and only if this matrix has rank equal to the size n of the state vector.

The system (8.2) is said to be observable when one can determine the initial condition xp0q bysimply looking at the input and output signals uptq and yptq on a certain interval of time 0 ď t ď T ,i.e., one can solve

yptq “ CeAtxp0q `ż t

0CeApt´sqBupsqds` Duptq, @ 0 ď t ď T ,

uniquely for the unknown xp0q. To determine if a system is observable, one can compute theMATLAB R© Hint 32. obsv(sys)computes the controllabilitymatrix of the state-space systemsys. Alternatively, one can usedirectly obsv(A,C). . . p. 83

observability matrix, which is defined by

O–

»

CCACA2

...CAn´1

fi

ffi

ffi

ffi

ffi

ffi

fl

.

The system is observable if and only if this matrix has rank equal to the size n of the state vector.

82 João P. Hespanha

Example 8.3 (Aircraft roll-dynamics). The controllability and observability matrices for the state-space model in Example 8.1 are given by:

C “

»

0 0 ´10000 ´1000 5087550 ´2500 125000

fi

fl , O “

»

1 0 00 1 00 1 00 ´.875 ´200 ´.875 ´200 .7656 1017.5

fi

ffi

ffi

ffi

ffi

ffi

ffi

fl

.

Both matrices have rank 3 so the system is both controllable and observable. 2

8.5 StabilityThe system (8.2) is asymptotically stable when all eigenvalues of A have negative real parts. In this

MATLAB R© Hint 33. eig(A)computes the eigenvalues of thematrix A. . . p. 83

case, for any bounded input uptq the output yptq and the state xptq are also bounded, i.e.,

uptq ď c1, @t ě 0 ñ yptq ď c2, xptq ď c3 @t ě 0.

Moreover, if uptq converges to zero as t Ñ8, then xptq and yptq also converge to zero as t Ñ8.

Example 8.4 (Aircraft roll-dynamics). The eigenvalues of the matrix the A matrix for the state-spacemodel in Example 8.1 are t0,´.875,´50u so the system is not asymptotically stable. 2

8.6 MATLAB R© HintsMATLAB R© Hint 26 (ss). The command sys_ss=ss(A,B,C,D) assigns to sys_ss a MATLAB LTIstate-space model with realization

9x “ Ax ` Bu, y “ Cx ` Du.

Optionally, one can specify the names of the inputs, outputs, and state to be used in subsequentplots as follows:

sys_ss=ss(A,B,C,D,...’InputName’,’input1’,’input2’,...,...’OutputName’,’output1’,’output2’,...,...’StateName’,’input1’,’input2’,...)

The number of elements in the bracketed lists must match the number of inputs,outputs, and statevariables. 2

MATLAB R© Hint 27 (tf). The commands tf(sys_ss) and zpk(sys_ss) compute the transfer-function of the state-space model sys_ss specified as in Matlab Hint 26.

tf(sys_ss) stores (and displays) the transfer function as a ratio of polynomials on s.

zpk(sys_ss) stores (and displays) the polynomials factored as the product of monomials (for thereal roots) and binomials (for the complex roots). This form highlights the zeros and poles of thesystem. 2

MATLAB R© Hint 29 (ss). The command ss(sys_tf) computes the state-space model of the transferfunction sys specified as in Matlab Hints 1 or 2. 2

MATLAB R© Hint 28 (expm). The command expm(M) computes the matrix exponential eM. With thesymbolic toolbox, this command can be used to compute eAt symbolically as follows:

LQG/LQR Controller Design 83

syms texpm(A*t)

The first command defines t as a symbolic variable and the second computes eAt (assuming that thematrix A has been previously defined). 2

MATLAB R© Hint 30 (ctrb). The command ctrb(sys) computes the controllability matrix of thesystem sys. The system must be specified by a state-space model using, e.g., sys=ss(A,B,C,D),where A,B,C,D are a realization of the system. Alternatively, one can use directly ctrb(A,B). 2

MATLAB R© Hint 32 (obsv). The command obsv(sys) computes the observability matrix of thesystem sys. The system must be specified by a state-space model using, e.g., sys=ss(A,B,C,D),where A,B,C,D are a realization of the system. Alternatively, one can use directly obsv(A,C). 2

MATLAB R© Hint 33 (eig). The command eig(A) computes the eigenvalues of the matrix A. Alter-natively, eig(sys) computes the eigenvalues of the A matrix for a state-space system sys specifiedby sys=ss(A,B,C,D), where A,B,C,D are a realization of the system. 2

84 João P. Hespanha

Chapter 9

Linear Quadratic Regulation (LQR)

Contents9.1 Feedback Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859.2 Optimal Regulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869.3 State-Feedback LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879.4 Stability and Robustness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 889.5 Loop-shaping Control using LQR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909.6 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929.7 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

9.1 Feedback ConfigurationFigure 9.1 shows the feedback configuration for the Linear quadratic regulation (LQR) problem.

−yptq P R

k

zptq P Rℓ

uptq P Rm

processcontroller

Figure 9.1. Linear quadratic regulation (LQR) feedback configuration. Note the negative feedback and theabsence of a reference signal. Reference signals will be introduced in Chapter 11.

In this configuration, the state-space model of the process is of the form

9x “ Ax ` Bu, y “ Cx, z “ Gx ` Hu. (9.1)

and has two distinct outputs:

1. The measured output yptq P Rk corresponds to the signal(s) that can be measured and aretherefore available for control. If the controller transfer-matrix is C psq, we have

Y psq “ ´C psqUpsq,

where Y psq and Upsq denote the Laplace transforms of the process input uptq and the measuredoutput yptq, respectively.

2. The controlled output zptq P R` corresponds to a signal that one would like to make as smallas possible in the shortest possible amount of time.

85

86 João P. Hespanha

Sometimes zptq “ yptq, which means that our control objective is to make the whole measuredoutput very small. However, when the output yptq is a vector, often one simply needs to makeone of the measured outputs y1ptq small. In this case, one chooses zptq “ y1ptq.

Note 40. In the context of Exam-ple 8.1, one could imagine that,while both and θ and ω canbe measured, one may mostlywant to regulate the roll angleθ. . . p. 79

In some situations one chooses

zptq “„

y1ptq9y1ptq

,

which means that we want to make both the measured output y1ptq and its derivative 9y1ptqvery small. Many other options are possible.The choice of z should be viewed as a design parameter. In Section 10.7 we will study theimpact of this choice in the performance of the closed-loop.

9.2 Optimal RegulationThe LQR problem is defined as follows:

Problem 9.1 (Optimal LQR). Find the controller transfer-matrix C psq that makes the following cri-Notation 5. Given an m-vector,

v ““

v1 v2 ¨ ¨ ¨ vm‰

,

v denotes the Euclidean norm ofv , i.e.,

v “ v 1v “´

mÿ

i“1v2i

¯12 .

terion as small as possible

JLQR –

ż 8

0zptq2 ` ρ uptq2dt, (9.2)

where ρ is a positive constant. 2

The termż 8

0zptq2dt

corresponds to the energy of the controlled output and the termż 8

0uptq2dt

to the energy of the control input. In LQR one seeks a controller that minimizes both energies.However, decreasing the energy of the controlled output will require a large control input, and asmall control input will lead to large controlled outputs. The role of the constant ρ is to establish atrade-off between these conflicting goals.

1. When we chose ρ very large, the most effective way to decrease JLQR is to employ a smallcontrol input, at the expense of a large controlled output.

2. When we chose ρ very small, the most effective way to decrease JLQR is to obtain a very smallcontrolled output, even if this is achieved at the expense of employing a large control input.

Often the optimal LQR problem is defined more generally and consists of finding the controllerNote 41. The most general formfor the quadratic criteria isż 8

0x1Qx ` u1Ru` 2x1Nu dt

. . . p. 93

transfer-matrix C psq that minimizes

JLQR –

ż 8

0zptq1Qzptq ` ρu1ptqRuptqdt, (9.3)

LQG/LQR Controller Design 87

where Q is an ` ˆ ` symmetric positive-definite matrix, R an m ˆ m symmetric positive-definiteNote 42. Many choices for thematrices Q and R are possible,but one should always choose bothmatrices to be positive-definite.We recall that a symmetric q ˆq matrix M is positive-definite ifx1Mx ą 0, for every nonzero vec-tor x P Rq . . . p. 93

matrix, and ρ a positive constant.

Bryson’s rule A first choice for the matrices Q and R in (9.3) is given by the Bryson’s rule [5,p. 537]: select Q and R diagonal with

Qii “1

maximum acceptable value of z2i, i P t1, 2, . . . , `u

Rj j “1

maximum acceptable value of u2j, j P t1, 2, . . . , mu,

which corresponds to the following criteria

JLQR –

ż 8

0

´

ÿ

i“1Qii ziptq2 ` ρ

mÿ

j“1Rj j ujptq2

¯

dt.

In essence the Bryson’s rule scales the variables that appear in JLQR so that the maximum acceptablevalue for each term is one. This is especially important when the units used for the differentcomponents of u and z make the values for these variables numerically very different from eachother.

Although Bryson’s rule sometimes gives good results, often it is just the starting point to atrial-and-error iterative design procedure aimed at obtaining desirable properties for the closed-loopsystem. In Section 10.7 we will discuss systematic methods to chose the weights in the LQR criterion.

9.3 State-Feedback LQRIn the state-feedback version of the LQR problem (Figure 9.2), we assume that the whole state xcan be measured and therefore it is available for control.

−xptq P R

n

zptq P Rℓ

uptq P Rm

processcontroller

Figure 9.2. Linear quadratic regulation (LQR) with state feedback

Solution to the optimal state-feedback LQR Problem 9.1. The optimal state-feedback LQR controllerMATLAB R© Hint 34. lqr com-putes the optimal state-feedbackcontroller gain K . . . p. 92

for the criteria (9.3) is a simple matrix gain of the form

u “ ´Kx (9.4)

where K is the mˆ n matrix given by

K “ pH 1QH ` ρRq´1pB1P ` H 1QGq

and P is the unique positive-definite solution to the following equation

A1P ` PA` G1QG ´ pPB ` G1QHqpH 1QH ` ρRq´1pB1P ` H 1QGq “ 0,

known as the Algebraic Riccati Equation (ARE). 2

88 João P. Hespanha

9.4 Stability and RobustnessThe state-feedback control law (9.4), results in a closed-loop system of the form

Note 43. A system 9x “ Ax `Bu is asymptotically stable whenall eigenvalues of A have neg-ative real parts. See Sec-tion 8.5. . . p. 82

9x “ pA´ BK qx.

A crucial property of LQR controller design is that this closed-loop is asymptotically stable (i.e., allthe eigenvalues of A´ BK have negative real part) as long as the following two conditions hold:

1. The system (9.1) is controllable.Note 44. The definitions and testsfor controllability and observ-ability are reviewed in Sec-tion 8.4. . . p. 81

2. The system (9.1) is observable when we ignore y and regard z as the sole output .

Attention! When selecting themeasured output z , it is importantto verify that the observabilitycondition is satisfied.

Perhaps even more important is the fact that LQR controllers are inherently robust with respectto process uncertainty. To understand why, consider the open-loop transfer-matrix from the process’input u to the controller’s output u (Figure 9.3). The state-space model from u to u is given by

−x

uu

9x “ Ax ` BuK

Figure 9.3. State-feedback open-loop gain

9x “ Ax ` Bu, u “ ´Kx,

which corresponds to the following open-loop negative feedback mˆ m transfer-matrixNote. In a negative-feedbackconfiguration, the output of theprocess is multiplied by ´1 beforebeing connected to the input ofthe controller. Often a referencesignal is also added to the inputof the controller.

Lpsq “ K psI ´ Aq´1B.

We focus our attention in single-input processes (m “ 1), for which Lpsq is a scalar transfer-function

Note. LQR controllers also exhibitrobustness properties for multiple-input processes. However, in thiscase Lpsq is a m ˆ m transfer-matrix and one needs a multi-variable Nyquist criterion.

and the following holds:

Kalman’s Inequality. When H 1G “ 0, the Nyquist plot of Lpjωq does not enter a circle of radiusone around ´1, i.e.,

|1` Lpjωq| ě 1, @ω P R. 2

Kalman’s Inequality is represented graphically in Figure 9.4 and has several significant implications,which are discussed next.

´1´2

60o

Lpjωq

Im

Re

Figure 9.4. Nyquist plot for a LQR state-feedback controller

LQG/LQR Controller Design 89

Positive gain margin If the process’ gain is multiplied by a constant k ą 1, its Nyquist plot simplyexpands radially and therefore the number of encirclements does not change. This corresponds to apositive gain margin of `8.

Negative gain margin If the process’ gain is multiplied by a constant .5 ă k ă 1, its Nyquistplot contracts radially but the number of encirclements still does not change. This corresponds to anegative gain margin of 20 log10p.5q “ ´6dB.

Phase margin If the process’ phase increases by θ P r´60, 60s degrees, its Nyquist plots rotatesby θ but the number of encirclements still does not change. This corresponds to a phase margin of˘60 degrees.

+

+−

xu

∆mpsq

9x “ Ax ` BuK

|∆mpjωq| ď ℓmpωq, @ω

Figure 9.5. Unity feedback configuration with multiplicative uncertainty

Multiplicative uncertainty Kalman’s inequality guarantees thatNote 45. Why?. . . p. 93

ˇ

ˇ

ˇ

ˇ

Lpjωq1` Lpjωq

ˇ

ˇ

ˇ

ˇ

ď 2. (9.5)

Since, we known that the closed-loop system in Figure 9.5 remains stable for every multiplicativeuncertainty block ∆mpjωq with norm smaller than `mpωq, as long as

ˇ

ˇ

ˇ

ˇ

Lpjωq1` Lpjωq

ˇ

ˇ

ˇ

ˇ

ă1

`mpωq, (9.6)

we conclude that an LQR controller provides robust stability with respect to any multiplicativeuncertainty with magnitude smaller than 1

2 , because we then haveˇ

ˇ

ˇ

ˇ

Lpjωq1` Lpjωq

ˇ

ˇ

ˇ

ˇ

ď 2 ă 1`mpωq

.

However, much larger additive uncertainties may be admissible: e.g., when Lpjωq " 1, (9.6) willhold for `mpωq almost equal to 1; and when Lpjωq ! 1, (9.6) will hold for `mpωq almost equal to1Lpjωq " 1.

Attention! Kalman’s inequality is only valid when H 1G “ 0. When this is not the case, LQRcontrollers can be significantly less robust. This limits to same extent the controlled outputs thatcan be placed in z .

For example, consider the process 9x “ Ax ` Bu and suppose that we want to regulate a particularoutput y1 “ C1x . Choosing

z “ y1 “ C1x

leads to G “ C1 and H “ 0 and therefore H 1G “ 0, for which Kalman’s inequality holds. However,choosing

z “„

y19y1

C1xC1 9x

C1xC1Ax ` C1Bu

C1C1A

x `„

0C1B

u,

90 João P. Hespanha

leads toNote. If the transfer function fromu to y1 has two more poles thanzeros, then one can show thatC1B “ 0 and H “ 0. In this case,Kalman’s inequality holds also forthis choice of z .

G “„

C1C1A

, H “„

0C1B

,

and therefore

H 1G “ B1C 11C1A,

which may not be equal to zero. 2

9.5 Loop-shaping Control using LQRAlthough Bryson’s rule sometimes gives good results, it may not suffice to satisfy tight controlspecifications. We will see next a few other rules that allow us to actually do loop shaping usingLQR. We restrict our attention to the single-input case (m “ 1) and R “ 1, Q “ I , which correspondsto

JLQR –

ż 8

0zptq2 ` ρ uptq2dt.

Low-frequency open-loop gain For the range of frequencies for which |Lpjωq| " 1 (typically lowMATLAB R© Hint 35.sigma(sys) draws thenorm-Bode plot of the sys-tem sys. . . p. 93

frequencies), we have that

|Lpjωq| « Pzpjωqa

H 1H ` ρ

where

Pzpsq– GpsI ´ Aq´1B ` H

is the transfer function from the control signal u to the controlled output z . To understand theimplications of this formula, it is instructive to consider two fairly typical cases:

1. When z “ y1, with y1 – C1x scalar, we have

|Lpjωq| « |P1pjωq|?ρ .

where

P1psq– C1psI ´ Aq´1B

is the transfer function from the control input u to the output y1. In this case,

(a) the “shape” of the magnitude of the open-loop gain Lpjωq is determined by the magnitudeNote. Although the magnitude ofLpjωq mimics the magnitude ofP1pjωq, the phase of the open-loop gain Lpjωq always leads toa stable closed-loop with an ap-propriate phase margin.

of the transfer function from the control input u to the output y1;(b) the parameter ρ moves the magnitude Bode plot up and down.

2. When z ““

y1 γ 9y1‰1, we can show that

Note 46. Why?. . . p. 93|Lpjωq| « |1` jγω| |P1pjωq|

a

H 1H ` ρ. (9.7)

In this case the low-frequency open-loop gain mimics the process transfer function from u toy, with an extra zero at 1γ and scaled by 1?

H1H`ρ. Thus

LQG/LQR Controller Design 91

(a) ρ moves the magnitude Bode plot up and down (more precisely H 1H ` ρ),(b) large values for γ lead to a low-frequency zero and generally result in a larger phase

Note 47. The introduction of theoutput γ 9y1 has an effect sim-ilar to that of lead compensa-tion in classical control (see Sec-tion 7.3). . . p. 71Unfortunately, in LQR there is noequivalent to a lag compensator todecrease the high-frequency gain.We will see in Section 10.6 thatthis limitation of LQR can be over-come with output-feedback con-trollers.

margin (above the minimum of 60 degrees) and smaller overshoot in the step response.However, this is often achieved at the expense of a slower response.

High-frequency open-loop gain For ω " 1, we have that

|Lpjωq| « cω?ρ ,

for some constant c. We thus conclude the following:

1. LQR controllers always exhibit a high-frequency magnitude decay of ´20dB/decade.

2. The cross-over frequency is approximately given by

cωcross

?ρ « 1 ô ωcross «c?ρ ,

which shows that the cross-over frequency is proportional to 1?ρ and generally small valuesfor ρ result in faster step responses.

Attention! The (slow) ´20dB/decade magnitude decrease is the main shortcoming of state-feedbackLQR controllers because it may not be sufficient to clear high-frequency upper bounds on the open-loop gain needed to reject disturbances and/or for robustness with respect to process uncertainty.We will see in Section 10.6 that this can actually be improved with output-feedback controllers.

2

Example 9.1 (Aircraft roll-dynamics). Figure 9.6 shows Bode plots of the open-loop gain Lpsq “K psI´Aq´1B for several LQR controllers obtained for the aircraft roll-dynamics in Example 8.1. The

10−2

10−1

100

101

102

103

−180

−135

−90

Pha

se (

deg)

−40

−20

0

20

40

60

80

From: u To: Out(1)

Mag

nitu

de (

dB)

rho = 0.01rho = 1rho = 100u to roll anglegamma = 0.01

Open−loop Bode Diagrams

Frequency (rad/sec)

(a) Open-loop gain for several values of ρ. This param-eter allow us to move the whole magnitude Bode plot upand down.

10−2

10−1

100

101

102

103

−180

−135

−90

Pha

se (

deg)

−40

−20

0

20

40

60

80

From: u To: Out(1)

Mag

nitu

de (

dB)

gamma = 0.01gamma = 0.1gamma = 0.3u to roll angle(rho = 0.01)

Open−loop Bode Diagrams

Frequency (rad/sec)

(b) Open-loop gain for several values of γ . Larger valuesfor this parameter result in a larger phase margin.

Figure 9.6. Bode plots for the open-loop gain of the LQR controllers in Example 9.1. As expected, for lowfrequencies the open-loop gain magnitude matches that of the process transfer function from u to θ (but withsignificantly lower/better phase) and at high-frequencies the gain’s magnitude falls at ´20dB/decade.

controlled output was chosen to be z –“

θ γ 9θ‰1, which corresponds to

G –

1 0 00 γ 0

, H –

00

.

92 João P. Hespanha

The controllers were obtained with R “ 1, Q “ I2ˆ2, and several values for ρ and γ . Figure 9.6(a)shows the open-loop gain for several values of ρ and Figure 9.6(b) shows the open-loop gain forseveral values of γ .

Figure 9.7 shows Nyquist plots of the open-loop gain Lpsq “ K psI ´ Aq´1B for different choicesof the controlled output z . In Figure 9.7(a) z –

θ 9θ‰1, which corresponds to

−5 −4 −3 −2 −1 0 1 2−3

−2

−1

0

1

2

3

−1−2

π/3

From: u To: uuOpen−loop Nyquist Diagram (rho = 1, gamma = 0.1)

Real Axis

Imag

inar

y A

xis

(a) H 1G “ 0

−5 −4 −3 −2 −1 0 1 2−3

−2

−1

0

1

2

3

−1−2

π/3

From: u To: uuOpen−loop Nyquist Diagram

Real Axis

Imag

inar

y A

xis

(b) H 1G ‰ 0

Figure 9.7. Bode plots for the open-loop gain of the LQR controllers in Example 9.1

G –

1 0 00 1 0

, H –

00

.

In this case, H 1G “ r 0 0 0 s and Kalman’s inequality holds as can be seen in the Nyquist plot. InFigure 9.7(b), the controlled output was chosen to be z –

θ 9τ‰1, which corresponds to

G –

1 0 00 0 ´50

, H –

050

.

In this case we have H 1G “ r 0 0 ´2500 s and Kalman’s inequality does not hold. We can see fromthe Nyquist plot that the phase and gain margins are very small and there is little robustness withrespect to unmodeled dynamics since a small perturbation in the process can lead to an encirclementof the point ´1. 2

9.6 MATLAB R© HintsMATLAB R© Hint 34 (lqr). The command [K,S,E]=lqr(A,B,QQ,RR,NN) computes the optimalstate-feedback LQR controller for the process

9x “ Ax ` Bu

with criteria

J –ż 8

0xptq1QQxptq ` u1ptqRRuptq ` 2x 1ptqNNuptqdt.

For the criterion in (9.2) one should select

QQ “ G1G, RR “ H 1H ` ρI, NN “ G1H

and for the criterion (9.3)Note. Cf. Sidebar 41. . . p. 86

LQG/LQR Controller Design 93

QQ “ G1QG, RR “ H 1QH ` ρR, NN “ G1QH.

This command returns the optimal state-feedback matrix K, the solution P to the correspondingAlgebraic Riccati Equation, and the poles E of the closed-loop system. 2

MATLAB R© Hint 35 (sigma). The command sigma(sys) draws the norm-Bode plot of the systemsys. For scalar transfer functions this command plots the usual magnitude Bode plot but for vectortransfer function it plots the norm of the transfer function versus the frequency. 2

9.7 To Probe FurtherNote 41 (General LQR). The most general form for a quadratic criteria is

J –ż 8

0xptq1Qxptq ` u1ptqRuptq ` 2x 1ptqNuptqdt. (9.8)

Since z “ Gx ` Hu, the criterion in (9.2) is a special form of (9.8) with

Q “ G1G, R “ H 1H ` ρI, N “ G1H

and (9.3) is a special form of (9.8) with

Q “ G1QG, R “ H 1QH ` ρR, N “ G1QH.

For this criteria, the optimal state-feedback LQR controller is still of the form

u “ ´K x

but now K is given by

K “ R´1pB1P ` Nq

and P is a solution to the following Algebraic Riccati Equation (ARE)

A1P ` PA` Q ´ pPB ` NqR´1pB1P ` N 1q “ 0. 2

Note 42. A symmetric k ˆ k matrix M is positive-definite if

x 1Mx ą 0,

for every nonzero vector x P Rk . Positive-definite matrices are always nonsingular and their inversesare also positive-definite.To test if a matrix is positive define one can compute its eigenvalues. If they are all positive the

MATLAB R© Hint 33. eig(A)computes the eigenvalues of thematrix A. . . p. 83

matrix is positive-definite, otherwise it is not. 2

Note 45 (Multiplicative uncertainty). Since the Nyquist plot of Lpjωq does not enter a circle ofradius one around ´1, we have that

|1` Lpjωq| ě 1 ñ

ˇ

ˇ

ˇ

ˇ

11` Lpjωq

ˇ

ˇ

ˇ

ˇ

ˇ

ˇ

ˇ

ˇ

1´ Lpjωq1` Lpjωq

ˇ

ˇ

ˇ

ˇ

ď 1 ñ

ˇ

ˇ

ˇ

ˇ

Lpjωq1` Lpjωq

ˇ

ˇ

ˇ

ˇ

ď 2. 2

Note 46 (Equation (9.7)). When z ““

y γ 9y‰1, we have that

z “„

yγ 9y

CxγCAx ` γCBu

ñ G “„

CγCA

, H “„

0γCB

.

In this case,

Pzpsq “„

PypsqγsPypsq

1γs

Pypsq,

where Pypsq– C psI ´ Aq´1B, and therefore

|Lpjωq| «a

1` γ2ω2 |Pypjωq|a

H 1H ` ρ“|1` jγω| |Pypjωq|

a

H 1H ` ρ. 2

94 João P. Hespanha

9.8 Exercises9.1. Verify using the diagram in Figure 11.1 that, for the single-input case (m “ 1), the closed-looptransfer function Tupsq from the reference r to the process input u is given by

Tupsq “1

1` L pKF ` Nq,

where Lpsq “ K psI ´ Aq´1B, and the closed-loop transfer function Tz from the reference r to thecontrolled output z is given by

Tzpsq “1

1` LPzpKF ` Nq,

where Pzpsq “ GpsI ´ Aq´1B ` H . 2

9.2. Consider an inverted pendulum operating near the upright equilibrium position, with linearizedmodel given by

9θ:θ

0 1g` ´ b

m`2

θ9θ

`

01m`2

u, y “ θ,

where u denotes an applied torque, the output y “ θ is the pendulum’s angle with a vertical axispointing up, and ` “ 1m, m “ 1Kg, b “ .1N/m/s, g “ 9.8m/s2.

1. Design a PD controller using LQR

2. Design a PID controller using LQRHint: Consider an “augmented” process model with state θ, 9θ, zptq “

şt0 θpsqds.

For both controllers provide the Bode plot of the open-loop gain and the closed-loop step response.2

Chapter 10

LQG/LQR Output Feedback

Contents10.1 Output Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9510.2 Full-order Observers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9510.3 LQG Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9610.4 LQG/LQR Output Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9710.5 Separation Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9810.6 Loop-gain Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9810.7 Loop Shaping using LQR/LQG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10010.8 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10010.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

10.1 Output FeedbackThe state-feedback LQR formulation considered in Chapter 9.3 suffered from the drawback that theoptimal control law

uptq “ ´Kxptq (10.1)

required the whole state x of the process to be measurable. An possible approach to overcome thisdifficulty is to estimate the state of the process based solely on the measured output y, and use

uptq “ ´K xptq

instead of (10.1), where xptq denotes an estimate of the process’ state xptq. In this chapter weconsider the problem of constructing state estimates.

10.2 Full-order ObserversConsider a process with state-space model

9x “ Ax ` Bu, y “ Cx, (10.2)

where y denotes the measured output, u the control input. We assume that x cannot be measuredand our goal to estimate its value based on y.

Suppose we construct the estimate x by replicating the process dynamics as in

9x “ Ax ` Bu. (10.3)

95

96 João P. Hespanha

To see if this would generate a good estimate for x , we can define the state estimation error e– x´xand study its dynamics. From (10.2) and (10.3), we conclude that

9e “ Ax ´ Ax “ Ae.

This shows that when the matrix A is asymptotically stable the error e converges to zero for anyinput u, which is good news because it means that x eventually converges to x as t Ñ8. However,when A is not stable e is unbounded and x grow further and further apart from x as t Ñ 8. Toavoid this, one includes a correction term in (10.3):

9x “ Ax ` Bu` Lpy´ yq, y “ C x, (10.4)

where y should be viewed as an estimate of y and L a given nˆ k matrix. When x is equal (or veryclose) to x , then y will be equal (or very close) to y and the correction term Lpy´ yq plays no role.However, when x grows away from x , this term will (hopefully!) correct the error. To see how thiscan be done, we re-write the estimation error dynamics now for (10.2) and (10.4):

9e “ Ax ´ Ax ´ LpCx ´ C xq “ pA´ LC qe.

Now e converges to zero as long as A ´ LC is asymptotically stable, It turns out that, even whenA is unstable, in general we will be able to select L so that A ´ LC is asymptotically stable. Thesystem (10.4) can be re-write as

9x “ pA´ LC qx ` Bu` Ly, (10.5)

and is called a full-order observer for the process. Full-order observers have two inputs—the process’Note. “Full-order” refers to thefact that the size of its state xis equal to the size of the pro-cess’ state x , even though theoutput y may directly providethe values of some componentsof x . In fact, we will find suchobservers useful even when thewhole state can be measured toimprove the high-frequency re-sponse of an LQR controller. SeeSection 10.7. . . p. 100

control input u and its measured output y—and a single output—the state estimate x . Figure 10.1shows how a full-order observer is connected to the process.

z

y

x

u

9x “ Ax ` Bu

9x “ pA ´ LC qx ` Bu ` Ly

Figure 10.1. Full-order observer

10.3 LQG EstimationAny choice of L in (10.4) for which A ´ LC is asymptotically stable will make x converge to x , aslong at the process dynamics is given by (10.2). However, in general the output y is affected bymeasurement noise and the process dynamics are also affected by disturbance. In light of this, amore reasonable model for the process is

9x “ Ax ` Bu` Bd, y “ Cx ` n, (10.6)

where d denotes a disturbance and n measurement noise. In this we need to re-write the estimationerror dynamics for (10.6) and (10.4), which leads to

9e “ Ax ` Bd ´ Ax ´ LpCx ` n´ C xq “ pA´ LC qe` Bd ´ Ln.

Because of n and d, the estimation error will generally not converge to zero, but we would still like itto remain small by appropriate choice of the matrix L. This motivates the so called Linear-quadraticGaussian (LQG) estimation problem:

LQG/LQR Controller Design 97

Problem 10.1 (Optimal LQG). Find the matrix gain L that minimizes the asymptotic expected value Note. A zero-mean white noiseprocess n has an autocorrelationof the form

Rnpt1, t2q– E“

npt1q n1pt2q‰

“ QN δpt1 ´ t2q.

Such process is wide-sense sta-tionary in the sense that its meanis time-invariant and its autocor-relation Rpt1, t2q only depends onthe difference τ – t1 ´ t2 . Itspower spectrum is the same for ev-ery frequency ω and given by

Snpωq–ż 8

´8

Rpτqe´jωτdτ “ QN .

of the estimation error:

JLQG – limtÑ8

E“

eptq2‰

,

where dptq and nptq are zero-mean Gaussian noise processes (uncorrelated from each other) withpower spectrum

Sdpωq “ QN , Snpωq “ RN , @ω. 2Solution to the optimal LQG Problem 10.1. The optimal LQG estimator gain L is the n ˆ k matrix

MATLAB R© Hint 36. kalmancomputes the optimal LQGestimator gain L. . . p. 100

given by

L “ PC 1R´1N

and P is the unique positive-definite solution to the following Algebraic Riccati Equation (ARE)

Note 42. A symmetric qˆq matrixM is positive definite if x1Mx ą0, for every nonzero vector x PRq . . . p. 93

AP ` PA1 ` BQN B1 ´ PC 1R´1N CP “ 0.

When one uses the optimal gain L in (10.5), this system is called the Kalman-Bucy filter.

A crucial property of this system is that A´ LC is asymptotically stable as long as the followingtwo conditions hold:

1. The system (10.6) is observable.

2. The system (10.6) is controllable when we ignore u and regard d as the sole input.Different choices of QN and RN result in different estimator gains L:

1. When RN is very small (when compared to QN ), the measurement noise n is necessarily smallso the optimal estimator interprets a large deviation of y from y as an indication that theestimate x is bad and needs to be correct. In practice, this lead to large matrices L and fastpoles for A´ LC .

2. When RN is very large, the measurement noise n is large so the optimal estimator is much moreconservative in reacting to deviations of y from y. This generally leads to smaller matrices Land slow poles for A´ LC .

We will return to the selection of QN and RN in Section 10.6.

10.4 LQG/LQR Output FeedbackWe now go back to the problem of designing an output-feedback controller for the process:

9x “ Ax ` Bu, y “ Cx, z “ Gx ` Hu.

Suppose that we designed a state-feedback controller

u “ ´Kx (10.7)

that solves an LQR problem and constructed an LQG state-estimator9x “ pA´ LC qx ` Bu` Ly.

We can obtain an output-feedback controller by using the estimated state x in (10.7), instead of theMATLAB R© Hint 37.reg(sys,K,L) computes theLQG/LQR positive output-feedback controller for the processsys with regulator gain K andestimator gain L. . . p. 100

true state x . This leads to the following output-feedback controller9x “ pA´ LC qx ` Bu` Ly “ pA´ LC ´ BK qx ` Ly, u “ ´K x,

with negative-feedback transfer matrix given by

C psq “ K psI ´ A` LC ` BK q´1L.

This is usually known as an LQG/LQR output-feedback controller and the resulting closed-loop isshown in Figure 10.2.

98 João P. Hespanha

´

eT “ ´y

y

z

u9x “ Ax ` Bu

z “ Gx ` Hu

y “ Cx

9x “ pA ´ LC ´ BK qx ´ LeT

u “ ´K x

Figure 10.2. LQG/LQR output-feedback

10.5 Separation PrincipleThe first question to ask about an LQG/LQR controller is whether or not the closed-loop system willbe stable. To answer this question we collect all the equations that defines the closed-loop system:

9x “ Ax ` Bu, y “ Cx, (10.8)9x “ pA´ LC qx ` Bu` Ly, u “ ´K x. (10.9)

To check the stability of this system it is more convenient to consider the dynamics of the estimationerror e– x´ x instead of the the state estimate x . To this effect we replace in the above equationsx by x ´ e, which yields:

9x “ Ax ` Bu “ pA´ BK qx ` BKe, y “ Cx,9e “ pA´ LC qe, u “ ´K px ´ eq.

This can be written in matrix notation as„

9x9e

A´ BK BK0 A´ LC

xe

, y ““

C 0‰

xe

.

Separation Principle. The eigenvalues of the closed-loop system (10.8) are given by those of theNote. Any eigenvalue of a blockdiagonal matrix must be an eigen-value of one of the diagonal blocks.

state-feedback regulator dynamics A´BK together with those of state-estimator dynamics A´ LC .In case these both matrices are asymptotically stable, then so is the closed-loop (10.8).

10.6 Loop-gain RecoveryWe saw in Sections 9.4 and 10.7 that state-feedback LQR controllers have desirable robustnessproperties and that we can shape the open-loop gain by appropriate choice of the LQR weightingparameter ρ and the choice of the controlled output z . It turns out that we can, to some extent,recover the LQR open-loop gain for the LQG/LQR controller.

Loop-gain recovery. Suppose that the process is single-input/single-output and has no zeros in theright half-place. SelectingNote. B “ B corresponds to an

input disturbance since the pro-cess becomes

9x “ Ax ` Bu` Bd“ Ax ` Bpu` dq.

B – B, QN – 1, RN – σ, σ ą 0,

the open-loop gain for the output-feedback LQG/LQR controller converges to the open-loop gain forthe state-feedback LQR state-feedback controller over a range of frequencies r0, ωmaxs as we makeσ Ñ 0, i.e.,

C pjωqPpjωq σ Ñ 0ÝÝÝÝÝÝÝÝÑ K pjωI ´ Aq´1B, @ω P r0, ωmaxs

In general, the larger ωmax is, the smaller σ needs to be for the gains to match.

LQG/LQR Controller Design 99

Attention! 1. To achieve loop-gain recovery we need to chose RN – σ , even if this does notaccurately describe the noise statistics. This means that the estimator may not be optimal forthe actual noise.

2. One should not make σ smaller than necessary because we do not want to recover the (slow)´20dB/decade magnitude decrease at high frequencies. In practice we should make σ just Note. We need loop recovery up

to the cross-over frequency tomaintain the desired phase mar-gin, otherwise the LQG/LQR con-troller may have a phase marginthat is much smaller than that ofthe original LQR controller.

small enough to get loop recovery until just above or at cross-over. For larger values of ω, theoutput-feedback controller may actually behave much better than the state-feedback one.

3. When the process has zeros in the right half-plane, loop-gain recovery will generally only workup to the frequencies of the nonminimum-phase zeros.When the zeros are in the left half-plane but close to the axis, the closed-loop will not be veryrobust with respect to uncertainty in the position of the zeros. This is because the controllerwill attempt to cancel these zeros. 2

Example 10.1 (Aircraft roll-dynamics). Figure 10.3(a) shows Bode plots of the open-loop gain forthe state-feedback LQR state-feedback controller vs. the open-loop gain for several output-feedbackLQG/LQR controller obtained for the aircraft roll-dynamics in Example 8.1. The LQR controller was

10−2

10−1

100

101

102

103

−180

−135

−90

Pha

se (

deg)

−80

−60

−40

−20

0

20

40

60

80

From: u To: Out(1)

Mag

nitu

de (

dB)

sigma = 0.01sigma = 1e−05sigma = 1e−08LQR loop−gain(rho = 0.01, gamma=0.1)

Open−loop Bode Diagrams

Frequency (rad/sec)

(a) Open-loop gain

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

0.5

1

1.5

sigma = 0.01sigma = 1e−05sigma = 1e−08LQR loop−gain(rho = 0.01, gamma=0.1)

Step Response

Time (sec)

Am

plitu

de

(b) Closed-loop step response

Figure 10.3. Bode plots and closed-loop step response for the open-loop gain of the LQR controllers in Exam-ples 10.1, 11.2.

designed using the controlled output z –“

θ γ 9θ‰1, γ “ .1 and ρ “ .01. For the LQG state-

estimators we used B “ B and RN “ σ for several values of σ . We can see that, as σ decreases,

100 João P. Hespanha

the range of frequencies over which the open-loop gain of the output-feedback LQG/LQR controllermatches that of the state-feedback LQR state-feedback increases. Moreover, at high frequencies theoutput-feedback controllers exhibit much faster (and better!) decays of the gain’s magnitude. 2

10.7 Loop Shaping using LQR/LQGWe can now summarize the procedure to do open-loop gain shaping using LQG/LQR, to be contrastedwith the classical lead-lag compensation briefly recalled in Section 7.3:Note. A significant diference be-

tween this procedure and that dis-cussed in Section 7.3, is that sta-bility of the closed loop is now al-ways automatically guaranteed.

1. Start by designing the LQR gain K assuming that the full state can be measured to obtain anappropriate loop gain in the low-frequency range, up to the cross-over frequency.This can be done using the procedure described in Section 10.7, where

(a) the parameter ρ can be used to move the magnitude Bode plot up and down, and(b) the parameter γ can be used to improve the phase margin.

2. Use LQG to achieve loop-gain recovery up to the cross-over frequency.This can be done using the procedure described in Section 10.6, by decreasing σ just to thepoint where one gets loop recovery until just above or at the cross-over frequency. Hopefully,this still permits satisfying any high-frequency constraints for the loop gain.

10.8 MATLAB R© HintsMATLAB R© Hint 36 (kalman). The command [est,L,P]=kalman(sys,QN,RN) computes the op-timal LQG estimator gain for the process

9x “ Ax ` Bu` BBd, y “ Cx ` n, (10.10)

where dptq and nptq are uncorrelated zero-mean Gaussian noise processes with covariance matrices

E“

dptqd1pτq‰

“ δpt ´ τqQN, E“

nptq n1pτq‰

“ δpt ´ τqRN.

The variable sys should be a state-space model created using sys=ss(A,[B BB],C,0). ThisAttention! The process model sysshould have the D matrix equal tozero, even though (10.10) seems toimply otherwise.

command returns the optimal estimator gain L, the solution P to the corresponding algebraic Riccatiequation, and a state-space model est for the estimator. The inputs to est are ru; ys, and itsoutputs are ry; xs.For loop transfer recovery (LTR), one should set

BB “ B, QN “ I, RN “ σ I, σ Ñ 0. 2

MATLAB R© Hint 37 (reg). The function reg(sys,K,L) computes a state-space model for a positiveAttention! Somewhat unexpect-edly, the command reg producesa positive feedback controller.

output feedback LQG/LQR controller for the process with state-space model sys with regulator gainK and estimator gain L. 2

10.9 Exercises10.1. Consider an inverted pendulum on a cart operating near the upright equilibrium position, withlinearized model given by

»

p9p9θ:θ

fi

ffi

ffi

fl

»

0 1 0 00 0 ´2.94 00 0 0 10 0 11.76 0

fi

ffi

ffi

fl

»

p9pθ9θ

fi

ffi

ffi

fl

`

»

0.3250´.3

fi

ffi

ffi

fl

F

where F denotes a force applied to the cart, p the cart’s horizontal position, and θ the pendulum’sangle with a vertical axis pointing up.

LQG/LQR Controller Design 101

1. Design an LQG/LQR output-feedback controller that uses only the angle θ and the positionof the cart p.

2. Design an LQG/LQR output-feedback controller that uses the angle θ, the angular velocity 9θ,the position of the cart p, and its derivative using LQG/LQR (full-state feedback).Why use LQG when the state is accessible?

For both controllers provide the Bode plot of the open-loop gain of the LQR control Lpsq “ kpsI ´Aq´1B, the open-loop gain of the LQR controller C psqPpsq, and the closed-loop step response. 2

102 João P. Hespanha

Chapter 11

Set-point control

Contents11.1 Nonzero Equilibrium State and Input . . . . . . . . . . . . . . . . . . . . . . . . . . . 10311.2 State feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10411.3 Output feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10511.4 MATLAB R© Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10511.5 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

11.1 Nonzero Equilibrium State and InputOften one does not want to make z as small as possible, but instead make it converge as fast aspossible to a given constant set-point value r . This can be achieved by making the state x and theinput u of the process (9.1) converge to values x˚ and u˚ for which

Ax˚ ` Bu˚ “ 0, r “ Gx˚ ` Hu˚. (11.1)

The right equation makes sure that z will be equal to r when x and u reach x˚ and u˚, respectively.The left-equation makes sure that when these values are reached, 9x “ 0 and therefore x will remainequal to x˚, i.e., x˚ is an equilibrium state.

Given the desired set-point r for x , computing x˚ and u˚ is straightforward because (11.1) is a Note. When the process transfer-function has an integrator, onegenerally gets u˚ “ 0.

system of linear equations and in general the solution to these equations is of the form

x˚ “ Fr, u˚ “ Nr. (11.2)

For example, when the number of inputs to the process m is equal to the number of controlled outputs Note. The matrix“ A BG H

is invert-ible unless the process’ transfer-function from u to z has a zeroat the origin. This derivative ef-fect will always make z convergeto zero when the input convergesto a constant.

MATLAB R© Hint 38. When thenumber of process inputs mis larger than or equal to thenumber of controlled outputs ` ,the matrices F and N in (11.2)can be easily computed usingMATLAB R© . . . p. 105

` , we have„

A BG H

x˚u˚

0r

ô

x˚u˚

A BG H

´1 „0r

, (11.3)

and F is an nˆ ` matrix given by the top n rows and right-most ` columns of“

A BG H

‰´1 and N is anmˆ ` matrix given by the bottom m rows and right-most ` columns of

A BG H

‰´1.

Attention! When the number of process inputs m is larger than the number of controlled outputs `we have an over-actuated system and the system of equations (11.1) will generally have multiplesolutions. One of them is

x˚u˚

A BG H

1ˆ„A BG H

A BG H

1˙´1 „0r

. (11.4)

103

104 João P. Hespanha

In this case, we can still express x˚ and u˚ as in (11.2).

When the number of process inputs m is smaller than the number of controlled outputs ` we havean under-actuated system and the system of equations (11.1) may not have a solution. In fact, asolution will only exists for some specific references r . However, when it does exist, the solution canstill express x˚ and u˚ as in (11.2). 2

11.2 State feedbackWhen one wants z to converge to a given set-point value r , the state-feedback controller should be

Note 48. Why?. . . p. 105u “ ´K px ´ x˚q ` u˚ “ ´Kx ` pKF ` Nqr, (11.5)

where x˚ and u˚ are given by (11.2) and K is the gain of the optimal regulation problem. Thecorresponding control architecture is shown in Figure 11.1. The state-space model for the closed-loop system is given by

9x “ Ax ` Bu “ pA´ BK qx ` BpKF ` Nqrz “ Gx ` Hu “ pG ´ HK qx ` HpKF ` Nqr.

−+ +

+r

x

x˚z

u

9x “ Ax ` BuKF

N

Figure 11.1. Linear quadratic set-point control with state feedback

Example 11.1 (Aircraft roll-dynamics). Figure 11.2 shows step responses for the state-feedbackLQR controllers in Example 9.1, whose Bode plots for the open-loop gain are shown in Figure 9.6.Figure 11.2(a) shows that smaller values of ρ lead to faster responses and Figure 11.2(b) shows that

0 1 2 3 4 5 60

0.2

0.4

0.6

0.8

1

1.2

1.4

rho = 0.01rho = 1rho = 100gamma = 0.01

Step Response

Time (sec)

Am

plitu

de

(a)

0 1 2 3 4 5 60

0.2

0.4

0.6

0.8

1

1.2

1.4

gamma = 0.01gamma = 0.1gamma = 0.3(rho = 0.01)

Step Response

Time (sec)

Am

plitu

de

(b)

Figure 11.2. Step responses for the closed-loop LQR controllers in Example 11.1

larger values for γ lead to smaller overshoots (but slower responses). 2

LQG/LQR Controller Design 105

11.3 Output feedbackWhen one wants z to converge to a given set-point value r , the output-feedback LQG/LQR controllershould be

Note 49. Why?. . . p. 1069x “ pA´ LC ´ BK qx ` LpCx˚ ´ yq, u “ K x ` u˚, (11.6)

where x˚ and u˚ are given by (11.2). The corresponding control architecture is shown in Figure 11.3.The state-space model for the closed-loop system is given by Note. When z “ y, we have

G “ C , H “ 0 and in this caseCx˚ “ r . This corresponds toCF “ 1 in Figure 11.3. When theprocess has an integrator we getN “ 0 and obtain the usual unity-feedback configuration.

9x9x

Ax ` BpK x ` u˚qpA´ LC ´ BK qx ` LpCx˚ ´ Cxq

A BK´LC A´ LC ´ BK

xx

`

BNLCF

r

z “ Gx ` HpK x ` u˚q ““

G HK‰

xx

` HNr

+ − +

+r

y

Cx˚z

u

9x “ Ax ` Bu

y “ Cx

9x “ pA ´ LC ´ BK qx ` Lv

u “ K xCF

N

Figure 11.3. LQG/LQR set-point control

Example 11.2 (Aircraft roll-dynamics). Figure 10.3(b) shows step responses for the output-feedbackLQG/LQR controllers in Example 10.1, whose Bode plots for the open-loop gain are shown in Fig-ure 10.3(a). We can see that smaller values of σ lead to a smaller overshoot mostly due to a largergain margin. 2

11.4 MATLAB R© HintsMATLAB R© Hint 38. When the number of process inputs m is larger than or equal to the numberof controlled outputs ` , the matrices F and N in (11.2) that correspond to the equilibria in either(11.3) or (11.4) can be computed using the following MATLAB R© commands:

M=pinv([A,B;G,H]);F=M(1:n,end-l+1:end);N=M(end-m+1:end,end-l+1:end);

where n denotes the size of the state and l the number of controlled outputs. 2

11.5 To Probe FurtherNote 48 (Set-point control with state-feedback). To understand why (11.5) works, suppose we define

z “ z ´ r, x “ x ´ x˚, u “ u´ u˚.

Then

9x “ Ax ` Bu “ Apx ´ x˚q ` Bpu´ u˚q ` Ax˚ ` Bu˚

z “ Gx ` Hu´ r “ Gpx ´ x˚q ` Hpu´ u˚q ` Gx˚ ` Hu˚ ´ r

106 João P. Hespanha

and we conclude that

9x “ Ax ` Bu, z “ Gx ` Hu. (11.7)

By selecting the control signal in (11.5), we are setting

u “ u´ u˚ “ ´K px ´ x˚q “ ´K x,

which is the optimal state-feedback LQR controller that minimizes

JLQR –

ż 8

0

`

zptq1Qzptq˘

` ρ`

u1ptqRuptq˘

dt,

This controller makes the system (11.7) asymptotically stable and therefore x , u, z all converge tozero as t Ñ8, which means that z converges to r . 2

Note 49 (Set-point control with output-feedback). To understand why (11.6) works suppose we define

z “ z ´ r, x “ x ´ x˚ ` x .

Then

9x “ pA´ LC qx (11.8)9x “ pA´ BK qx ´ LC x (11.9)z “ Gpx ´ xq ` HK x ´ r. (11.10)

1. Since A´ LC is asymptotically stable, we conclude from (11.8) that x Ñ 0 as t Ñ8.In practice, we can view the state x of the controller as an estimate of x˚ ´ x .

2. Since A ´ BK is asymptotically stable and x Ñ 0 as t Ñ 8, we conclude from (11.9) thatx Ñ 0 as t Ñ8.

3. Since x Ñ 0 and x Ñ 0 as t Ñ8, we conclude from (11.10) that z Ñ r as t Ñ8. 2

11.1. Verify equations (11.8), (11.9), and (11.10). 2

Part IV

Nonlinear Control

107

Nonlinear Control 109

110 João P. Hespanha

Introduction to Nonlinear Control

uptq P Rm

xptq P Rn

9x “ fpx, uq

uptq P Rm

xptq P Rn

u “ kpxq

9x “ fpx, uq

Figure 11.4. Nonlinear process with m inputs Figure 11.5. Closed-loop nonlinear system withstate-feedback

In this section we consider the control of nonlinear systems such as the one shown in Figure 11.4.Our goal is to construct a state-feedback control law of the form Note. This control-law implicitly

assumes that the whole state x canbe measured.u “ kpxq

that results in adequate performance for the closed-loop system

9x “ f`

x, kpxq˘

.

Typically, at least we want x to be bounded and converge to some desired reference value r .

Pre-requisites

1. Basic knowledge of nonlinear ordinary differential equations.

2. Basic knowledge of continuous-time linear controller design.

3. Familiarity with basic vector and matrix operations.

Further reading A more extensive coverage of nonlinear control can be found, e.g., in [9].

111

112 João P. Hespanha

Chapter 12

Feedback linearization controllers

Contents12.1 Feedback Linearization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11312.2 Generalized Model for Mechanical Systems . . . . . . . . . . . . . . . . . . . . . . . . 11412.3 Feedback Linearization of Mechanical Systems . . . . . . . . . . . . . . . . . . . . . . 11612.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

12.1 Feedback LinearizationIn feedback linearization control design, we decompose the control signal u into two componentswith distinct functions:

u “ unl ` v,

where

1. unl is used to “cancel” the process’ nonlinearities, and

2. v is used to control the resulting linear system.

u

y

Fdragg

From Newton’s law:

m:y “ Fdrag ´ mg` u

“ ´12cρA

9y| 9y| ´ mg` u,

where m is the vehicle’s mass, g gravity’s ac-celeration, Fdrag “ ´

12cρA 9y| 9y| the drag force,

and u an applied force.

Figure 12.1. Dynamics of a vehicle moving vertically in the atmosphere

113

114 João P. Hespanha

To understand how this is done, consider the vehicle shown in Figure 12.1 moving vertically in theNote. For large objects movingthrough air, the air resistance isapproximately proportional to thesquare of the velocity, correspond-ing to a drag force that opposesmotion, given by

Fdrag “ ´12 cρA

9y| 9y|

where ρ is the air density, A thecross-sectional area, and c thedrag coefficient, which is 0.5 for aspherical object and can reach 2for irregularly shaped objects [11].Fdrag always points in the oppositedirection of 9y.

atmosphere. By choosing

u “ unlp 9yq ` v, unlp 9yq–12cρA

9y| 9y| ` mg,

we obtain

m:y “ ´12cρA

9y| 9y| ´ mg` punlp 9yq ` vq “ v ñ :y “ 1mv.

In practice, we transformed the original nonlinear process into a (linear) double integrator withtransfer function from v to y given by

T psq– 1ms2 .

We can now use linear methods to find a controller for v that stabilizes the closed-loop. E.g., a PDNote. Any linear method can beused to design the controller forv , but we shall see shortly thatrobustness with respect to multi-plicative uncertainty is importantfor the closed-loop.

controller of the form

v “ KPe` KD 9e, e– r ´ y.

Figure 12.2 shows a diagram of the overall closed-loop system. From an “input-output” perspective,the system in the dashed block behaves as a linear system with transfer function T psq– 1

ms2 .

+ +

+−

r e uv

unl

y

1

2cρA 9y| 9y| ` mg

m:y “ ´1

2cρA 9y| 9y| ´ mg ` uKPe ` KD 9e

Figure 12.2. Feedback linearization controller.

12.2 Generalized Model for Mechanical SystemsThe equations of motion of many mechanical systems can be written in the following general formNote. These include robot-arms,

mobile robots, airplanes, heli-copters, underwater vehicles, hov-ercraft, etc. Mpqq:q` Bpq, 9qq 9q` Gpqq “ F, (12.1)

where

• q P Rk is a k-vector with linear and/or angular positions called the vector of generalizedcoordinates;

• F P Rk is a k-vector with applied forces and/or torques called the vector of generalized forces;

• Gpqq is a k-vector sometimes called the vector of conservative forces (typically, gravity orforces generated by springs);

• Mpqq is a k ˆ k non-singular symmetric positive-definite matrix called the mass matrix ; andNote 42. A symmetric qˆq matrixM is positive definite if x1Mx ą0, for every nonzero vector x PRq . . . p. 93

Nonlinear Control 115

• Bpq, 9qq is a k ˆ k matrix sometimes called the centrifugal/Coriolis/friction matrix, for systemswith no friction we generally have

9q1Bpq, 9qq 9q “ 0, @ 9q P Rk

whereas for systems with friction

9q1Bpq, 9qq 9q ě 0, @ 9q P Rk ,

with equality only when 9q “ 0.

Examples

θ

g

m

θ1

θ2

ℓ1

ℓ2

m1

m2

Figure 12.3. Inverted pendulum Figure 12.4. Two-link robot manipulator

Example 12.1 (Inverted pendulum). The dynamics of the inverted pendulum shown in Figure 12.3 aregiven by

m`2:θ “ mg` sin θ ´ b 9θ ` T ,

where T denotes a torque applied at the base, and g is the gravity’s acceleration. This equation canbe identified with (12.1), provided that we define Note. When the pendulum is at-

tached to a cart and the input u isthe cart’s acceleration :z , we haveT “ ´m`u cos θ but this makesthe problem more difficult, espe-cially around θ “ ˘π2. Why?

q– θ, F – T , Mpqq– m`2, Bpqq– b, Gpqq– ´mg` sin θ. 2

Example 12.2 (Robot arm). The dynamics of the robot-arm with two revolution joints shown inFigure 12.4 can be written as in (12.1), provided that we define

q–

θ1θ2

, F –

τ1τ2

.

where τ1 and τ2 denote torques applied at the joints. For this system

Mpqq–„

`22m2

2 ` 2`1`2 cos θ2 ` `21 pm1 ` m2q `2

2 ` `1`2m2 cos θ2`22m2 ` `1`2m2 cos θ2 `2

2m2

Bpq, 9qq–„

´2m2`1`2 9θ2 sin θ2 ´m2`1`2 9θ2 sin θ2m2`1`2 9θ1 sin θ2 0

Gpqq– g„

m2`2 cospθ1 ´ θ2q ` pm1 ` m2q`1 cos θ1m2`2 cospθ1 ´ θ2q

.

where g is the gravity’s acceleration [2, p. 202–205]. 2

116 João P. Hespanha

x

y

θ

ℓFp

Fs

Figure 12.5. Hovercraft

Example 12.3 (Hovercraft). The dynamics of the hovercraft shown in Figure 12.5 can be written asin (12.1), provided that we define

q–

»

xyθ

fi

fl , F –

»

pFs ` Fpq cos θ ´ F` sin θpFs ` Fpq sin θ ` F` cos θ

`pFs ´ Fpq

fi

fl ,

where Fs, Fp, and F` denote the starboard, portboard, and lateral fan forces. The vehicle in thephotograph does not have a lateral fan, which means that F` “ 0. It is therefore called underactuatedbecause the number of controls (Fs and Fp) is smaller than the number of degrees of freedom (x , y,and θ). For this system

Mpqq–

»

m 0 00 m 00 0 J

fi

fl , Bpqq–

»

dv 0 00 dv 00 0 dω

fi

fl ,

where m “ 5.5 kg is the mass of the vehicle, J “ 0.047 kg m2 its rotational inertia, dv “ 4.5 thecoefficient of linear friction, dω “ .41 the coefficient of rotational friction, and ` “ 0.123 m themoment arm of the forces. In these equations, the geometry and mass centers of the vehicle areassumed to coincide [3]. 2

12.3 Feedback Linearization of Mechanical SystemsA mechanical system is called fully actuated when one has control over the whole vector or generalizedforces. For such systems we regard u– F as the control input and we can use feedback linearizationto design nonlinear controllers. In particular, choosing

F “ u “ unlpq, 9qq `Mpqq v, unlpq, 9qq– Bpq, 9qq 9q` Gpqq,

we obtain

Mpqq:q` Bpq, 9qq 9q` Gpqq “ Bpq, 9qq 9q` Gpqq `Mpqq v ô :q “ v.

Expanding the k-vectors :q and v in their components, we obtain»

:q1:q2...:qk

fi

ffi

ffi

ffi

fl

»

v1v2...vk

fi

ffi

ffi

ffi

fl

and therefore we can select each vi as if we were designing a controller for a double integrator

:qi “ vi.

Nonlinear Control 117

Attention! Measurement noise can lead to problems in feedback linearization controllers. When themeasurements of q and 9q are affected by noise, we have

Mpqq:q` Bpq, 9qq 9q` Gpqq “ unlpq` n, 9q` wq `Mpq` nq v,

where n is measurement noise in the q sensors and w the measurement noise in the 9q sensors. Inthis case

Mpqq:q` Bpq, 9qq 9q` Gpqq “ Bpq` n, 9q` wqp 9q` wq ` Gpq` nq `Mpq` nq v (12.2)

and (with some work) one can show that

:q “`

I ` ∆˘

v ` d, (12.3)

where Note. See Exercise 12.1. p. 117

∆ – Mpqq´1`Mpq` nq ´Mpqq˘

,

d – Mpqq´1´

`

Bpq` n, 9q` wq ´ Bpq, 9qq˘

9q` Bpq` n, 9q` wqw ` Gpq` nq ´ Gpqq¯

.

Since ∆ and d can be very large, with feedback linearization controllers it is particularly importantto make sure that the controller selected for v is robust with respect to multiplicative uncertaintyand good at rejecting disturbances.

12.4 Exercises12.1. Verify that (12.3) is indeed equivalent to (12.2), by solving the latter equation with respect to:q. 2

12.2. Design a feedback linearization controllers to drive the inverted pendulum in Example 12.1to the up-right position. Use the following values for the parameters: ` “ 1 m, m “ 1 kg,b “ .1 N m´1s´1, and g “ 9.8 m s´2. Verify the performance of your system in the presence ofmeasurement noise using Simulink. 2

118 João P. Hespanha

Chapter 13

Lyapunov Stability

Contents13.1 Lyapunov Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11913.2 Lyapunov Stability Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12113.3 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12213.4 LaSalle’s Invariance Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12213.5 Liénard Equation and Generalizations . . . . . . . . . . . . . . . . . . . . . . . . . . . 12313.6 To Probe Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12513.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

13.1 Lyapunov StabilityAlthough feedback linearization provides a simple method to design controllers for nonlinear systems.The resulting controllers are sometimes very sensitive to measurement noise because it prevents aperfect cancellation of the nonlinearities. It turns out that such cancellation is not always needed.

Consider again the vehicle shown in Figure 12.1 and suppose that we simply want to control itsvelocity 9y. For simplicity, we assume that the applied force u is constant and larger than mg (i.e.,there is an excess upward force) and that the units were chosen so that all constant coefficient arenumerically equal to 1:

:y “ ´ 9y| 9y| ` 1.

Since

´ 9y| 9y| ` 1 “ 0 ô 9y “ 1,

we conclude that 1 is the only equilibrium-point for the system, i.e.,

9yptq “ 1, @t ě 0,

is the only possible constant trajectory for the system. A question that may then arise is:

Will 9yptq converge to 1 as t Ñ8, when 9yp0q ­“ 1?

To study this question we will consider an “error” system that looks at the difference from 9y to theequilibrium-point 1. Defining x – 9y´ 1, we conclude that

9x “ ´px ` 1q|x ` 1| ` 1. (13.1)

and the previous question could be reformulated as

119

120 João P. Hespanha

Will xptq converge to 0 as t Ñ8, when xp0q ­“ 0?

To address this question, suppose that we define

V pxq “ x2

and compute V ’s derivative with respect to time using the chain rule:

9V ptq “dV

`

xptq˘

dt “BVBx

9x “ 2x`

´ px ` 1q|x ` 1| ` 1˘

#

´2x2px ` 2q x ě ´12xpx2 ` 2x ` 2q x ă ´1.

(13.2)

Figure 13.1 shows the right-hand-side of the above equation as a function of x . Three conclusions

−2 −1.5 −1 −0.5 0 0.5 1 1.5 2−35

−30

−25

−20

−15

−10

−5

0

replacements

x

9 V

Figure 13.1. 9V vs. x

can be drawn from here:

Boundedness For every initial condition xp0q, |xptq| will remain bounded for all t ě 0, i.e., it willnot blow up. This is because V

`

xptq˘

“ x2ptq cannot increase.

Stability If we start xp0q very close to zero, then xptq will remain very close to zero for all timest ě 0. This is because V

`

xptq˘

“ x2ptq will always be smaller or equal than V`

xp0q˘

.

Convergence xptq Ñ 0 as t Ñ 8. This is because the right-hand side of (13.2) is only equal tozero when x “ 0 and therefore 9V will be strictly negative for any nonzero x .This finally provides an answer to the previous questions: Yes! x Ñ 0 as t Ñ8.

When a system exhibits these three properties we say that the origin is globally asymptoticallystable. This notion of stability for nonlinear systems was originally proposed by Aleksandr Lyapunovand now carries his name.

Definition 13.1 (Lyapunov stability). Given a system

9x “ fpxq, t ě 0, x P Rn, (13.3)

we say that:

(i) the trajectories are globally bounded if for every initial condition xp0q, there exists a scalarα`

xp0q˘

ě 0 such that›

›xptq›

› ď α`

xp0q˘

, @t ě 0;

(ii) the origin is globally stable if the trajectories are globally bounded and αpxp0qq Ñ 0 asxp0q Ñ 0;

Nonlinear Control 121

(iii) the origin is globally asymptotically stable if it is globally stable and in addition xptq Ñ 0 ast Ñ8.

Attention! The requirement (ii) is rather subtle but very important. In essence, it says that if wechoose the initial condition xp0q very close to the origin, then the upper bound αpxp0qq will also bevery small and the whole trajectory stays very close to the origin. 2

13.2 Lyapunov Stability TheoremThe technique used before to conclude that the origin is globally asymptotically stable for thesystem (13.1) is a special case of a more general method proposed by Aleksandr M. Lyapunov. Hismain contribution to nonlinear control was the realization that an appropriate choice of the functionV pxq could make proving stability very simple. In the example above (and in fact in most one-dimensional systems) V pxq “ x2 works well, but for higher dimensional systems the choice of V pxqis critical.

Lyapunov Stability Theorem. Suppose that there exists a scalar-valued function V : Rn Ñ R withthe following properties:

(i) V pxq is differentiable;(ii) V pxq is positive definite, which means that V p0q “ 0 and

V pxq ą 0, @x ‰ 0.

(iii) V pxq is radially unbounded, which means that V pxq Ñ 8 whenever x Ñ8;(iv) ∇xV pxq ¨ fpxq is negative definite, which means that ∇xV p0q ¨ fp0q “ 0 and

Notation 6. Given a scalar func-tion of n variables fpx1, . . . , xmq,∇x f denotes the gradient of f , i.e.,

∇x fpx1, x2, . . . , xmq “”

BfBx1

BfBx2 ¨ ¨ ¨

BfBxm

ı

.

∇xV pxq ¨ fpxq ă 0, @x ‰ 0.

Then the origin is globally asymptotically stable for the system (13.3). The function V pxq is called

Note 50. What is the intuition be-hind Lyapunov’s stability theo-rem? p. 121

a Lyapunov function. 2

The function V pxq “ x2 considered before satisfies all the conditions of the Lyapunov StabilityTheorem for the system (13.1) so our conclusion that the origin was globally asymptotically stableis consistent with this theorem.

Note 50 (Lyapunov Stability Theorem). When the variable x is a scalar,

9V ptq “dV

`

xptq˘

dt “BVBx

9x “ BVBx fpxq,

but when x and f are n-vectors, i.e.,

9x “ fpxq ô

»

9x19x2...9xn

fi

ffi

ffi

ffi

fl

»

f1pxqf2pxq

...fnpxq

fi

ffi

ffi

ffi

fl

,

we haveNote 51. These derivatives existbecause of condition (i) in Lya-punov Stability Theorem.9V ptq “

dV`

xptq˘

dt “

nÿ

i“1

BVBxi

9xi “BVBxi

fipxq “∇xV pxq ¨ fpxq.

Condition (iv) thus requires V pxq to strictly decrease as long x ‰ 0. Because of condition (ii), x ‰ 0is equivalent to V pxq ą 0 so V pxq must decrease all the way to zero.Since V pxq is only zero at zero and condition (iii) excludes the possibility that V pxq Ñ 0 as x Ñ8,this necessarily implies that x Ñ 0 as t Ñ8. 2

122 João P. Hespanha

Example 13.1. Consider the following system

:y` p1` | 9y|qpy` 9yq “ 0.

Defining x ““

x1 x2‰1–

y 9y‰1, this system can be written as 9x “ fpxq as follows:

9x1 “ x2,9x2 “ ´p1` |x2|qpx1 ` x2q.

Suppose we want to show that the origin is globally asymptotically stable. A “candidate” LyapunovNote. Finding a Lyapunov func-tion is more an art than a sci-ence. Fortunately several “artists”already discovered Lyapunov formany systems of interest. Moreon this shortly. . .

function for this system is

V pxq– x21 ` px1 ` x2q2.

This function satisfies the requirements (i)–(iii). Moreover,

∇xV pxq ¨ fpxq “ 2x1 9x1 ` 2px1 ` x2qp 9x1 ` 9x2q“ 2x1x2 ` 2px1 ` x2q

`

x2 ´ p1` |x2|qpx1 ` x2q˘

“ 2x1p´x1 ` x1 ` x2q ` 2px1 ` x2q`

x2 ´ p1` |x2|qpx1 ` x2q˘

“ ´2x21 ` 2px1 ` x2q

`

x1 ` x2 ´ p1` |x2|qpx1 ` x2q˘

“ ´2x21 ´ 2|x2|px1 ` x2q2 ď 0.

Since we only have equality to zero when x1 “ x2 “ 0, we conclude that (iv) also holds and thereforeV pxq is indeed a Lyapunov function and the origin is globally asymptotically stable. 2

13.3 Exercise13.1. The average number of data-packets sent per second by any program that uses the TCPprotocol (e.g., ftp) evolves according to an equation of the form:

9r “ 1RTT 2 ´

23pdroprpr ` dq,

where r denotes the average sending rate, RTT denotes the round-trip time for one packet inseconds, pdrop the probability that a particular packet will be dropped inside the network, and dthe average sending rate of other data-flows using the same connection. All rates are measured inpackets per second. Typically one packet contains 1500bytes.

1. Find the equilibrium-point req for the sending rate.Hint: When d “ 0, your expression should simplify to

req “a

32RTT?pdrop

.

This is known as the “TCP-friendly” equation.

2. Verify that the origin is globally asymptotically stable for the system with state x – r ´ req.2

13.4 LaSalle’s Invariance PrincipleConsider now the system

:y` 9y| 9y| ` y3 “ 0

Nonlinear Control 123

Defining x ““

x1 x2‰1–

y 9y‰1, this system can be written as 9x “ fpxq as follows:

9x1 “ x2, (13.4)9x2 “ ´x2|x2| ´ x3

1 . (13.5)

A candidate Lyapunov function for this system is

V pxq– x222 `

x414 .

This function satisfies the requirements (i)–(iii). However,

∇xV pxq ¨ fpxq “ x2 9x2 ` x31 9x1 “ ´|x2|x2

2

and therefore it does not satisfy (iv) because

∇xV pxq ¨ fpxq “ 0 for x2 “ 0, x1 ‰ 0.

However,

∇xV pxq ¨ fpxq “ 0 ñ x2 “ 0

so V can only stop decreasing if x2 converges to zero. Moreover, if we go back to (13.5) we seethat x2ptq “ 0, @t must necessarily imply that x1ptq “ 0, @t . So although V pxq is not a Lyapunovfunction, it can still be used to prove that the origin is globally asymptotically stable. The argumentjust used to prove that the origin is asymptotically stable is due to J. P. LaSalle:

LaSalle’s Invariance Principle. Suppose that there exists a scalar-valued function V : Rn Ñ R thatNote 52. In general, LaSalle’s In-variance Principle is stated in amore general form. . . p. 125

satisfies the conditions (i)–(iii) of the Lyapunov Stability Theorem as well as

(iv)’ ∇xV pxq ¨ fpxq is negative semi-definite, which means that

∇xV pxq ¨ fpxq ď 0, @x,

and, in addition, for every solution xptq for which

∇xV`

xptq˘

¨ f`

xptq˘

“ 0, @t ě 0 (13.6)

we must necessarily have that

xptq “ 0, @t ě 0. (13.7)

Then the origin is globally asymptotically stable for the system (13.3). In this case the function V pxqis called a weak Lyapunov function. 2

13.5 Liénard Equation and GeneralizationsLaSalle’s Invariance principle is especially useful to prove stability for systems with dynamics de-scribed by the Liénard equation:

Note 53. The system consideredin Section 13.4 was precisely ofthis form.

:y` bpy, 9yq 9y` λpyq “ 0,

where y is a scalar and bpy, 9yq, λpyq are functions such that

bpy, 9yq ą 0, @ 9y ­“ 0 (13.8)λpyq ‰ 0, @y ­“ 0 (13.9)

Λpyq–ż y

0λpzqdz ą 0, @y ­“ 0 (13.10)

limyÑ8

Λpyq “ 8. (13.11)

124 João P. Hespanha

This type of equation arises in numerous mechanical systems from Newton’s law.

Defining x ““

x1 x2‰1–

y 9y‰1, the Liénard equation can be written as 9x “ fpxq as follows:

9x1 “ x2, (13.12)9x2 “ ´bpx1, x2qx2 ´ λpx1q. (13.13)

A candidate Lyapunov function for this system isNote. This is how we got the Lya-punov function for the system inSection 13.4. Verify!

V pxq– x222 ` Λpx1q. (13.14)

This function satisfies the requirements (i)–(iii) of the Lyapunov Stability Theorem andNote. Recall that (i) asked forV pxq to be differentiable, (ii)asked for V pxq to be positive defi-nite, and (iii) asked for V pxq to beradially unbounded.

∇xV pxq ¨ fpxq “ x2 9x2 ` λpx1q 9x1 “ ´bpx1, x2qx22 ď 0,

since bpx1, x2q ą 0 for every x2 ‰ 0 [cf. (13.8)]. Moreover, from (13.8) we conclude that

∇xV pxq ¨ fpxq “ 0 ñ x2 “ 0.

Because of (13.13), any trajectory with x2ptq “ 0, @t necessarily must have λ`

x1ptq˘

“ 0, @t , whichin turn implies that x1ptq “ 0, @t because of (13.9). Therefore V pxq is a weak Lyapunov functionand the origin is globally asymptotically stable.

The type of weak Lyapunov function used for the Liénard equation can also be used for higher-order dynamical system of the form

Mpqq:q` Bpq, 9qq 9q` Lq “ 0, (13.15)

where q is a k-vectors and Mpqq, Bpq, 9qq, and L are k ˆ k matrices with Mpqq and L symmetricand positive definite.

Defining

x “„

x1x2

q9q

P R2k ,

the system (13.15) can be written as 9x “ fpxq as follows:

9x1 “ x2,

9x2 “ ´Mpx1q´1´

Bpx1, x2qx2 ` Lx1¯

.

A candidate Lyapunov function for this system is

V pxq– 12x12Mpx1qx2 `

12x11Lx1. (13.16)

This function satisfies the requirements (i)–(iii) andNote. Using the product rule:dpx1Mxq

dt “ dxdt1Mx ` x1M dx

dt `

x1 dMdt x . But since dxdt1Mx is a

scalar, it is equal to its transposeand we get dpx1Mxq

dt “ 2x1M dxdt `

x1 dMdt x .

∇xV pxq ¨ fpxq “ x 12Mpx1q 9x2 `12x12

´dMpx1qdt

¯

x2 ` 9x 11Lx1

“ ´x 12´

Bpx1, x2q ´12dMpx1qdt

¯

x2.

Using LaSalle’s Invariance Principle, we conclude that the origin is globally asymptotically stable aslong as

Bpx1, x2q ´12dMpx1qdt

is positive definite. This will be used shortly to design controllers for mechanical systems.

Nonlinear Control 125

13.6 To Probe FurtherNote 52 (LaSalle’s Invariance Principle). LaSalle’s Invariance Principle is generally stated in thefollowing form.

LaSalle’s Invariance Principle. Suppose that there exists a scalar-valued function V : Rn Ñ R thatsatisfies the conditions (i)–(iii) of Lyapunov Stability Theorem as well as

(iv)” ∇xV pxq ¨ fpxq is negative semi-definite, which means that

∇xV pxq ¨ fpxq ď 0, @x.

Then the origin is globally stable for the system (13.3). Moreover, let E denote the set of all pointsfor which ∇xV pxq ¨ fpxq “ 0, i.e.,

E –

x P Rn :∇xV pxq ¨ fpxq “ 0(

,

and let M be the largest invariant set for the system (13.3) that is fully contained in E . Then every Note. A set M is said to be invari-ant for the system (13.3) if everytrajectory that starts inside M willremain inside this set forever.

solution to (13.3) approaches M as t Ñ8. In case M only contains the origin, the origin is globallyasymptotically stable for the system (13.3).

The condition (iv)’ that appeared in Section (iv), requires that any solution xptq that stays inside theset E forever, must necessarily be the identically zero [see equation (13.6)]. This means that the setM can only contain the origin, because otherwise there would be another solution xptq that wouldstart inside M Ă E and stay inside this set forever. 2

13.7 Exercises13.2. For the following systems, show that the origin is asymptotically stable using the Lyapunovfunction provided.

#

9x “ ´x ` y´ xy2

9y “ ´x ´ y´ x2yV px, yq “ x2 ` y2 (13.17)

#

9x “ ´x3 ` y4

9y “ ´y3px ` 1qV px, yq “ x2 ` y2 (13.18)

#

9x “ ´x ` 4y9y “ ´x ´ y3 V px, yq “ x2 ` 4y2 (13.19)

#

9x “ x ` 4y9y “ ´2x ´ 5y

V px, yq “ ax2 ` bxy` cy2 (13.20)

For the last system, determine possible values for the constants a, b, and c (recall that V must bepositive definite). 2

13.3. For the following systems, show that the origin is asymptotically stable using the Lyapunovfunction provided.

#

9x “ y9y “ ´x ´ y

V px, yq “ x2 ` y2 (13.21)#

9x “ y9y “ ´y|y| ´ 3x

V px, yq “ ax2 ` by2 (13.22)

For the last system, determine possible values for the constants a and b (recall that V must bepositive definite). 2

13.4. Consider the hovercraft model in Example 12.3. Show that if the generalized force vector isset to F “ ´q, then the origin is globally asymptotically stable. 2

126 João P. Hespanha

Chapter 14

Lyapunov-based Designs

Contents14.1 Lyapunov-based Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12714.2 Application to Mechanical Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12814.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

14.1 Lyapunov-based ControllersIn Lyapunov-based designs one starts by selecting a candidate Lyapunov function and then choosesthe control signal for which the chosen Lyapunov function does indeed decrease along the trajectoriesof the closed-loop system.

To understand how this can be done, consider again the vehicle shown in Figure 12.1 with unitschosen so that all constant coefficient are numerically equal to 1

:y “ ´ 9y| 9y| ´ 1` u

and suppose we want y to converge to some constant reference value r . Defining the tracking errore– y´ r , we conclude that

:e “ ´ 9e| 9e| ´ 1` u.

Setting the state

x “„

x1x2

e9e

the dynamics of the system can be written as 9x “ fpx, uq as follows:

9x1 “ x2 (14.1)9x2 “ ´x2|x2| ´ 1` u, (14.2)

and we would like to make the origin globally asymptotically stable.In view of what we saw for the Liénard equation, we will try to make Note. Compare with equation

(13.14). Essentially, we areaiming for λpx2q – x2 , whichwould lead to Λpx1q “ λ x

212 .

We will find other options inExercise 14.1. p. 129

V pxq– x222 ` λ

x212 , λ ą 0

a Lyapunov function for the system by appropriate choice of u. This function satisfies the requirements(i)–(iii) and

∇xV pxq ¨ fpx, uq “ x2 9x2 ` λx1 9x1 “ ´x22 |x2| ` x2p´1` u` λx1q.

127

128 João P. Hespanha

A simple way to make the system Lyapunov stable is then to select

´1` u` λx1 “ 0 ô u “ 1´ λx1 “ 1´ λpy´ rq,

which leads to

∇xV pxq ¨ fpx, uq “ ´x22 |x2|,

and therefore the candidate V pxq becomes a weak Lyapunov function for the closed-loop:

9x1 “ x2,9x2 “ ´x2|x2| ´ 1` upx1q “ ´x2|x2| ´ λx1.

Attention! A feedback linearization controller for (14.2) would cancel both the nonlinearity ´x2|x2|and the ´1 terms, using a controller of the form

upx1, x2q “ 1` x2|x2| ´ KPx1 ´ KDx2, KP , KD ą 0.

However, in the presence of measurement noise this would lead to the following closed-loop system

9x1 “ x29x2 “ ´x2|x2| ´ 1` upx1 ` n1, x2 ` n2q “ ´KPx1 ´ KDx2 ` d

where d is due to the noise and is equal to

d – ´KPn1 ´ KDn2 ´ x2|x2| ` x2|x2 ` n2| ` n2|x2 ` n2|.

The main difficulty with this controller is that n2 appears in d multiplied by x2 so even with littlenoise, d can be large if x2 is large.

Consider now the Lyapunov-based controllerNote. This controller does not at-tempt to cancel the term x2|x2|that actually helps in making 9V ă0.

upx1q “ 1´ λx1

also in the presence of noise:

9x1 “ x29x2 “ ´x2|x2| ´ 1` upx1 ` n1q “ ´x2|x2| ´ λx1 ` d, d “ ´λn1.

This controller is not affected at all by noise in the measurement of x2 “ 9y and the noise in themeasurement of x1 “ y´ r is not multiplied by the state. 2

14.2 Application to Mechanical SystemsConsider again a fully actuated mechanical system of the following form

Mpqq:q` Bpq, 9qq 9q` Gpqq “ u (14.3)

and suppose that we want to make q converge to some constant value r . Defining

x “„

x1x2

q´ r9q

P R2k ,

the system (14.3) can be written as 9x “ fpx, uq as follows:

9x1 “ x2,

9x2 “ ´Mpx1 ` rq´1´

Bpx1 ` r, x2qx2 ` Gpx1 ` rq ´ u¯

.

Nonlinear Control 129

Based on what we saw in Section 13.5, we will try to make Note. Compare this V pxq withequation (13.16). p. 124

V pxq– 12x12Mpx1 ` rqx2 `

γ12 x

11x1, γ1 ą 0

a Lyapunov function for the system by appropriate choice of u. This function satisfies the requirements(i)–(iii) and

∇xV pxq ¨ fpxq “ x 12Mpx1 ` rq 9x2 `12x12

´dMpx1 ` rqdt

¯

x2 ` γ1 9x 11x1

“ ´x 12´

Bpx1 ` r, x2qx2 ´12dMpx1 ` rq

dt x2 ` Gpx1 ` rq ´ u´ γ1x1¯

.

Since in general x 12Bpx1` r, x2qx2 ď 0, a simple way to make the system Lyapunov stable is to select

´12dMpx1 ` rq

dt x2 ` Gpx1 ` rq ´ u´ γ1x1 “ γ2x2

ô u “ ´12dMpx1 ` rq

dt x2 ` Gpx1 ` rq ´ γ1x1 ´ γ2x2

“ ´12dMpqqdt

9q` Gpqq ´ γ1pq´ rq ´ γ2 9q,

which leads to

∇xV pxq ¨ fpxq “ ´x 12Bpx1 ` r, x2qx2 ´ γ2x 12x2.

and therefore the candidate V pxq becomes a weak Lyapunov function for the closed-loop.

Attention! For several mechanical system

x 12´

Bpx1 ` r, x2qx2 ´12dMpx1 ` rq

dt

¯

x2 ě 0.

For those systems it suffices to select

Gpx1 ` rq ´ u´ γ1x1 “ γ2x2 ô u “ Gpx1 ` rq ´ γ1x1 ´ γ2x2 (14.4)“ Gpqq ´ γ1pq´ rq ´ γ2 9q,

which leads to

∇xV pxq ¨ fpxq “ ´x 12´

Bpx1 ` r, x2qx2 ´12dMpx1 ` rq

dt

¯

x2 ´ x 12Bpx1 ` r, x2qx2 ´ γ2x 12x2

ď ´γ2x 12x2. 2

The controller (14.4) corresponds to the control architecture shown in Figure 14.1. This controllerresembles the feedback linearization controller in Figure 12.2, with the key difference that now thegravity term is cancelled, but not the friction term. 2

14.3 Exercises14.1. Design a controller for the system (14.2) using the following candidate Lyapunov function

V pxq– x222 ` λx1 arctanpx1q, λ ą 0.

What is the maximum value of u that this controller requires? Can you see an advantage of usingthis controller with respect to the one derived before? 2

130 João P. Hespanha

`

`

´

´

uq

9q

rγ1p¨q

γ2

Gp¨q

Process

Figure 14.1. Control architectrure corresponding to the Lyapunov-based controller in (14.4).

14.2. Consider again system (14.2) and the following candidate Lyapunov function

V pxq– x222 ` λx1 arctanpx1q, λ ą 0.

Find a Lyapunov-based control law upx1, x2q that keeps

∇xV pxq ¨ fpx, uq ď ´x22 |x2|,

always using the u with smallest possible norm. This type of controller is called a point-wisemin-norm controller and is generally very robust with respect to process uncertainty. 2

14.3. Design a Lyapunov based controller for the inverted pendulum considered in Exercise 12.2 andcompare its noise rejection properties with the feedback linearization controller previously designed.

2

14.4. Re-design the controller in Exercise 14.3 to make sure that the control signal always remainsbounded. Investigate its noise rejection properties.

Hint: Draw inspiration from Exercises 14.1 and 14.2. 2

Bibliography

[1] R. Adrain. Research concerning the probabilities of the errors which happen in making observa-tions. The Analyst, I:93–109, 1808. Article XIV. (cited in p. 23)

[2] J. J. Craig. Introduction to Robotics Mechanics and Control. Addison Wesley, Reading, MA, 1986.(cited in p. 115)

[3] L. Cremean, W. Dumbar, D. van Gogh, J. Hickey, E. Klavins, J. Meltzer, and R. Murray. TheCaltech multi-vehicle wireless testbed. In Proc. of the 41st Conf. on Decision and Contr., Dec.2002. (cited in p. 116)

[4] G. E. Dullerud and F. Paganini. A Course in Robust Control Theory. Number 36 in Texts inApplied Mathematics. Springer, New York, 1999. (cited in p. 55)

[5] G. F. Franklin, J. D. Powell, and A. Emami-Naeini. Feedback Control of Dynamic Systems.Prentice Hall, Upper Saddle River, NJ, 4th edition, 2002. (cited in p. 6, 8, 15, 60, 67, 80, 87)

[6] C. F. Gauss. Theoria motus corporum coelestium in sectionibus conicis solem ambientum (thetheory of the motion of heavenly bodies moving around the sun in conic sections). Hamburg,Germany, 1809. URL http://134.76.163.65/agora_docs/137784TABLE_OF_CONTENTS.html. (cited in p. 23)

[7] B. Hayes. Science on the farther shore. American Scientist, 90(6):499–502, Nov. 2002. (cited inp. 23)

[8] J. P. Hespanha. Linear Systems Theory. Princeton Press, Princeton, New Jersey, Sept. 2009.ISBN13: 978-0-691-14021-6. Information about the book, an errata, and exercises are availableat http://www.ece.ucsb.edu/~hespanha/linearsystems/. (cited in p. 77)

[9] H. K. Khalil. Nonlinear Systems. Prentice Hall, Englewood Cliffs, NJ, 3rd edition, 2002. (cited inp. 111)

[10] L. Ljung. System Identification: Theory for the user. Information and System Sciences Series.Prentice Hall, Upper Saddle River, NJ, 2nd edition, 1999. (cited in p. 3, 15, 23)

[11] R. A. Serway and R. J. Beichner. Physics for Scientists and Engineers. Brooks Cole, 5th edition,1999. (cited in p. 114)

[12] J. V. Vegte. Feedback Control Systems. Prentice Hall, Englewood Cliffs, NJ, 3rd edition, 1994.(cited in p. 79)

131