You are on page 1of 28

Page 1 of 28

Self Tuning and Adaptive Control coursework


Gary Evans
1a)
The ARMAX model is given by:

A q 1 y t q k B q 1 u t

1.1

a q

The polynomials for A and B are substituted with A q

na

1
b0
and B q

i 1

nb

bi q i

giving:

i 1

nb

a i q i y t q k b0
bi q i u t

i 1
i 1

na

1.2

which is rearranged to give:

y t u t q k b0

bi q i y t

i 1

na

na

i 1

ai q i

1.3

Now the output is time-shifted by k steps:

y t k u t b0

bi q i y t k

i 1

nb

na

i 1

ai q i

1.4

q-i, the time-shift operator is now applied:


y t k u t b0 u t i

nb

bi y t k 1

i 1

na

ai

1.5

i 1

This is then inserted into the cost function, J GMV Py t k Rr t Q 'u t


2

J GMV

P u t b0 u t i bi y t k i a i Rr t
i 1
i 1

nb

na

1.6

'2 u

The equation is expanded by multiplying out the brackets, and all terms not involving u(t) are neglected to give the
modified cost function:

n
n

2
2
~ 2 2 t 2 2u t u t i
1.7 ' u

2
u

2
u

Rr

b0
bi
b0
ai
b0
Q t

J GMV P u b0
i 1
i 1
b

This is differentiated with respect to u(t):

Gary Evans.
Self-tuning and adaptive control.

Page 2 of 28

~
J GMV J GMV
u t

u t

2b02 u t 2b0 u t i

nb

bi 2b0 y t k i

i 1

a i 2b0 Rr t 2

i 1

na

'21.8
u

The minimum of the cost function is required, so the above is equated to zero:
nb
na

0 P 2 b0 b0 u t u t i bi y t k i
ai Rr t

i 1
i 1

'2 u

1.9

re-arranging for u(t) gives

u t P 2 b02

nb
na

' 2 P 2 b u t i b y t k i
a i Rr t
0
i

i 1
i 1

1.10

' 2
Q

gives the required result:


Pb0

Substituting Q

na

u t

bi u t i Rr t

i 1

Pb0 Q

a i y t k 1

i 1

nb

1.11

1b)
The roles of the three individual cost weightings; P, R and Q:
A high value of P, relative to Q, implies a high accuracy of the set point tracking.
A high value of Q, relative to P, implies that the control effort is highly constrained (A value of 0 implies no limits on
the controller, as is the case for the minimum variance controller).
R is adjusted if the initial ratio of P to Q is such that the output never reaches its set point. If there is a 10% shortfall
error then R is increased by 10%.
If P=R=1 and Q=0 the controller becomes a minimum variance (MV) controller.

1c)
A system is characterised by na=2, nb=1, nc=0 and k=0.
The general form of the control law is as follows:

u t

P Pb0

na

i 1


b1u t i Rr (t )

i 1

2 2
2
P b0 Q

ai y t k i

nb

1.12

The GMV control law for the above system is as follows (with R=1):

u t

P a1 y t a 2 y t 1 b1u t 1 r t
Pb0 Q

Gary Evans.
Self-tuning and adaptive control.

1.13

Page 3 of 28

1d)
Whilst GMV overcomes problems with the Minimum Variance controllers it does have problems of its own, e.g.
offset. To alleviate the offset problem we can make use of incremental control. This automatically introduces an
integrator, which can overcome the steady state error. This is implemented in the form of the Incremental GMV
(IGMV) controller.

Gary Evans.
Self-tuning and adaptive control.

Page 4 of 28

2
A system is modelled by the discrete input/output ARMAX representation.

A q 1 y t q k B q 1 C q 1 e t

2.1

where

2.2

2.3

2.4

A q 1 a 0 a1 q 1 a 2 q 2 ... a na q na , a0 =1
B q 1 b0 b1 q 1 b2 q 2 ... bnb q nb , b00
C q 1 c 0 c1 q 1 c 2 q 2 ... c nc q nc , c0 =1

2a
A system is characterised by na=2, nb=1, nc=0 and k=0.

2a.i
The equivalent state space representation in the so called implicit delay observable canonical form is:
x t 1 P x t Qu t Re t

2.5

y t H x t e t

2.6

na=2, nb=1, nc=0 and k=0, therefore the state space representation is:

0
0 0

P 1 0 a2
0 1 a1

0

Q b1
b0

H 0

a2
a1

2.7

2a.ii
Now, to check for controllability:
A system is controllable if

Kc Q

PQ

P2Q

...

P N 1 Q

2.8

is of full rank N.
Now,

0
0 0

PQ 1 0 a 2
0 1 a1

0
0

b1 a 2 b0
b0
b1 a1b0

Gary Evans.
Self-tuning and adaptive control.

2.9

Page 5 of 28

0
0 0

P 1 0 a2
0 1 a1
2

0 0
0
0 0


1 0 a2 0 a2
0 1 a1 1 a1

0
0 0

P Q 0 a2
a 2 a1
0 a1 a 2 a12
2

a 2 a1

2.10

a 2 a12

0
0

b1 a 2 b1 b0 a 2 a1
b0 b1 a1 b0 a 2 a12

2.11

2.9, 2.10 and 2.11 are inserted into 2.8 to give the Kalman controllability matrix:

P PQ P Q b1
b0

0
a 2 b0
b1a 2 b0

a 2 b1 b0 a 2 a1
b1 a1 b0 a 2 a12

2.12

The top row is made up of zeros, so the matrix is not of full rank N and therefore is not controllable.

2a.iii
We can reduce the dimension of the steady state representation:

b1
0 a 2
Q
1 a1
b0

H 0

0 a 2

1 a1

PQ

a 2

a1

b1 a 2 b0

b0 b1 a1b0

2.13

2.14

Inserting 2.13 and 2.14 into the Kalman controllability matrix gives:

Kc Q

b1
b0

PQ

a 2 b0

b1 a1b0

2.15

2.15 is of full rank N and thus is controllable.

2b)
The state space and polynomial controllers are identical in the absence of noise. In the presence of noise the control
action of the state-space controller is smoother due to the filtering action of the controller. Consequently the output
is not so highly controlled. This may not be such a problem depending on the application. E.g. a ship positioning
problem; there is no point in the thrusters being active to counteract wave motion as this is a waste of energy. The
converse is true for polynomial pole-placement controller. This may be an advantage in some applications. E.g.the
control of an open loop unstable system.

2c)
A system exists with na=2, nb=1, nc=0 and k=1. Pole placement control is to be used to control the system. The pole
placement control law is given by:

D q 1 u t G q 1 y t

Gary Evans.
Self-tuning and adaptive control.

2.16

Page 6 of 28

The order of the polynomial D(q-1) is given by nd=nb+k-1, with d0 = 0, and the order of polynomial G(q-1) is given by
ng=na-1.
The polynomial identity, or Diophantine equation, is given by:



where q is the closed loop pole-polynomial specified by the user, given by:

2.17

A q 1 D q 1 q k B q 1 G q 1 q 1
1

2.18

q 1 1 1 q 1 2 q 2

To obtain the coefficients of the controller polynomials:


Given the following:

d1

1
g0 B s
g1

2.19

where B is the band matrix:

B a1
a 2

b0
b1
0

b0

2.20

b`

and s is the column vector:

s T 1 a1

2 a 2

2.21

Pre-multiplying both sides of 2.19 by B gives:

B a1
a 2

b0
b1
0

b0
b1

d1 1 a1

g 0 2 a2
g1
0

2.22

multiplying 2.22 out gives:

d1 b0 g 0 1 a1

2.23

a1 d1 b1 g 0 b0 g 1 2 a 2

2.24

a 2 d 1 b1 g1 0

2.25

The form of the Diophantine equation, 2.17 is required, the right-hand side of which is:

2.26

q 1 1 1 q 1 2 q 1

To obtain the required terms in gamma, equation 2.22 is multiplied by q 1 q 2 q 3 , which is equivalent to
multiplying equation 2.23 by q-1, equation 2.24 by q-2 and equation 2.25 by q-3. Doing this and adding the resulting
equations gives:
Gary Evans.
Self-tuning and adaptive control.

Page 7 of 28

2
d1 q 1 b0 g 0 q 1 a1 d1 q 2 b1 g 0 q 2 b0 g1 q 2 a 2 d1 q 3 b1 g1 q 3 1 q 1 a1 q 1 2 q 2 a2.27
2q

To get the right hand side of 2.27 into the form required by the Diophantine equation, 1 a1 q 1 a 2 q 2 is added
to each side:
1
1 a1 q 1 a 2 q 2 d1 q 1 b0 g 0 q 1 a1 d 1 q 2 b1 g 0 q 2 b0 g 1 q 2 a 2 d 1 q 3 b1 g 1 q 3 1 1 q2.28
2 q 2

Factorising 2.28 gives:

1 a q
1

a 2 q 2 1 d 1 q 1 q 1 b0 b1 q 1 g 0 g 1 q 1 1 1 q 1 2 q 2

2.29

This is the expanded version of the Diophantine equation, 2.17. Thus the controller polynomials have been obtained
from 2.19.

3
The GPC cost function takes the form:

J GPC E

y t j r t j

j k

hc

j 1

u t j 1 2

3.1

where {.} denotes the expectation operator, y(t) and r(t) are the system output and set point reference respectively.
The incremental control action is defined by u(t) = u(t) u(t-1), is the controller cost weighting factor, h and hc
are the prediction horizon and cost horizon respectively (hc<h), and j is the discrete time index.

3a
We have the ARMAX representation:

y t a1 y t 1 a 2 y t 2 ... a n y t n a b0 u t k b1 t k 1 ... bnb u t k nb

3.2

and the equation for the next time step is:

y t 1 a1 y t a 2 y t 1 ... a n y t n a 1 b0 u t k 1 b1u t k ... bnb u t k nb 3.3


1
subtracting equation 3.2 from 3.1,.and using the definition

u t j u t j u t j 1 , for any k < j h

3.4

gives

y t 1 y t a1 y t a1 y t 1 a 2 y t 2 ... a na y t n a 1 a na y t n a b0 u t b1u t 3.5


1 ... bnb
carrying y(t) back to the right hand side gives:

y t 1 1 a1 y t a1 a 2 y t 1 a 2 a3 y t 2 ... a na y t n a b0 u t k 1 b1u t k 3.6


b2 u t
The term b0(t-k+1) is a quantity in the future, and therefore is unknown.
The same process can be applied to the equation for two time steps into the future, giving:

Gary Evans.
Self-tuning and adaptive control.

Page 8 of 28

y t 2 1 a1 y t 1 a1 a 2 y t a 2 a3 y t 1 ... a na y t 1 na b0 u t k 2 b1 t k3.7
1 ... b
Here, the terms b0(t-k+2) and b1(t-k+1) are unknown. At each successive time step another unknown appears. If
we were to predict h steps into the future we would have h unknowns.
~
This gives us a vector of unknown incremental control actions, u p

u~ p u t

u t 1

... u t h

3.8

The above can be simplified by writing down terms which are known, and which are unknown at each time step, e.g.:

3.9

3.10

y t 1 F1 q 1 y t G1 q 1 u t

and for the jth time step:

y t j F j q 1 y t G j q 1 u t j 1

where the subscript j takes values from 1 to h.


In order to separate the contribution of the future predicted outputs into that which is known up to time t and that
which appears in the futures, the component of y(t+j), j=1,2,,h, which is dependent on the previous outputs and
~
incremental inputs up to the time step t, denoted y t j is defined as:

~
y t 1 F1 q 1 y t G1 q 1 u t g 0 u t

3.11

~
y t 2 F2 q 1 y t G 2 q 1 u t 1 g 0 g1 q 1 u t 1

3.12

~
y t h Fh q 1 y t G h q 1 u t h 1 g 0 g1 q 1 ... g h 1 q h 1 u t h 1

3.13

Incorporating 3.13 into 3.10 leads to

r t 1 y t 1 ~
y t 1 g 0 u t

3.14

r t 2 y t 2 ~
y t 2 g 0 g1q 1 u t 1

3.15

r t h y t h ~
y t h g 0 g1q 1 ... g h 1 q h 1 u t h 1

3.16

This can be represented in the matrix form:


~ ~
r y Gu
y
p

~
where u p is the vector of future incremental controls, as given in 3.8 , G is the lower triangular matrix:

<<<< check for transposed matrices >>>>

Gary Evans.
Self-tuning and adaptive control.

3.17

Page 9 of 28

g0

g1 q

g0

g1 q 1

.
.

3.18

.
.

g q h 1
h 1

g0

g1 q 1

0
g 0

and r is the vector of future set points:

r r t 1

r t 2 ... r t h

3.19

Recall equation 3.1, the GPC cost function :

J GPC E

hc

j k

j 1

y t j r t j 2 u t j 1 2

3.20

Re-expressing the cost function, making use of the vector/matrix notation leads to:

J GPC G u~ p ~
y r

Gu~
T

~
y r

T
p

up

3.21

3b
~
The cost function from equation, 3.21, is expanded, and any terms not involving u p (the subscript is omitted
throughout) are neglected, to give:
~
~ T G T Gu
~u
~T GT ~
~T GT r ~
~ r T Gu
~ u
~T u
~
J u
y u
y T Gu

3.22

~
~
Now J is differentiated with respect to u using the following rules of vector differentiation:

z T w1 v

T
1

vT w2 z

z T w3 z
z

3.23

3.24

T
3

z w3 z

3.25

Differentiating the terms of the expanded cost function, 3.22, using equations 3.23, 3.24 and 3.25 gives:

~ T G T Gu
~
u
GT G
~
u

~ GT G u
~ using 3.25
u

~T GT ~
u
y
GT ~
y using 3.24
~
u

Gary Evans.
Self-tuning and adaptive control.

3.26

3.27

Page 10 of 28

~T GT r
u
G T r using 3.24
~
u

3.28

~
~
y T Gu
GT ~
y using 3.23
~
u

3.29

~
r T Gu
G T r using 3.23
~
u

3.30

~T u
~
u
~T I u
~ 2 I u
~ using 3.25
IT u
~
u

3.31

Taking the equations 3.26 to 3.31, which are the differentiated terms of 3.22, the following is obtained:
~
J
~ 2G T ~
~
2G T G u
y 2G T r 2 I u
~
u

3.32

This is equated to zero for a minimum, divided through by 2 and rearranged to give:

~~
~
0 G T Gu
y r I u

3.33

~
This is arranged to give u :

~ GT G I
u

GT r ~
y

Gary Evans.
Self-tuning and adaptive control.

3.34

Page 11 of 28

4
Justification of Self-tuning control for a system exhibiting time-varying behaviour and non-linear characteristics.

4a
Even though PID control has advantages, such as

not needing a mathematical model


being easy to tune and implement
being fairly well understood

it is not suitable for non-linear or time-varying systems.


The PID controller is linear, and fails on non-linear systems (most practical systems). PID controllers are tuned for a
set operating point, where they give good performance. As the system deviates away from this point performance
suffers.
The form of STC control is shown below:
noise

System
output y(t)

System

Estimate model
parameters

Estimated
parameter vector

Control
input u(t)

Control law
Reference r(t)

Figure 1. The form of STC control.

b)
There are different classifications of self-tuning control. These classifications are explicit and implicit, which both
can be dual and non-dual.
In explicit schemes the model parameters are explicitly estimated and the controller parameters are obtained
indirectly.
In implicit schemes the controller parameters are estimated directly, the model parameters are implicit in the
procedure.
The explicit scheme allows a greater degree of interrogation, the implicit scheme is more of a black box scheme.
Non-dual: The controllers output serves as an ideal input into the system only. This may cause problems in
estimation, particularly in steady state (i.e. when the controller is working properly).

Gary Evans.
Self-tuning and adaptive control.

Page 12 of 28

4c & 4b (Non-dual continued...)


Problems in estimation cause the controller to input an inappropriate control, this leads to better estimation (from
information), which leads on to better control. The two algorithms interact in an opposing manner. The performance
can oscillate, and this is not desirable.
Dual: The controller output serves as an ideal signal for the system input and estimation. Variation (providing
information) can be specified on u(t). Overall, although peak performance may be sacrificed, the STC operates more
consistently desirable.

4d
The Recursive Least Squares algorithm is based on the Linear Least Squares (LLS) algorithm, which calculates the
parameters of the system by finding the least squares error. The LLS algorithm operates on all the data each time that
the calculation is performed, whereas the RLS algorithm amends the previous estimate with the new data from each
new iteration.
The RLS algorithm is simple to understand and easy to implement, however, it is not suited for some parameter
estimation tasks. The algorithm is not able to accurately identify time-varying parameters. This is due to the fact that
the algorithm contains data over the entire time that data has been collected from the system, and earlier data values
will be for a system with different parameters, thus impacting on the estimation.
Forgetting factors provide a solution to this - later data values are given more weighting than earlier values, thus
having more of an impact on the parameter estimation. However, the algorithm only functions well with slowly
changing parameters. Covariance matrix resetting can accommodate abrupt changes in parameters; this works by
setting the data in the system to zero when a sudden change is encountered.

Gary Evans.
Self-tuning and adaptive control.

Page 13 of 28

5.1
The following system:

1.0 1.5q

0.7 q 2 y t q 1 1.0 b1q 1 u t

5.1

where the value of the coefficient b1 varies from 0.5 to 0.6 over 200 variables, may be modelled in Matlab with the
following code:
% Clear the previous set of parameters
clear;
% System parameters
a1 = -1.5;
a2 = 0.7;
b0 = 1.0;
% Zero previous input and output variables
yt_1 = 0; yt_2 = 0;
ut_1 = 0; ut_2 = 0;
rt=1;
for i=1:200
ut=rt;
%vary b1
b1 = 0.5 + ( 0.1 * i/200 );
%system model
yt = -a1*yt_1 - a2*yt_2 + b0*ut_1 + b1*ut_2;
%
yt_2
yt_1
ut_2
ut_1

Time shift the variables


= yt_1;
= yt;
= ut_1;
= ut;

end

5.2)
Self-tuning controllers require a model of the system, so to implement the controller it is necessary to estimate the
model parameters.
A Recursive Least Squares (RLS) estimation routine may be implemented as follows:
%... set up variables
% set up initial vectors for RLS
n = 4;
x = zeros(n,1);
theta = x;
% Set up the covariance matrix
P = 100000*eye(n);
for i=1:200
%
RLS algorithm
P = P - P*x*((1 + x'*P*x)^(-1))*x'*P;
perror = (yt - x'*theta);
theta = theta + P*x*perror;
end

The initial variables may be inserted into the code from section 5.1 before the main program loop, and the RLS
algorithm is placed into the main program loop. The full code for this can be found in the appendix as
fivepointtwo.m. The output from this program is shown in figure 2 below:
Gary Evans.
Self-tuning and adaptive control.

Page 14 of 28

1.5
1

Estimated parameters

0.5
0
-0.5
-1
-1.5
-2

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 2. The estimated parameters with the RLS algorithm.

The output parameter vector gives:


Parameter

Value

a2
a1
a0
b1

0.7007
-1.5011
0.9993
0.5468

Figure 3. The parameter vector at iteration 200.

It is not clear from figure 2, but the output of the parameter vector shows that the RLS estimation routine has failed
to correctly identify the model parameters. The reason is that the model parameters are time-dependent. The RLS
algorithm fails as it retains all information received about the system, which gives erroneous results as the earlier
system information is no longer relevant. The algorithm may be amended to include forgetting factors, where later
observations are given more weight than earlier ones. The algorithm needs new information continually injected into
the system, so a series of ramps of value 1 to 1 with a period of 20 iterations was used.
The routine is now as follows:
% set up initial vectors for RLS
n = 4;
x = zeros(n,1);
theta = x;
% Set up the covariance matrix
P = 100000*eye(n);
forgettingfactor = 0.9;
for i=1:200
%
FFF algorithm
% P = P - P*x*((1 + x'*P*x)^(-1))*x'*P; %normal RLS
P = (P - P*x*((1 + x'*P*x)^(-1))*x'*P)/forgettingfactor;
perror = (yt - x'*theta);
theta = theta + P*x*perror;
end

The full code for this is found in the appendix in fivepointtwob.m. The output of this program is shown in figure 4
below:

Gary Evans.
Self-tuning and adaptive control.

Page 15 of 28

1.5
1

Estimated parameters

0.5
0
-0.5
-1
-1.5
-2

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 4. The estimated parameters with a fixed forgetting factor of 0.9.

The parameter vector is given as:


Parameter

Value

a2
a1
a0
b1

0.6997
-1.4997
1.0018
0.5942

Figure 5. The parameter vector at the 200th iteration.

The parameters are closer than the case of no forgetting factors, but the parameters still havent been correctly
identified.

Kalman Filter
The code for the Kalman filter is as follows:
% set up initial vectors
n = 4;
x = zeros(n,1);
theta = x;
% Set up the covariance matrix
P = 100000*eye(n);
% Set up the noise information
Rw = [0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1];
rv = 1;
for i=1:200
%
%
%

Kalman filter algorithm


Prediction
P = P + Rw;
Correction
K = P*x/(rv +x'*P*x);
perror = (yt - x'*theta);
theta = theta + K*perror;
P = (eye(n) - K*x')*P;

end

Gary Evans.
Self-tuning and adaptive control.

Page 16 of 28

The full code for the algorithm is found in the appendix in file fivepointtwoc.m. The output of this program is shown
below in figure 6.
1.5
1

Estimated parameters

0.5
0
-0.5
-1
-1.5
-2

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 6. The estimated parameters using a Kalman filter.

The parameter vector for the Kalman filter is given as:


Parameter

Value

a2
a1
a0
b1

0.7000
-1.5000
1.0000
0.5997

Figure 7. The parameter vector at the 200th iteration.

The Kalman filter has correctly identified the time-invariant parameters. The time-varying parameter, b1, has been
identified much more accurately than with the RLS or VFF algorithms, but not 100% accurately. This is still as
expected as the system is responding to a previous time input, where the value of the parameter had not reached 0.6.

5.3
A self-tuning controller is now implemented. The implementation allows the user to decide the type of controller by
selecting from a menu.
The control action works by amending the system input. In the code, a switch statement dictates which type of
control action will take place.
The reference signal is as follows:
1.5

System input

0.5

-0.5

-1

-1.5

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 8. The reference for the system.


Gary Evans.
Self-tuning and adaptive control.

Page 17 of 28

The program first sets up the general variables for modelling the system and the estimation routines. The program
then prompts the user to enter their choice of control. A switch statement then sets up the variables relevant to that
control. The main program loop is as before, where the system is modelled and the Kalman filter is used to estimate
the system. The amendment over the Kalman filter is the implementation of the control - the system input is modified
according to the chosen control method. The relevant control is selected in the code with a switch statement. The
system is estimated with a Kalman filter, this isn't strictly necessary as the system is known, but it was desired to see
the control schemes operating on the estimated parameters.
The algorithm is as follows:
Set up variables for system modelling and Kalman filter
User chooses control algorithm
Initialise variables for control algorithm
FOR i=1 TO 200
Model system
Estimate system model
Perform the chosen control algorithm
Time shift variables
END FOR
Plot results

The full code for 5.3 is in the appendix named fivepointthree.m

Pole-placement
The polynomial pole-placement adjusts the poles in the closed-loop characteristic equation.
The system is modelled by

y t
B q 1
q k
u t
A q 1

5.2

The desired closed loop characteristic equation is denoted by q 1 , the Diophantine equation, 2.17, is solved to
give the controller:

u t

y t
Dq

G q 1

5.3

Wellstead proposes values for ng and nd. The values proposed are nd=nb+k-1, ng=na-1. For the system being modelled
nd=0, ng=1. The form of the control algorithm is now:

u t g 0 y t g1 y t 1
A pre-filter is added by multiplying the reference by

5.4

1
, this an overall steady-state gain of unity.
B 1

The values of 1 and 2 are found by arranging equations 2.23 and 2.24 with a value of d1=0.
The algorithm for polynomial pole-placement is given below.
g0 = -(gamma1 - a1)/b0; g1 = -(gamma2 - a2)/b0;
m = (1 + gamma1 + gamma2)/b0;
ut = g0*yt + g1*yt_1 + m*rt;

The output for two poles centred on the origin is shown in figure 9. The system is under-damped and the system
response is therefore very oscillatory.

Gary Evans.
Self-tuning and adaptive control.

Page 18 of 28

5
4

3
2
Control action

System response

2
1
0

1
0
-1
-2

-1

-3

-2

-4
-3

20

40

60

80

100
120
Iterations

140

160

180

-5

200

Figure 9. System output for two poles centred on the


origin.

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 10. Control action for two poles centred on the


origin.

The output for two poles at 0.5 is displayed in figure 11. The output is over-damped and there is a large steady-state
error.
2

0.5

1.5

0.4
0.3
0.2

0.5

Control action

System response

0.1
0

-0.5

-0.1

-1

-0.2

-1.5

-0.3
0

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 11. The output for two poles situated at 0.5.

-0.4

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 12. The control action for two poles situated at 0.5

The output for two poles at 0.7071 is displayed in figure 13.


5

0.6

0.4

0.2

Control action

System response

0
-1
-2

0
-0.2
-0.4

-3
-0.6

-4
-5

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 13. The system output for two poles at 0.7071.

-0.8

20

40

60

80

100
120
Iterations

140

160

180

Figure 14. The control action for two poles at 0.7071

Here the result of being on the edge of instability can be seen; the output is oscillating with a large error.

Gary Evans.
Self-tuning and adaptive control.

200

Page 19 of 28

Generalised Minimum Variance (GMV)


The GMV control law for the system being modelled is given by (see 1.13):

P a1 y t a 2 y t 1 b1u t 1 Rr t
Pb0 Q

u t

5.5

and this is implemented with the following code:


ut = (Pw*a1*yt + a2*yt_1 - b1*ut_1) + Rw*rt)/(Pw*b0 + Qw);

The GMV control extends on the Minimum Variance control, which achieved a dead-beat optimum performance.
The MV controller exerted a very high control effort, which may not be possible in practice. The GMV controller
aims to constrain the variance of the control. P, Q and R are tuning parameters as discussed in section 1b.
The controller parameters P=R=1 and Q=0 implies that a high accuracy of set-point tracking is required.
3.5

2.5

1.5

Control action

System response

1
0.5
0

0
-1
-2

-0.5

-3

-1
-1.5

20

40

60

80

100
120
Iterations

140

160

180

-4

200

Figure 15. System output for GMV control, P=R=1, Q=0

20

40

60

80

100
120
Iterations

140

160

180

Figure 16. Control effort for GMV control, P=R=1, Q=0

The system is very accurately modelled, with both fast response and high steady-state accuracy with minimal
overshoot. However, the control effort necessary to realise this may not be physically possible. With this in mind, the
value of Q is increased to investigate the result of constraining the control effort. The parameters used are now P=1,
Q=1, R=1.
2

1
0.8

1.5

0.6
0.4
Control action

System response

1
0.5
0

0.2
0
-0.2
-0.4

-0.5

-0.6
-1
-1.5

-0.8
0

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 17. System output for GMV control, P=R=Q=1.

-1

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 18. Control effort for P=Q=R=1

Figure 17 shows that the control action is of a much lower magnitude than for the case where Q=0. There is a steady
state error of approximately 10%, so the value of R is increased by 10% giving R=1.1, Q=1, P=1, plotted in figure
19.
Gary Evans.
Self-tuning and adaptive control.

200

Page 20 of 28

1
0.8

1.5

0.6
System response

0.4
Control action

0.5
0
-0.5

0
-0.2
-0.4

-1
-1.5

0.2

-0.6
-0.8
0

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 19: System output for P=Q=1, R=1.1.

-1

20

40

60

80

100
120
Iterations

140

160

180

Figure 20. Control effort for P=Q=1, R=1.1.

Figure 19 shows that the steady state error is now much reduced. Further fine-tuning of the parameter R would result
in the steady state error being reduced to zero.

Incremental Generalised Minimum Variance (IGMV)


IGMV control replaces the adjusting of R, to reduce the steady state error, with an integrator. Since there is no tuning
requirement on R, it is only the ratio of P to Q that is important. P is thus set to unity, and Q is the only tuning
parameter.
The IGMV control action is given by:

u t u t 1 u t

5.6

where

na i

b0
u t

i 1

~ y t k i
a
i

2
0

nb

i 1
2

bi u t i r t

5.7

For the above system this expands to

u t

b0 a~1 y t 1 a~2 t 2 a~3 y t 3 b1 u t 1 t t


b02 Q w2

5.8

where

a~i a i a i 1
Equation 5.8 is implemented as follows:
delta_ut = b0*( (a1-1)*yt_1 + (a2-a1)*yt_2 + (0-a2)*yt_3 - b1*delta_ut_1 + rt);
delta_ut = delta_ut / (b0^2 + Qw^2);
ut = ut_1 + delta_ut;
% time shift the variables specific to this controller
yt_3 = yt_2;
delta_ut_1 = delta_ut;

Gary Evans.
Self-tuning and adaptive control.

5.9

200

Page 21 of 28

It was found that values of Q of less than a value of approximately 4.3 led to an unstable system response, as shown
in figure 21. The controller action is not constrained adequately and the integrator action of the Incremental control
leads to instability.
4
0.4

0.3
0.2

0.1

Control action

System response

-1
-2

0
-0.1
-0.2

-3

-0.3

-4

-0.4

-5

-0.5

20

40

60

80

100
120
Iterations

140

160

180

200

-0.6

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 22. Control action for IGMV control, Q=4.3.

Figure 21. System response for IGMV control, Q=4.3.

IGMV control with an increasing value of Q is plotted in figures 23 to 27.


2

1.5

1.5

0.5

System response

System response

0
-0.5
-1
-1.5
-2

0.5

-0.5

-1
0

20

40

60

80

100
120
Iterations

140

160

180

200

-1.5

Figure 23. IGMV control with Q = 5.5.

20

40

60

80

100
120
Iterations

140

160

180

200

140

160

180

200

Figure 24. IGMV with Q = 6.5.

1.5

1
0.8

0.4

0.5

System response

System response

0.6

-0.5

0.2
0
-0.2
-0.4
-0.6

-1

-1.5

-0.8
-1
0

20

40

60

80

100
120
Iterations

Figure 25. IGMV with Q = 7.5.

Gary Evans.
Self-tuning and adaptive control.

140

160

180

200

20

40

60

80

100
120
Iterations

Figure 26. IGMV with Q = 8.5.

Page 22 of 28

1
0.8
0.6
System response

0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0

20

40

60

80

100
120
Iterations

140

160

180

200

Figure 27. IGMV with Q = 20.

Figures 23 to 27 show that as Q is increased, the overshoot and oscillations are reduced. However, this also results in
the system being slower to reach the reference, and for a large value of Q (and so large constraint on the control
effort), that the system is unable to reach the reference.

Gary Evans.
Self-tuning and adaptive control.

Page 23 of 28

Appendix
fivepointtwo.m
% Gary Evans.
% Attempt to model system with RLS.
% Model not accurate - fails to track varying b1 parameter
% Clear the previous set of parameters
clear;
% System parameters
a1 = -1.5;
a2 = 0.7;
b0 = 1.0;
% Zero previous input and output variables
yt_1 = 0; yt_2 = 0;
ut_1 = 0; ut_2 = 0;
% set up initial vectors for RLS
n = 4;
x = zeros(n,1);
theta = x;
% Set up the covariance matrix
P = 100000*eye(n);
%reference
rt = 1;
for i=1:200
%change the reference every 10 samples
if mod(i,10)==0
rt = -rt;
end
%no control action
ut = rt;
%vary b1
b1 = 0.5 + ( 0.1 * i/200 );
%b1 = 0.5;
%system model
yt = -a1*yt_1 - a2*yt_2 + b0*ut_1 + b1*ut_2;
%

RLS algorithm
P = P - P*x*((1 + x'*P*x)^(-1))*x'*P;
perror = (yt - x'*theta);
theta = theta + P*x*perror;

Time shift the variables


yt_2 = yt_1;
yt_1 = yt;
ut_2 = ut_1;
ut_1 = ut;
%

Update the observation vector


x(1) = -yt_2;
x(2) = -yt_1;
x(3) = ut_1;
x(4) = ut_2;
%
Store the output of the system
store(i,1) = yt;
%
Store the system parameters
store(i,2:n+1) = theta';
end
% output the parameter vector
theta
clf;

Gary Evans.
Self-tuning and adaptive control.

Page 24 of 28

figure(1)
plot(store(:,1))
xlabel('Iterations')
ylabel('System response');
figure(2)
plot(store(:,2:n+1))
xlabel('Iterations')
ylabel('Estimated parameters');

fivepointtwob.m
%
%
%
%
%
%

Gary Evans
Attempt to model system with FFF.
To track varying b1 parameter.
FFF works fine - but needs varying input into the system
or else information is lost (as steady state). Series of ramps
works fine.

% Clear the previous set of parameters


clear;
% System parameters
a1 = -1.5;
a2 = 0.7;
b0 = 1.0;
% Zero previous input and output variables
yt_1 = 0; yt_2 = 0;
ut_1 = 0; ut_2 = 0;
% set up initial vectors for RLS
n = 4;
x = zeros(n,1);
theta = x;
% Set up the covariance matrix
P = 100000*eye(n);
forgettingfactor = 0.9;
%reference
rt = 1;
for i=1:200
change the reference every 10 samples
if mod(rt,10)==0
rt = -rt;
end
%no control action
ut = rt;
%vary b1
b1 = 0.5 + ( 0.1 * i/200 );
%system model
yt = -a1*yt_1 - a2*yt_2 + b0*ut_1 + b1*ut_2;
%

FFF algorithm
% P = P - P*x*((1 + x'*P*x)^(-1))*x'*P; %normal RLS
P = (P - P*x*((1 + x'*P*x)^(-1))*x'*P)/forgettingfactor;
perror = (yt - x'*theta);
theta = theta + P*x*perror;

Time shift the variables


yt_2 = yt_1;
yt_1 = yt;
ut_2 = ut_1;
ut_1 = ut;
%

Update the observation vector


x(1) = -yt_2;
x(2) = -yt_1;
x(3) = ut_1;
x(4) = ut_2;

Gary Evans.
Self-tuning and adaptive control.

Page 25 of 28

%
Store the output of the system
store(i,1) = yt;
%
Store the system parameters
store(i,2:n+1) = theta';
end
theta
clf;
figure(1)
plot(store(:,1))
xlabel('Iterations')
ylabel('System response');
figure(2)
plot(store(:,2:n+1))
xlabel('Iterations')
ylabel('Estimated parameters');

fivepointtwoc.m
% Gary Evans
% Attempt to model system a Kalman filter.
% Clear the previous set of parameters
clear;
% System parameters
a1 = -1.5;
a2 = 0.7;
b0 = 1.0;
% Zero previous input and output variables
yt_1 = 0; yt_2 = 0;
ut_1 = 0; ut_2 = 0;
% set up initial vectors
n = 4;
x = zeros(n,1);
theta = x;
% Set up the covariance matrix
P = 100000*eye(n);
% Set up the noise information
Rw = [0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1];
rv = 1;
%reference
rt = 1;
for i=1:200
change the reference every 10 samples
if mod(rt,10)==0
rt = -rt;
end
%no control action
ut = rt;
%vary b1
b1 = 0.5 + ( 0.1 * i/200 );
%system model
yt = -a1*yt_1 - a2*yt_2 + b0*ut_1 + b1*ut_2;
%
%
%

Kalman filter algorithm


Prediction
P = P + Rw;
Correction
K = P*x/(rv +x'*P*x);
perror = (yt - x'*theta);
theta = theta + K*perror;

Gary Evans.
Self-tuning and adaptive control.

Page 26 of 28

P = (eye(n) - K*x')*P;
%

Time shift the variables


yt_2 = yt_1;
yt_1 = yt;
ut_2 = ut_1;
ut_1 = ut;
%

Update the observation vector


x(1) = -yt_2;
x(2) = -yt_1;
x(3) = ut_1;
x(4) = ut_2;
%
Store the output of the system
store(i,1) = yt;
%
Store the system parameters
store(i,2:n+1) = theta';
end
theta
clf;
figure(1)
plot(store(:,1))
xlabel('Iterations')
ylabel('System response');
figure(2)
plot(store(:,2:n+1))
xlabel('Iterations')
ylabel('Estimated parameters');

fivepointthree.m
% Gary Evans
% Clear the previous set of parameters
clear;
Pw=0; Qw=0; Rw=0;
% System parameters
a1 = -1.5;
a2 = 0.7;
b0 = 1.0;
% Zero previous input and output variables
yt_1 = 0; yt_2 = 0;
ut_1 = 0; ut_2 = 0;
%for IGMV
delta_ut_1 = 0;
yt_3=0;
% Set the system input
rt = 1;
% ------------------------% For Kalman filter
% set up initial vectors
n = 4;
x = zeros(n,1);
theta = x;
% Set up the covariance matrix
P = 100000*eye(n);
% Set up the noise information
Rw = [0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1];
rv = 1;
%reference
rt = 1;
% ------------------------% Request the control scheme

Gary Evans.
Self-tuning and adaptive control.

Page 27 of 28

disp('Enter the control scheme')


disp('1: Pole Placement')
disp('2: GMV')
disp('3: IGMV')
disp('4: GPC')
ContSch = input('> ');
rand('seed',0);
%rand('normal');
switch ContSch
case 1
disp('Pole placement')
disp('Enter values for the poles:')
% Poles of the closed loop system
j = sqrt(-1);
pole1 = input('Enter pole 1 :');
pole2 = input('Enter pole 2 :');
p1 = pole1+j*0; p2 = pole2+j*0;
%p1 = 0.5+j*0; p2 = 0.5+j*0;
gamma1 = -(p1 + p2); gamma2 = p1*p2;
case 2
Pw = input('Enter the weighting Pw : ');
Qw = input('Enter the weighting Qw : ');
Rw = input('Enter the weighting Rw : ');
case 3
disp('IGMV')
Qw = input('Enter the weighting Qw : ');
case 4
disp('GPC')
otherwise
disp('That option is not recognised.')
end
for i= 1:200
%

Change the reference signal every 50 signals


if mod(i,50) == 0
rt = -rt;
end
%vary b1
b1 = 0.5 + ( 0.1 * i/200 );

System model
yt = -a1*yt_1 - a2*yt_2 + b0*ut_1 + b1*ut_2;

%
%

Kalman filter algorithm


Prediction
P = P + Rw;
Correction
K = P*x/(rv +x'*P*x);
perror = (yt - x'*theta);
theta = theta + K*perror;
P = (eye(n) - K*x')*P;

switch ContSch
case 1
% Pole placement
%
g0 = -(gamma1 - a1)/b0; g1 = -(gamma2 - a2)/b0;
g0 = -(gamma1 - theta(2))/b0; g1 = -(gamma2 - theta(1))/b0;
m = (1 + gamma1 + gamma2)/b0;
ut = g0*yt + g1*yt_1 + m*rt;
case 2
%GMV
%problems with Pw=1, Qw=1, specifically Rw=0 - gives ut=0.
%ut = (Pw*(a1*yt + a2*yt_1) + Rw*rt)/(Pw*b0 + Qw);
%ut = (Pw*(a1*yt + a2*yt_1 -b1*ut_1) + Rw*rt)/(Pw*b0 + Qw);
ut = (Pw*(theta(2)*yt + theta(1)*yt_1 - theta(4)*ut_1) + Rw*rt)/(Pw*b0 + Qw);
case 3
% IGMV
%delta_ut = b0*( (a1-1)*yt_1 + (a2-a1)*yt_2 + (0-a2)*yt_3 - b1*delta_ut_1 + rt);
%delta_ut = delta_ut/(b0^2 + Qw^2);
delta_ut = b0*( (theta(2)-1)*yt_1 + (theta(1)-theta(2))*yt_2 + (0-theta(1))*yt_3 theta(4)*delta_ut_1 + rt) / (b0^2 + Qw^2);
ut = ut_1 + delta_ut;

Gary Evans.
Self-tuning and adaptive control.

Page 28 of 28

% time shift the variables specific to this controller


yt_3 = yt_2;
delta_ut_1 = delta_ut;
case 4
% GPC
otherwise
%no controller
ut=rt;
end
%
yt_2
yt_1
ut_2
ut_1

Time shift the variables


= yt_1;
= yt;
= ut_1;
= ut;

%
x(1)
x(2)
x(3)
x(4)

Update the observation vector


= -yt_2;
= -yt_1;
= ut_1;
= ut_2;

Store the output of the system


store(i,1) = yt;

Store the system parameters


store(i,2:n+1) = theta';

Store the reference


store(i,n+2) = rt;

Store the control action


store(i,n+3) = ut;

Store the iterations


store(i,n+4) = i;

end
%display the parameter vector
theta
% Clear the graphics screen
clf;
figure(1),plot(store(:,n+4),store(:,1),store(:,n+4),store(:,n+2)),xlabel('Iterations'),
ylabel('System response');
%plot(store(:,2:n+1)),xlabel('Iterations'),ylabel('Estimated parameters');
%figure(2), plot(store(:,n+2)),xlabel('Iterations'),ylabel('Reference');
figure(2), plot(store(:,n+3)),xlabel('Iterations'),ylabel('Control action');

Gary Evans.
Self-tuning and adaptive control.

You might also like