# Control Systems/Estimators and Observers

## Estimators and Observers

A problem arises in which the internal states of many systems cannot be
directly observed, and therefore state feedback is not possible. What we
can do is try to design a separate system, known as an **observer** or
an **estimator** that attempts to duplicate the values of the state
vector of the plant, except in a way that is observable for use in state
feedback. Some literature calls these components \"observers\", although
they do not strictly observe the state directly. Instead, these devices
use mathematical relations to try and determine an estimate of the
state. Therefore, we will use the term \"estimator\", although the terms
may be used interchangeably.

### Creating an Estimator

There are several observer structures including Kalman\'s, sliding mode,
high gain, Tau\'s, extended, cubic and linear observers. To illustrate
the basics of observer design, consider a linear observer used to
estimate the state of a linear system. Notice that we know the *A*, *B*,
*C*, and *D* matrices of our plant, so we can use these exact values in
our estimator. We know the input to the system, we know the output of
the system, and we have the system matrices of the system. What we do
not know, necessarily, are the initial conditions of the plant. What the
estimator tries to do is make the estimated state vector approach the
actual state vector quickly, and then mirror the actual state vector. We
do this using the following system for an observer:

$$\hat{x}' = A\hat{x} + Bu + L(y - \hat{y})$$

$$\hat{y} = C\hat{x} + Du$$

*L* is a matrix that we define that will help drive the error to zero,
and therefore drive the estimate to the actual value of the state. We do
this by taking the difference between the plant output and the estimator
output.

![](State_Feedback_with_Estimator.svg "State_Feedback_with_Estimator.svg"){width="500"}

In order to make the estimator state approach the plant state, we need
to define a new additional state vector called *state error signal*
$e_x(t)$. We define this error signal as:

$$e_x(t) = x - \hat{x}$$

and its derivative:

$$e_x'(t) = x' - \hat{x}'$$

We can show that the error signal will satisfy the following
relationship:

$$e_x'(t) = Ax + Bu - (A\hat{x} + Bu + L(y - \hat{y}))$$

$$e_x'(t) = A(x- \hat{x}) - L(Cx - C\hat{x})$$

$$e_x'(t) = (A - LC)e_x(t)$$

We know that if the eigenvalues of the matrix *(A - LC)* all have
negative real parts that:

$$e_x(t) = e^{(A - LC)(t-t_0)}e_x(t_0) \to 0$$ when $t \to \infty$. This
$e_x(\infty) = 0$ means that the difference between the state of the
plant $x(t)$ and the estimated state of the observer $\hat{x}(t)$ tends
to fade as time approaches infinity.

### Separation Principle

We have two equations:

$$e_x[k + 1] = (A - LC)e_x[k]$$

$$x[k + 1] = (A - BK)x[k] + BK \cdot e_x[k]$$

We can combine them into a single system of equations to represent the
entire system:

$$\begin{bmatrix}e_x[k + 1] \\ x[k + 1]\end{bmatrix} = \begin{bmatrix}A - LC & 0 \\ +BK & A - BK\end{bmatrix} \begin{bmatrix}e_x[k] \\ x[k]\end{bmatrix}$$

We can find the characteristic equation easily using the **separation
principle**. We take the Z-Transform of this digital system, and take
the determinant of the coefficient matrix to find the characteristic
equation. The characteristic equation of the whole system is: (remember
the well known $(zI-A)^{-1}$)

$$\begin{vmatrix}zI - A + LC & 0 \\ -BK & zI - A + BK\end{vmatrix} = |zI - A + LC| |zI - A + BK|$$

Notice that the determinant of the large matrix can be broken down into
the product of two smaller determinants. The first determinant is
clearly the characteristic equation of the estimator, and the second is
clearly the characteristic equation of the plant. Notice also that we
can design the *L* and *K* matrices independently of one another.

It is worth mentioning that if the order of the system is *n*, this
characteristic equation (full-order state observer plus original system)
becomes of order *2n* and so has twice the number of roots of the
original system.

### The L Matrix

You should select the *L* matrix in such a way that the error signal is
driven towards zero as quickly as possible. The transient response of
the estimator, that is the amount of time it takes the error to
approximately reach zero, should be significantly shorter than the
transient response of the plant. The poles of the estimator should be,
by rule of thumb, at least 2-6 times faster then the poles of your
plant. As we know from our study of classical controls, to make a pole
faster we need to:

S-Domain:Move them further away from the imaginary axis (in the Left Half Plane!).\
Z-Domain:Move them closer to the origin.

Notice that in these situations, the faster poles of the estimator will
have less effect on the system, and we say that the plant poles dominate
the response of the system. The estimator gain *L* can be computed using
the dual of **Ackerman\'s formula** for selecting the gain *K* of the
state feedback controller:

$$L = \alpha_e(z)Q\begin{bmatrix}0\\0\\ \vdots \\1\end{bmatrix}$$

Where *Q* is the observability matrix of the plant, and α~e~ is the
characteristic equation of your estimator.

This can be computed in MATLAB with the following command:

`L=acker(A', C', K)';`

where L is the estimator gain and K is the poles for the estimator.

### Composite System

Once we have our *L* and *K* matrices, we can put these together into a
single composite system equation for the case of state-feedback and zero
input:

$$\begin{bmatrix}x[n + 1]\\ \bar{x}[n+1]\end{bmatrix} = \begin{bmatrix} A & -BK \\ LH & A - BK - LH\end{bmatrix} \begin{bmatrix}x[n] \\ \bar{x}[n]\end{bmatrix}$$

$$u[n] = -K \bar{x}[n]$$

Taking the Z-Transform of this discrete system and solving for an
input-output relation gives us:

$$\frac{U(z)}{Y(z)} = -K[zI - A + BK +L C]^{-1}L$$

Notice that this is not the same as the transfer function, because the
input is on top of the fraction and the output is on bottom. To get the
transfer function from this equation we need to take the inverse of both
sides. The determinant of this inverse will then be the characteristic
equation of the composite system.

Notice that this equation gives us the ability to derive the system
input that created the particular output. This will be valuable later.

## Reduced-Order Observers

In many systems, at least one state variable can be either measured
directly, or calculated easily from the output. This can happen in the
case where the *C* matrix has only a single non-zero entry per system
output.

If one or more state variables can be measured or observed directly, the
system only requires a **reduced-order observer**, that is an observer
that has a lower order than the plant. The reduced order observer can
estimate the unmeasurable states, and a direct feedback path can be used
to obtain the measured state values.

