Post on 19-Jul-2022
Controlo por Computador 25
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Computer Control
Parts 1, 2 – English version
J. Miranda Lemos
Professor Catedrático do IST
2018
Controlo por Computador 26
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Course syllabus
1. Structure of a computer control system
2. Models in computer control
3. Model identification
4. Controller design
Controlo por Computador 27
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
1. Structure of a Computer Control System
Objective: Provide a perspective of the topics addressed in the course.
Franklin, Powell, Workman, Digital Control of Dynamic Systems, 3rd ed., cap 3
Controlo por Computador 28
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Tracking an object with the LEGO NXT robot
r
d
Relação entrea velocidadee a posição(integral)
VelocidadeComandodo motor
Distância
Sensor dedistância
Distânciadesejada
r +
-
Erro
e uK=4
dvMotor ecaixa develocidade
PerurbaçãoSoftware
Sistemafísico
Controlo por Computador 29
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Increasing the gain 𝐾 the motor excitation 𝑢 increases and the robot reacts faster.
Relação entrea velocidadee a posição(integral)
VelocidadeComandodo motor
Distância
Sensor dedistância
Distânciadesejada
r +
-
Erro
e uK=4
dvMotor ecaixa develocidade
PerurbaçãoSoftware
Sistemafísico
Tempo
r
d
e
u=ke
Controlo por Computador 30
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
A simple example: Mathematical model of the NXT robot
Objective: Model the NXT moving along a straight line in order to go to a
specified position.
How can we do it?
Controlo por Computador 31
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
𝑥 the actual NXT position
𝑅 the desired
“break time in strips” o duration ℎ
Observe the position at instants 0 (initial position), ℎ, 2ℎ, 3ℎ, ..., 𝑛ℎ, ...
𝑛ℎ represensta a generic time instant in which we observe the position of
the robot (𝑛 is called discrete time)
Objective: Relate the position of the robot in different time instants.
Controlo por Computador 32
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Grafic of the position of the robot in different time instants
Present position = Previous position + velocity × time interval
𝑥((𝑛 + 1)ℎ) = 𝑥(𝑛ℎ) + 𝛼𝑢(𝑛ℎ)ℎ
𝑢 is the command of the motor (0 a 100%); 𝛼𝑢 is the robot velocity
Tempo(n-1)h nh0 h 2h 3h 4h ... ...
x(0)
x(nh)x((n-1)h)
x
Controlo por Computador 33
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
What is the value of parameter 𝜶?
Do experiments with the robot. We observe that
𝑢 = 100% corresponds to a velocity of 1 𝑚/𝑠
Hecce
100 𝛼 = 1
and
𝛼 = 0,01
Controlo por Computador 34
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Model of the movement of robot:
𝑥((𝑛 + 1)ℎ) = 𝑥(𝑛ℎ) + 𝛼𝑢(𝑛ℎ)ℎ
Control algorithm
Tracjking error (difference between the desired and the actual position):
𝑒(𝑛ℎ) = 𝑅 − 𝑥(𝑛ℎ)
Motor command
𝑢(𝑛ℎ) = 𝐾𝑒(𝑛ℎ)
Model of the controlled system (closed-loop system)
𝑥((𝑛 + 1)ℎ) = 𝑥(𝑛ℎ) + 𝛼𝐾ℎ(𝑅 − 𝑥(𝑛ℎ))
Controlo por Computador 35
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Difference equations
𝑥((𝑛 + 1)ℎ) = 𝑥(𝑛ℎ) + 𝛼𝐾ℎ(𝑅 − 𝑥(𝑛ℎ))
𝑥((𝑛 + 1)ℎ) = (1 − 𝛼𝐾ℎ)𝑥(𝑛ℎ) + 𝛼𝐾ℎ𝑅
A special case: 𝛼 = 0,01 ℎ = 1 𝐾 = 60 then 𝛼𝐾ℎ = 0,6 and 1 − 𝛼𝐾ℎ = 0,4
The difference equation becomes
𝑥(𝑛 + 1) = 0,4𝑥(𝑛) + 0,6𝑅
If we know the initial position 𝑥(0) and the value of the reference 𝑅, we can
compute 𝑥(1) from 𝑥(0), and
𝑥(2) from 𝑥(1),
𝑥(3) from 𝑥(2), ...
Controlo por Computador 36
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
𝑥(𝑛 + 1) = 0,4𝑥(𝑛) + 0,6
𝑥(0) = 0
𝑥(1) = 0,4𝑥(0) + 0,6 = 0,4 × 0 + 0,6 = 0,6
𝑥(2) = 0,4𝑥(1) + 0,6 = 0,4 × 0,6 + 0,6 = 0,84
𝑥(3) = 0,4𝑥(2) + 0,6 = 0,4 × 0,84 + 0,6 = 0,936
𝑥(4) = 0,4𝑥(3) + 0,6 = 0,9744
𝑥(5) = 0,4𝑥(4) + 0,6 = 0,98976
The best is to use a computer and a language like MATLAB…
But the important point is the fact that the difference equation represents the
whole sequence of numbers that is its solution
Controlo por Computador 37
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Equilibrium points
The equilibrium corresponds to a situation in which the solution is constant:
𝑥(𝑛 + 1) ≈ 𝑥(𝑛) = ��
For the equation
𝑥(𝑛 + 1) = 0,4𝑥(𝑛) + 0,6𝑅
the equilibrium satisfies
�� = 0,4�� + 0,6𝑅
and is given by
�� =0,6
1 − 0,4𝑅 = 𝑅
Controlo por Computador 38
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Stability
Can we prove that the error goes to zero when the time increases?
Obtain an equation for the erroir and solve it.
𝑥((𝑛 + 1)ℎ) = 𝑥(𝑛ℎ) + 𝛼𝐾ℎ(𝑅 − 𝑥(𝑛ℎ))
Multiply by −1 and add 𝑅 a to both sides:
𝑅 − 𝑥((𝑛 + 1)ℎ) = 𝑅 − 𝑥(𝑛ℎ) − 𝛼𝐾ℎ(𝑅 − 𝑥(𝑛ℎ))
Use the definition of tracking error
𝑒((𝑛 + 1)ℎ) = 𝑒(𝑛ℎ) − 𝛼𝐾ℎ𝑒(𝑛ℎ)
𝑒((𝑛 + 1)ℎ) = [1 − 𝐾ℎ𝛼]𝑒(𝑛ℎ)
Controlo por Computador 39
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Error equation
𝑒((𝑛 + 1)ℎ) = [1 − 𝐾ℎ𝛼]𝑒(𝑛ℎ)
Solution of the error equation
𝑒(𝑛ℎ) = 𝑒(0)(1 − 𝐾ℎ𝛼)𝑛
Controlo por Computador 40
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Error equation
𝑒((𝑛 + 1)ℎ) = [1 − 𝐾ℎ𝛼]𝑒(𝑛ℎ)
Solution of the error equationo
𝑒(𝑛ℎ) = 𝑒(0)(1 − 𝐾ℎ𝛼)𝑛
Stability condition
|1 − 𝐾ℎ𝛼| < 1
0 < 𝐾 <2
ℎ𝛼
Condition so that there are no oscillations
0 < 𝐾 <1
ℎ𝛼
Controlo por Computador 41
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Computer control structure
u yD/A
A/D Sensor
Sistema a Controlar
Porto de Saída
Controlador
Porto de Entrada
Computador de Controlo
Sinal de
comando do
actuador
Variável
Física de
saída
Sinal
proporcional
à variável
Sinal de comando
Controlo por Computador 42
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Data acquisition hardware (simplified)
Relógio
Impulsos do relógioPorto deentrada
Micro-computador
INTCC
Sinal a
amostrar
b0
b7
b1Conversor A/D
Ao receber um impulso de relógio, o conversor
A/D retém uma amostra do sinal e inicia a sua
conversão para um número binário.
Quando os bits b0 a b7 atingem o valor correcto,
o sinal de conversão completa CC é activado e o
pino de nterrupção do microcomputador é
actuado.
Se as interrupções não estiverem inibidas, a
subrotina de interrupção começa a ser executada,
sendo efectuada a leitura do porto de entrada,
onde estão ligados os pinos do A/D.
Controlo por Computador 43
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Software structure for computer control
->Inibe interrupções
->Lê y no porto de entrada, ligado ao A/D
->Cálcula o controlo u
->Escreve u no porto de saída ligado ao D/A
->Desinibe interrupções
->Retorna ao programa principal
Programaprincipal
Salta quando chegauma interrupção do
relógio
Controlo por Computador 44
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Time diagram of computer control
Sinal gerado pelo Relógio
Activa interrupções no flanco ascendente
Interrupção do
relógio
Intervalo de amostragem
Interrupção dorelógio
Lê y no
A/DCalculau(tn)
Escreve
u(tn) no D/A
Espera novainterrupção
tn tn+1
Atraso de cálculo
u(tn)
u(tn-1)
Variável Manipulada
The computer considers the
variables only at sampling times;
There is a delay due to
computation and A/D and D/A
conversion
Controlo por Computador 45
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Remark that:
The manipulated variable 𝑢 is constant between consecutive sampling intervals.
Between 2 consecutive sampling instants the manipulated variable is constant. This
fact imposes a constraint on the sampling interval.
There is a delay between the instant tn in which the interrupt arrives (sampling instant)
and the time instant in which 𝑢 is written to the D/A. This delay is mainly due to the
computation time.
The computation may be neglected if it is very small compared with the sampling
interval.
If the computation time is not negligible, it must be considered in control design as an
additional pure delay in the process model.
Controlo por Computador 46
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Control objectves
u yD/A
A/D Sensor
Sistema a Controlar
Porto de Saída
Controlador
Porto de Entrada
Computador de Controlo
Sinal de
comando do
actuador Variável
Física a
controlar
Perturbações
Os objectivos de controlo
dizem respeito à capacidade
de efectuar as manobras
desejadas, tendo em conta a
dinâmica do processo e as
perturbações.
Sinal de
comando
Controlo por Computador 47
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Control objectives (examples)
Keep y at the required value, even in the presence of disturbances
(regulation problem);
Track references for 𝑦, even in the presence of disturbances (servo
problem);
Stabilize the plant to control;
Impose a specified dynamics to the controlled system;
Optimize the system (for instrance minimize the energy) – Optimal Control
Keep a constant behavior even when the plant changes (Adaptive Control).
Controlo por Computador 48
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Exemplo: Controlador Digital com acção integral
Problema: Como actuar no comando do motor do avião para manter o
impulso constante?
Solução: Controlo proporcional
Será que, em regime estacionário, o impulso é igual ao impulso desejado?
Repare-se que não. Se assim for o erro e será nulo e o comando será zero,
ou seja o motor pára.
R yuK+
-
e
Controlo por Computador 49
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Solução para erro estático nulo: Efeito integral
Quando o erro é nulo, a saída do integrador fica constante mas não
necessariamente nula.
R yuK+
-
e
1
sTi
Integrador
Controlo por Computador 50
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
A equação que descreve o controlador PI é:
e r y
u t K e tT
e di
t
( ) ( ( ) ( ) )1
0
Quando o erro é nulo o controlo vem dado pelo valor do integrador.
As constantes K e Ti são os ganhos do controlador, podendo ser escolhidas,
por exemplo, de acordo com as regras de Ziegler e Nichols, ou outras mais
adequadas.
Desafio: usando a transformada de Laplace, mostre que se o controlador tiver
um integrador (pólo na origem) o erro estático de seguimento é nulo.
Controlo por Computador 51
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Uma revisão breve: Controlo por realimentação
VKG
KGW
KG
GR
KG
KGYcL
111
𝐾𝐺 é o ganho de malha
R U
W
yK(s) G(s)
v
-
Controlo por Computador 52
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
O controlador 𝐾(𝑠) é projectado por forma a “moldar” o ganho de malha:
VKG
KGW
KG
GR
KG
KGYcL
111
|K(jw)G(jw)|
Especificação devida
ao ruído: Atenuação
na alta frequência
Especificação
relativa ao
seguimento da
referência e
rejeição das
perturbações Para que o “quadro” seja completo temos
de considerar a estabilidade e a incerteza
no conhecimento do modelo.
Controlo por Computador 53
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Como implementar em computador as equações do controlador PI?
e r y
u t K e tT
e di
t
( ) ( ( ) ( )1
0
Considere-se a equação do integrador:
u tT
e di
i
t
( ) ( ) 1
0
Derivando ambos os membros da equação:
du
dt Te t
i
i
1
( )
du
dt
u nh u n h
h
i
( ) (( ) )1
Controlo por Computador 54
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Isto resulta nas seguintes equações de diferenças para o
Algoritmo PI digital:
𝑒(𝑛ℎ) = 𝑟 − 𝑦(𝑛ℎ)
u nh u n hh
Te nhi i
i
( ) (( ) ) ( ) 1
u nh K u nh e nhi( ) ( ( ) ( ))
𝑛 é o instante de amostragem (número inteiro)
ℎ é o interval de amostragem (normalmente é omitido)
Controlo por Computador 55
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Pseudocódigo para PI digital
No início de cada intervalo de amostragem, executar recursivamente:
1. Ler no porto de entrada ligado ao A/D a variável y
2.Calcular o erro e r y
3.Calcular a variável manipulada u por
u uh
Te
u K u e
i ianterior
i
i
( )
em que uianterior é a saída do integrador no instante de amostragem anterior
4. Escrever u no porto de saída ligado ao D/A
5. Fazer u uianterior i
6. Esperar nova interrupção
Controlo por Computador 56
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Motivação para o Controlo Adaptativo
Há situações em que a dinâmica do sistema a controlar varia ao longo do
tempo.
Isto pode ser devido, por exemplo, à existência de não linearidades nos
actuadores ou no próprio sistema. Neste caso, a dinâmica linearizada vai
variar com o ponto de trabalho (por exemplo com a velocidade de equilíbrio).
Pode ainda acontecer que a dinâmica varie devido a factores como o
envelhecimento ou alterações do ambiente ou outros factores.
Nesta situação, a afinação do controlador adequada a um ponto de trabalho
pode não o ser para outro.
Controlo por Computador 57
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Exemplo: Válvula não linear
f u u( ) 4 G s
s( )
( )
1
1 3 K 015. Ti 1
A resposta do sistema controlado depende do ponto de funcionamento.
Um controlador bem afinado para um ponto de funcionamento pode não estar
bem afinado para outro.
R yuK(1+ )+
-
e 1Ti s f(.) G(s)
Controlador PI Actuador Sistema
Controlo por Computador 58
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
As figuras seguintes mostram a resposta a um escalão na referência de
amplitude 0.1, para duversos pontos de funcionamento, com um PI
sintonizado em torno de r=0.2.
0 10 20 30 40 50 60 70 80 90 1000.1
0.15
0.2
0.25
0.3
0.35
0.4
0 10 20 30 40 50 60 70 80 90 1002.9
2.95
3
3.05
3.1
3.15
3.2
3.25
3.3
0 10 20 30 40 50 60 70 80 90 1004.9
4.95
5
5.05
5.1
5.15
5.2
5.25
5.3
Controlo por Computador 59
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Exemplo de variação da dinâmica numa aeronave
Num avião a dinâmica linearizada altera-se com as condições de voo. A figura
mostra a dependência dos valores próprios do sistema com a velocidade de
equilíbrio
Extraída de Neves da Silva, R. (1994). Controlo de Aeronave não tripulada usando técnicas LQG/LTR de ganho variável Tese de Mestrado, IST -
Departamento de Engenharia Electrotécnica e de Computadores.
Controlo por Computador 60
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Devido à variação da dinâmica com as condições de voo, utilizando um
controlador de ganhos fixos, pode ter-se um bom comportamento numa gama
de funcionamento e um mau funcionamento noutras zonas.
Exemplo do controlo do ângulo de pitch com um controlador fixo quando a
velocidade aumenta progressivamente:
.Extraído de Rato, L. M. (1994). Técnicas de Controlo Adaptativo aplicadas a uma aeronave não tripulada Tese de Mestrado, IST - Departamento de
Engenharia Electrotécnica e de Computadores
Controlo por Computador 61
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Uma possibilidade consiste em adaptar os ganhos para compensar alterações
da dinâmica devidas a variações da velocidade:
Adaptador
Controladoru
y
Ajuste dos
ganhos do controlador
Controlo por Computador 62
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
O bloco Adaptador por ser obtido de vários modos:
Tabela que altera os ganhos do controlador de um modo fixo, para cada
valor de velocidade. Esta técnica denomina-se gain-schedulling.
Identificação da dinâmica com o método dos mínimos quadrados, refazendo-
se o cálculo dos ganhos repetidamente, em tempo real. Esta técnica
denomina-se Controlo Adaptativo.
Controlo por Computador 63
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
"Gain-scheduling"
x
x
x
+
Controlador
V baixo
Controlador
V médio
Controlador
V alto
u
V
V
V
(V)
(V)
(V)
u
O valor da variável manipulada em
cada instante resulta resulta da
combinação linear das variáveis
calculadas pelos vários
controladores.
Por exemplo, a velocidades baixas, o
controlador respectivo é multiplicado
por um peso próximo de 1 enquanto
o controlador de velocidades altas é
multiplicado por zero.
Controlo por Computador 64
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Controlo Adaptativo vs. "Gain Scheduling"
A solução do controlo de sistemas variáveis no tempo por "gain scheduling" é
útil em muitas situações mas levanta problemas quando:
Não é possível conhecer a priori qual o controlador a utilizar numa dada
situação;
É necessário recorrer a um número muito elevado de controladores.
Uma outra possibilidade, que se estuda neste curso é o Controlo adaptativo.
Controlo por Computador 65
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Controlo Adaptativo
Numa das famílias de Controlo Adaptativo, o Adaptador é constituído por dois
blocos:
Identificador, que estima continuamente os parâmetros (e. g. a posição dos
pólos, dos zeros e o ganho) de um modelo, a partir dos dados de entrada e
saída medidos.
Projecto do Controlador, que recalcula continuamente os ganhos do
controlador tendo em conta as novas estimativas do modelo.
Deste modo, quando a dinâmica do sistema se altera, o identificador dá conta
desse facto e os ganhos do controlador são alterados para frazer face à nova
situação.
Controlo por Computador 66
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
No caso do exemplo do controlo do ângulo de pitch, é possível, recorrendo ao
Controlo Adaptativo, obter uma resposta com características razoavelmente
constantes quando a velocidade varia de 10 a 40 m/s:
Extraído de Rato, L. M. (1994). Técnicas de Controlo Adaptativo aplicadas a uma aeronave não tripulada Tese de Mestrado, IST - Departamento de
Engenharia Electrotécnica e de Computadores
Controlo por Computador 67
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Isto é possível graças ao ajuste dos ganhos do controlador efectuado pelo
adaptador:
Extraído de Rato, L. M. (1994). Técnicas de Controlo Adaptativo aplicadas a uma aeronave não tripulada Tese de Mestrado, IST - Departamento de
Engenharia Electrotécnica e de Computadores.
O adaptador actualiza constantemente o modelo melhor ajustado aos dados e
recalcula os ganhos do controlador de acordo com esta estimativa do modelo.
Controlo por Computador 68
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
2 - Models in Computer Control
Objective: Introduce the class of plant models used in this course for control
design
Bibliografy: Astrom e Wittenmark, CCS, Cap. 3, em especial as secções 3.2, 3.4, 3.5, 3.6 e 3.7
Franklin, Powell, Workman, Digital Control of Dynamic Systems, 3rd ed., caps. 3 a 6.
Controlo por Computador 69
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
SLITs em tempo discreto
SLITs – Linear Time Invariant Systems in discrete time
Linearity (Superposition Principle holds):
u k y k
u k y k
au k bu k ay k by k
1 1
2 2
1 2 1 2
( ) ( )
( ) ( )
( ) ( ) ( ) ( )
SLITu(k) y(k)
Controlo por Computador 70
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Time Invariance
u k y k
u k k y k k
( ) ( )
( ) ( )
0 0
Controlo por Computador 71
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
SLIT description by difference equations
Constant coefficients
y k n a y k n a y kn( ) ( ) ( ) 1 1
b u k m b u k m b u km0 1 1( ) ( ) ( )
Coefficients
Equation
order
Controlo por Computador 72
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
n initial conditions specified:
y n
y
( )
( )
1
0
Show that:
The linear difference equation with constant coefficients represents a linear
time invariant system
The solution of the linear difference equations with n initial conditions
specified exists and is unique.
Controlo por Computador 73
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example of a difference equation
𝑦(𝑘 + 1) = 0,5𝑦(𝑘) + 𝑢(𝑘), initial condition 𝑦(0) = 0
Step response
𝑘 𝑢(𝑘) 𝑦(𝑘)
0 1 0 (initial condition)
1 1 1 + 0,5 × 0 = 1 2 1 1 + 0,5 × 1 = 1,5
3 1 1 + 0,5 × 1,5 = 1,75
4 1 1 + 0,5 × 1,75 = 1,875 5 1 1 + 0,5 × 1,875 = 1,9375
6 1 1 + 0,5 × 1,9375 = 1,96875
What is the number to which the output is approaching (equilibrium)?
Controlo por Computador 74
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Equilibrium
𝑦(𝑘 + 1) = 0,5𝑦(𝑘) + 𝑢(𝑘)
At the equilibrium, 𝑦 is constant, and thus
�� = 0,5�� + 1
�� = 2
End of the example.
Controlo por Computador 75
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Description of SLITs by difference equations
Difference equation with forward shifts:
y k n a y k n a y kn( ) ( ) ( ) 1 1
b u k m b u k m b u km0 1 1( ) ( ) ( )
Difference equation with backwards shifts:
y k a y k a y k nn( ) ( ) ( ) 1 1
b u k n m b u k n m b u k nm0 1 1( ( )) ( ( ) ) ( )
Transform one in the other by shifting time n steps.
Controlo por Computador 76
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example
𝑦(𝑘 + 2) + 𝑎1𝑦(𝑘 + 1) + 𝑎2𝑦(𝑘) = 𝑢(𝑘 + 1)
In this case, 𝑛 = 2, 𝑚 = 1.
Delaying the time 2 steps (the order of the system):
𝑦(𝑘) + 𝑎1𝑦(𝑘 − 1) + 𝑎2𝑦(𝑘 − 2) = 𝑢(𝑘 − 1)
Controlo por Computador 77
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Causality
A system is causal if y(k) depends only on inputs and outputs up to time k.
System described by a linear difference equation:
y k n a y k n a y kn( ) ( ) ( ) 1 1
b u k m b u k m b u km0 1 1( ) ( ) ( )
This system is causal if
n m
Controlo por Computador 78
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
System pure delay
y k a y k a y k nn( ) ( ) ( ) 1 1
b u k n m b u k n m b u k nm0 1 1( ( )) ( ( ) ) ( )
An input sample applied at time instant 𝑘 influences the output only after time
𝑘 + (𝑛 − 𝑚)
delay
Controlo por Computador 79
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Hereafter only causal systems are considered.
For causal systems the delay, d, is positive:
d n m 0
In many cases, without loss of generality (why?), we assume
d 1
Controlo por Computador 80
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
A detour: The Z transform
Consider the sequence
,2,1,0),( kkf
This sequence is mapped by the Z transform in the function of complex
variable
0
)()(k
kzkfzF
Controlo por Computador 81
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example
Find the Z transform of the sequence
1)( kf ,2,1,0k
Help ( Z transform definition):
0
)()(k
kzkfzF
Help (Sum of the geometrical series):
rr
i
i
1
1
0 for 1r
Controlo por Computador 82
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Solution
2
00
111)()(
zzzzkfzF
k
k
k
k
11
11
z
z
z
Controlo por Computador 83
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example
Find the Z transform of the sequence
ahkekf )( ,2,1,0k
Help ( Z transform definition):
0
)()(k
kzkfzF
Help (sum of the geometrical series):
rr
i
i
1
1
0 for 1r
Controlo por Computador 84
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Solution
ahah
k
kah
k
kahk
ez
z
zezezezF
10
1
0 1
1)(
Controlo por Computador 85
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Table Z and Laplace transforms (take kht )
Controlo por Computador 86
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Z transform properties
1.Linearity
)()()()( zGzFkgkfZ
2.Time shift
)()( zFzkfqZ nn
1
0
)()()(n
j
jnn zjfzFzkfqZ
Ex.: :1n )0()()( fzFzkqfZ
:2n 122 )1()0()()( zffzFzkfqZ
Controlo por Computador 87
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
3.Final value theorem
)()1(lim)(lim 1
1zFzkf
zk
4.Convolution
The convolution between two sequences )(kf and )(kg is defined by
k
j
jkgjfkgf0
)()()(
Then
)().( zGzFgfZ
Controlo por Computador 88
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Solving difference equations
Solve the difference equation
)()()1( kbukayky com 0)0( y
Approach
Equação dediferenças
Equaçãoalgébrica
Solução daeq. algébrica
Solução daeq. diferenças
? Fácil
TransformadaZ inversa
TransformadaZ
Difícil
Controlo por Computador 89
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example: Solution of a difference equation with the Z transform
)()()1( kbukayky
Take the Z transform
)()()0()( zbUzaYzyzzY
)0()()( yaz
zzU
az
bzY
With 0)0( y : )()( zU
az
bzY
Controlo por Computador 90
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Step response:
0,1)( kku 1)(
z
zzU
)1)(()()(
zaz
bzzU
az
bzY
Simple fraction decomposition:
1
1
11)( 11
z
z
az
az
za
b
zazzY a
ba
ba
k
a
b aky
1)(1
Controlo por Computador 91
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Discrete transfer function
Assume the model represented by the forward difference equation
y k n a y k n a y k b u k m b u k m b u kn m( ) ( ) ( ) ( ) ( ) ( ) 1 0 11 1
Take the Z transform with zero initial conditions to obtain the discrete transfer
function:
G zY z
U z
b z b z b
z a z a z a
m m
m
n n n
n
( )( )
( )
0 1
1
1
1
2
2
SLITu(k) y(k)
Controlo por Computador 92
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Forward operator
x k qx k( ) ( ) 1
Sucessão
Sucessão avançada
Operador avanço
Controlo por Computador 93
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
System operator (forward)
Difference equation:
y k n a y k n a y kn( ) ( ) ( ) 1 1
b u k m b u k m b u km0 1 1( ) ( ) ( )
Replace y k n( ) by q y kn ( )
q y k a q y k a y kn n
n( ) ( ) ( )
1
1 b u k m b u k m b u km0 1 1( ) ( ) ( )
Solving with respect to 𝑦(𝑘)
y kb q b q b q b
q a q a q au k
m m
m m
n n
n n
( ) ( )
0 1
1
1
1
1
1
Controlo por Computador 94
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
y kb q b q b q b
q a q a q au k
m m
m m
n n
n n
( ) ( )
0 1
1
1
1
1
1
H qb q b q b q b
q a q a q a
B q
A q
m m
m m
n n
n n
( )( )
( )
0 1
1
1
1
1
1
Operador de transferência
do sistema (avanço)
B(q)
A(q)
Controlo por Computador 95
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Backward operator
x k q x k( ) ( ) 1 1
Sucessão atrasada Sucessão
Operador atraso
Controlo por Computador 96
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
System operator (backward)
Difference equation:
y k a y k a y k nn( ) ( ) ( ) 1 1
b u k n m b u k n m b u k nm0 1 1( ( )) ( ( ) ) ( )
Replace y k n( ) by q y kn ( ):
y k a q y k a q y kn
n( ) ( ) ( )
1
1
b u k n m b u k n m b u k nm0 1 1( ( )) ( ( ) ) ( )
Solve with respect to 𝑦(𝑘):
y k qb b q b q
a q a q a qu kd m
m
n
n( ) ( )
0 1
1
1
1
2
21
Controlo por Computador 97
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Reciprocal polynomial
The recyprocal polynomial of A q( ) is defined as
A q q A qn*( ) ( ) 1
Remark: In general, the reciprocal of the reciprocal is not the original
polynomial!
System operator in terms of the reciprocal operator
H q qb b q b q
a q a qq
B q
A q
d m
m
n
n
d*
*
*( )( )
( )
1 0 1
1
1
1
1
11
Controlo por Computador 98
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The representation in terms of the forward operator is better to study stability;
The representation in terms of the backwards operator is better to design
controllers and implement algorithms;
Controlo por Computador 99
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Exercise
)()(5.0)1( kukyky
)(4)1()(3)1(2)2( kukukykyky
For each os these systems:
a) Writte the equation in a form in which the most advanced sample of the
output is )(ky .
b) Writte the transfer function in powers of z and 1z .
c) What is the pure delay in each case?
Controlo por Computador 100
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
State model in discrete time
Example: Population model
Divide the population in age ranks (cohorts).
)(kxi is the number of individuals in age range i at time k
Let
Range index: ni ,,2,1,0
Discrete time: ,2,1,0k
Controlo por Computador 101
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
If there are no deads, all the individuals of age i in the year k will be of age
1i in the year 1k :
)()1(1 kxkx ii 1,,2,1,0 ni
k=0
k=1
k=2
k=3
x0
x1 x2 x3 x4
k=0 k=1 k=2 k=3
x0
x1
k=0 k=1 k=2 k=3
Controlo por Computador 102
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
If some individuals die, only a fraction of individuals with age i in the year k
will have age 1i in the year 1k :
)()1(1 kxkx iii 10 i 1,,2,1,0 ni
The members of the population at age range 0 result from the reproduction of
the individuals in the different ranges:
)()()()1( 11000 kxkxkxkx nn
Controlo por Computador 103
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
)()1(1 kxkx iii 10 i 1,,2,1,0 ni
)()()()1( 11000 kxkxkxkx nn
In matrix form:
)(
)(
)(
)(
0000
00
000
000
)1(
)1(
)1(
)1(
2
1
0
1
1
0
210
2
1
0
kx
kx
kx
kx
kx
kx
kx
kx
nn
n
n
)()1( kAxkx
Controlo por Computador 104
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Mckerel captures in the North Sea between 1910 and 1914 (Hjort, 1926).
12
34
56
719101911
19121913
1914
0
20
40
60
80
Idade [ano]Ano
Ca
ptu
ras
Controlo por Computador 105
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example: State model of the Apach server
J. Hellerstein, X. Diao, S. Parekh, D. Tilbury (2004). Feedback Control of Computing Systems. Wiley Interscience. pp. 229-234.
Inputs: MaxClients (MC), KeepAlive (KA)
Outputs: CPU, MEM
11)()()(1 kKAKAkKAku med 600)()()(2 kMCMCkMCku med
58.0)()()(1 kCPUCPUkCPUky med 55.0)()()(2 kMEMMEMkMEMky med
)(
)(
00028.000025.0
00044.00085.0
)(
)(
63.0026.0
11.054.0
)1(
)1(
2
1
2
1
2
1
ku
ku
kx
kx
kx
kx
)(
)(
10
01
)(
)(
2
1
2
1
kx
kx
ky
ky
Controlo por Computador 106
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Conclusion:
State model for linear systems
)()()1( kBukAxkx
)()()( kDukCxky
State model for nonlinear systems
)(),()1( kukxfkx
))(()( kxhky
In both cases the output equation models sensors.
Controlo por Computador 107
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Conversion between linear models
How to obtain the transfer function given a state model?
Apply the Z transfer with zero initial conditions
𝑥(𝑘 + 1) = 𝐴𝑥(𝑘) + 𝐵𝑢(𝑘)
𝑧𝑋(𝑧) = 𝐴𝑋(𝑧) + 𝐵𝑈(𝑧)
(𝑧𝐼 − 𝐴)𝑋(𝑧) = 𝐵𝑈(𝑧)
𝑋(𝑧) = (𝑧𝐼 − 𝐴)−1𝐵𝑈(𝑧)
𝑌(𝑧) = 𝐶𝑋(𝑧) = 𝐶(𝑧𝐼 − 𝐴)−1𝐵𝑈(𝑧)
Conclusion: The discrete transfer function
𝐺(𝑧) =𝑌(𝑧)
𝑈(𝑧)= 𝐶(𝑧𝐼 − 𝐴)−1𝐵
Controlo por Computador 108
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Model conversion II
Obtain a state model for a given transfer function.
Example: Sistems without zeros
Obtain a state realization for the transfer function
𝐺(𝑧) =𝑏0
𝑧3 + 𝑎1𝑧2 + 𝑎2𝑧 + 𝑎3
Corresponds to the difference equation
𝑦(𝑘 + 3) = −𝑎1𝑦(𝑘 + 2) − 𝑎2𝑦(𝑘 + 1) − 𝑎3𝑦(𝑘) + 𝑏0𝑢(𝑘)
Controlo por Computador 109
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
𝑦(𝑘 + 3) = −𝑎1𝑦(𝑘 + 2) − 𝑎2𝑦(𝑘 + 1) − 𝑎3𝑦(𝑘) + 𝑏0𝑢(𝑘)
Take as state variables the output and its first 𝑛 − 1 forward shifts.
(𝑛 is the system order). In this case, 𝑛 = 3, and the state is defined as 𝑥1(𝑘) = 𝑦(𝑘) 𝑥2(𝑘) = 𝑦(𝑘 + 1)
𝑥3(𝑘) = 𝑦(𝑘 + 2) From the definition of the state:
𝑥1(𝑘 + 1) = 𝑦(𝑘 + 1) = 𝑥2(𝑘) 𝑥2(𝑘 + 1) = 𝑦(𝑘 + 2) = 𝑥3(𝑘)
𝑥3(𝑘 + 1) = 𝑦(𝑘 + 3) From the difference equation
𝑥3(𝑘 + 1) = −𝑎3𝑥1(𝑘) − 𝑎2𝑥2(𝑘) − 𝑎1𝑥3(𝑘) + 𝑏0𝑢(𝑘)
Controlo por Computador 110
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
𝑥1(𝑘 + 1) = 𝑥2(𝑘)
𝑥2(𝑘 + 1) = 𝑥3(𝑘)
𝑥3(𝑘 + 1) = −𝑎3𝑥1(𝑘) − 𝑎2𝑥2(𝑘) − 𝑎1𝑥3(𝑘) + 𝑏0𝑢(𝑘)
State model in matrix form:
[
𝑥1(𝑘 + 1)𝑥2(𝑘 + 1)𝑥3(𝑘 + 1)
] = [0 1 00 0 1
−𝑎3 −𝑎2 −𝑎1
] [
𝑥1(𝑘)𝑥2(𝑘)𝑥3(𝑘)
] + [00𝑏0
] 𝑢(𝑘)
𝑦(𝑘) = [1 0 0] [
𝑥1(𝑘)𝑥2(𝑘)𝑥3(𝑘)
]
Controlo por Computador 111
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Systems with zeros
𝐺(𝑧) =𝑏0𝑧 + 𝑏1
𝑧3 + 𝑎1𝑧2 + 𝑎2𝑧 + 𝑎3
Break the system in a part without zeros and a part without poles.
The state is defined as before, but taking 𝑥1 instead of 𝑦.
Only the output equation is affected:
𝑦(𝑘) = 𝑏1𝑥1(𝑘) + 𝑏0𝑥2(𝑘)
u yx1b0z+b1
Sistema semzeros
Controlo por Computador 112
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Using MATLAB for linear model conversion
MATLAB (Control Systems Toolbox) can be used to convert models:
ss2tf converts the state model to the transfer function;
tf2ss converts the transfer function to the state model (remark that the
state realization is not the one defined above))
tf define a system by its transfer function.
series transfer function of a series of 2 transfer functions.
Use the help or doc of these functions to know how they work and to know
more functions.
Controlo por Computador 113
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Model of a sampled system
What is the discrete transfer function “seen” by the computer?
Relógio
D/A A/DG(s)
Sistema
u(kh) y(kh)u(t) y(t)
Controlo por Computador 114
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
To compute a transfer function:
Apply a signal to the input, with zero initial conditions
Observe the output
Compute the Z transforms of the input and of the corresponding output
Make their quotient
What is the most convenient test signal to apply?
Controlo por Computador 115
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
If we use a discrete step, a continuous step is issued, rendering easier the
computations
Relógio
D/A A/DG(s)
Sistema
u(kh) y(kh)u(t) y(t)
Controlo por Computador 116
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
y t TLs
G s( ) ( )
1
1
y kh TL
sG s
t kh( ) ( )
11
The equivalent discrete transfer function is
G zZ y kh
Z u khd ( )
( )
( )
Relógio
D/A A/DG(s)
Sistema
u(kh) y(kh)u(t) y(t)
Controlo por Computador 117
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Let u(kh) be a step. Its Z transform is
Z u khz
( )
1
1 1
kht
d sGs
TLZzzG )(1
)1()( 11
Controlo por Computador 118
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Model of a SLIT with zero order hold sampling (Conclusion)
kht
d sGs
TLZzzG )(1
)1()( 11
Relógio
D/A A/DG(s)
Sistema
u(kh) y(kh)u(t) y(t)
Controlo por Computador 119
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
MATLAB functions
MATLAB functions to:
Compute the discrete equivalent to a given continuous system: c2d
Inverse operation (the solution may not be unique): d2c
They only work for linear models.
Controlo por Computador 120
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example – Model of a sampled system
Obtain the discrete equivalent to
G sa
s a( )
?
Solution:
G z z Z TLa
s s ad t kh( ) ( )
( )
1 1 1
Controlo por Computador 121
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Simple fraction decomposition
a
s s a s s a( )
1 1
11 0
sf t t ( )
f kh k
F zz
( )
( )
1 0
1
1 1
10
0
1
1 1
s af t e t
f kh e k
F ze z
at
ahk
ah
( )
( )
( )
Controlo por Computador 122
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
G z zz e zd ah( ) ( )
11
1
1
1
1
1 1
G ze z
e zd
ah
ah( )( )
1
1
1
1
The convergence region must be chosen so that the system is causal.
Controlo por Computador 123
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The continuous system response to the step coincides, at the sampling
instants, with the response of the discrete system
This does not happen with other type of insputs, for instance a sinusoid.
For this reason the method is also called step invariant method.
0 1 2 3 4 5 6 7 80
0.2
0.4
0.6
0.8
1
0 1 2 3 4 5 6 7 8-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Controlo por Computador 124
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Controlo por Computador 125
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Controlo por Computador 126
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Pole transform
A pole at si is transformed in a pole zi of
the discrete model, given by
z ei
s hi h = sampling interval
Controlo por Computador 127
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
2nd
order system with conjugate poles
w
w w0
2
2
0 0
22s s
The poles are transformed in the
roots of the polynomial
z a z a2
1 2
a e hh
1
2
02 10 w wcos
a e h
2
2 0 w
These formulas are useful to establish specifications.
Controlo por Computador 128
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Zero mapping
There is no simple rule to mapp the zeros.
A continuous time minimum phase system can be mapped into a non-
minimum-phase system (in which there are zeros outside the unit circle) in
discrete time. This fact happens when decreasing the sampling interval.
Decreasing the sampling rate is not always a good decision (opposite to signal
processing).
See exemples AW pp. 73-75
Controlo por Computador 129
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Sampling the state model
Given the continuous state model:
)()(
)()()(
tCxty
tbutAxtx
What is the model “seen” in discrete time?
Controlo por Computador 130
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Obtaining the sampled state model
Definition of the sampling instants ( h is the sampling period):
htt kk 1
Using the formula of variation of constants1:
1
11 )()()()()(
1
k
k
kkk
t
t
stA
k
ttA
k dssbuetxetx
If u is constant during each sampling period:
)()()(1
1 )(
1 k
t
t
stA
k
Ah
k tbudsetxetxk
k
k
1 Ver Controlo em Espaço de Estados
Controlo por Computador 131
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
)()()(1
1 )(
1 k
t
t
stA
k
Ah
k tbudsetxetxk
k
k
To compute the integral, make the change of variable stk 1:
h
A
h
A
t
t
stAded
d
dsedse
k
k
k
0
0
(1
1 )
Therefore
)()()(0
1 k
h
A
k
Ah
k tbudetxetx
Controlo por Computador 132
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
)()()(0
1 k
h
A
k
Ah
k tbudetxetx
Defining
Ahe
h
A bde0
The sampled state model is
)()(
)()()1(
kCxky
kukxkx
Controlo por Computador 133
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Approximation for fast sampling (small h ):
AhIeAh bhbAIbde h
h
A
0
2
02
This corresponds to approxima the derivative by finite differences:
)()()()1(
kbukAxh
kxkx
Controlo por Computador 134
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example: 1st
order system
)()()( tutxtx R ,0
he
10
h
h
ede
)(1)()1( kuekxekx hh
Controlo por Computador 135
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example: double integrator
uxdt
dx
1
0
00
10
xy 01
ht
Ah AsITLe
11
s
sAsI
0
1
2)det( sAsI (as expected!)
Controlo por Computador 136
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
s
s
s
sAsIadj
T
0
1
1
0)(
s
ss
AsI
AsIadjAsI
10
11
)det(
)( 21
10
111t
AsITL
Controlo por Computador 137
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
10
1 heAh
h
hdd
hh
211
0
10
12
00
End of example
Controlo por Computador 138
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
3.Parametric identification.
Parameter estimation.
Recursive and non-recursive methods.
Least squares and maximum likelihood.
Referência: AW cap. 13, FP
Controlo por Computador 139
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Fitting a curve to experimental data
An experimental situation:
We want to relate the current I with the
tension V in the circuit..
Apply different values of the tension and
register data
Tension [volt] Current [mA]
V1=1 I1=2.1
V2=2 I2=3.9
V3=3 I3=6.2
V4=4 I4=7.9
+
-V g=?
I
Controlo por Computador 140
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The model assumed:
I gV
g is a parameter to be estimated from data.
Due to experimental measuring errors, the data
Does not satisfy the model.
How to decide which is straight line that
best fits data?
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50
1
2
3
4
5
6
7
8
9
10
V [volt]
I [m
A]
Controlo por Computador 141
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
According to the Principle of Least Squares, the parameter is estimated such
as to estimate the sum of the squares of the deviations.
Accordingly, the estimate of g minimizes
J g g g g g( ) . . . . 21 1 39 2 6 2 3 7 9 42 2 2 2
What we expect to observe
given the model (depends on
the estimate g)
The actual
observation
Controlo por Computador 142
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Least squares cost J g( )
J(g)
g g^
Controlo por Computador 143
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Since J g( ) is a quadratic function of g , the least squares estimate verifies
1
20
dJ
dgg g
or
1 21 1 2 39 2 3 62 3 4 7 9 4 0. . . . g g g g
This equation simplifies to 60 1201 0 .g and the LS estimate is given by
.g 2 00
Controlo por Computador 144
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Ajuste de uma recta a dados experimentais (Caso geral)
Suponhamos que a relação teórica entre duas grandezas X e Y é do tipo
Y X
em que é um parâmetro desconhecido que se pretende estimar.
Repare-se que, conhecendo uma estimativa de podemos responder a
perguntas do tipo "Se X valer … quanto se espera que valha Y ? "
Controlo por Computador 145
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Suponhamos que são observados n pares X Y i ni i, , , , 1 correspondentes a
outros tantos ensaios experimentais. Dispõe-se da tabela
Y
X1 Y1
X2 Y2
X3 Y3
X4 Y4
X5 Y5
X
Controlo por Computador 146
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Pretende-se estimar a recta melhor ajustada aos dados experimentais, de
acordo com o critério de mínimos quadrados.
De acordo com esta critério, a estimativa é
tal que minimiza a soma dos quadrados dos
desvios:
J Y Xi i
i
n
( )
2
1
O que estamos à
espera que seja Yi
O que efectivamente
observamos
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50
1
2
3
4
5
6
7
8
9
10
V [volt]
I [m
A]
Desvio i
Xi
Yi
Controlo por Computador 147
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
A estimativa de mínimos quadrados verifica a equação (eq. "normal"):
1
20
dJ
d
ou seja
X Y Xi i i
i
n
1
0
Esta equação tem por solução
X Y
X
i ii
n
ii
n
1
2
1
Controlo por Computador 148
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Minimum or not?
A condição 1
20
dJ
d
não garante necessariamente que J( ) seja mínimo
para . É necessário impor uma condição na segunda derivada:
d J
dX i
i
n2
2
2
1
0
Neste exemplo, esta condição é verificada se for feita pelo menos uma
medida com X 0 (o que tem uma interpretação geométrica imediata).
Veremos a seguir que se estimarmos mais do que um parâmetro a segunda
derivada deixa de ser um escalar. A condição de mínimo é então a de que os
dados sejam tais que a matriz de segundas derivadas seja definida positiva.
Controlo por Computador 149
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Bom, ou apenas óptimo?
A estimativa de mínimos quadrados é "óptima" no sentido em que minimiza
um funcional de custo. No entanto, o funcional de custo pode não ser o mais
adequado.
Como caricatura, pode dizer-se que os bons relógios são os que estão
parados pois dão horas absolutamente certas duas vezes por dia.
Um outro exemplo é o de um caçador que vê dois pombos. Se disparar para o
ponto que minimiza a distância média quadrática aos dois pombos…
Isto sugere que por vezes são necessários outros critérios.
Controlo por Computador 150
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Outros critérios de Estimação
Ops exemplos anterios sugerem a utilidade de utilizar critérios que
ultrapassem as limitações dos Mínimos Quadrados. Um dos mais utilizados
em Estimação é o critério de Máxima Verosimilhança.
No entanto, quando a motivação é o Controlo Adaptativo, os Mínimos
Quadrados gozam (quando integrados num sistema de controlo em cadeia
fechada) de propriedades que os tornam suficientes para muitas aplicações.
São além disso simples e de convergência robusta.
Controlo por Computador 151
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Carl Frederich Gauss (1777-1855) utilizou pela primeira vez
o critério de mínimos quadrados para a estimação de
parâmetros em equações.
Em 1801, o astronomo italiano Piazzi observou pela primeira
vez um pequeno planeta denominado Ceres. Infelizmente, a
duração das observações era muito curta devido a Ceres se
ser escondido atrás do Sol, pelo que estas eram insuficientes para estimar os
parâmetros da sua órbita pelos métodos tradicionais. Recorrendo ao critértio
dos mínimos quadrados, Gauss efectuou uma estimativa (bastante diferente
das obtidas pelos métodos clássicos) que foi brilhantemente confirmada pelas
observações experimentais.
Controlo por Computador 152
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
What is the least squares estimate of the
Gravity acceleration g ?
Model: h gt
e 2
2
t [s] h [m]
1 8.49
2 20.05
3 50.65
4 72.19
5 129.85
6 171.56
h(t)
0
Controlo por Computador 153
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Parameter estimates in difference equations
Model:
y t a y t a y t n b u t b u t mn m( ) ( ) ( ) ( ) ( ) 1 01 1 1
Problem: From samples of u and y , estimate parameters a bi j,
u y
ESTIMADOR
Sistema a
Identificar
Controlo por Computador 154
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example
Consider the model
)1()()()1( kekbukayky
Data
y kk
2
1
1000
30( )
u kk
2
1
1000
50( )
y k y kk
( ) ( )
1 11
1000
y k u kk
( ) ( )
1 361
1000
y k u kk
( ) ( )
201
1000
Find the LS estimate of parameters a and b
Write the LS functional
Compute the partial derivatives of the cost with respect to the parameters and equate to zero
White noise; corresponds
To model deviations
Controlo por Computador 155
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
J y k ay k bu kk
N
1
21
2
1
( ) ( ) ( )
J
ay k y k ay k bu k
k
N
( ) ( ) ( ) ( )1 01
J
bu k y k ay k bu k
k
N
( ) ( ) ( ) ( )1 01
( ) ( ) ( ) ( ) ( )a y k b y k u k y k y kk
N
k
N
k
N2
1 1 1
1
30 20 1 a b
( ) ( ) ( ) ( ) ( )a u k y k b u k u k y kk
N
k
N
k
N
1
2
1 1
1 20 50 36 a b
. .a b 0 61 0 964
Controlo por Computador 156
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Matrix notation
y t a y t a y t n b u t b u t m e tn m( ) ( ) ( ) ( ) ( ) ( ) 1 01 1 1
Define the regressor , ,by
( ) ( ) ( ) ( ) ( )t y t y t n u t u t m1 1 1 1
And the vector of parameters to estimate, , by
a a b bn m1 1
The model is written (linear regression model)
y t t e t( ) ( ) ( ) 1
Controlo por Computador 157
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Least Squares Criteria
Given N observations, estimate the vector of parameters o by a vector by
minimizing:
JN
y t tt
N
( ) ( ) ( )
1
21
2
1
Controlo por Computador 158
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
y
y
y N N
e
e
e N
( )
( )
( )
( )
( )
( )
1
2
0
1
1
1
2
y
y
y N N
e
e
e N
( )
( )
( )
( )
( )
( )
1
2
0
1
1
1
2
Controlo por Computador 159
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
y
y
y N N
e
e
e N
( )
( )
( )
( )
( )
( )
1
2
0
1
1
1
2
The set of N observations verifies
y
y N 1
N np np 1
N 1
Controlo por Computador 160
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Another way to write the LS functional
JN N
1
2
1
2
2
Since:
y
It is:
JN
y y 1
2
JN
y y y 1
22
Controlo por Computador 161
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The least squares estimate satisfies
J 0
Gradient of a quadratic form
x x Ax x A2
Recall that
JN
y y y 1
22
Therefore
JN
y1
22 2
Controlo por Computador 162
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The least squares estimate satisfies the equation
0222
1 y
NJ
or
y
Computing the transpose
y
Controlo por Computador 163
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Normal equation
The least squares estimate of the parameter vector in the linear regression
model
y t t e t( ) ( ) ( ) 1
Satisfies the normal equation
y
If the inverse of exists, the least squares estimate is unique and is given
by
1
y
Controlo por Computador 164
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example - Invertibility of the matrix
Consider the system
y k b u k b u k e k( ) ( ) ( ) ( ) 0 11 2
a) is it possible to find estimates of b0 and b1 when the input is always
u k k( ) 1 ?
b) What about if we know that b1 0 ?
c) And if u( )0 0 and u k k( ) 1 1?
Suggestion: Write the matrix when N=4 and then consider what happens
with higher values of N.
Zero mean
noise
Controlo por Computador 165
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Condições de Excitação Persistente
Para que a estimativa de mínimos quadrados exista e seja única é necessário
que a matriz seja definida positiva. Caso contrário o funcional de
mínimos quadrados não tem um mínimo.
A matriz é definida positiva se os dados forem suficientemenbte ricos, o
que depende da entrada do sistema.
As condições na entrada do sistema que levam a que 0 dizem-se
condições de excitação persistente.
Controlo por Computador 166
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Estimation error covariance matrix and information matrix
Definition of the error covariance matrix
P E
When the residuals forma white sequence, it is true that:
i)The least squares estimate is unbiased:
E 0
ii)When the variance of the residuals is 1:
P
1
Controlo por Computador 167
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
This fact motivates the definition of the information matrix by
P 1
Controlo por Computador 168
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Recursive Estimator
Objective: Obtain the current estimate by combining the previous estimate with
the most recent data, without the need to writte the normal equation
RLS = Recursive Least Squares
RLS
New data
y t t( ), ( ) 1
Previous estimate ( )t 1
and auxiliary variables
P t( )1
New estimate ( )t and
auxiliary variables P t( )
Controlo por Computador 169
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Non-recursive estimator given t observations:
( ) t y
1
Can be written as:
( ) ( ) ( ) ( ) t t y k kk
t
1
1
1
Where the information matrix is
( ) ( ) ( )t k kk
t
1 11
Controlo por Computador 170
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The information matrix verifies
( ) ( ) ( ) ( )t t t t 1 1 1 (1)
Furthermore
( ) ( ) ( ) ( ) t t y k kk
t
1
1
1 (2) e
( ) ( ) ( ) ( )t t y k kk
t
11
(3)
We want: Write ( ) t as a function of ( ) t 1 , ( )t , y t( ) and ( )t 1
Sugesttion: Isolate the last term of the sum in (2).
Writte (3) for t 1;
use (1);
Controlo por Computador 171
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
( ) ( ) ( ) ( ) t t y k kk
t
1
1
1
( ) ( ) ( ) ( ) ( ) ( ) t t y k k y t tk
t
1
1
1
1 1
( ) ( ) ( ) ( )t t y k kk
t
1 1 11
1
( ) ( ) ( ) ( ) ( ) ( ) t t t t y t t 1 1 1 1
Controlo por Computador 172
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
( ) ( ) ( ) ( ) ( ) ( ) t t t t y t t 1 1 1 1
( ) ( ) ( ) ( )t t t t 1 1 1
Therefore:
( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) t t t t t t t y t t 1 1 1 1 1 1
( ) ( ) ( ) ( ) ( ) ( ) ( ) t t t t y t t t 1 1 1 11
Controlo por Computador 173
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The equations of the recursive estimator are:
( ) ( ) ( ) ( ) ( ) ( ) ( ) t t t t y t t t 1 1 1 11
( ) ( ) ( ) ( )t t t t 1 1 1
Drawback: We need to invert a matrix in each iteration.
Difference between what we expect to be the
output y(t) given the estimate and what we
really observe.
New
estimate Previous
estimate Vector gain
We need to invert a matrix in
each iteration
Controlo por Computador 174
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Is it possible to avoid matrix inversion?
( ) ( ) ( ) ( ) ( ) ( ) ( ) t t t t y t t t 1 1 1 11
( ) ( ) ( ) ( )t t t t 1 1 1
In terms of the covariance the equations become:
( ) ( ) ( ) ( ) ( ) ( ) ( ) t t P t t y t t t 1 1 1 1
P t t t t( ) ( ) ( ) ( )
1 1 11
Controlo por Computador 175
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
P t t t t( ) ( ) ( ) ( )
1 1 11
Matrix inversion lemma
A BCD A A B DA B C DA
1 1 1 1 1
11
Apply this lemma with
A t P t 1 1 1 1 ( ) ( ) , B t ( )1 , C 1, D t ( )1
We get:
)1()1(1)1()1()1()1()1()1()(1
tPtttPtttPtPtP
Scalar
Controlo por Computador 176
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Recursive Least Squares algorithm (RLS)
Model:
y t t e to( ) ( ) ( ) 1
Estimator:
( ) ( ) ( ) ( ) ( ) ( ) t t K t y t t t 1 1 1
K t P t t( ) ( ) ( ) 1 "Kalman gain"
P t P tP t t t P t
t P t t( ) ( )
( ) ( ) ( ) ( )
( ) ( ) ( )
1
1 1 1 1
1 1 1 1
"Riccati equation"
Controlo por Computador 177
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Using algebraic manipulations, the Kalman gain and the Riccati equation can
be written as:
K tP t t
t P t t( )
( ) ( )
( ) ( ) ( )
1 1
1 1 1 1
P t I K t t P t( ) ( ) ( ) ( ) 1 1
The RLS parameter estimation algorithm is a special case of the Kalman filter.
Controlo por Computador 178
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example: Recursive estimation of a parameter
0 20 40 60 80 100 120 140 160 180 2000
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
Ganho fixo=0.03
Ganho fixo=0.5
Ganho de Kalman
y t t e to
o
( ) ( ) ( )
1
2
Estimator gain:
High Fast initial convergence but high
fluctuations in steady-state.
Low slow convergence.
The Kalman gain is initially high and
then decreases.
Controlo por Computador 179
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
MATLAB code for the example
thrls=0;
thsm=0;
thbig=0;
p=10;
theta0=2;
tfinal=200;
for t=1:tfinal
pp(t)=p;
fi=1+0.1*rand;
y=theta0*fi+0.2*randn;
p=p-p*fi*fi*p/(1+fi*p*fi);
kalm=p*fi;
thrls=thrls+kalm*(y-thrls*fi);
thsm=thsm+0.03*(y-thsm*fi);
thbig=thbig+0.5*(y-thbig*fi);
sth(t,1)=thrls;
sth(t,2)=thsm;
sth(t,3)=thbig;
end;
axis([0 tfinal 0 5])
hold on
plot(sth)
hold off
Controlo por Computador 180
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
0 20 40 60 80 100 120 140 160 180 20010
-3
10-2
10-1
100
101
This example illustrates the convergence of the RLS algorithm
Initially, since our uncertainty about our true value of the parameter to estimate
is high, we select a high value for the
covariance, in this case P 10.
The Kalman gain is high and the convergence
is fast.
As time goes on and we receive more data, P
decreases and the kalman gain also, causing
the convergence of the estimates.
Controlo por Computador 181
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The estimator may be envisaged as a
Mechanism that reduces our
uncertainty about the true value of the
parameter through the observations.
The uncertainty is measured by the
Probability density function of the
Estimation error.
In this example the uncertainty is
described by a gaussian pdf with
variance proportional to P .
0 0.5 1 1.5 2 2.5 3 3.5 40
1
2
3
4
5
6
Parameter probability density
given 200 observations
Initial parameter probability
density function
Controlo por Computador 182
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
An example with unidentifiable parameters
Increasing the number of observations, we reduce the uncertainty about the
sum, but there is a high uncertainty in the perpendicular direction.
-5 -4 -3 -2 -1 0 1 2 3 4 5-5
-4
-3
-2
-1
0
1
2
3
4
5
y k b u k b u k e k( ) ( ) ( ) ( ) 0 11 2
Only the sum can be identified
Parameter
probability
density
Controlo por Computador 183
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
An example of unidentifiable parameters in closed loop
Process model:
y t ay t bu t e t( ) ( ) ( ) ( ) 1 1 (*)
This system is coupled with the controller:
u t Ky t( ) ( )
Let be an arbitrary constant. From the controller definition
u t Ky t( ) ( ) 0
Since u t Ky t( ) ( ) 0 , we can add this quantity to (*) and obtain:
y t a K y t b u t e t( ) ( ) ( ) ( ) ( ) ( ) 1 1
Controlo por Computador 184
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Therefore, the controlled system is described by any model of the form
y t a K y t b u t e t( ) ( ) ( ) ( ) ( ) ( ) 1 1
This fact shows that any parameters �� and �� that satisfy
a a K b b
Lead to the same input/output relation. Eliminating , we obtain the following
relation between the parameters to estimate
b bK
a a 1
Any estimate ( , )a b that verifies this condition descries the data equally well.
Controlo por Computador 185
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The estimates belong to the straight line, but they are not equal to the true
process values. In to obtain estimates close to the true ones, we can either
Change the controller gain K
Add an external signal to the control action
a
b1/K
a
^
b
Controlo por Computador 186
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Sleeping in RLS
If the data is adequate, the entries of the Kalman gain decrease and may
become very small.
From this point on, the estimates become approximately constant. If the
system to identify changes, it takes a long time for the estimates to converge
to a new value.
We say that the algorithm is “sleeping”.
Controlo por Computador 187
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Exponential forgetting
Sleeping in RLS happens because the algorithm weights equaly recent data
and remote past data.
To avoid this effect, the least squares functional is modified to include an
exponential weight that weights less the observations in the past:
J y t kt k
k
t
1
21
2
1
( ) ( )
is called the forgetting factor. It satisfies 0 1
Exponential weight, smaller for oldest data
Controlo por Computador 188
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Assimptotic memory
The asymptotic memory N provides an idea of the number of data points that
influence the current estimate.
N
1
1
samll -> Small # data retained; “agile” to track parameter changes
big -> Many data points retained; the algorithm is more slow to track
changes but is more precise
N
1
0.99 100
0.98 50
0.95 20
Controlo por Computador 189
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
RLS with exponential forgetting
Minimizes the cost functional with exponential forgetting.
( ) ( ) ( ) ( ) ( ) ( ) t t K t y t t t 1 1 1
K tP t t
t P t t( )
( ) ( )
( ) ( ) ( )
1 1
1 1 1
P t I K t t P t( ) ( ) ( ) ( ) / 1 1
Show that these equations minimize the weighted functional.
Observe that the information matrix is updated according to
( ) ( ) ( ) ( )t t t t 1 1 1
Controlo por Computador 190
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Covariance windup
We want to estimate parameters a and b in the model
y t ay t bu t e t( ) ( ) ( ) . ( ) 1 01 1
The true value of the parameters is
a 06. b 01.
(In practice, you never know the true value; it is used here for comparison!)
Use RLS with exponential forgetting and 095.
Consider two different situations for the input 𝑢:
Constant input
Constant input added with a white noise signal (dither noise)
Controlo por Computador 191
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Results with a constant input
Initially, the trace of 𝑃 decreases and the estimate approaches its true value
of a 06. . However, since the system is not excited and a forgetting factor is
used, 𝑃 starts to increase, leading to an increase of the Kalman gain and
strong fluctuations of the estimate.
0 50 100 150 200 250 3000
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0 50 100 150 200 250 30010
-1
100
101
102
103
104
tr(P)
a
Controlo por Computador 192
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Results with a variable input
When the input 𝑢 is sufficiently exciting, the trace of 𝑃 does go up again due to
forgetting (because there is new information arriving) and the estimate is kept
close to the true value, although with fluctuations.
0 50 100 150 200 250 3000
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0 50 100 150 200 250 30010
-2
10-1
100
101
102
103
104
tr(P)
a
Controlo por Computador 193
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Time varying systems
0 50 100 150 200 250 3000
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Lbd=0.99
Lbd=0.95
The parameter a changes at t=100 from
0.6 to 0.8.
The figure shows the results with two
different values of the forgetting factor.
When 𝜆 is smaller, the adaptation of the
estimate to the new value is faster, but
the steady-state estimate has more
fluctuations.
Controlo por Computador 194
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Other types of forgetting algorithms
Variable forgetting factor. The forgetting factor is close to 1 when the
power of the residues is low and is decreased when the power increases.
Directional forgetting. The forgetting factor acts only proportionally to the
direction of the incoming information to avoid forgetting about parameters for
which no new information is available.
Controlo por Computador 195
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Numerically robust algorithms
The equations for the RLS that have been presented are not numerically
robust. One way to solve this problem is to use Bierman’s UD algorithm in
which what is propagated are matrices 𝑈 (an upper triangular matrix with 1’s in
the diagonal) and 𝐷 (a diagonal matrix), such that P UDU T .
The positive definite and symmetric characters of 𝑃 are ensured in this way.
Furthermore, since 𝑈 is a kind of square-root of 𝑃, the range of numbers used
by the algorithm is smaller, a fact that increases the relative precision and
reduces numerical problems.
Chapter 13 of AW includes a PASCAL procedure for this algorithm.
Controlo por Computador 196
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
The effect of colored noise
0 100 200 300 400 500 600 700 800 900 10000.2
0.3
0.4
0.5
0.6
0.7
0.8
Ruído colorido
Ruído branco
Valor verdadeiro
When the noise is white the estimate is
unbiased, i. e., the mean of the error is
zero.
This is no longer true when the noise is
colored. The figure shows the estimate
of parameter a in
y t ay t bu t e t ce t( ) ( ) ( ) ( ) ( ) 1 1
when c 0 and when c 095.
Controlo por Computador 197
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Asymptotic behavior of the least squares estimator
Question: Does the LS estimate converge to the true value of the parameters?
True model:
)()()( 0 tvtty
The least squares estimate is
N
t
N
t
tytttN1
1
1
)()()(')()(ˆ
Controlo por Computador 198
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
)()()( 0 tvtty
N
t
N
t
tytttN1
1
1
)()()(')()(ˆ
N
t
N
t
tvttttN1
0
1
1
)()(')()(')()(ˆ
And hence
N
t
N
t
tvtN
ttN
N1
1
1
0 )()(1
)(')(1
)(ˆ
The LS estimate is given by the true value added to a bias.
Under what conditions is the bias zero?
Controlo por Computador 199
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
In order for the LS estimate to be unbiased, i. e.
0)(ˆ ENE
It must be
0)()(1
N
t
tvtE
In general, this happens if )(tv is uncorrelated with )(,),1( ntyty , which
is equivalent to:
)(tv must be uncorrelated with ),2(),1( tvtv
For the LS estimate to be unbiased the noise must be white.
Controlo por Computador 200
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Examplo
Consider the process described by the ARMAX model
𝑦(𝑡) = 𝑎𝑦(𝑡 − 1) + 𝑏𝑢(𝑡 − 1) + 𝑒(𝑡) + 𝑐𝑒(𝑡 − 1)
where u and e are white and independent, with zero mean and unit variance.
Find the LS estimates a and b as a function of cba ,, .
Sugestion: )()()( 0 tvtty
N
t
N
t
tytN
ttN
N1
1
1
)()(1
)(')(1
)(ˆ
Assume valid the approximations
)(')()(')(1
1
ttEttN
N
t
)()()()(
1
1
tytEtytN
N
t
Controlo por Computador 201
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
)1()()1()1()( tcetetbutayty
)1()()1(
)1()(
tcete
tu
tybaty
0' )1( t
)(tv
Controlo por Computador 202
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
𝜑(𝑡 − 1) = [𝑦(𝑡 − 1) 𝑢(𝑡 − 1)]𝑇 𝜃 = [𝑎 𝑏]𝑇
Leastquares estimate
�� = 𝐸[𝜑(𝑡 − 1)𝜑𝑇(𝑡 − 1)]−1. 𝐸[𝜑(𝑡 − 1)𝑦(𝑡)]
Calculus of the information matrix
Λ = 𝐸 {[𝑦(𝑡 − 1)
𝑢(𝑡 − 1)] [𝑦(𝑡 − 1) 𝑢(𝑡 − 1)]} =
= [𝐸[𝑦2(𝑡 − 1)] 𝐸[𝑦(𝑡 − 1)𝑢(𝑡 − 1)]
𝐸[𝑦(𝑡 − 1)𝑢(𝑡 − 1)] 𝐸[𝑢2(𝑡 − 1)]] = [
𝜎𝑦2 0
0 1]
Λ−1 = [
1
𝜎𝑦2 0
0 1
]
Controlo por Computador 203
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
𝐸[𝜑(𝑡 − 1)𝑦(𝑡)] = [𝐸[𝑦(𝑡)𝑦(𝑡 − 1)]
𝐸[𝑦(𝑡)𝑢(𝑡 − 1)]]
Use the model to observe that
𝐸[𝑦(𝑡)𝑢(𝑡 − 1)] = 𝐸[(𝑎𝑦(𝑡 − 1) + 𝑏𝑢(𝑡 − 1) + 𝑒(𝑡) + 𝑐𝑒(𝑡 − 1))𝑢(𝑡 − 1)] = 𝑏
Furthermore
𝐸[𝑦(𝑡)𝑦(𝑡 − 1)]
= 𝑎𝜎𝑦2 + 𝑏𝐸[𝑦(𝑡 − 1)𝑢(𝑡 − 1)] + 𝐸[𝑒(𝑡)𝑦(𝑡 − 1)] + 𝑐𝐸[𝑒(𝑡 − 1)𝑦(𝑡 − 1)]
= 𝑎𝜎𝑦2 + 𝑐
Finaly �� = [
1
𝜎𝑦2 0
0 1] [
𝑎𝜎𝑦2 + 𝑐
𝑏] = [
𝑎 +𝑐
𝜎𝑦2
𝑏]
Controlo por Computador 204
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Estimation in the presence of colored noise
In the presence of colored noise, least squares yield a biased estimate. This
fact means that, after many observations, the estimate does not approximate
the true parameter value.
Methods to solve the problem:
Instrumental Variables
Extended Least Squares
Maximum Likelihood
Of these, ML is the most general and powerful, although the most heavy from
the computational point of view.
Controlo por Computador 205
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Extended least squares
Heuristic generalization of least squares for ARMAX models:
)()(')( tvtty o )()1()()( 1 ntectectetv n )(te white
Assume that, at time 𝑡 the following estimates are available
)(,),1( ntt of )(,),1( ntete
The estimate )(t of )(te can be computed from
nc
cnttttyt
ˆ
ˆ
ˆ
)()1()(')()( 1
Controlo por Computador 206
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
)()1()()(')( 1 ntectectetty no
Let
)()1()(':)(' nttttes nes cc ˆˆ'ˆ:'ˆ 1
The extended LS estimate is computed according to
)(ˆ)(')()()()1(ˆ tttytKtt eseseseses
)(tKes is the Kalman gain that corresponds to the regressor )(tes .
Finally:
)(ˆ)(')()( tttyt es
Controlo por Computador 207
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Maximum Likelihood method
Let y be a random variable (r.v.) whose probability density function ),( yp
depends on an unknown parameter
We want to estimate as a function of the observations of y and assuming
that we know the function ),( yp .
It is remarked that ),( yp becomes a function of only when an
observation y is made.
Controlo por Computador 208
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Maximum likelihood estimator
Given an observation y choose the value of that maximizes the likelihood
function defined as
),(:),( ypyL
Or, equivalently
,log yL
Thus
,logmaxˆ yLML or 0,log ˆ
ML
yL
Controlo por Computador 209
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example
)()( tety
is an unknown constant that we want to estimate from observations of y
(corrupted by the noise )(te ).
At each time t the pdf of e is
2
)(2
1exp
2
1)( eep te
)(),( 2121tetett independent r.v. (white noise)
We want to estimate by the method of maximum likelihood, as a function of
')()1( tyyY .
Controlo por Computador 210
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Sugestion
Let 1x and 2x be independent r.v. Then
)()(),(2121 xxxx ppp
Considering this fact and the form of the pdf of )(ty , compute the joint pdf of
the vector of observations Yp (that depends on ).
Take the logarithm and equate the derivative to zero.
Controlo por Computador 211
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Considering the observation model, for each observation:
2
)( ))((2
1exp
2
1)),((
tytyp ty
Since the )(te are independent for different 𝑡
t
i
iyY iypYp1
)( )),((),(
Therefore,
t
itY iyYp
1
2
2/))((
2
1exp
2
1),(
Controlo por Computador 212
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
t
itY iyYp
1
2
2/))((
2
1exp
2
1),(
t
i
Y iyt
Yp1
2)(
2
12log
2,(log
The maximum likelohoiod estimate satisfies
0ˆ,(log
MLY Yp
or
0ˆ)(1
t
i
MLiy and the ML estimate is
t
i
ML iyt 1
)(1
Controlo por Computador 213
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Properties of the ML estimator
Consistency
-20 -10 0 10 20 30 400
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
N muito grande
N grande
N pequeno
o
p(
ML)
ML
Controlo por Computador 214
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Cramer-Rao bound
The precision of an unbiased estimator is bounded by the Cramer-Rao
inequality: 1 JP
T
ooEP )ˆ)(ˆ( is the estimation error covariance matrix
LEJ log
2
2
is Fisher information matrix
The ML estimator is asymptotically efficient, i. e., when the number of
observations grows unbound, the error covariance matrix approaches the
Cramer-Rao bound.
Controlo por Computador 215
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Estimation with MATLAB
z=[y u];
na=4;
nb=1;
nc=4;
nk=1;
nn=[na nb nc nk];
th=armax(z,nn);
yh=idsim(u,th);
plot(t,[y yh]);
[Phi,Gamma,C,D,K,X0]=th2ss(th);
T=0.05;
[A,B]=d2c(Phi,Gamma,T);
[num,den]=ss2tf(A,B,C,D);
The function armax approximates ML estimates. It is suitable for colored noise
Least squares estimates are obtained with the function arx
Controlo por Computador 216
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
A simple example with colored noise (simulation)
0 20 40 60 80 100 120 140 160 180 200-2
-1
0
1
2Mínimos Quadrados
0 20 40 60 80 100 120 140 160 180 200-2
-1
0
1
2Máxima Versomilhança
Controlo por Computador 217
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Example: Identification of a flexible bar
We want to identify the model from experimental data.
M otor
B raçoflexível
V eiodo m otor
D/A
A m pl i ficadorde potência
S ensor A /D
u
y
Medida do ângulo doveio do motorC
Controlador doângulo doveio do motor
Dinâmica domotor controlado
Dinâmica da barraflexível
Comandodo motor
Posição doveio do motor
Posição daponta da barra
Controlo por Computador 218
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Open loop step response
2490 2500 2510 2520 2530 2540 2550 2560 2570 2580 2590 2600
-8
-6
-4
-2
0
2
4
6
8
Tempo [número da amostra]
y
Output data
What features can we see in
the response?
Controlo por Computador 219
J. Miranda Lemos IST-DEEC, Área Científica de Sistemas, Decisão e Controlo
Response features
Oscillatory with small damping. (conjugate poles)
High frequency oscillation. (add conjugate poles in high frequency)
Nonminimum phase zero