Algorithm Search⌘K

Algorithmadvanced

High-gain observer

Also called high gain observer.

An observer for systems in observable form whose gains grow with a small parameter, so the estimation error decays as fast as wanted.

Time
O(n + q) worst
Space
O(n) extra
Where
n = the order of the system; q = the number of arithmetic operations to evaluate the nominal model once
Properties
deterministicexactonlineiterative
Origin
Farzad Esfandiari, Hassan K. Khalil, Laurent Praly, Ahmed N. Atassi, 1992

A high-gain observer is a state observer for a nonlinear system in observable form, a chain of integrators x˙i=xi+1\dot x_i = x_{i+1} that ends in x˙n=ϕ(x,u)\dot x_n = \phi(x, u), with the output y=x1y = x_1. It is a Luenberger observer for the chain whose gains are αi/εi\alpha_i / \varepsilon^i for a small parameter ε>0\varepsilon > 0. As ε\varepsilon goes to 00, the error decays on the time scale ε\varepsilon, and the effect of an error in the model ϕ\phi shrinks like a power of ε\varepsilon. It does not need an exact model. The price is a large transient in the estimates, the peaking phenomenon, and a high sensitivity to measurement noise.

In plain words

You measure a position and want the velocity, and maybe the acceleration, without a good model of the forces. You can run a model and correct it by the measured error. If you make the correction very strong, the model hardly matters: the estimate is pulled onto the measurement so fast that the forces have no time to push it away. The stronger the correction, the smaller the remaining error. But a strong correction overreacts at the start, when the estimate is far from the truth, and gives a huge, short spike in the estimated velocity. If a controller uses that spike, it can push the machine hard in the wrong direction. The usual cure is to limit the control, so the spike passes without harm. Noise on the measurement is amplified in the same way, which sets a limit on how strong the correction can be.

The problem

Input. A system in observable form

x˙i=xi+1(i=1,…,n−1),x˙n=ϕ(x,u),y=x1,\dot x_i = x_{i+1} \quad (i = 1, \dots, n - 1), \qquad \dot x_n = \phi(x, u), \qquad y = x_1,

with a measured output yy and a known input uu. A nominal model ϕ0(x^,u)\phi_0(\hat x, u) of ϕ\phi; ϕ0=0\phi_0 = 0 is allowed. Coefficients α1,…,αn\alpha_1, \dots, \alpha_n such that sn+α1sn−1+⋯+αns^n + \alpha_1 s^{n-1} + \dots + \alpha_n is Hurwitz, and a small ε>0\varepsilon > 0. Many systems with a well-defined relative degree nn take this form in the coordinates y,y˙,…,y(n−1)y, \dot y, \dots, y^{(n-1)}.

Output. The right side of the observer, which an ODE solver or a sampled implementation integrates, such that the scaled errors ηi=(xi−x^i)/εn−i\eta_i = (x_i - \hat x_i) / \varepsilon^{n-i} obey

εη˙=A0η+εBδ,δ=ϕ(x,u)−ϕ0(x^,u),\varepsilon \dot \eta = A_0 \eta + \varepsilon B \delta, \qquad \delta = \phi(x, u) - \phi_0(\hat x, u),

where A0A_0 is the companion matrix of the Hurwitz polynomial and B=(0,…,0,1)TB = (0, \dots, 0, 1)^T.

The algorithm

  1. HIGH-GAIN-OBSERVER(x̂, y, u, ε, α, φ_0)
  2. 1e ← y - x̂_1
  3. 2for i ← 1 to n - 1
  4. 3ẋ̂_i ← x̂_{i+1} + (α_i / ε^i) e
  5. 4ẋ̂_n ← φ_0(x̂, u) + (α_n / ε^n) e
  6. 5return ẋ̂

Line L1 is the output error. Lines L2 and L3 copy the chain of integrators and add the correction with gain αi/εi\alpha_i / \varepsilon^i. Line L4 uses the nominal model for the last equation. In matrix form the observer is x^˙=Ax^+Bϕ0(x^,u)+Lo(y−Cx^)\dot{\hat x} = A \hat x + B \phi_0(\hat x, u) + L_o (y - C \hat x), with AA the shift matrix, C=(1,0,…,0)C = (1, 0, \dots, 0) and Lo=(α1/ε,…,αn/εn)TL_o = (\alpha_1 / \varepsilon, \dots, \alpha_n / \varepsilon^n)^T. The eigenvalues of A−LoCA - L_o C are the roots of the Hurwitz polynomial divided by ε\varepsilon.

Example

Van der Pol oscillator with no model. Let x˙1=x2\dot x_1 = x_2, x˙2=−x1+(1−x12)x2\dot x_2 = -x_1 + (1 - x_1^2) x_2, y=x1y = x_1, x(0)=(2,0)x(0) = (2, 0). The observer uses ϕ0=0\phi_0 = 0, so it knows nothing about the dynamics except the chain, with α=(2,1)\alpha = (2, 1) (both roots at −1/ε-1/\varepsilon) and x^(0)=(0,0)\hat x(0) = (0, 0). The joint system is integrated with 4th order Runge-Kutta with step 0.0020.002.

ε\varepsilon max⁡t≥2∣e1∣\max_{t \ge 2} \lvert e_1 \rvert max⁡t≥2∣e2∣\max_{t \ge 2} \lvert e_2 \rvert peak of ∣e2∣\lvert e_2 \rvert ∣e1(0)∣/(eε)\lvert e_1(0) \rvert / (e \varepsilon)
0.04 0.00742 0.372 18.46 18.39
0.02 0.00189 0.189 36.82 36.79
0.01 0.000475 0.0950 73.59 73.58

The remaining errors scale like ε2\varepsilon^2 in x1x_1 and ε\varepsilon in x2x_2, as the scaled error equation predicts (e1=εη1e_1 = \varepsilon \eta_1, e2=η2e_2 = \eta_2, η=O(ε)\eta = O(\varepsilon)). The peak grows like 1/ε1/\varepsilon. For δ=0\delta = 0 the error is e2(t)=−(t/ε)e−t/εe1(0)/εe_2(t) = -(t/\varepsilon) e^{-t/\varepsilon} e_1(0)/\varepsilon, whose largest value ∣e1(0)∣/(eε)|e_1(0)| / (e \varepsilon) at t=εt = \varepsilon is the last column. At ε=0.02\varepsilon = 0.02 and t=0.02t = 0.02 the true velocity is −0.039-0.039 and the estimate is 36.7836.78.

Peaking in output feedback. Let x˙1=x2\dot x_1 = x_2, x˙2=x23+u\dot x_2 = x_2^3 + u, with the state feedback u=−x23−x1−x2u = -x_2^3 - x_1 - x_2, which makes the origin globally asymptotically stable. Put the estimates of the observer (with ϕ0=x^23+u\phi_0 = \hat x_2^3 + u) into the feedback, from x(0)=(0.1,0)x(0) = (0.1, 0) and x^(0)=0\hat x(0) = 0, with RK4 and step 0.00050.0005. Without saturation, ∣x∣|x| reaches 0.7580.758 and ∣u∣|u| reaches 5252 for ε=0.01\varepsilon = 0.01; 3.083.08 and 393393 for ε=0.005\varepsilon = 0.005; and for ε=0.0025\varepsilon = 0.0025 the state escapes to infinity before t=0.02t = 0.02. A smaller ε\varepsilon makes it worse. With uu and the x^2\hat x_2 inside ϕ0\phi_0 clipped to [−1,1][-1, 1], the state never exceeds its initial size 0.10.1 for ε=0.0025\varepsilon = 0.0025, and at t=5t = 5 it is within 0.010.01 of 00, as with state feedback.

Correctness

The full proof is in proofs/correctness.md. Its main steps:

  • The scaled error equation. Subtracting the observer from the plant and dividing xi−x^ix_i - \hat x_i by εn−i\varepsilon^{n-i} gives εη˙=A0η+εBδ\varepsilon \dot \eta = A_0 \eta + \varepsilon B \delta. This is algebra, and the tests check it exactly in Fraction for 150 random cases with n=1n = 1 to 44.
  • Theorem (exponential decay and ultimate bound). Let P0P_0 solve the Lyapunov equation P0A0+A0TP0=−IP_0 A_0 + A_0^T P_0 = -I and let ∣δ∣≤M|\delta| \le M along the motion. Then W=ηTP0ηW = \eta^T P_0 \eta satisfies εW˙≤−∥η∥2+2εM∥P0B∥∥η∥\varepsilon \dot W \le -\|\eta\|^2 + 2 \varepsilon M \|P_0 B\| \|\eta\|, with ∥⋅∥\|\cdot\| the Euclidean norm. So η\eta decays exponentially with rate of order 1/ε1/\varepsilon until ∥η∥\|\eta\| is of order εM\varepsilon M, and then stays there. In the original coordinates, xi−x^i=O(εn+1−i)x_i - \hat x_i = O(\varepsilon^{n+1-i}) after a transient of length O(εln⁡(1/ε))O(\varepsilon \ln(1/\varepsilon)).
  • Theorem (peaking). ∥η(0)∥\|\eta(0)\| is of order ∥e(0)∥/εn−1\|e(0)\| / \varepsilon^{n-1}, so the estimates of x2,…,xnx_2, \dots, x_n have transients of size up to 1/εn−11/\varepsilon^{n-1}. For n=2n = 2 and α=(2,1)\alpha = (2, 1) the peak is exactly ∣e1(0)∣/(eε)|e_1(0)| / (e \varepsilon) when δ=0\delta = 0.
  • Theorem (separation, cited). For a state feedback that makes the origin asymptotically stable, saturated outside a compact set of interest, output feedback with a high-gain observer recovers the region of attraction and the trajectories of state feedback as ε→0\varepsilon \to 0 (Atassi and Khalil 1999). This page does not reprove it; the example shows it.
Proof: The high-gain observer error decays on the time scale eps to a size that is a power of eps, with a peak of order eps to the power 1 - nfull

The plant is

x˙i=xi+1(i=1,…,n−1),x˙n=ϕ(x,u),y=x1,\dot x_i = x_{i+1} \quad (i = 1, \dots, n - 1), \qquad \dot x_n = \phi(x, u), \qquad y = x_1,

and lines L1 to L5 compute the right side of

x^˙i=x^i+1+αiεi(y−x^1)(i=1,…,n−1),x^˙n=ϕ0(x^,u)+αnεn(y−x^1),\dot{\hat x}_i = \hat x_{i+1} + \frac{\alpha_i}{\varepsilon^i} (y - \hat x_1) \quad (i = 1, \dots, n - 1), \qquad \dot{\hat x}_n = \phi_0(\hat x, u) + \frac{\alpha_n}{\varepsilon^n} (y - \hat x_1),

with ε>0\varepsilon > 0 and p(s)=sn+α1sn−1+⋯+αnp(s) = s^n + \alpha_1 s^{n-1} + \dots + \alpha_n Hurwitz. Let ei=xi−x^ie_i = x_i - \hat x_i and δ=ϕ(x,u)−ϕ0(x^,u)\delta = \phi(x, u) - \phi_0(\hat x, u). Here ∥⋅∥\|\cdot\| is the Euclidean norm of a vector and the norm it induces on matrices.

Lemma 1: the scaled error equation

Let ηi=ei/εn−i\eta_i = e_i / \varepsilon^{n-i} for i=1,…,ni = 1, \dots, n, and let

A0=(−α11−α2⋱⋮1−αn0⋯0),B=(0,…,0,1)T.A_0 = \begin{pmatrix} -\alpha_1 & 1 & & \\ -\alpha_2 & & \ddots & \\ \vdots & & & 1 \\ -\alpha_n & 0 & \cdots & 0 \end{pmatrix}, \qquad B = (0, \dots, 0, 1)^T.

Then εη˙=A0η+εBδ\varepsilon \dot \eta = A_0 \eta + \varepsilon B \delta.

Proof. Since y=x1y = x_1, the output error is e1e_1. For i<ni < n, e˙i=ei+1−(αi/εi)e1\dot e_i = e_{i+1} - (\alpha_i / \varepsilon^i) e_1. Divide by εn−i\varepsilon^{n-i} and multiply by ε\varepsilon:

εη˙i=ei+1εn−i−1−αie1εn−1=ηi+1−αiη1.\varepsilon \dot \eta_i = \frac{e_{i+1}}{\varepsilon^{n-i-1}} - \alpha_i \frac{e_1}{\varepsilon^{n-1}} = \eta_{i+1} - \alpha_i \eta_1.

For i=ni = n, e˙n=δ−(αn/εn)e1\dot e_n = \delta - (\alpha_n / \varepsilon^n) e_1, so εη˙n=εδ−αnη1\varepsilon \dot \eta_n = \varepsilon \delta - \alpha_n \eta_1. These are the rows of A0η+εBδA_0 \eta + \varepsilon B \delta. □\square

The characteristic polynomial of A0A_0 is p(s)p(s), since A0A_0 is a companion matrix (expand the determinant of sI−A0sI - A_0 along the first column). So A0A_0 is Hurwitz. In the time τ=t/ε\tau = t / \varepsilon the equation reads dη/dτ=A0η+εBδd\eta / d\tau = A_0 \eta + \varepsilon B \delta: the observer error is a fixed Hurwitz system driven by a term of size ε\varepsilon.

Theorem 1: exponential decay and ultimate bound

Let P0=P0T>0P_0 = P_0^T > 0 solve P0A0+A0TP0=−IP_0 A_0 + A_0^T P_0 = -I; it exists because A0A_0 is Hurwitz (theorem of the Lyapunov equation). Let λ1=λmin⁡(P0)\lambda_1 = \lambda_{\min}(P_0), λ2=λmax⁡(P0)\lambda_2 = \lambda_{\max}(P_0), β=∥P0B∥\beta = \|P_0 B\|, and assume ∣δ(t)∣≤M|\delta(t)| \le M on an interval [0,t1)[0, t_1). Then for t∈[0,t1)t \in [0, t_1)

∥η(t)∥≤λ2λ1 ∥η(0)∥ e−t/(4λ2ε)+4βλ2λ1 εM.\|\eta(t)\| \le \sqrt{\frac{\lambda_2}{\lambda_1}}\, \|\eta(0)\|\, e^{-t/(4 \lambda_2 \varepsilon)} + 4 \beta \sqrt{\frac{\lambda_2}{\lambda_1}}\, \varepsilon M.

Proof. Let W=ηTP0ηW = \eta^T P_0 \eta. By Lemma 1,

εW˙=ηT(P0A0+A0TP0)η+2εηTP0Bδ≤−∥η∥2+2εβM∥η∥.\varepsilon \dot W = \eta^T (P_0 A_0 + A_0^T P_0) \eta + 2 \varepsilon \eta^T P_0 B \delta \le -\|\eta\|^2 + 2 \varepsilon \beta M \|\eta\|.

When ∥η∥≥4εβM\|\eta\| \ge 4 \varepsilon \beta M, the last term is at most ∥η∥2/2\|\eta\|^2 / 2, so εW˙≤−∥η∥2/2≤−W/(2λ2)\varepsilon \dot W \le -\|\eta\|^2 / 2 \le -W / (2 \lambda_2). Let w=Ww = \sqrt W. Where W>0W > 0, w˙=W˙/(2w)\dot w = \dot W / (2 w), so w˙≤−w/(4λ2ε)\dot w \le -w / (4 \lambda_2 \varepsilon) whenever ∥η∥≥4εβM\|\eta\| \ge 4 \varepsilon \beta M. The set {W≤λ2(4εβM)2}\{W \le \lambda_2 (4 \varepsilon \beta M)^2\} contains the ball ∥η∥≤4εβM\|\eta\| \le 4 \varepsilon \beta M, and on its boundary ∥η∥≥4εβM\|\eta\| \ge 4 \varepsilon \beta M, so W˙≤0\dot W \le 0 there and the set is positively invariant. Outside it, ww decays at least like w(0)e−t/(4λ2ε)w(0) e^{-t / (4 \lambda_2 \varepsilon)}. So w(t)≤max⁡(w(0)e−t/(4λ2ε),λ2 4εβM)w(t) \le \max(w(0) e^{-t/(4 \lambda_2 \varepsilon)}, \sqrt{\lambda_2}\, 4 \varepsilon \beta M), and with λ1∥η∥≤w≤λ2∥η∥\sqrt{\lambda_1} \|\eta\| \le w \le \sqrt{\lambda_2} \|\eta\| the bound follows. □\square

This is the ultimate bound argument with comparison functions in Khalil 2002 (Section 4.8), written out for a quadratic WW.

Consequence in the original errors. Since ei=εn−iηie_i = \varepsilon^{n-i} \eta_i, after the transient

∣ei(t)∣≤εn−i∥η(t)∥≤c εn+1−iM,c=8βλ2/λ1,|e_i(t)| \le \varepsilon^{n-i} \|\eta(t)\| \le c\, \varepsilon^{n+1-i} M, \qquad c = 8 \beta \sqrt{\lambda_2 / \lambda_1},

once the exponential term is below the constant term. With ∥η(0)∥≤∥e(0)∥/εn−1\|\eta(0)\| \le \|e(0)\| / \varepsilon^{n-1} (for ε≤1\varepsilon \le 1), this takes a time of at most 4λ2εln⁡(∥e(0)∥/(4βεnM))4 \lambda_2 \varepsilon \ln(\|e(0)\| / (4 \beta \varepsilon^n M)), which is O(εln⁡(1/ε))O(\varepsilon \ln(1/\varepsilon)). In the page example, n=2n = 2: e1=O(ε2)e_1 = O(\varepsilon^2) and e2=O(ε)e_2 = O(\varepsilon), and the tests measure e1/ε2e_1 / \varepsilon^2 between 4.54.5 and 4.84.8 and e2/εe_2 / \varepsilon between 9.29.2 and 9.69.6 for ε=0.04,0.02,0.01\varepsilon = 0.04, 0.02, 0.01.

The bound ∣δ∣≤M|\delta| \le M must hold along the motion. If ϕ\phi and ϕ0\phi_0 are continuous and xx stays in a compact set, it holds as long as x^\hat x stays bounded; if ϕ0\phi_0 is evaluated at clipped estimates, as in the second example of the page, it holds for all tt with a constant MM that does not depend on ε\varepsilon.

Theorem 2: peaking

For n≥2n \ge 2 and e1(0)≠0e_1(0) \neq 0, ∥η(0)∥≥∣e1(0)∣/εn−1\|\eta(0)\| \ge |e_1(0)| / \varepsilon^{n-1}, so the bound of Theorem 1 allows transients of size 1/εn−11/\varepsilon^{n-1}, and they occur. For n=2n = 2, α=(2,1)\alpha = (2, 1), δ=0\delta = 0 and e2(0)=0e_2(0) = 0:

e2(t)=−tεe−t/εe1(0)ε,max⁡t≥0∣e2(t)∣=∣e1(0)∣e ε at t=ε.e_2(t) = -\frac{t}{\varepsilon} e^{-t/\varepsilon} \frac{e_1(0)}{\varepsilon}, \qquad \max_{t \ge 0} |e_2(t)| = \frac{|e_1(0)|}{e\, \varepsilon} \text{ at } t = \varepsilon.

Proof. With δ=0\delta = 0 the errors obey e˙1=e2−(2/ε)e1\dot e_1 = e_2 - (2/\varepsilon) e_1, e˙2=−(1/ε2)e1\dot e_2 = -(1/\varepsilon^2) e_1. The matrix has the double eigenvalue −1/ε-1/\varepsilon. Try e1=(a+bt)e−t/εe_1 = (a + b t) e^{-t/\varepsilon} with a=e1(0)a = e_1(0). From e˙1=e2−(2/ε)e1\dot e_1 = e_2 - (2/\varepsilon) e_1 and e2(0)=0e_2(0) = 0: e˙1(0)=−2a/ε\dot e_1(0) = -2a/\varepsilon, and e˙1(0)=b−a/ε\dot e_1(0) = b - a/\varepsilon, so b=−a/εb = -a/\varepsilon and e1=a(1−t/ε)e−t/εe_1 = a (1 - t/\varepsilon) e^{-t/\varepsilon}. Then e2=e˙1+(2/ε)e1=ae−t/ε(−1/ε−(1/ε)(1−t/ε)+(2/ε)(1−t/ε))=−a(t/ε2)e−t/εe_2 = \dot e_1 + (2/\varepsilon) e_1 = a e^{-t/\varepsilon} (-1/\varepsilon - (1/\varepsilon)(1 - t/\varepsilon) + (2/\varepsilon)(1 - t/\varepsilon)) = -a (t/\varepsilon^2) e^{-t/\varepsilon}. Check the second equation: e˙2=−ae−t/ε(1/ε2−t/ε3)=−(1/ε2)e1\dot e_2 = -a e^{-t/\varepsilon} (1/\varepsilon^2 - t/\varepsilon^3) = -(1/\varepsilon^2) e_1. The function τe−τ\tau e^{-\tau} has its largest value 1/e1/e at τ=1\tau = 1. □\square

The tests check this formula along an RK4 solution with tolerance 10−510^{-5}, and the peak of the Van der Pol example (where δ≠0\delta \neq 0) agrees with it within 0.40.4 percent.

Effect of peaking on a feedback loop

The peak of Theorem 2 is the reason a high-gain observer can destabilize a plant whose state feedback is globally asymptotically stable. In the second example of the page, the plant x˙2=x23+u\dot x_2 = x_2^3 + u receives an input of size about 1/ε21/\varepsilon^2 times a cubic in the peak during a time of order ε\varepsilon, which can drive it to a finite escape time; the tests measure an escape before t=0.02t = 0.02 for ε=0.0025\varepsilon = 0.0025. If uu is clipped to [−Mu,Mu][-M_u, M_u], the plant moves at most O(εln⁡(1/ε))O(\varepsilon \ln(1/\varepsilon)) during the transient of Theorem 1, which tends to 00 with ε\varepsilon. After the transient the estimates are close to the state, and the loop behaves like the state feedback loop with a small perturbation. The full statement, that the region of attraction and the trajectories of state feedback are recovered as ε→0\varepsilon \to 0, is the separation principle of Atassi and Khalil (1999); this page cites it and does not reprove it. The tests measure the recovery for ε=0.0025\varepsilon = 0.0025.

Complexity

Count real operations at unit cost, as in the real RAM. One evaluation of the right side costs O(n)O(n) operations for the chain and the corrections, plus qq for ϕ0\phi_0. The gains αi/εi\alpha_i / \varepsilon^i can be computed once. The estimate takes O(n)O(n) space. The observer is stiff: its eigenvalues are of size 1/ε1/\varepsilon, so an explicit integrator needs a step of order ε\varepsilon (here 0.2ε0.2 \varepsilon or less), and a run over a time TT costs O((n+q)T/ε)O((n + q) T / \varepsilon).

Properties

  • Model free in the limit. The model error δ\delta enters multiplied by ε\varepsilon, so even ϕ0=0\phi_0 = 0 works, with an error that is a power of ε\varepsilon.
  • Asymptotic, not finite time. The error decays exponentially, and with δ≠0\delta \neq 0 it stays at a size of order εM\varepsilon M in η\eta. A sliding mode observer reaches zero error in finite time instead.
  • Peaking. The transient grows like ε1−n\varepsilon^{1-n} in x^n\hat x_n. This is not a numerical artifact; it follows from the pole placement at −1/ε-1/\varepsilon with a fixed initial error.
  • Noise amplification. Measurement noise of size μ\mu produces an error of size about μ/εi−1\mu / \varepsilon^{i-1} in x^i\hat x_i, while the model error term shrinks like εn+1−i\varepsilon^{n+1-i}. So there is a best ε\varepsilon for given noise and model error (Khalil and Praly 2014).
  • Linear in the output. The correction is linear, so the observer is a linear filter of yy when ϕ0=0\phi_0 = 0. It is then an approximate differentiator of yy.

Variants and improvements

  • Extended high-gain observer. Add one more integrator state for δ\delta. The observer then estimates the model error, which a controller can cancel. This is the observer of active disturbance rejection control.
  • Saturating the estimates. Instead of the control, clip each estimate to the range it takes under state feedback. Either clipping protects the plant from the peak.
  • Switched or adaptive gain. Start with a moderate ε\varepsilon and lower it after the transient, or adapt it to the noise level, to trade peaking and noise against accuracy.
  • Low-power observers. Observers whose gains grow like 1/ε1/\varepsilon or 1/ε21/\varepsilon^2 only, built from cascades of small blocks, reduce the size of the gains for large nn.
  • Multi-output systems. Apply the construction to each chain of a system in a block observable form.

When to use it

Use it for output feedback of nonlinear systems that are in observable form or can be brought to it, such as mechanical systems where only positions are measured, when the model is uncertain and the measurement noise is small. It is the standard tool for proving that a state feedback design, such as feedback linearization or backstepping, still works with output feedback. If the noise is large, prefer a stochastic filter such as the extended Kalman filter. If you need exact estimates in finite time and the model error has a known bound, prefer a sliding mode observer.

Pitfalls

  • Peaking into the plant. Using the estimates of lines L3 and L4 in a feedback without saturation can destabilize the plant, and making ε\varepsilon smaller makes it worse (example 2).
  • Peaking inside the observer at line L4. If ϕ0\phi_0 grows fast, such as x^23\hat x_2^3, the peak in x^2\hat x_2 can make the observer itself escape. Evaluate ϕ0\phi_0 at clipped estimates.
  • Too small an eps. The noise amplification grows like 1/εn−11/\varepsilon^{n-1}, and the observer becomes stiff. An explicit integrator with a step that is not small compared with ε\varepsilon diverges.
  • Sampled implementation. A discrete-time observer needs a sampling period that is small compared with ε\varepsilon, or a discretization that is exact for the linear part, such as the zero-order hold discretization.
  • Wrong form. The construction relies on the chain x˙i=xi+1\dot x_i = x_{i+1}. If the system is not in this form, the coordinate change must be found first, and the observer of the original state needs its inverse.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

ctlsim.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the control pages of https://algorithm.tamnd.com/. The authors are listed in prov/.

"""Fixed step simulation for the control pages.

Conventions:
- A continuous-time system is a function f(t, x, u) that returns x' as a
  flat list. x is a flat list. u is whatever the control returns (a flat
  list, a scalar, or None when there is no control).
- A discrete-time system is a function F(k, x, u) that returns x_(k+1).
- The integrator is the classical 4th order Runge-Kutta method with a fixed
  step dt. The input is held constant over each step.
- Time t_k = t0 + k dt is computed by multiplication, not by summation.
- The number of steps round((t1 - t0) / dt) and the hold ratio
  round(hold / dt) must match the real ratios within 1e-9 (relative), or
  ValueError is raised.

This file holds no controller or observer of a control page.
"""

__all__ = ["rk4_step", "simulate", "simulate_discrete", "lti"]


def _axpy(a, x, y):
    return [yi + a * xi for xi, yi in zip(x, y)]


def rk4_step(f, t, x, u, dt):
    """Return x(t + dt) after one RK4 step of x' = f(t, x, u), u held constant."""
    k1 = f(t, x, u)
    k2 = f(t + dt / 2, _axpy(dt / 2, k1, x), u)
    k3 = f(t + dt / 2, _axpy(dt / 2, k2, x), u)
    k4 = f(t + dt, _axpy(dt, k3, x), u)
    return [xi + dt / 6 * (a + 2 * b + 2 * c + d) for xi, a, b, c, d in zip(x, k1, k2, k3, k4)]


def _ratio(num, den, what):
    r = round(num / den)
    if abs(r * den - num) > 1e-9 * max(abs(num), abs(den)):
        raise ValueError(what + " is not an integer multiple of dt")
    return r


def simulate(f, x0, t0, t1, dt, control=None, hold=None):
    """Simulate x' = f(t, x, u) from x(t0) = x0 to t1 with RK4 and step dt.

    control(t, x) gives the input. It is called at each sampling instant
    t0 + j hold, and its value is held (zero-order hold) until the next
    instant. hold must be an integer multiple of dt; hold = None means
    hold = dt. With control = None the input is None.

    Returns (ts, xs, us): ts has N + 1 times, xs the N + 1 states, and us the
    N inputs, where us[k] acts on [ts[k], ts[k + 1]].
    """
    if dt <= 0:
        raise ValueError("dt must be positive")
    n_steps = _ratio(t1 - t0, dt, "t1 - t0")
    if n_steps < 0:
        raise ValueError("t1 is before t0")
    r = 1 if hold is None else _ratio(hold, dt, "hold")
    if r < 1:
        raise ValueError("hold must be at least dt")
    x = list(x0)
    ts = [t0]
    xs = [list(x)]
    us = []
    u = None
    for k in range(n_steps):
        t = t0 + k * dt
        if control is not None and k % r == 0:
            u = control(t, list(x))
        x = rk4_step(f, t, x, u, dt)
        ts.append(t0 + (k + 1) * dt)
        xs.append(x)
        us.append(u)
    return ts, xs, us


def simulate_discrete(F, x0, N, control=None):
    """Run x_(k+1) = F(k, x_k, u_k) for k = 0, ..., N - 1.

    u_k = control(k, x_k), or None if control is None. Returns (xs, us) with
    N + 1 states and N inputs. Exact if F and control are exact.
    """
    x = list(x0)
    xs = [list(x)]
    us = []
    for k in range(N):
        u = control(k, list(x)) if control is not None else None
        x = list(F(k, x, u))
        xs.append(x)
        us.append(u)
    return xs, us


def lti(A, B=None):
    """Return f(t, x, u) = A x + B u for the system x' = A x + B u.

    u may be a flat list, a scalar (one input) or None (zero input). B may
    be None for a system with no input.
    """
    def f(t, x, u):
        dx = [sum(a * xi for a, xi in zip(row, x)) for row in A]
        if B is None or u is None:
            return dx
        uu = u if isinstance(u, (list, tuple)) else [u]
        return [d + sum(b * ui for b, ui in zip(row, uu)) for d, row in zip(dx, B)]
    return f


def _self_test():
    import math
    f = lti([[-1.0]])
    _, xs, _ = simulate(f, [1.0], 0.0, 1.0, 0.01)
    assert abs(xs[-1][0] - math.exp(-1.0)) < 1e-9
    return True


if __name__ == "__main__":
    _self_test()
high_gain_observer.py 69 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/high-gain-observer/. The authors are listed in prov/CY2X2T.jsonl.

"""High-gain observer for a system in observable (chain of integrators) form

    x_i' = x_(i+1),   i = 1, ..., n - 1,
    x_n' = phi(x, u),   y = x_1,

with a nominal model phi0 of phi (phi0 = 0 is allowed). The observer is

    xh_i' = xh_(i+1) + (alpha_i / eps^i) (y - xh_1),   i = 1, ..., n - 1,
    xh_n' = phi0(xh, u) + (alpha_n / eps^n) (y - xh_1),

where s^n + alpha_1 s^(n-1) + ... + alpha_n is Hurwitz and eps > 0 is small.
In the scaled errors eta_i = (x_i - xh_i) / eps^(n-i) the error equation is

    eps eta' = A0 eta + eps B delta,   delta = phi(x, u) - phi0(xh, u),

with A0 the companion matrix of the polynomial above, so the error decays
on the time scale eps and ends of size O(eps^(n+1-i)) in x_i.

observer_rhs returns xh' for use inside an ODE solver. With exact data and
an exact phi0 the result is exact (int and Fraction stay exact).
"""

from fractions import Fraction

__all__ = ["observer_rhs", "saturate", "peak_bound_n2"]


def _pow_div(a, eps, i):
    d = eps ** i
    if isinstance(a, int) and isinstance(d, int):
        return Fraction(a, d)
    return a / d


def observer_rhs(xh, y, u, eps, alpha, phi0):
    """Return the derivative of the estimate xh.

    alpha: the n coefficients alpha_1..alpha_n of a Hurwitz polynomial.
    phi0(xh, u): the nominal model of the last equation.
    """
    n = len(xh)
    if len(alpha) != n:
        raise ValueError("alpha must have len(xh) entries")
    if eps <= 0:
        raise ValueError("eps must be positive")
    e = y - xh[0]  # @line L1
    dx = []
    for i in range(1, n):  # @line L2
        dx.append(xh[i] + _pow_div(alpha[i - 1], eps, i) * e)  # @line L3
    dx.append(phi0(xh, u) + _pow_div(alpha[n - 1], eps, n) * e)  # @line L4
    return dx  # @line L5


def saturate(v, m):
    """Clip v to [-m, m]; the usual guard against peaking."""
    return max(-m, min(m, v))


def peak_bound_n2(e1_0, eps):
    """Peak of |e2| for n = 2, alpha = (2, 1), delta = 0, e2(0) = 0.

    Then e2(t) = -(t / eps) exp(-t / eps) e1(0) / eps, with the peak
    |e1(0)| / (e eps) at t = eps.
    """
    import math
    return abs(e1_0) / (math.e * eps)
test_high_gain_observer.py 165 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/high-gain-observer/. The authors are listed in prov/CY2X2T.jsonl.

import math
import random
from fractions import Fraction

import ctlsim
from high_gain_observer import observer_rhs, peak_bound_n2, saturate

# Simulations: classical RK4 (ctlsim) on the joint state (plant, observer),
# with the observer evaluated inside the right side. Steps: DT = 0.002 for
# eps >= 0.01 and DT_FAST = 0.0005 for eps down to 0.0025, so that
# DT / eps <= 0.2. Tolerances are stated at each check.
DT = 0.002
DT_FAST = 0.0005


def steps(T, dt):
    n = round(T / dt)
    assert abs(n * dt - T) < 1e-12
    return n


def vdp(t, x, u):
    return [x[1], -x[0] + (1 - x[0] ** 2) * x[1]]


def estimate_vdp(eps, T=4.0):
    # Van der Pol plant; the observer uses phi0 = 0 and alpha = (2, 1).
    def f(t, z, u):
        return vdp(t, z[:2], None) + observer_rhs(z[2:], z[0], None, eps, [2.0, 1.0], lambda xh, u: 0.0)

    ts, zs, us = ctlsim.simulate(f, [2.0, 0.0, 0.0, 0.0], 0.0, T, DT)
    assert len(us) == steps(T, DT)
    return ts, zs


def test_scaled_error_equation_exact():
    # eps eta' = A0 eta + eps B delta with eta_i = (x_i - xh_i) / eps^(n-i), exactly.
    rng = random.Random(11)
    for _ in range(150):
        n = rng.randint(1, 4)
        x = [Fraction(rng.randint(-20, 20), rng.randint(1, 6)) for _ in range(n)]
        xh = [Fraction(rng.randint(-20, 20), rng.randint(1, 6)) for _ in range(n)]
        eps = Fraction(1, rng.randint(2, 50))
        alpha = [Fraction(rng.randint(1, 9)) for _ in range(n)]
        u = Fraction(rng.randint(-5, 5))

        def phi(x, u):
            return x[0] * x[-1] - x[0] ** 3 + u

        def phi0(xh, u):
            return xh[0] * xh[-1] + u

        xdot = x[1:] + [phi(x, u)]
        xhdot = observer_rhs(xh, x[0], u, eps, alpha, phi0)
        eta = [(x[i] - xh[i]) / eps ** (n - 1 - i) for i in range(n)]
        etadot = [(xdot[i] - xhdot[i]) / eps ** (n - 1 - i) for i in range(n)]
        delta = phi(x, u) - phi0(xh, u)
        for i in range(n):
            a0eta = -alpha[i] * eta[0] + (eta[i + 1] if i + 1 < n else 0)
            assert eps * etadot[i] == a0eta + (eps * delta if i == n - 1 else 0)


def test_page_example_scaling():
    # late errors (t >= 2) and the peak of |e2|, measured:
    # eps = 0.04: 0.00742, 0.372, 18.46; 0.02: 0.00189, 0.189, 36.82; 0.01: 0.000475, 0.0950, 73.59
    expected = {0.04: (0.00742, 0.372, 18.46), 0.02: (0.00189, 0.189, 36.82), 0.01: (0.000475, 0.0950, 73.59)}
    for eps, (m1, m2, pk) in expected.items():
        ts, zs = estimate_vdp(eps)
        late = [z for t, z in zip(ts, zs) if t >= 2]
        e1 = max(abs(z[0] - z[2]) for z in late)
        e2 = max(abs(z[1] - z[3]) for z in late)
        peak = max(abs(z[1] - z[3]) for z in zs)
        assert abs(e1 - m1) < 0.01 * m1 and abs(e2 - m2) < 0.01 * m2 and abs(peak - pk) < 0.01 * pk
        # order eps^2 in x1, eps in x2, 1 / eps for the peak
        assert 4.5 < e1 / eps ** 2 < 4.8 and 9.2 < e2 / eps < 9.6 and 0.73 < peak * eps < 0.74
        # the linear part predicts the peak |e1(0)| / (e eps) within 0.4 percent
        assert abs(peak - peak_bound_n2(2.0, eps)) < 0.004 * peak


def test_table_eps_002():
    ts, zs = estimate_vdp(0.02)
    table = {0.02: (1.99961, -0.03882, 1.99981, 36.78373), 0.5: (1.83772, -0.53452, 1.83796, -0.51069), 2.0: (0.32332, -1.83297, 0.32407, -1.75703)}
    for t, row in table.items():
        z = zs[steps(t, DT)]
        assert all(abs(a - b) < 5e-6 for a, b in zip(z, row))


def test_peaking_closed_form():
    # delta = 0: plant x' = 0 at x = (2, 0); e2(t) = -(t / eps) exp(-t / eps) e1(0) / eps
    eps = 0.05

    def f(t, z, u):
        return [0.0, 0.0] + observer_rhs(z[2:], z[0], None, eps, [2.0, 1.0], lambda xh, u: 0.0)

    ts, zs, us = ctlsim.simulate(f, [2.0, 0.0, 0.0, 0.0], 0.0, 0.5, DT)
    assert len(us) == steps(0.5, DT)
    for t, z in zip(ts, zs):
        tau = t / eps
        # RK4 error with DT / eps = 0.04, against a peak of 14.7
        assert abs((z[1] - z[3]) - (-tau * math.exp(-tau) * 2.0 / eps)) < 1e-5


def output_feedback(eps, guard, T):
    # x1' = x2, x2' = x2^3 + u; state feedback u = -x2^3 - x1 - x2, with the
    # estimates of the observer (phi0 = xh2^3 + u). guard = None: no
    # saturation; guard = 1: u and the xh2 in phi0 are clipped to [-1, 1].
    def control(xh):
        v = -xh[1] ** 3 - xh[0] - xh[1]
        return v if guard is None else saturate(v, guard)

    def phi0(xh, u):
        v = xh[1] if guard is None else saturate(xh[1], guard)
        return v ** 3 + u

    def f(t, z, u):
        uu = control(z[2:])
        return [z[1], z[1] ** 3 + uu] + observer_rhs(z[2:], z[0], uu, eps, [2.0, 1.0], phi0)

    z = [0.1, 0.0, 0.0, 0.0]
    n = steps(T, DT_FAST)
    assert n <= 10000
    peak_x, peak_u = 0.0, 0.0
    for k in range(n):
        try:
            z = ctlsim.rk4_step(f, k * DT_FAST, z, None, DT_FAST)
        except OverflowError:
            return None, (k + 1) * DT_FAST, peak_u
        peak_x = max(peak_x, abs(z[0]), abs(z[1]))
        peak_u = max(peak_u, abs(control(z[2:])))
        if peak_x > 1e6:
            return None, (k + 1) * DT_FAST, peak_u
    return z, peak_x, peak_u


def test_peaking_without_saturation():
    # eps = 0.01: |x| reaches 0.758 and |u| 52; eps = 0.005: 3.08 and 393;
    # eps = 0.0025: the state escapes before t = 0.02.
    z, px, pu = output_feedback(0.005, None, 1.0)
    assert z is not None and 3.0 < px < 3.2 and 390 < pu < 400
    z, t_escape, pu = output_feedback(0.0025, None, 1.0)
    assert z is None and t_escape < 0.02


def test_saturation_recovers_state_feedback():
    # with the guard, |u| <= 1, the state never exceeds its initial size 0.1,
    # and at t = 5 it is within 0.01 of 0 (state feedback decays like e^(-t/2)).
    z, px, pu = output_feedback(0.0025, 1.0, 5.0)
    assert z is not None and px <= 0.1 + 1e-6 and pu <= 1.0
    assert max(abs(z[0]), abs(z[1])) < 0.01
    assert max(abs(z[0] - z[2]), abs(z[1] - z[3])) < 1e-3


def test_errors_and_exact_types():
    assert observer_rhs([0, 0], 1, None, 1, [2, 1], lambda xh, u: 0) == [2, 1]
    assert observer_rhs([0, 0], 1, None, Fraction(1, 2), [2, 1], lambda xh, u: 0) == [4, 4]
    assert saturate(-3, 1) == -1 and saturate(0.5, 1) == 0.5
    for bad in [lambda: observer_rhs([0.0], 1.0, None, 0.0, [1.0], lambda xh, u: 0.0), lambda: observer_rhs([0.0, 0.0], 1.0, None, 0.1, [1.0], lambda xh, u: 0.0)]:
        try:
            bad()
        except ValueError:
            continue
        raise AssertionError("no error")

History

High-gain observers appeared in several forms in the 1980s, in the work of Gauthier and others on observers for uniformly observable systems and in the work of Khalil and his students on output feedback. Esfandiari and Khalil (1992) showed that output feedback with a high-gain observer can destabilize a system because of peaking, and that saturating the control outside a compact set solves the problem. Atassi and Khalil (1999) proved a separation principle: as ε→0\varepsilon \to 0, the output feedback loop recovers the asymptotic stability, the region of attraction and the trajectories of the state feedback loop. Khalil and Praly (2014) surveyed the theory, including the effect of noise and the extended observers that also estimate disturbances.

References

  1. F. Esfandiari and H. K. Khalil, Output feedback stabilization of fully linearizable systems, International Journal of Control 56(5), 1007-1037, 1992, the high-gain observer for output feedback, the peaking phenomenon, and the saturation of the control outside a compact set
  2. A separation principle for the stabilization of a class of nonlinear systems, the recovery of the state feedback performance by output feedback with a high-gain observer as the parameter goes to zero
  3. H. K. Khalil and L. Praly, High-gain observers in nonlinear feedback control, International Journal of Robust and Nonlinear Control 24(6), 993-1015, 2014, the survey of the observer, the scaled error equation, peaking, and the effect of measurement noise
  4. Hassan K. Khalil, Nonlinear Systems, third edition, Prentice Hall, 2002, Section 14.5, High-gain observers

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example