---
title: Observability and state observers
heading: When the outputs reveal every state, the observability matrix, the Luenberger observer and its error dynamics, choosing observer poles, duality with state feedback, and the separation principle for output feedback
eyebrow: S9 · Lesson 37 · Observability and state observers
xp: 50
---

::: hook
State feedback needs every state, but sensors cost money and some states, like a motor's flux or a rotor's speed in a sensorless drive, can't be measured at all. The fix is to run a model of the plant alongside it, feed the model the same input, and correct the model continuously with the difference between the measured output and the model's prediction. David Luenberger described this observer in 1964. When the outputs carry enough information, a property called observability, the model's state converges to the real one, and feeding back the estimate works almost as well as feeding back the truth.
:::

::: play
- An observer for a double integrator that measures only position: the plot shows the estimation errors after the velocity estimate starts off by 1.
- The error obeys $s^2 + l_1s + l_2$: $l_2$ sets the observer's natural frequency ($\sqrt{l_2}$) and $l_1$ its damping.
- The position error starts at zero but grows briefly before the observer pulls both back: the observer learns the velocity by watching the position drift.
:::

```sim plot
view: graph
x: t = 0..2 s
y: e = -0.4..1.1
slider: l = 2..40 = 14 log
slider: m = 4..400 = 100 log
plot: Re(exp(-l/2*t)*sin(sqrt(m - l^2/4 + 0*j)*t)/sqrt(m - l^2/4 + 0*j)) | samples: 600 | label: position error
plot: Re(exp(-l/2*t)*(cos(sqrt(m - l^2/4 + 0*j)*t) + l/2*sin(sqrt(m - l^2/4 + 0*j)*t)/sqrt(m - l^2/4 + 0*j))) | samples: 600 | color: ch3 | label: velocity error
readout: observer natural frequency, rad/s = sqrt(m) | digits: 3
readout: observer damping ratio = l/(2*sqrt(m)) | digits: 3
```

::: predict
## A system has two decoupled states, $\dot{x}_1 = -x_1$ and $\dot{x}_2 = -2x_2$, and only $x_1$ is measured. Can an observer estimate $x_2$?

- [ ] Yes, with a high enough observer gain
- [x] No: nothing about $x_2$ ever reaches the output
- [ ] Only if $x_2$ is unstable
- [ ] Only in steady state

::: reveal
$x_2$ never affects y, so no processing of y can recover it. The observability matrix $\begin{pmatrix} C \\ CA \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ -1 & 0 \end{pmatrix}$ has rank 1. Because $x_2$ is stable the model's guess still converges, at the plant's own rate, but the observer can't speed that up. Such a system is **detectable** but not observable.
:::
:::

::: nameit
## Observability

$\dot{x} = Ax + Bu$, $y = Cx$ is **observable** if the initial state can be found from the output and input over a finite time. The test:

$$W_o = \begin{pmatrix} C \\ CA \\ \vdots \\ CA^{n-1} \end{pmatrix} \text{ has rank } n$$

## The observer

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

The error $e = x - \hat{x}$ obeys $\dot{e} = (A - LC)e$, independent of the input. If the system is observable, L can place the eigenvalues of A − LC anywhere. That's the dual of state feedback: placing eig(A − LC) is placing eig($A^T - C^TL^T$), a state-feedback problem for the pair $(A^T, C^T)$.

For a double integrator measuring position, the error polynomial is $s^2 + l_1s + l_2$, so $l_1 = 2\zeta_o\omega_o$, $l_2 = \omega_o^2$.

## Choosing observer poles

Faster observer poles make the estimate converge sooner but amplify measurement noise, since a large L trusts each new measurement heavily. A common choice puts them two to six times faster than the controller's. The Kalman filter (lesson 39) chooses L optimally from the noise levels.

## The separation principle

Feed back the estimate, $u = -K\hat{x} + k_rr$. With states $(x, e)$ the closed loop is block triangular:

$$\begin{pmatrix} \dot{x} \\ \dot{e} \end{pmatrix} = \begin{pmatrix} A - BK & BK \\ 0 & A - LC \end{pmatrix}\begin{pmatrix} x \\ e \end{pmatrix} + \dots$$

so its eigenvalues are those of A − BK together with those of A − LC. The controller and the observer can be designed separately. (Separate design doesn't guarantee good robustness; lesson 39 comes back to this.)
:::

::: example
## The servo of lesson 34, $\ddot\theta = -62.5\dot\theta + 1250u$, measures only θ. Design an observer with $\omega_o$ = 200 rad/s and ζ = 0.7.

::: solution
1. **Error dynamics.** With $C = (1, 0)$:
   $$A - LC = \begin{pmatrix} -l_1 & 1 \\ -l_2 & -62.5 \end{pmatrix}$$
2. **Its characteristic polynomial.**
   $$\begin{aligned} &s^2 + (l_1 + 62.5)s \\ &\quad + 62.5l_1 + l_2 \end{aligned}$$
3. **Match the target.** For $\omega_o$ = 200 rad/s and ζ = 0.7 the target is $s^2 + 280s + 40{,}000$:
   $$\begin{aligned} l_1 &= 280 - 62.5 \\ &= 217.5 \\ l_2 &= 40{,}000 - 62.5 \times 217.5 \\ &= 26{,}406 \end{aligned}$$
4. **Speed.** The estimation error settles in about
   $$\begin{aligned} t_s &\approx \frac{4}{0.7 \times 200}\ \text{s} \\ &= 29\ \text{ms} \end{aligned}$$
   four times faster than the controller's poles at $\omega_n$ = 50.

**Answer:** $l_1$ = 217.5 and $l_2$ = 26,406, and the estimation error settles in about 29 ms.
:::
:::

::: example
## With the state feedback of lesson 34 and this observer, what are the closed-loop poles?

::: solution
1. **Separation principle.** The closed-loop poles are the controller's and the observer's together:
   $$\begin{aligned} &-35 \pm j35.7 \\ &-140 \pm j143 \end{aligned}$$
2. **Characteristic polynomial.** The fourth-order polynomial is
   $$\begin{aligned} &(s^2 + 70s + 2500) \\ &\times (s^2 + 280s + 40{,}000) \end{aligned}$$
3. **Where the observer poles show.** They don't appear in the response to the reference at all, since the estimation error isn't excited by r; they show up only after disturbances or a wrong initial estimate.

**Answer:** −35 ± j35.7 from the controller and −140 ± j143 from the observer.
:::
:::

::: example
## A heater obeys $\dot{x} = -0.1x + 0.05(u + d)$, where d is an unknown, constant heat loss. Only x is measured. Design an observer that also estimates d, with error poles at $\omega_o$ = 1 rad/s, ζ = 0.7.

::: solution
1. **Augment the state.** Treat d as a state with $\dot d = 0$:
   $$\begin{aligned} A &= \begin{pmatrix} -0.1 & 0.05 \\ 0 & 0 \end{pmatrix} \\ C &= (1\ \ 0) \end{aligned}$$
2. **Error polynomial.** With $L = (l_1, l_2)^T$:
   $$s^2 + (0.1 + l_1)s + 0.05l_2$$
3. **Match the target.** For $\omega_o$ = 1 rad/s and ζ = 0.7 the target is $s^2 + 1.4s + 1$:
   $$\begin{aligned} l_1 &= 1.3 \\ l_2 &= 20 \end{aligned}$$
4. **Use the estimate.** Feeding $-\hat d$ forward cancels the disturbance, which gives the loop integral action without an explicit integrator.

**Answer:** $l_1$ = 1.3 and $l_2$ = 20.
:::
:::

::: check
given: w = 5 | 20 | 100; z = 0.6 | 0.8
answer: w^2
tolerance: 0.5%

## An observer for a double integrator measuring position needs error poles at $\omega_o$ = {w} rad/s, ζ = {z}. What's $l_2$?

::: right
Right. $l_2 = \omega_o^2$ = {answer} (and $l_1 = 2\zeta\omega_o$).
:::

::: misses
- [2*z*w] That's $l_1$.
- [any] Not yet. Match $s^2 + l_1s + l_2$ to the target.
:::
:::

::: check
given: a = 10 | 62.5; w = 100 | 300; z = 0.7 | 1
answer: w^2 - a*(2*z*w - a)
tolerance: 0.5%

## A servo $\ddot\theta = -\given{a}\dot\theta + bu$ measures θ. What observer gain $l_2$ puts the error poles at $\omega_o$ = {w}, ζ = {z}?

::: right
Right. $l_1 = 2\zeta\omega_o - a$, then $l_2 = \omega_o^2 - al_1$ = {answer}.
:::

::: misses
- [w^2] The plant's own damping term couples $l_1$ into the constant coefficient: subtract $al_1$.
- [any] Not yet. The error polynomial is $s^2 + (l_1 + a)s + al_1 + l_2$.
:::
:::

::: check
given: a = -2 | 1; b = 1 | 3; c = 0.5 | 1.5; d = -3 | -1; e = 1 | 2; f = 1 | -1
answer: e*(e*b + f*d) - f*(e*a + f*c)
tolerance: 0.5%

## $A = \begin{pmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{pmatrix}$, $C = \begin{pmatrix} \given{e} & \given{f} \end{pmatrix}$. What's $\det\begin{pmatrix} C \\ CA \end{pmatrix}$?

::: right
Right. {answer}: nonzero, so the pair is observable.
:::

::: misses
- [any] Not yet. CA is the row $(c_1a_{11} + c_2a_{21},\ c_1a_{12} + c_2a_{22})$.
:::
:::

::: check
given: w = 10 | 50; v = 40 | 200
answer: w^2*v^2
tolerance: 0.5%

## A controller places poles with $\omega_n$ = {w} and an observer places its poles with $\omega_o$ = {v}. What's the constant term of the fourth-order closed-loop characteristic polynomial?

::: right
Right. By separation it's the product $(s^2 + \dots + \omega_n^2)(s^2 + \dots + \omega_o^2)$, with constant term $\omega_n^2\omega_o^2$ = {answer}.
:::

::: misses
- [w^2 + v^2] The polynomials multiply, so their constant terms multiply.
- [any] Not yet. Separation principle.
:::
:::

::: check
given: w = 50 | 200 | 1000; z = 0.5 | 0.8
answer: 4/(z*w)*1000
unit: ms
tolerance: 0.5%

## About how long does an observer with error poles at $\omega_o$ = {w} rad/s and ζ = {z} take for its estimates to settle within 2%?

::: right
Right. $4/\zeta\omega_o$ = {answer} ms.
:::

::: misses
- [4/w*1000] Use the real part, $\zeta\omega_o$.
- [any] Not yet. The errors decay as $e^{-\zeta\omega_ot}$.
:::
:::

::: check
given: l = 8 | 14; m = 100 | 400; t = 0.05 | 0.2
answer: exp(-l/2*t)*sin(sqrt(m - l^2/4)*t)/sqrt(m - l^2/4)
tolerance: 1%

## A double-integrator observer has $l_1$ = {l}, $l_2$ = {m}. Its velocity estimate starts 1 unit off and its position estimate is right. What's the position error at t = {t} s?

::: right
Right. $e_1(t) = e^{-l_1t/2}\sin(\omega_dt)/\omega_d$ = {answer}.
:::

::: misses
- [any] Not yet. $\ddot{e}_1 + l_1\dot{e}_1 + l_2e_1 = 0$ with $e_1(0) = 0$, $\dot{e}_1(0) = 1$.
:::
:::

::: check
kind: parts
given: a = 0.1 | 0.5 | 2; b = 0.05 | 0.5 | 4; w = 1 | 5; z = 0.7 | 1

## A plant $\dot{x} = -\given{a}x + \given{b}(u + d)$ with a constant unknown d is measured through x. An observer estimates x and d with error poles at $\omega_o$ = {w} rad/s, ζ = {z}.

::: part
answer: 2*z*w - a
tolerance: 0.5%

### What is $l_1$?

::: misses
- [2*z*w] The plant's own damping a already contributes.
- [any] Match $s^2 + (a + l_1)s + bl_2$ to $s^2 + 2\zeta\omega_os + \omega_o^2$.
:::
:::

::: part
answer: w^2/b
tolerance: 0.5%

### What is $l_2$?

::: misses
- [w^2] The disturbance enters through b.
- [any] $l_2 = \omega_o^2/b$.
:::
:::
:::

::: check
kind: derivation
vars: w = 0.5..1000, z = 0.5..1

## A double integrator measuring position gets an observer with error poles at $\omega_o$ = w, ζ = z.

::: step
answer: 2*z*w

### What is $l_1$?
:::

::: step
answer: w^2

### What is $l_2$?
:::

::: step
answer: 4/(z*w)

### About how long does the error take to settle to 2%?
:::

::: right
Right. The observer's poles set how fast the estimate forgets a wrong start, and how much it trusts noisy measurements.
:::
:::

::: explain
## Why does an observer need the plant's input as well as its output?

::: model
The observer is a copy of the plant's model that runs in parallel and is corrected by the output error. If the copy didn't get the same input, it would drift away from the real plant every time the input changed, and the correction term would have to account for the input's whole effect through the output, which arrives late and filtered. Feeding the input in makes the model move exactly as the plant does, so the estimation error obeys $\dot{e} = (A - LC)e$ with no input term at all. The correction then only has to remove the initial mismatch and the effects of disturbances and model errors.
:::
:::

::: practice

::: check
given: w = 8 | 60; z = 0.7 | 0.9
answer: 2*z*w
tolerance: 0.5%

## $l_1$ for a double-integrator observer at $\omega_o$ = {w}, ζ = {z}?

::: misses
- [any] $2\zeta\omega_o$.
:::
:::

::: check
given: a = 5 | 30; w = 80 | 250; z = 0.6 | 0.8
answer: w^2 - a*(2*z*w - a)
tolerance: 0.5%

## $l_2$ for a servo with damping {a} s⁻¹, observer at $\omega_o$ = {w}, ζ = {z}?

::: misses
- [any] $\omega_o^2 - a(2\zeta\omega_o - a)$.
:::
:::

::: check
given: w = 30 | 400; z = 0.6 | 1
answer: 4/(z*w)*1000
unit: ms
tolerance: 0.5%

## Observer settling time at $\omega_o$ = {w}, ζ = {z}?

::: misses
- [any] $4/\zeta\omega_o$.
:::
:::
:::
