Digital Implementation of discrete-time Controllers

Post on 05-Nov-2021

10 views 0 download

Transcript of Digital Implementation of discrete-time Controllers

Digital Implementation of discrete-timeControllers

Silvano Balemi

Lugano, academic year 2011-2012

1 / 178

Table of contents

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

2 / 178

Miscellaneous

I Instructor:Silvano Balemisilvano.balemi@ieee.orgwww.dti.supsi.ch/˜smtTel: +41 (0) 32 356 0554

I Schedule:16.3, 30.3, 20.4, 4.5, 1.6 and 15.6Exam on 1.6, Lab session on 15.6

I Tools:Matlab, Simulink and Control System Toolbox

3 / 178

Bibliography

4 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

5 / 178

Motivation

I Increasing use of digital controllers (flexibility duringoperation, flexibility for modifications, more complexcontrollers realizable, lower price)

I Wide range of technical possibilities (very specific DSPs,programmable components)

I Collaboration in interdisciplinary teams

6 / 178

What is this course?

I Not a course on control design

I Understand the issues connecting control design andembedded control systems

I Be able to communicate with control engineers

I Master the tools necessary to specify and design an embeddedcontrol system

7 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

8 / 178

Fourier decomposition of a periodic signalConsider periodic function f(t) with period T

−2 −1 0 1 2 30

0.2

0.4

0.6

0.8

1

t

f(t)

Then

f(t) =A0

2+

∞∑n=1

An cos(nωt) +

∞∑n=1

Bn sin(nωt)

where

An =2

T

∫ T

0f(t) cos(nωt)dt and Bn =

2

T

∫ T

0f(t) sin(nωt)dt

9 / 178

Fourier decomposition complex representationPeriodic function f(t)

−2 −1 0 1 2 30

0.2

0.4

0.6

0.8

1

t

f(t)

Alternative representation

f(t) =∞∑−∞

Cnejnωt

where

Cn =1

T

∫ T2

−T2

f(t)e−jnωtdt =An − jBn

2

10 / 178

Fourier transform of time-limited signals

−2 −1.5 −1 −0.5 0 0.5 1 1.5 2 2.5 30

0.2

0.4

0.6

0.8

1

t

f(t)

Cn = 1T

∫ T2

−T2

f(t)e−jnωtdt = An−jBn2

= 1T

∫∞−∞ f(t)e−jnωtdt

for time-limited signals

11 / 178

Fourier transform of aperiodic signalsLet T →∞ then Cn → 0.

0 10 20 30 40 50 60 70 80 90 1000

0.2

0.4

0.6

0.8

t

f(t)

Thus define F (n · ω) = Cn · T which gives

F (n · ω) =

∫ ∞−∞

f(t)e−jn·ωtdt =⇒ F (ω) =

∫ ∞−∞

f(t)e−jωtdt

with a variable substitution and

f(t) =1

∫ ∞−∞

F (ω)e−jωtdω =

∫ ∞−∞

F (2πf)e−j2πftdf

12 / 178

Some Fourier transforms

f(t) F (ω)

δ(t) 1

1 2πδ(ω)

ejω0t 2πδ(ω − ω0)

cos(ω0t) π(δ(ω + ω0) + δ(ω − ω0))

sin(ω0t) jπ(δ(ω + ω0)− δ(ω − ω0))

1(t) πδ(ω) + 1jω

rect(t)2 sin ωτ

2

ω

sign(t) 2jω

e−r2

2σ2 σ√

2πe−σ2ω2

2

13 / 178

Laplace transform

Assume f(t) = 0 for t < 0. Laplace transform of f(t) is defined by

F (s) =

∫ ∞0

f(t)e−stdt

Has frequency interpretation (see Fourier transform)

14 / 178

Frequency representation: Bode diagramMagnitude 20 log(|F (ω)|) and phase arg(F (ω)) on logarithmicfrequency scale

−40

−30

−20

−10

0

10

20

30

40

Magnitude (

dB

)

10−1

100

101

−180

−135

−90

−45

0

Phase (

deg

)

Bode Diagram

Frequency (rad/sec)

15 / 178

Some Laplace transforms

f(t) F (s)

δ(t) 1

1(t) 1s

t · 1(t) 1s2

tn · 1(t) n!sn+1

e−a·t · 1(t) 1s+a

sin(ω · t) · 1(t) ωs2+ω2

cos(ω · t) · 1(t) ss2+ω2

e−at · sin(ω · t) · 1(t) ω(s+a)2+ω2

e−at · cos(ω · t) · 1(t) s+a(s+a)2+ω2

16 / 178

Properties of the Laplace transform

linearity L(αf1(t) + βf2(t)) = αF1(s) + βF2(s)

frequency delay L(e−atf(t)) = F (s+ a)

time delay L(f(t− T )) = e−sTF (s)

time scaling L(f(at)) = 1aF ( sa )

time derivative L(df(t)dt ) = sF (s)− f(0)

double time derivative L(d2f(t)dt2 ) = s2F (s)− sf(0)− f(0)

integration L(t∫0

f(τ)dτ

)= F (s)

s

initial value limt→0 f(t) = lims→∞ sF (s)

end value limt→∞ f(t) = lims→0 sF (s)

convolution in time f1(t) ∗ f2(t) = F1(s) · F2(s)

convolution in frequency f1(t) · f2(t) = 12πj · F1(s) ∗ F2(s)

17 / 178

Laplace transform for the solution of ordinary differentialequations

Given

xn + an−1 · x(n−1) + . . . + a1 · x+ a0x = u(t)

1. Take u(t) = 0 and solve for initial conditions

2. Then set initial conditions

xn(0) = x(n−1)(0) = . . . = x(0) = x(0) = 0

and solve for input u(t)

18 / 178

Solution of ODE with Laplace transform 1/3

Givendx

dt+ 3x = cos(3t) with x(0) = 1

1) Take u(t) = 0 and apply Laplace transform

L(dx

dt

)+ L(3x) = L(0)

sX(s)− x(0) + 3X(s) = 0

X(s) =1

s+ 3

x(t) = L−1(X(s)) = L−1

(1

s+ 3

)= e−3t

(Example by Piatti and Solder)

19 / 178

Solution of ODE with Laplace transform 2/3

2) Take x(0) = 0 and apply Laplace transform

sX(s)− x(0)︸︷︷︸0

+3X(s) =s

s2 + 9

X(s) =1

(s+ 3)(s2 + 9)=

1

s+ 3

s

s2 + 9

Then

x(t) = L−1(X(s)) = L−1(

1s+3

ss2+9

)= L−1

(1s+3

)∗ L−1

(s

s2+9

)= e−3t ∗ cos(3t)

=cos(3t) + sin(3t)− e−3t

6

1+2) Complete solution

x(t) =cos(3t) + sin(3t) + 5e−3t

6

20 / 178

Solution of ODE with Laplace transform 3/3

2) with unknown u(t)

sX(s)− x(0)︸︷︷︸0

+3X(s) = U(s)

X(s) =1

s+ 3U(s)

Then

x(t) = L−1(X(s)) = L−1(

1s+3U(s)

)= L−1

(1s+3

)∗ u(t) = e−3t ∗ u(t)

1+2) Complete solution

x(t) = e−3t + e−3t ∗ u(t)

21 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

22 / 178

Dirac impulse δ(t)

Time-limited impulse of unit integral value with width going to 0.

1/ε

- �

6

? -

ε

6

limε→0

-

1

-

6

t

6

Then:

f(a) =

∫ ∞−∞

f(t) · δ(t− a)dt

23 / 178

Step response of a sampled system

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.05

0.1

0.15

0.2

0.25

0.3

0.35

Step Response

Time (sec)

Am

plit

ude

24 / 178

Sample and Hold

?�

-�� -T

ZOH

-sample & hold

6

-66666

t

f?(t)

6

-����� 6

-

f

f fh

fh

f?t

fh(t)

t

f(t)

25 / 178

Sampling

�� -T

f f??

�- f?(t) =

∞∑k=−∞

f(t) · δ(t− k · T )-?×f(t)

∞∑k=−∞

δ(t− k · T )

⇐⇒

Multiplication with a train of unit impulses(operation is linear but time-variant)

F ?(s) =

∫ ∞0

f?(t) ·e−st dt =

∫ ∞0

f(k · T ) ·∞∑k=0

δ(t− kT ) ·e−st dt

F ?(s) =

∞∑k=0

f(kT ) · e−skT

26 / 178

Train of impulses and its Fourier expansion

∞∑k=−∞

δ(t− kT ) =

∞∑n=−∞

Cnej 2πnTt

with coefficients

Cn =1

T

∫ T/2

−T/2

( ∞∑k=−∞

δ(t− kT )

)ej

2πnTtdt

yields∞∑

k=−∞δ(t− kT ) =

1

T

∞∑n=−∞

ej2πnTt

27 / 178

Sampled signal

F ?(s) =

∫ ∞0

f(t) ·∞∑k=0

δ(t− kT ) · e−st dt

=

∫ ∞0

f(t) · 1

T

∞∑n=−∞

ej2πnTt · e−st dt

=1

T

∞∑n=−∞

∫ ∞0

f(t) · ej2πnTt · e−st dt

=1

T

∞∑n=−∞

∫ ∞0

f(t) · e−(s−j 2πnT

)t dt

=1

T

∞∑n=−∞

F (s− j 2πnT

)

⇒ F ?(s) =1

T

∞∑n=−∞

F (s− jωsn) with ωs =2π

T

28 / 178

Spectrum of a sample signal

−2 −1.5 −1 −0.5 0 0.5 1 1.5 20

0.2

0.4

0.6

0.8

1Spectrum of a signal

−2 −1.5 −1 −0.5 0 0.5 1 1.5 20

0.2

0.4

0.6

0.8

1Spectrum of a sampled signal

29 / 178

Hold

Linear and time-invariant operation

T-

6

-

0t

1

T

1(t− T )

1(t)

0t

16

Impulse response of a Zero-order hold

zoh(t) = 1(t)− 1(t− T ) ⇒ ZOH(s) =1

s− 1

s· e−sT =

1− e−sT

s

30 / 178

Z transform

Laplace transformation of the sample signal with z = esT

F (z) = F ?(s)|esT=z =

∞∑k=0

f(kT ) · z−k =

∞∑k=0

fk · z−k

where fk = f(t)|t=kT = f(kT ).

The z-transform correspond to the sequence

{fk} = {f0, f1, f2, . . . }

with the function F (z) = Z({fk})

31 / 178

Relation between different transforms

?

�-��

T

-@@R��

@@

-�

-�

���

f(t)

F (s)

L

f ?(t)

t = kT

F ?(s) F (z)

{fk}

ZL

z = esT

Zs

ue

ue

6

?

32 / 178

Examples of z-transforms

{fk} = {0, 1, 2, 1, 0, 0, 0, 0, 0, . . . }

F (z) = 0·z0+1·z−1+2·z−2+1·z−3 =1

z+

2

z2+

1

z3=z2 + 2 · z + 1

z3

{fk} = {1, 1, 1, 1, 1, . . . }

F (z) = 1 · z0 + 1 · z−1 + 1 · z−2 + 1 · z−3 + 1 · z−4 + . . .

F (z) =z

z − 1

{fk} = {0, T, 2T, 3T, . . . , kT, . . .}

F (z) = T · (0 · z0 + 1 · z−1 + 2 · z−2 + 3 · z−3 + 4 · z−4 + . . . )

z ·F (z)−F (z) = (z − 1) ·F (z) = T · (1 + z−1 + z−2 + z−3 + . . . )

F (z) = T · z

(z − 1)2

33 / 178

Some transformations

f(t) F (s) F (z)

1(t)1

s

z

z − 1

t · 1(t) 1

s2T · z

(z − 1)2

e−at · 1(t) 1

s+ a

z

z − e−aT

tn · e−at · 1(t) n!

(s+ a)n+1(−1)n · dn

danz

z − e−aT

sin(ωt) · 1(t) ω

s2 + ω2

z · sin(ωT )z2 − 2 · z · cos(ωT ) + 1

cos(ωt) · 1(t) s

s2 + ω2

z · (z − cos(ωT ))

z2 − 2 · z · cos(ωT ) + 1

e−at · sin(ωt) · 1(t) ω

(s+ a)2 + ω2

z · e−aT · sin(ωT )z2 − 2 · z · e−aT · cos(ωT ) + e−2aT

e−at · cos(ωt) · 1(t) s+ a

(s+ a)2 + ω2

z · (z − e−aT · cos(ωT ))z2 − 2 · z · e−aT · cos(ωT ) + e−2aT

34 / 178

Properties of the z-transform

Linearity Z (a · {fk}+ b · {gk}) = a · Z ({fk}) + b · Z ({gk})

Delay Z ({fk−m}) = z−m · Z ({fk}) per m ≥ 0

Anticipation Z ({fk+m}) = zm ·(Z ({fk})−

∑m−1i=0 fi · z−i

)Damping Z

({fk · e−akT }

)= F (z · eaT )

Difference Z({fk} − {fk−1}) = z−1z · Z({fk})

Convolution Z({fk ∗ gk}) = Z({∑k

i=0 fi · gk−i})

= F (z) ·G(z)

Initial value f0 = limz→∞

Z({fk}) = limz→∞

(f0 + f1 · z−1 + . . . )

End value limk→∞

fk = limz→1

z − 1

z· Z({fk}) = lim

z→1(z − 1) · Z({fk})

35 / 178

z transform

From the Laplace transformationI Factorization

G(z) = Zs(G(s)) = Zs

(np∑n=1

R(pn) · 1

s− pn

)=

np∑n=1

R(pn)· z

z − epnT

with residuals R(pn) = N(s)dD(s)ds

∣∣∣∣s=pn

(single poles)

I Using “primitives”

G(s) =1

s+ a⇒ g(t) = k · e−at ⇒ G(z) = k

z

z − e−aT

36 / 178

Inverse z- transform

1. Inverse transform via factorization

Z({bk}) = Z({1, b, b2, b3, . . . }) =z/b

z/b− 1=

z

z − b

F (z) =K1 · zz − p1

+K2 · zz − p2

+ . . . +Knp · zz − pnp

⇒ fk =

np∑i=0

Ki · pki

2. Inverse trasnform via recursion

F (z) =bn · zn + bn−1 · zn−1 + . . . + b0zn + an−1 · zn−1 + . . . + a0

=

∞∑k=0

fk · z−k

⇒ fk = f(kT ) = bn−k−an−1·fk−1−an−2·fk−2−. . .−a0·fk−n

37 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

38 / 178

Dynamic systems

Outputs of static system only depends on current inputs

- -yu

y = f(u)

Outputs of dynamic system also depends on history (state)

- -yu

y = f(x, x, u)

Variable derivatives and the relationships between variables lead todifferential equations

39 / 178

Linear time-invariant systems

Linearity

f(αu1(t) + βu2(t)) = αf(u1(t)) + βf(u2(t))

Time-Invariance

y(t) = f(x(t), x(t), u(t))⇒ y(t+ t0) = f(x(t), x(t), u(t+ t0))

for same initial conditions x0 at t resp. t+ t0.

40 / 178

Example: LCR circuit

? ?

-

l ? ?

C

iLiRiC

Ru uC

L

C · duCdt

= iC

L · diLdt

= uL

uc = R · iRiL = iR + iCu = uL + uC

C · duCdt

= − 1

R· uC + iL

L · diLdt

= −uC + u

2nd order system2 first-order differential equations

41 / 178

Example: Mass and spring

-

DD��DD��DD��DD

-

dF (t)

k

M

x(t)

M · x+ d · x+ k · x = F

2nd order system1 second-order differential equation

42 / 178

Example: Quarter car (Slide Prof. Savaresi)

�� �� �� �� �� �� �� �� �� �� �� �� �� ��

6

���� HH ��

6

6

m

body

wheel

zt

kt

zkd

M

zr

M · z = −M · g − d · (z − zt)− k · (z − zt)m · zt = −m · g + d · (z − zt) + k · (z − zt)

+kt · (zr − zt)

4th order system2 second-order differential equations

43 / 178

Example: Magnetic suspension

M

i

uR,L

y

M · d2y

dt2= M · g − k · i

2(t)

y2(t)

u(t) = R · i(t) + L · di(t)dt

3rd order system1 first-order and 1 second-order differential equation

44 / 178

Example: Thermal system

�����ZZ

ZZZ

����*

-Text Tint

C

ΦinΦout

Φout(t) =Tint(t)− Text(t)

1/(A · k)

C · dTint(t)

dt= Φin(t)− Φout(t)

⇓C · Tint +A · k · Tint = Φin +A · k · Text

1st order system1 first-order differential equation

45 / 178

Example: Hydraulic system

� -

6

?

6

2R

h

2r

dh

dt= −C ·

√2 · g · h ·

( rR

)2

1st order system1 first-order non-linear differential equation

46 / 178

1) Differential equation

One single n-th order differential equation

y(n) + . . . + a1 · y + a0 · y = bn · u(n) + . . . + b1 · u+ b0 · u

Example:-

DD��DD��DD��DD

-

dF (t)

k

M

x(t)

M · x(t) + d · x(t) + k · x(t) = F (t)

47 / 178

1) Differential equation (cont)

set of n 1st order differential equations

Example:-

DD��DD��DD��DD

-

dF (t)

k

M

x(t)

x(t) = v(t)

M · v(t) + d · v(t) + k · x(t) = F (t)

48 / 178

2) State-space representation

n first-order differential equations in vector form{x = f(x,u, t)y = g(x,u, t)

or for LTI systems

{x = A · x +B · uy = C · x +D · u

Example:-

DD��DD��DD��DD

-

dF (t)

k

M

x(t)

[x1

x2

]=

[0 1

− kM − d

M

]·[x1

x2

]+

[01M

]· F

y =[

1 0]·[x1

x2

]+[

0]· F

49 / 178

3) Transfer function

Differential equation

y(n) + . . . + a1 · y + a0 · y = bn · u(n) + . . . + b1 · u+ b0 · u

Laplace transformation with zero initial conditions

sn ·Y + . . . +a1 · s ·Y +a0 ·Y = bn · sn ·U + . . . + b1 · s ·U + b0 ·U

⇒ Y (s)

U(s)=bn · sn + bn−1 · sn−1 + bn−2 · · ·n−2 + · · ·+ b1 · s+ b0sn + an−1 · sn−1 + an−2 · sn−2 + · · ·+ a1 · s+ a0

Example:

-

DD��DD��DD��DD

-

dF (t)

k

M

x(t)

G(s) =1M

s2 + dM s+ k

M

50 / 178

4) Time-domain solution (here with distinct modes)

Differential equation

y(n) + . . . + a1 · y + a0 · y = bn · u(n) + . . . + b1 · u+ b0 · u

Time-domain solution

y(t) =

n∑i=1

hi · eλi·t︸ ︷︷ ︸f(t)

+

∫ ∞0

n∑i=1

ki · eλi·τ︸ ︷︷ ︸g(τ)

·u(t−τ)dτ = f(t)+g(t)∗u(t)

I (complex) parameters λ are often called “modes” of thesystem

I for complex modes αi · eλi·t+βi · eλi·t = ri · eσi·t · cos(ωit+ϕi)

I g(t) is the impulse response

I f(t) is the free response

51 / 178

Summary of example: Mass and spring systemDifferential equation:

M · x(t) + d · x(t) + k · x(t) = F (t)

State-space representation: x =

[0 1

− kM − d

M

]· x +

[01M

]· F

y =[

1 0]· x +

[0]· F

Transfer function:

G(s) =1

Ms2 + ds+ k

Time-domain solution (ω=√

kM−( d

2M )2):

y(t) = e−d

2Mt[cos(ωt)+

d2Mω

sin(ωt), 1ω

sin(ωt)

]·[x0v0

]+

(e− d

2Mt

M·ω sin(ωt)

)∗u(t)

52 / 178

Summary of descriptions for Linear Time-invariant SystemsDifferential equation:

y(n) + . . . + a1 · y + a0 · y = bn · u(n) + . . . + b1 · u+ b0 · u

State-space representation:{x = A · x +B · uy = C · x +D · u

Transfer function:

Y (s)

U(s)=bn · sn + bn−1 · sn−1 + bn−2 · sn−2 + · · ·+ b1 · s+ b0sn + an−1 · sn−1 + an−2 · sn−2 + · · ·+ a1 · s+ a0

Time-domain solution:

y(t) = C · Φ(t) · x0 + g(t) ∗ u(t) = f(t) + g(t) ∗ u(t)

where x0 is initial state and Φ(t) = L−1((s · I −A)−1)

53 / 178

Equivalence of representations

differentialequation

� -

-

?

6

?���

���

���

���

����*HHH

HHHHHH

HHHHHHj

transferfunction

time-domaintrajectory

statespace

y(t)G(s)

54 / 178

Examples of representation change

{x(t) = A·x(t) +B ·u(t)y(t) = C ·x(t) +D ·u(t)

⇒{s ·X(s) = A·X(s) +B ·U(s)

Y(s) = C ·X(s) +D·U(s)

⇒ Transfer function:

Y (s) = (C · (s · I −A)−1 ·B +D︸ ︷︷ ︸G(s)

) · U(s)

⇒ Time-domain solution:

y(t) = L−1(C · (sI −A)−1· x0 + (C · (sI −A)−1·B +D) · U(s)

)= C · L−1

((sI −A)−1

)· x0 + L−1 (G(s) · U(s))

= C · Φ(t) · x0︸ ︷︷ ︸f(t)

+ (C · Φ(t) ·B +D · δ(t))︸ ︷︷ ︸g(t)

∗u(t)

55 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

56 / 178

Trajectory and equilibrium

Trajectory:

x = f(x(t), u(t)) = A · x(t) +B · u(t)

x(t) = tr(x0, u(t)) = Φ(t) · x0 + (Φ(t) ·B)︸ ︷︷ ︸gx(t)

∗u(t)

Equilibrium point as a static trajectory:

I Solutions of 0 = f(x, u)

I For linear systems0 = f(x, u) = A · x+B · u⇒ x = −A−1 ·B · u when A is full rank.

57 / 178

Stable trajectory (figure by Prof. Rocco)

0 1 2 3 4 5 6 7 8 9 10−1

0

1

2

3

4

5

6

δε

perturbedmotion

nominalmotion

x0

‖x0 − x0‖ < δ(ε) → ‖x(t)− x(t)‖ < ε ∀t > 0

Trajectory with perturbed initial state remains “close” to nominaltrajectory.

58 / 178

Asymptotically stable trajectory (figure by Prof. Rocco)

0 1 2 3 4 5 6 7 8 9 10−1

0

1

2

3

4

5

6

δε

perturbedmotion

nominalmotion

x0

limt→∞‖x(t)− x(t)‖ = 0 ∀ x0 | ‖x0 − x0‖ < δ(ε)

Trajectory with perturbed initial state converges to nominaltrajectory.

59 / 178

Asymptotically stable trajectory (figure by Prof. Rocco)

0 1 2 3 4 5 6 7 8 9 10−1

0

1

2

3

4

5

6

δε

perturbedmotion

nominalmotion

x0

limt→∞‖x(t)− x(t)‖ = 0 ∀ x0 | ‖x0 − x0‖ < δ(ε)

Trajectory with perturbed initial state converges to nominaltrajectory.

60 / 178

Unstable trajectory (figure by Prof. Rocco)

0 1 2 3 4 5 6 7 8 9 10−1

0

1

2

3

4

5

6

δε

perturbedmotion

nominalmotion

x0

Trajectory diverges from nominal one even for the smallestperturbation of the initial state.

61 / 178

Example: equilibrium point (figure by Prof. Rocco)

Stability analysis can be applied to equilibrium point(equilibrium point is static trajectory)

Point x2 stable, x3 unstable

62 / 178

Stability analysis

Recall, from trajectory

x(t) = Φ(t) · x(0)︸ ︷︷ ︸free response

+ gx(t) ∗ u(t)︸ ︷︷ ︸forced response

Both Φ(t) and gx(t) = Φ(t) ·B are of the form

Ki · tn · eλ·t if λi is realKi · tn · eσ·t · cos(ωi · t+ ϕi) if λi = σi + j · ωi is complex

63 / 178

System stability: Role of λ

I From trajectory:stability is determined if exponentials terms decay, i.e. σ ≤ 0(real part of λ is non-positive)Note: limt→∞ t

n · eσ·t = 0 for all negative σNote: σ < 0 is necessary in presence of pole multiplicity

I From transfer function:λ are the roots of denominator, i.e. solutions of d(s) = 0

I From state-space representation:λ are the eigenvalues of A, i.e. solutions of |λ · I −A| = 0

64 / 178

Stability analyis

I System with impulse response g(t) = cos(10 · t) is stable

I System with free response f(t) = et · cos(3 · t) is unstable

I System with transfer function G(s) = 1s+1 is asymptotically

stable

I System with state-space representation 1 1 10 −2 0

1 0 0

is unstable (one eigenvalue is 1, the other -2)

65 / 178

Stability of LTI systems: poles

−10 −8 −6 −4 −2 0 2 4 6 8 10

−10

−8

−6

−4

−2

0

2

4

6

8

10 0.160.340.50.64

0.76

0.86

0.94

0.985

0.160.340.50.64

0.76

0.86

0.94

0.985

2

4

6

8

10

2

4

6

8

10

Root Locus

Real Axis

Imagin

ary

Axis

66 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

67 / 178

System with digital controller

- -

6

-

-controller

digital

A/D

D/A continuousprocess

digital part analog part

u y

1. Sample

2. (Digitalization)

3. Hold

68 / 178

Discrete-time transfer function from time domain

Y (z)?

�-�� �� -��u

T

u?

U(z)G(s)

y

T

y?

?

No transfer function between u and y but between u∗ and y∗.

Y ∗(s) = G∗(s) · U∗(s)

i.e.Y (z) = G(z) · U(z)

Two different proofs: in time domain and in frequency domain.

69 / 178

Time-domain proof of discrete-time transfer function

Y ?(s) =

∫ ∞0

y?(t) · e−st dt =

∫ ∞0

(∫ ∞0

g(t− τ) · u?(τ) dτ

)?· e−st dt

Y ?(s) =

∫ ∞0

∞∑k=0

(∫ ∞0

g(t− τ) ·∞∑m=0

u(τ) · δ(τ −mT ) dτ

)·δ(t− kT )·e−st dt

Y ?(s) =

∞∑k=0

∞∑m=0

(∫ ∞0

g(kT − τ) · u(τ) · δ(τ −mT ) dτ

)· e−skT

Y ?(s) =

∞∑m=0

∞∑k=0

g(kT −mT ) · u(mT ) · e−skT

and with variable substitution l = k −m

Y ?(s) =

( ∞∑l=0

g(lT ) · e−slT)·

( ∞∑m=0

u(mT ) · e−smT)

= G?(s) · U?(s)

70 / 178

Frequency-domain proof of discrete-time transfer function

Y ?(s) = (G(s) · U?(s))? =1

T

∞∑n=−∞

(G(s− jnωs) · U?(s− jnωs))

but because

U?(s) =1

T

∞∑k=−∞

(U(s− jkωs)

then

U?(s− jnωs) =1

T

∞∑k=−∞

(U(s− jnωs − jkωs)

With the variable change m = n+ k

U?(s−jnωs) =1

T

∞∑m−n=−∞

U(s−jmωs) =1

T

∞∑m=−∞

U(s−jmωs) = U?(s)

Finally

Y ?(s) =

(1

T

∞∑n=−∞

G(s− jnωs)

)· U?(s) = G?(s) · U?(s)

71 / 178

Transfer function with ZOH

?

�-�� - �� -��

?

�u

U(z)T

1− e−sT

sG(s)

GZOH(z)

y

T

y?

Y (z)

u?

Gzoh(z) = Z

L−1(1− e−Ts) · G(s)

s︸ ︷︷ ︸Gs(s)

∣∣∣∣∣∣∣∣t=kT

= Z

(L−1 (Gs(s))

∣∣t=kT

− L−1(e−Ts ·Gs(s)

)∣∣t=kT

)= Z (gs(t)|t=kT − gs(t− T )|t=kT )

= Z (gs(kT )− gs(kT − T ))

Gzoh(z) = Gs(z)− z−1 ·Gs(z) =z − 1

z·Gs(z) =

z − 1

z· Zs

(G(s)

s

)72 / 178

Transfer function with ZOH: Example

G(s) =s− 1

s+ 1⇒

GZOH(z) =z − 1

z· Zs

(G(s)

s

)=

z − 1

z· Zs

(s− 1

s · (s+ 1)

)=

z − 1

z· Zs

(2

s+ 1− 1

s

)=

z − 1

z·(Zs(

2

s+ 1

)−Zs

(1

s

))=

z − 1

z·(

2z

z − e−T− z

z − 1

)=

2(z − 1)

z − e−T− 1

GZOH(z) =z − 2 + e−T

z − e−T

73 / 178

Discrete-time state-space representation

{x = A · x+B · uy = C · x+D · u

u constant during sampling period (u(t) = u(0), 0 ≤ t < T )

x(t) = Φ(t)·x(0)+(Φ(t)·B)∗u(t) = Φ(t)·x(0)+

(∫ t

τ=0Φ(t)·B dt

)︸ ︷︷ ︸

Γ(t)

·u(0)

Φ(T ) = L−1((s · I −A)−1

)∣∣t=T

Γ(T ) = L−1

((s · I −A)−1 ·B · 1

s

)∣∣∣∣t=T

⇒{xk+1 = Φ(T ) · xk + Γ(T ) · ukyk = C · xk +D · uk

74 / 178

Summary of descriptions for discrete-time LTI SystemsDifference equation:

yk+n+ . . . +a1 · yk+1 +a0 · yk = bn ·uk+n+ . . . + b1 ·uk+1 + b0 ·uk

State-space representation:{xk+1 = Φ · xk + Γ · ukyk = C · xk +D · uk

Transfer function:

Y (z)

U(z)=bn · zn + bn−1 · zn−1 + bn−2 · zn−2 + · · ·+ b1 · z + b0zn + an−1 · zn−1 + an−2 · zn−2 + · · ·+ a1 · z + a0

Time-domain solution:

{yk} = C · {Φk} · x0︸ ︷︷ ︸{fk}

+ {C · Φk−1 · Γ +D · δ(k)}︸ ︷︷ ︸{gk}

∗{uk}

75 / 178

Stability of discrete-time LTI systems: poles

s =⇒ z = es·T

−10 −8 −6 −4 −2 0 2 4 6 8 10

−10

−8

−6

−4

−2

0

2

4

6

8

10 0.160.340.50.64

0.76

0.86

0.94

0.985

0.160.340.50.64

0.76

0.86

0.94

0.985

2

4

6

8

10

2

4

6

8

10

Root Locus

Real Axis

Imagin

ary

Axis

−1.5 −1 −0.5 0 0.5 1 1.5−1.5

−1

−0.5

0

0.5

1

1.5

0.1π/T

0.2π/T

0.3π/T

0.4π/T0.5π/T

0.6π/T

0.7π/T

0.8π/T

0.9π/T

π/T

0.1π/T

0.2π/T

0.3π/T

0.4π/T0.5π/T

0.6π/T

0.7π/T

0.8π/T

0.9π/T

π/T

0.10.2

0.30.40.50.60.70.80.9

Root Locus

Real Axis

Imagin

ary

Axis

76 / 178

Pole positions and step responses

−1 0 1−1

0

1

0 10 200

10

20

p=1

(sec)

−1 0 1−1

0

1

0 10 200

5

p=.8

(sec)

−1 0 1−1

0

1

0 10 200

0.5

1

p=−.8

(sec)

−1 0 1−1

0

1

0 10 200

1

2

p=.5

(sec)

−1 0 1−1

0

1

0 10 200

0.5

1

p=−.5

(sec)

−1 0 1−1

0

1

0 10 200

2

4

p=1+/−j

(sec)

−1 0 1−1

0

1

0 10 20−1

0

1

p=−1+/−j

(sec)

−1 0 1−1

0

1

0 10 200

0.5

1

p=+/−j

(sec)

−1 0 1−1

0

1

0 10 200

0.5

1

p=0

(sec)

−1 0 1−1

0

1

0 10 200

0.5

1

p=−1

(sec)

77 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

78 / 178

Control problem

controller processue yr

Given plant G(s), find controller Gc(s) such that closed-loopsystem with transfer function

Gcl(s) =Gc(s) ·G(s)

1 +Gc(s) ·G(s)

satisfies behavior specification

79 / 178

Mathematical model of closed-loop sampled system

- -

6

-

-controller

digital

A/D

D/A continuousprocess

digital part analog part

u y

e -e?

E(z)+−

r?

�?

- -- -

QQ

ZOH

y?

u?G(s)

yG?c(s)

Y (z)

T

80 / 178

Analysis of mathematical model of sampled systems

d -e?

E(z)+−

r?

�?

- -- -

QQ

ZOH

y?

u?G(s)

yG?c(s)

Y (z)

T

?

�?

�d - - �� --6

�� G(s)y-

processprogrammodel

D/A convmodel

T

y?

conv A/Dmodel

Y (z)ZOHG?c(s)

e?

E(z)

u?

+T

r?

model

Gc(z) =E(z)

U(z)Gcl(z) =

Y (z)

R(z)=

Gc(z) ·G(z)

1 +Gc(z) ·G(z)

81 / 178

Stability of closed-loop system: example

U(z)- ##

T

y?

Y (z)

y-

u?

?

�Gc(z)

�?

?

�e -

HHH

6

-��

T

1− e−sT

sG(s)

−+T

r?

y?

G(s) =10

s+ 1⇒ GZOH(z) = 10 · 1− e−T

z − e−TWith Gc(z) = 1 then

Gcl(z) =Gc(z) ·Gzoh(z)

1 +Gc(z) ·Gzoh(z)= 10 · 1− e−T

z − (11 · e−T − 10)

Pole of Gcl(z) is (11 · e−T − 10): it is inside of the unit circle only if

0 < T < log ( 119

)

82 / 178

Control implementation: an example

Consider

Gc(z) =E(z)

U(z)=

z + 3

z2 + z + 1

Then

(z2 + z + 1) · U(z) = (z + 3) · E(z)

(1 + z−1 + z−2) · U(z) = (z−1 + 3 · z−2) · E(z)

U(z) + z−1 · U(z) + z−2 · U(z) = z−1 · E(z) + 3 · z−2 · E(z)

{uk}+ {uk−1}+ {uk−2} = {ek−1}+ 3 · {ek−2}

uk + uk−1 + uk−2 = ek−1 + 3 · ek−2

and finally

uk = −uk−1 − uk−2 + ek−1 + 3 · ek−2

83 / 178

C-code controller implementation: example

ek 1=0; ek 2=0; uk 1=0; uk 2=0;

while TRUE

{yk=read yk();

ek=yrefk-yk;

uk=-uk 1-uk 2+ek 1+3*ek 2;

write(uk);

uk 2=uk 1; uk 1=uk;

ek 2=ek 1; ek 1=ek;

}

ek 1=0; ek 2=0; uk 1=0; uk 2=0;

while TRUE

{uk=-uk 1-uk 2+ek 1+3*ek 2;

yk=read yk();

write(uk);

ek=yrefk-yk;

uk 2=uk 1; uk 1=uk;

ek 2=ek 1; ek 1=ek;

}

Minimize control delay!

84 / 178

C-code controller implementation: example

ek 1=0; ek 2=0; uk 1=0; uk 2=0;

while TRUE

{yk=read yk();

ek=yrefk-yk;

uk=-uk 1-uk 2+ek 1+3*ek 2;

write(uk);

uk 2=uk 1; uk 1=uk;

ek 2=ek 1; ek 1=ek;

}

ek 1=0; ek 2=0; uk 1=0; uk 2=0;

while TRUE

{uk=-uk 1-uk 2+ek 1+3*ek 2;

yk=read yk();

write(uk);

ek=yrefk-yk;

uk 2=uk 1; uk 1=uk;

ek 2=ek 1; ek 1=ek;

}

Minimize control delay!

84 / 178

Control design

I Controller designed in continuous-time domain and thentransformed to discrete-time domain

I Controller designed in discrete-time domain

85 / 178

Discrete-time approximation of PID controllers

Gc(s) = P +I

s+D · s

I Approximated transfer function Gc(z) = P + I · T ·zz−1 +D · z−1T ·z

uk = uk−1 + (P + I · T +DT

) · ek − (P + 2 ·DT

) · ek−1 +DT·ek−2

I Approximation with explicit integral termxk = xk−1 + I · T · ek

uk = P · ek + xk +D

T· (ek − ek−1)

86 / 178

Discrete-time approximation with frequency prewarping

Trasformations z = 2+T ·ω2−T ·ω and ω = 2

Tz−1z+1

G(s)-

c2d(...,′zoh′)GZOH(z)

-d2c(...,′tustin′)

G(w)-

Gc(w)-

c2d(...,′tustin′)Gc(z)

Stretching of frequency band [−ωs, ωs] onto whole s-plane

87 / 178

Frequency prewarping: example

1. G(s) = 1s

2. Gzoh(z) = T(z−1)

3. Gzoh(w) = T( 2+Tw2−Tw−1)

= T (2−Tw)(2+Tw)−(2−Tw) = T (2−Tw)

2Tw = 2−Tw2w

Gc(w) = KP , pole at −b

4. Gcl(w) = Gc(w)·Gzoh(w)1+Gc(w)·Gzoh(w) =

KP2−Tw2w

1+KP2−Tw2w

= KP (2−Tw)2w+KP (2−Tw)

5. 2KP2−KP ·T = b ⇒ 2KP = 2 · b− b ·KP · T ⇒ KP = 2·b

2+b·T

6. Gc(w) = 2·b2+b·T ⇒ Gc(z) = 2·b

2+b·T

88 / 178

Frequency prewarping: example

I Discrete-time Euler approximation

I Discrete-time Tustin approximation

I Discrete-time design

89 / 178

Controller design with polynomial controller

Given Plant

GZOH(z) =N(z)

D(z)=bn · zn + bn−1 · zn−1 + bn−2 · zn−2 + · · ·+ b1 · z + b0zn + an−1 · zn−1 + an−2 · zn−2 + · · ·+ a1 · z + a0

Assume controller of the form

Gc(z) =NC(z)

DC(z)=bm · zm + bm−1 · zm−1 + bm−2 · zm−2 + · · ·+ b1 · z + b0zm + am−1 · zm−1 + am−2 · zm−2 + · · ·+ a1 · z + a0

Then

Gcl(z) =Gc(z) ·GZOH(z)

1 +Gc(z) ·GZOH(z)=

NC(z) ·N(z)

NC(z) ·N(z) +DC(z) ·D(z)

If n+m ≤ 2 ·m+ 1 (i.e. m ≥ n− 1) the we can place all poles ofthe closed-loop system.

90 / 178

Pole assignment: state-feedback controller

If system satifies a property called controllability

cc -

6- -- -?-

6-

-

z−1 CΓ+

+xk yk

+

+rk+ −

K

D

uk

State feedback with uk = rk −K · xk yields{xk+1 = Φ·xk + Γ·uk = (Φ− Γ·K)·xk + Γ·rkyk = C ·xk +D ·uk = (C −D ·K)·xk +D·rk

Any chosen set of closed-loop poles can be obtained throughappropriate matrix K.

91 / 178

Observer/Estimator

If system satifies a property called observability

d d-

6- -

���-

-

-?d6

xk - �z−1 C+

L

D+

+

towards controller

yk+−

ykxk+1uk

Output error feedback with L yields state error system

(ex)k+1 = (Φ− L · C) · (ex)k

Any chosen set of poles for the error system can be obtainedthrough appropriate matrix L.

92 / 178

Closed-loop system with discrete-time observer

Φ

d

d d d

d -

6

- - -? -

-

-

-

-

-

6

-

���

-?-

-

6

-

1z CΓ

++

xk yk+

+

Φ

D

uk

C+

+

L

D

+

+

yk+−

yk

+

K

rk

xkxk+1

uk

1z

d

93 / 178

State-feedback controller with static error compensartion

d dd- --6

-

6- -- -?-

6

d T

z − 1-

-

−+rk −Ke z−1 CΓ

++

xk yk+

+

Φ

K

D

uk

−+

Controller forextended system Φext =

[Φ 0

−C · T 1

]Γext =

−D · T

]

94 / 178

Discrete-time controllers: design or approximations?

GZOH(z)

continuous-time

Gc(s)discrete-time approximation

discrete-time modelling

discrete-timedesign

Gc(z)

G(w)

G(s)

Gc(w)

design

����������9

-

-

?

XXXXXXXXXXz?

?

95 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

96 / 178

Sources of quantization errors

I Arithmetic operations

I Coefficient quantization

I Converter resolution

97 / 178

Fixed-point arithmetic

N =

n−1∑j=−m

bj · 2j = (bn−1 . . . b0.b−1b−2 . . . b−m)2 with bj ∈ {0, 1}

Example

1101.0102 = 1·23+1·22+0·21+1·20+0·2−1+1·2−2+1·2−3 = 13.625

C + 1 bit normalized representation with fictitious binary point

98 / 178

Q-Format representation

General representation with I bits for integer part (QI), F bits forfractional part (QF ) and additional bit for sign

L = QI +QF + 1

C+1 bit normalized representation is Q0.C

Example: Consider the 4-bit representation Q0.3 (one sign bit and3 bits for the fractional part).

0.875 = .111Q0.3 0.5 = .100Q0.3

.111Q0.3 × .100Q0.3 = .011Q0.3 = 0.375

(Note: 0.875× 0.5 = 0.4375)

99 / 178

Representation of signed numbers in fixed-point arithmetic

C + 1 bit normalized representation: word length C

I signed magnitude: number positive if b0 = 0, otherwisenegative

N = (−1)b0 ·∑C

i=1 bi · 2−i 0.75 = 0.112, −0.75 = 1.112

I one’s complement: complement of bits if negative

N = −b0·(2−C−1)+∑C

i=1 bi·2−i 0.75 = 0.112, −0.75 = 1.002

I two’s complement: complement bits and add 1 to LSB

N = −b0 +∑C

i=1 bi · 2−i 0.75 = 0.112, −0.75 = 1.012

Two’s complement is most popular(simpler computing architectures)

100 / 178

Fixed-point arithmetic quantizazion error

Truncation error

a) signed magnitude and one’s complement

−2−C < e ≤ 0, x ≥ 00 ≤ e < 2−C , x < 0

b) two’s complement

−2−C < e ≤ 0

Rounding error

c) signed magnitude, one’s complement andtwo’s complement

−2−C

2 ≤ e < 2−C

2

101 / 178

Quantization in fixed-point arithmetic operations

Quantization in operation

I multiplication: quantization introduced

I addition: no quantization introduced

→ Attention to overflow with addition(no overflow with multiplication in C + 1 normalizedrepresentation)

102 / 178

Floating-point arithmetic

Mantissa M and exponent E are fixed-point numbers

N = M × 2E

Mantissa has normalized representation (0.5 ≤M < 1)

exponent

. . .. . .

sign bitsign bit

mantissa

? ?

� -� -

Example IEEE 754 single precision format: mantissa 23+1 bits,exponent 7+1 bits

103 / 178

Floating-point arithmetic quantizazion errorError is relative: only M is quantized (no quantization in E)

Q(x) = (1 + er) · x

Truncation error

a) signed magnitude and one’s complement

−2 · 2−C < er ≤ 0

b) two’s complement

−2 · 2−C < er ≤ 0, x ≥ 00 ≤ er < 2 · 2−C , x < 0

Rounding error

c) signed magnitude, one’s complement and two’s complement

−2−C ≤ er ≤ 2−C

104 / 178

Quantization in floating-point arithmetic operations

Quantization in operation

I multiplication: quantization through rounding or truncation ofmantissa M

M1 · 2E1 ·M2 · 2E2 = (M1 ·M2) · 2(E1+E2)

I addition: quantization through rounding or truncation ofmantissa M

M1 ·2E1 +M2 ·2E2 = M1 ·2E1 +M2

2E1−E2︸ ︷︷ ︸M ′2

·2E1 = (M1+M ′2)·2E1

M2 is shifted to the right by E1 − E2 bits (E1 > E2)

→ Attention to overflow with addition

105 / 178

Roundoff of parameters: Choice of representation

Pole p = 0.995 ⇒ 0.5% error(almost LSB of 8 bits leads to instability)

Alternative representation:

Pole p = 1− 0.005 ⇒ Low accuracy needed

106 / 178

Roundoff of parameters

Consider fourth-order transfer function [?]

H(z) =z3 + 1.584z2 + 1.2769z + 0.5642

z4 + 2.689z3 + 3.3774z2 + 2.3823z + 0.6942

Two complex poles at 0.4965± j · 0.8663.Quantization with 3 fractional bits (Q0.3)

H(z) =z3 + 1.5z2 + 1.25z + 0.5

z4 + 2.625z3 + 3.375z2 + 2.375z + 0.625

leads to two poles at 1.08!

107 / 178

Roundoff of parameters: SensitivityConsider characteristic polynomial P (pj , αk) = 0

P (pj + δpj , αk + δαk) = 0 ≈ P (pj , αk)︸ ︷︷ ︸0

+∂P

∂z

∣∣∣∣z=pj

· δpj +∂P

∂αk· δαk

0 ≈ ∂P

∂z

∣∣∣∣z=pj

· δpj +∂P

∂αk· δαk

Then the following holds:

δpj ≈ −∂P/∂αk∂P/∂z

∣∣∣∣z=pj

· δαk

Example: for characteristic polynomial

P (z, αk) =∏nl=1(z− pl) = P (z, αk) = zn +α1 · zn−1 + . . . +αn

⇒ δpj = −pn−kj∏

l 6=j(pj − pl)· δαk (most sensitive parameter?)

108 / 178

Good representations of controller “filters”

Parallel (or modal) realization

e

-

-

-

- -

6

?

1st or 2nd

order

...

order

order

1st or 2nd

1st or 2nd

Serial realization

order order- -- -1st or 2nd

order

1st or 2nd 1st or 2nd

109 / 178

Good representations (2)

First order subsystem Second order subsystem

H1(z) = 1+β1·z−1

1−α1·z−1 H2(z) = 1+β1·z−1+β2·z−2

1−α1·z−1−α2·z−2

z

1

beta1alpha1

y(k)u(k)

z

1

z

1

beta1alpha1

beta2alpha2

y(k)u(k)

110 / 178

A/D converter quantization

?

?

+

T

xq(k)x(k)x(t)

�� - -?

�� - -

T

e(k)

xq(k)x(t) x(k)

+ e

6-

Assume noise is uniformly distributed over quantization interval

I Rounding with step q = 2−nbits : E(e2) = q2

12

I Truncation with step q = 2−nbits : E(e2) = q2

3

111 / 178

A/D Signal-to-noise ratio

Input sequence x with zero mean, with unity level as a 3σ event(range=[-1,1], σ = 1

3)

E(x2) =

(1

3

)2

=1

9

The signal-to-noise ratio is given by

(S/N)dB = 10 · log10

σ(x)

σ(e)

leading to the minimal number of bits of the A/D converter withrounding quantization:

nbits ≥(S/N)dB + log10(3

4)

log10(4)

112 / 178

Limit cycles and dither

Example from [?].

xk+1 = α · xk, α < 1⇓

xk+1 = Q(α · xk), α < 1

α · k · q︸︷︷︸x

≥ k · q − q/2

⇓k · q ≥ 1

2q

1−α

-?

-

?

-

-

...............................................................................................................

...................................................

6

?

� -

� -

6

................................................................................................

?

6

6

............................................................................................................................................................

6

?����������������

α·x

k ·q

k ·q − q/2α·k ·q

x3, x4, . . .

x2

x1

slope 1/αx

q

α · x1α · x2

113 / 178

Limit cycles and dither (2)

a1 = −1.78, a2 = 0.9

I oscillation with amplitude δy = 12

q1−α . For q = 0.1 amplitude

δy = 0.5 (5 times quantization)

I high frequency signal (dither) of amplitude 3q beforequantization

114 / 178

Limit cycles and dither (3)

0 20 40 60 80 100 120 140−4

−2

0

2

4

6q=0 and q=0.1 showing limit cycle (no dither)

0 20 40 60 80 100 120 140−4

−2

0

2

4

6q=0 and q=0.1 showing reduced limit cycle for dither=4q

115 / 178

Propagation of quantization errors

c- -����

-- -����

?-u y =⇒ u yε

-+

xqxx xq

x = xq + ε

Y (z) = H(z) · U(z)−Hq(z) · E(z, x)

Hq(z) is tf from quantization error to output. Error at output is

∆Y (z) = Y (z)− Y (z) = Hq(z) · E(z, x)

and in the time domain

δyn =n∑k=0

hqk · εn−k(x).

116 / 178

Worst-case quantization error

|δyn| =

∣∣∣∣∣∞∑k=0

hqkεn−k

∣∣∣∣∣ ≤∞∑k=0

∣∣hqkεn−k∣∣ =

∞∑k=0

∣∣hqk∣∣ |εn−k| ≤ ∞∑k=0

∣∣hqk∣∣·q2|δyn| ≤

q

2·∞∑k=0

∣∣hqk∣∣ ∀n

117 / 178

Worst-case quantization error (2)

Multiple sources

|δyn| ≤m∑j=0

qj2·∞∑k=0

∣∣∣hqk,j∣∣∣ ∀n

Example:

Hq(z) =1

z − α⇒ |δyn| ≤

q

2· 1

1− |α|∀n

118 / 178

Steady-state quantization error

δy∞ = limn→∞

δyn = limn→∞

∞∑k=0

hqkεn−k(x) =

∞∑k=0

hqkε∞

|δy∞| =

∣∣∣∣∣∞∑k=0

hqk

∣∣∣∣∣ · ε∞ ≤∣∣∣∣∣∞∑k=0

hqk

∣∣∣∣∣ · q2 = |Hq(1)| · q2

119 / 178

Steady-state quantization error

0 5 10 15 20 25 30−2

0

2

convolution between e and h for t=10s

0 5 10 15 20 25 30−2

0

2convolution between e and h for t=20s

0 5 10 15 20 25 30−2

0

2

convolution between e and h for t=30s

120 / 178

Steady state quantization error (2)

Multiple sources

|δy∞| ≤m∑j=0

qj2·∣∣∣Hq

j (1)∣∣∣

Example:

Hq(z) =1

z − α⇒ |δy∞| ≤

q

2· 1

1− α

121 / 178

Stochastic quantization error estimate

Consider uniformly distributed error − q2 ≤ ε ≤

q2 . Approximate ε

with white noise w (same zero mean and variance σ2 = q2/12).

Rw(k) =

q2

12k = 0

0 k 6= 0

Then

σ2δyn =

q2

12·∞∑k=0

(hq(k))2

122 / 178

Stochastic quantization error estimate

Multiple sources

σ2δyn =

m∑j=0

q2j

12·∞∑k=0

(hqj(k))2

Example:

Hq(z) =1

z − α⇒ σδyn = q ·

√1

12(1− α2)

123 / 178

Stochastic quantization error estimate: proof 1Remind that the spectrum of a signal s is

Ss(z) = Z(Rs(k))

and thatSδy(z) = Hq(z)Hq(z−1)Sw(z)

then

Rδy = Z−1(Sδy(z)) = Z−1(Hq(z)Hq(z−1)Sw(z))

If s is white noise then

Sw(z) = Z(Rw) = Z

( ∞∑k=−∞

Rw(k)z−k

)= Rw(0) =

q2

12

Rδy = Z−1(Hq(z)Hq(z−1))q2

12⇒ σ2

δy = Rδy(0)

124 / 178

Stochastic quantization error estimate: proof 2

E(δy2n(k)) = E

(k∑

m=0

hq(m) · w(k −m)

(k∑

n=0

hq(n) · w(k − n)

)=

∑km=0

∑kn=0 h

q(m) · hq(n) · E (w(k − n) · w(k −m))

ButE(w(k −m) · w(k − n)) = E(w2) · δ(m− n)

Then

E(δy2n(k)) = E(w2) ·

k∑m=0

(hq(m))2

and for k approaching infinity

σ2δyn =

q2

12·∞∑m=0

(hq(m))2

125 / 178

Comparison between different quantization error measures

z + 1

z2 − 2z cosα+ r2, r = 0.9 (from [?])

0 50 100 1500

2

4

6

8

10

12Fig. 10.5 2nd order Bound x, steady state + and rms error o

alpha

norm

aliz

ed q

uantization e

rror

126 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

127 / 178

The δ operator

Consider known shift operator q defined by

q xk := xk+1

The sampling-time dependent δT operator is defined as

δT :=q− 1

T

which gives

δT xk =xk+1 − xk

T

Note:

limT→0

δT xk =d

dtx(t)

∣∣∣∣t=k·T

128 / 178

The δ transform

Transform can be introduced with corresponding complex variableγ defined as

γ =z − 1

T

Region of converge:

s z γ

1 2/T 1/T

Note that poles close to 1 in z become close to 0 in γ.

129 / 178

Implementation with state-space form

Consider standard state-space representation{qxk = Φ · xk + Γ · ukyk = C · xk +D · uk

New state-space representation with δT operator is{δTxk = ΦδT · xk + ΓδT · ukyk = C · xk +D · uk

where ΦδT = Φ−IT and ΓδT = Γ

T

130 / 178

Next-state expression in state-space form

The next state expressed in function of previous state is{xk+1 = xk + T · ΦδT · xk +T · ΓδT · ukyk = C · xk +D · uk

or {xk+1 = xk + (Φ− I) · xk +Γ · ukyk = C · xk +D · uk

⇒ New matrix Φ− Ieigenvalues at λ− 1 for each eigenvalue λ of Φ.

131 / 178

Implementation with transfer function

Given controller transfer function C(z), replace z with

z = T · γ + 1

to obtain C(γ).

Implement new “delay” element γ−1 as follows

e-- -γ−1 ⇔ z−1T--

6

-

132 / 178

Implementation exampleGiven is the transfer function

C(z) =z

z − a

Then new transfer function

C(γ) =(γ · T + 1)

(γ · T + 1)− a=

γ + 1T

γ + 1−aT

with pole is at γ = a−1T .

-

cc

-6

-

c

z−1

T

1T

a−1T

a−1T

6-

a

z−1

c c-

6-

γ−1

1T

c

-

6-

-

6-

��-

??�-

?

??

133 / 178

Feedback of quantization noise

Filter quantization error, and feedb it back in front of quantizer.Noise distribution in frequency can be altered (very useful inacoustics)

+

Filter−

134 / 178

Scaling of variables

Many techniques exist. In the simplest case of a linear algorithm, anode can be scaled by

I multiplying all incoming values by K

I dividing the outgooing value by K

The node value will be increased by K

135 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

136 / 178

The wind-up phenomenon

Saturated actuated (limited actuation voltage, limited flow, etc.)leads to output overshoot.

0 0.01 0.02 0.03 0.04 0.050

50

100

150

200

250

300

350

400

450

500

actuation

none

saturation

AWup measure

0 0.01 0.02 0.03 0.04 0.050

50

100

150

200

250

300

350

400

450

500

output

none

saturation

AWup measure

Cases: without saturation, with saturation and with saturationtogether with anti-wind-up measure

137 / 178

PID controller with anti-wind-up measure inspired fromanalog solution

Integral value is “counter-integrated” in presence of saturation

u

1

Saturation

Kaw

Kd

Kp

Discrete−timederivator

z−1

ts.z

Discrete−TimeIntegrator

K Ts

z−1Ki

e

1

138 / 178

Anti-wind-up trough saturated feedback and FIR filterimplementation

All signals bounded in solution with FIR filter in feedbackN(z) and D(z) are numerator and denominator polynomials in z−1

u

2

u

1

Saturation

Saturation

N(z)

D(z)

1−D(z)

1

N(z)

1e

2

e

1

139 / 178

Anti-wind-up trough saturated feedback for state-feedbackcontrollers

All signals bounded in solution with FIR filter in feedback

u

1

Saturation 1

Ny(z)

11−D(z)

1

Nr(z)

1

y

2

ref

1

140 / 178

Anti-wind-up with FIR filter and low-pass filter

If anti-wind-up measure is too fast (actuation jumps from boundto bound), slow down wind-up dynamics with low-pass filter F (z)

F (z) is polynomial in z−1 with well stable poles (no further energystored) Case F (z) = 1 corresponds to case without low-pass filter.

Same idea can be applied to state-feedback controllerimplementation

u

1

F(z)−D(z)

F(z)

N(z)

F(z) e

1

141 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

142 / 178

Fast/slow sampling?

High frequency

I Better performance

I cost of design-to-costavoided

Low frequency

I lower cost components

I more time for complexalgorithms

Lowest frequency that meets specifications!

143 / 178

Frequency glossary

ωs : Sampling frequency

ωb : Closed-loop bandwidth

ωr : Open-loop resonance frequency

−40

−20

0

20

40

Magnitude (

dB

)

10−1

100

101

−180

−135

−90

−45

0

Phase (

deg)

Bode Diagram

Frequency (rad/sec)

ωr

ωb

ωs

144 / 178

Sampling theorem’s limits

d -e?

E(z)+−

r?

�?

- -- -

QQ

ZOH

y?

u?G(s)

yG?c(s)

Y (z)

T

Reconstruction of time-domain signals from r? → y?

ωsωb

> 2

Condition on CLOSED-LOOP bandwidth!

145 / 178

Sampling theorem’s limits

Open-loop frequencies may be higher than sampling frequency (apriori knowledge)!

Cost:

I Higher error sensitivities if ωsωr< 2

I Accuracy of high-frequency dynamics function of samplingfrequency

146 / 178

SmoothnessDepending on application (human involvement, mechanical stress)

6 ≤ ωsωb≤ 40

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

OU

TP

UT

S

Wb*t (rad)

11.3 (a) Ws/Wb = 4

−−o−− X1

−−x−− X2

−−−−− U/4

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

OU

TP

UT

S

Wb*t (rad)

11.3 (b) Ws/Wb = 8

−−o−− X1

−−x−− X2

−−−−− U/4

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

OU

TP

UT

S

Wb*t (rad)

11.3 (c) Ws/Wb = 20

−−o−− X1

−−x−− X2

−−−−− U/4

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1O

UT

PU

TS

Wb*t (rad)

11.3 (d) Ws/Wb = 40

−−o−− X1

−−x−− X2

−−−−− U/4

147 / 178

Delay

For humans, delay < 10% of rise time

⇒ ωsωb

> 20

Example: ωb = 1rad/sRise time 3s

Sampling time 0.3sfs = 3.3Hz, ωs = rad/s

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

OU

TP

UT

S

Wb*t (rad)

11.3 (a) Ws/Wb = 4

−−o−− X1

−−x−− X2

−−−−− U/4

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

OU

TP

UT

S

Wb*t (rad)

11.3 (b) Ws/Wb = 8

−−o−− X1

−−x−− X2

−−−−− U/4

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

OU

TP

UT

S

Wb*t (rad)

11.3 (c) Ws/Wb = 20

−−o−− X1

−−x−− X2

−−−−− U/4

0 2 4 6 8−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

OU

TP

UT

S

Wb*t (rad)

11.3 (d) Ws/Wb = 40

−−o−− X1

−−x−− X2

−−−−− U/4

148 / 178

Sensitivity wrt random plant disturbances

Sometime “the” critierion for sample rate selection

Degrading wrtcontinuous-time system

Example:

100

101

102

1

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6

2.8

3Fig. 11.5

SAMPLING MULTIPLE, Ws/Wb

DIS

CR

ET

E/C

ON

TIN

UO

US

R

MS

⇒ ωsωb

> 20

149 / 178

Disturbance sensitivity with observer and quantization

Quantization worsens disturbance sensitivity

Degrading wrtcontinuous-time system

Same example:

100

101

102

1

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6

2.8

3Fig. 11.6

Sampling multiple, Ws/Wb

Dis

cre

te/c

ontin

uo

us

RM

S

−−−−−−−−− no quantization

−x−−x−−x− 9 bit word size

−*−−*−−*− 8 bit word size

−o−−o−−o− 7 bit word size

⇒ ωsωb

> 20

150 / 178

Disturbance sensitivity with resonances frequency higherthan sampling frequency

Resonance frequency increases noise level

Same example:given ωr

ωb> 6

100

101

102

1

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6

2.8

3Fig. 11.7

DIS

CR

ET

E/C

ON

TIN

UO

US

R

MS

Plant damping

−o−−o− zeta = 0

−*−−*− zeta=0.02

SAMPLING MULTIPLE, Ws/Wb2ω

rωr

ωr/2

⇒ ωsωr

> 2

151 / 178

Sensitivity to parameter variations

Separation principle for matched systemsConsider whole system with plant and controller/observer[xk+1

xk+1

]=

Φcl︷ ︸︸ ︷[Φ −Γ ·K

L · C Φ− L · C − Γ ·K

]·[xkxk

]+

[ΓΓ

]· uk

yk+1 = C · xk

Then characteristic polyonmial |zI − Φcl| = 0 gives∣∣∣∣ z · I − Φ Γ ·K−L · C z · I − Φ + L · C + Γ ·K

∣∣∣∣ = 0

⇓|z · I − Φ + Γ ·K| |z · I − Φ + L · C| = 0

proving the separation principle.

152 / 178

Sensitivity to unprecisely known process parameters

Assume model used for controller and observer design is

(Φ,Γ, C,D) 6= (Φ, Γ, C, D)

Then ∣∣∣∣ z · I − Φ Γ ·K−L · C z · I − Φ + L · C + Γ ·K

∣∣∣∣ = 0

⇓|z · I − Φ + Γ ·K|

∣∣∣z · I − Φ + L · C∣∣∣ 6= 0

for at least some designed controller and observer poles

153 / 178

Sensitivity to parameter variationsExample: aircraft with fuselage bendingPlant: λ = −2± j13.5 and bending mode with ξ = 0.01 andωr = 25 rad/s.Objective: rigid body motion: s = −16± j10 (notch for bendingmode)

Robust methods

improvements with higher f

154 / 178

Measurement noise and antialiasing filters

Same example: 1Hz fundamental +60Hz noise sampled at 28Hz

0 0.5 1 1.5 2−1.5

−1

−0.5

0

0.5

1

1.5Fig. 11.12, (a) signal + noise

time (sec)0 0.5 1 1.5 2

−1.5

−1

−0.5

0

0.5

1

1.5(c) prefiltered (a)

time (sec)

0 0.5 1 1.5 2−1.5

−1

−0.5

0

0.5

1

1.5(b) 28 Hz sampled (a)

time (sec)0 0.5 1 1.5 2

−1.5

−1

−0.5

0

0.5

1

1.5(d) 28 Hz sampled (c)

time (sec)

155 / 178

Measurement noise and antialiasing filtersSame example: use of 1st order filter ωp

100

101

102

103

1

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6

2.8

3Fig. 11.13

SAMPLING MULTIPLE, Ws/Wb

DIS

CR

ET

E/C

ON

TIN

UO

US

R

MS

−o−−−−o− Wp/Wb = 20

−*−−−−*− Wp/Wb = 10

−+−−−−+− Wp/Wb = 5

−x−−−−x− Wp/Wb = 2

⇒ ωsωb

= 25 for 20% degrading

156 / 178

Noise and prefilters

Example of second order system with noise (homework!)

0 10 20 30 40 50 60 70 80 90 100

0

0.5

1no n

ois

e

0 10 20 30 40 50 60 70 80 90 100

0

0.5

1

nois

e

0 10 20 30 40 50 60 70 80 90 100

0

0.5

1

w. filter

0 10 20 30 40 50 60 70 80 90 100

0

0.5

1

syste

m+

filter

157 / 178

Measurement noise and antialiasing filters: Conclusions

ue -e?

E(z)+−

r?

�?

- - - -

6

QQ

u?Gc(z) G(s) Filter

y

T

YF (z)

ZOH

y?F

-

1. Prefilter useful (if bandwidth of noise is close to closed-loopbandwidth)

2. Place prefilter before the A/D conversion (analog filter!)

3. Prefilter bandwidth close to closed-loop bandwidthωpωb≈ 2

4. Include prefilter in plant model before controller design

158 / 178

Multirate sampling

159 / 178

Multirate sampling: Small and large cart with spring andforces on the two carts

Same computation power(9Hz+71Hz MR vs. 40Hz SR)

Noise on small cart Noise on large chart

160 / 178

Introduction

Mathematical background

Discrete-time signals

Systems

System properties

Sampled systems

Closed-loop systems

Quantization causes and effects

Remedies against quantization effects

Anti-wind-up measure

Sample rate selection

Implementation issues

161 / 178

Control Hardware

I Power speed x word length x instruction power

I ALU (all basic operations) + MAC (multipl.+addition)

I Instruction set (fixed/floating point arithmetics, dedicatedinstruction set)

I benchmarksI whetstone: fortran floating pointI dhrystone: integer processesI SPEC

I Addressing: direct, indirect, immediate, relative, circular, ...

I I/O: lines vs. I/O space

I EDC: parity on data, on data/addresses (CD), data and HWredundancy, correction, watch-dogs

I Interrupts: from inputs, from A/D converters, ...

I ROM, RAM, PROM, EPROM, EEPROM.

162 / 178

Requirements on DSP/DSC

Parameter Processor type

General Signal ControlSpeed Slow to fast Fast FastMAC Seldom Always AlwaysInstruction length RISC to complex Simple, math Simple, mathWord length Small to large Medium to large Medium to largeMemory size Small to large Small to medium SmallAddressing mode Many complex Simple & circular SimpleI/O Separate, large Integral, small Integral, smallEDC None to parity None, parity, ECC None to ECC

163 / 178

Typical architectures

I Harvard architecture:I separate data and program memoryI separate program address bus (PAB) and program data bus

(PDB)I separate data address bus (XAB) and data bus (XDB)I high pin count

I Extended Harvard architecture:I Multiple data buses (X/Y)

I Modified Harvard architecture:I Common program and data buses

164 / 178

Example: Extended Harvard Architecture

I Data bus and program data bus

I Address bus and program address bus

Freescale DSP56K

165 / 178

Example: Amba buses

I AHB(Advanced High Performance Bus)I Connect between high-performance system modules

I ASB(Advanced System Bus)I Subset of AHB

I APB(Advanced Peripheral Bus)I Simple interface for low-performance peripherals

166 / 178

Example: Multiplier Accumulator/Logic Unitc (MAC)

167 / 178

Addressing mode

LD R, #5430 Immediate (load #5430 in register)

LD R, $500F Direct (load value in 500F)

LD R, ($500F) Indirect (load value in address found in 500F)

LD R, $500F, M2 Relative indexed

LD R, $500F, M2+ Relative

168 / 178

Floating points versus fixed point

Floating point

I Dynamic range

I Development time

Fixed point

I Speed

I Simple implementation

I Less storage

I Less consumption

I Product cost

I Simple error analysis

(Consult spry061.pdf of TI)

169 / 178

Interfaces

I ADC, DAC

I Digital I/Os

I PWM I/O

I SV PWM I/O

I Encoders (QUAD)

I sin/cos interfaces

170 / 178

Converters

I Resolution

I Range

I Slew rate at output (D/A)

I Conversion time (A/D), settling time (D/A)

I Code, offset

I Linearity, repeatability

I Conversion signal

I Digital interface

171 / 178

Sample and holds

I Capacitance value: trade-off between bandwidth ↓, samplingaccuracy ↓, droop (drift) ↑ and noise ↑

I 20mV at 10Mhz can mean 4 out of 12 bits of noise! (aliasing)

172 / 178

Digital I/O and PWM outputs

I Calibration

I Control signals

I Power electronics control

I Vector control

{iSα = iaiSβ = 1√

3ia + 2√

3ib

{iSd = iSα cos θ + iSβ sin θiSa = −iSα sin θ + iSβ cos θ

173 / 178

Vector control

174 / 178

Encoders, sin/cos interfaces

175 / 178

Software tasks

I Signalling

I Monitoring

I Error detection + correction

I Redundancy

I Safety functions

I Calibration

I Self-test at start-up

Total code =7× control code

Control code uses25% of T

176 / 178

SW development tools

I Assembler/Linker

I Simulator

I Emulator

I Compiler

I Integrated SW development environment

I Various tools

177 / 178

Design tools

I Design of controller and simulation of its behavior

I Test of C-code for controller in simulation environment

I Generation of header files for different designs

fid=fopen(’headerfile.h’,’w’);

fprintf(fid,’#define PAR1 %d\n’,PAR1);fprintf(fid,’#define PAR2 %d\n’,PAR2);...

fprintf(fid,’#define PARN %d\n’,PARN);fclose(fid);

I Automatic code generation

178 / 178