Chapter 04

The Kalman Filter

A state you cannot measure, recovered from one you can. The Kalman filter runs a replica of the plant alongside the real thing and corrects it with the output error, using a gain that is not tuned by hand but computed in closed form from a Riccati recursion. That recursion is autonomous — it runs offline, before any measurement arrives — which means the accuracy of a software sensor can be quoted before the sensor exists.

Reading: ~34 min Interactive: 1 widgets Source: Polimi MIDA2 2025/26 — Lecture 5, slides 9–17 (Ch. 2.3 opens — SW-sensing) · Polimi MIDA2 2025/26 — Lecture 6 (Ch. 2.3 — the Kalman filter) · Polimi MIDA2 2025/26 — Lecture 8, slides 1–6 (Ch. 2.3 — coloured noise, model extension) · Polimi MIDA2 2025/26 — Lecture 19, slides 1–3 (Kalman filtering in MATLAB)

01 · Motivation

Deleting a sensor and keeping the signal

A plant has nn internal states and pp measured outputs, and almost always npn\gg p — for one reason, which is that physical sensors cost money. Software sensing is the business of getting the missing npn-p signals anyway.

The states you cannot afford to measure are exactly the ones you want. They feed the control algorithm, and they feed monitoring: fault detection and predictive maintenance both need to watch quantities that no instrument is reading.

There are two ways out, and choosing between them is an economics problem before it is a control problem. Adding a physical sensor costs a fixed amount per unit produced. Developing a software sensing algorithm costs a large amount once and nothing thereafter. Break-even sits where the development cost equals NN times the unit hardware cost, so:

High-volume production

A city car built by the hundred thousand amortises the development cost immediately. Software sensing wins, and every unit shipped widens the margin.

Low-volume production

A supercar built by the hundred never amortises it. Installing the physical sensor is simply cheaper.

That is the clean version. In practice three things bend it. First, redundancy: safety-critical aerospace and automotive systems run both, at low volume, precisely because two independent estimates of the same quantity are worth more than either. Second, some sensors are not merely expensive but infeasible — nothing can be installed where the signal lives. Third, hardware carries costs that do not appear on the unit price: installation complexity, space and weight, energy consumption. The net trend across industry is steadily towards more software sensors and fewer physical ones.

The two questions every software-sensing design must answer

Before any algorithm, two questions decide whether the project is possible and whether it is worth doing.

  1. Is it feasible? Only if the state can be reconstructed from the output at all — which is exactly the observability test from chapter 01. That rank condition stops being a classification exercise here and becomes a go/no-go gate.
  2. How good will it be? The estimation error var[x(t)x^(t)]\operatorname{var}\big[x(t)-\hat x(t)\big] is the software sensor’s noise specification — the direct analogue of the noise figure printed on a physical sensor’s datasheet. §05 shows that this number is computable in advance.

What the Kalman filter is asked to deliver

The chapter’s model-based approach sets out three problems and one bonus:

#problemgivenwantedstatus
1kk-step output predictionu(1..N)u(1..N), y(1..N)y(1..N)y^(N+kN)\hat y(N+k\lvert N)not new — MIDA1 solves it with ARMA/ARMAX
2kk-step state predictionsame, state unmeasuredx^(N+kN)\hat x(N+k\lvert N)new — input/output models cannot do this
3state filteringsamex^(NN)\hat x(N\lvert N)the main motivation — this is the software sensor
4gray-box identificationsamemodel parametersa side benefit, not the goal (chapter 07)

Problem 2 is where input/output models run out. An ARMAX model has no state to predict; it describes the plant from the outside. Getting at xx requires the internal description, which is why the whole of this chapter is written in state space.

why

Chapter 2.3 consumes a model, it does not build one

Everything below assumes {F,G,H}\{F,G,H\} is given, typically built white-box from physics. That is a standing assumption, not an oversight: identification is chapters 02 and 03, filtering is this one. The two meet only in chapter 07, where gray-box identification uses the filter itself to pin down unknown parameters.

02 · The model

The basic system and its two noises

Everything that follows is derived for the simplest useful case — no exogenous input, linear, time-invariant — and then extended. The extensions in §06 turn out to be nearly free; the real content is here.

Q

Building the covariances is a question in its own right

“Compute V1V_1, V2V_2 and V12V_{12}” has been set 3 times for 18 marks across the archive — 04/09/2024, 04/09/2025 and 16/07/2026 — always as part (a) of Q2, and always as the gateway to the Riccati work in the rest of the question. Get it wrong and every later part inherits the error.

The setup is the same every time: the two equations share a noise source, so V120V_{12}\ne0. That is the entire point of the question. A candidate who assumes V12=0V_{12}=0 out of habit loses the part and corrupts the DRE.

The basic system is a state-space model driven by two noises instead of an input:

The basic system

{x(t+1)=Fx(t)+v1(t)y(t)=Hx(t)+v2(t)\begin{cases}x(t+1)=Fx(t)+v_1(t)\\ y(t)=Hx(t)+v_2(t)\end{cases}

with xRnx\in\mathbb R^{n}, yRpy\in\mathbb R^{p} and — once §06 restores the input — uRmu\in\mathbb R^{m}. The SISO special case p=m=1p=m=1 is what every exam question uses, and it is worth noticing early that the general formulas below never assume it. Dropping Gu(t)Gu(t) makes the input/output pair a pure time series; §06 puts the input back at no cost.

v₁ — process noise

Also called state noise or model noise. An nn-component vector white noise, v1WN(0,V1)v_1\sim\mathrm{WN}(0,V_1). It represents internal disturbances and small modelling errors — the model is never exact, and v1v_1 is where that inexactness is booked.

v₂ — measurement noise

Also called output error or sensor error. A pp-component vector white noise, v2WN(0,V2)v_2\sim\mathrm{WN}(0,V_2). It models the noise on the physical sensors, which is why V2V_2 is usually the one you can look up.

V₁ — process noise covariance

n×nn\times n, symmetric, semi-definite positive (V10V_1\ge0). Semi-definite is enough: some state directions may be driven by no noise at all.

V₂ — measurement noise covariance

p×pp\times p, symmetric, and strictly definite positive (V2>0V_2>0). The strictness is not cosmetic — §03 shows it is what guarantees the filter exists.

V₁₂ — cross-covariance

n×pn\times p. Non-zero only at lag zero. In practice it is usually 00, but several formulas below are stated in the general case precisely because the exam is not.

Each noise carries the three standard white-noise properties — zero mean, the covariance above at lag zero, and zero correlation at every other lag. The cross-correlation is assumed to follow the same pattern:

Cross-correlation, non-zero only at lag zero

E[v1(t)v2(tτ)]={V12τ=00τ0\mathbb E\big[v_1(t)\,v_2(t-\tau)^{\top}\big]=\begin{cases}V_{12} & \tau=0\\ 0 & \tau\ne0\end{cases}

Because the system is dynamic, it also needs an initial condition — and being stochastic, that condition is itself probabilistic: E[x(1)]=X0\mathbb E[x(1)]=X_0 and var[x(1)X0]=P0\operatorname{var}\big[x(1)-X_0\big]=P_0. The special case P0=0P_0=0 says the initial state is known exactly. Finally, both noises are assumed uncorrelated with x(1)x(1), a technical assumption that the optimality proof needs.

Reading the covariances off a system

Exam systems never hand you V1V_1, V2V_2 and V12V_{12} directly. They hand you a model written in terms of named scalar noises and let you assemble the matrices — and they arrange for one noise to appear in both equations, so that the cross-covariance cannot be zero.

Exam format Worked example — one noise, two equations

The system as given

{x(t+1)=12x(t)+2v(t)+w(t)y(t)=x(t)w(t)\begin{cases}x(t+1)=\tfrac12x(t)+2v(t)+w(t)\\ y(t)=x(t)-w(t)\end{cases}

with vWN(0,1)v\sim\mathrm{WN}(0,1), wWN(0,2)w\sim\mathrm{WN}(0,2) and vwv\perp w. Note ww appears twice.

Identify the two noise terms

Match against the standard form: whatever is added to Fx(t)Fx(t) is v1v_1, whatever is added to Hx(t)Hx(t) is v2v_2.

F=12,H=1,v1(t)=2v(t)+w(t),v2(t)=w(t)F=\tfrac12,\qquad H=1,\qquad v_1(t)=2v(t)+w(t),\qquad v_2(t)=-w(t)

Expand the variances, keeping the cross terms

V1=E[(2v+w)2]=4E[v2]1+E[w2]2+4E[vw]0=6V_1=\mathbb E\big[(2v+w)^{2}\big]=4\underbrace{\mathbb E[v^2]}_{1}+\underbrace{\mathbb E[w^2]}_{2}+4\underbrace{\mathbb E[vw]}_{0}=6

V2=E[(w)2]=2V_2=\mathbb E\big[(-w)^{2}\big]=2

Here vwv\perp w kills the cross term. When the exam gives you E[vw]0\mathbb E[vw]\ne0 instead, that term survives and changes the answer — which is the trap in the embedded question below.

The cross-covariance is where the shared noise shows up

V12=E[(2v+w)(w)]=2E[vw]0E[w2]2=2V_{12}=\mathbb E\big[(2v+w)(-w)\big]=-2\underbrace{\mathbb E[vw]}_{0}-\underbrace{\mathbb E[w^2]}_{2}=-2

Non-zero, and it had to be: ww drives the state and corrupts the sensor at the same instant, so the two noises are correlated by construction.

Sanity check

A cross-covariance cannot exceed the geometric mean of the two variances: V12V1V2\lvert V_{12}\rvert\le\sqrt{V_1V_2}. Here 2123.462\le\sqrt{12}\approx3.46 ✓. It is a cheap check and it catches sign and arithmetic slips before they propagate into the Riccati equation.

×

Three ways this part goes wrong

  • Dropping the cross term when expanding V1V_1. For E[(av+bw)2]\mathbb E\big[(av+bw)^2\big] the answer is a2σv2+b2σw2+2abE[vw]a^2\sigma_v^2+b^2\sigma_w^2+2ab\,\mathbb E[vw]. When the problem states E[vw]0\mathbb E[vw]\ne0 that last term is not decoration — in the question below it drags V1V_1 from 154\tfrac{15}4 down to 34\tfrac34.
  • Assuming V12=0V_{12}=0 because “in practice it is”. In practice it usually is. In the exam it usually is not, and the whole design of the question is to check whether you noticed.
  • Losing the sign. v2=wv_2=-w makes V12V_{12} negative while leaving V2V_2 positive. Squaring kills the sign in the variances but not in the cross-covariance.
2026-07-q2a2026Q02Noise covariances V1, V2, V12hard6 pts
Consider the following system $$\begin{cases}x(t+1)=x(t)+\sqrt3\,v(t)-\tfrac{\sqrt3}{2}w(t)\\ y(t)=2x(t)+\tfrac1{\sqrt3}w(t)\end{cases}$$ with $v\sim\mathrm{WN}(0,1)$, $w\sim\mathrm{WN}(0,1)$ and $\mathbb E\!\left[v(t)w(t)^\top\right]=1$. a. Compute $V_1$, $V_2$ and $V_{12}$. b. Compute the DRE. Compute also the ARE solution(s). c. Graphically check the convergence to the ARE solution(s).

03 · The recursion

The filter, and the equation that feeds it

The Kalman filter is four equations plus a recursion for a matrix. Three of the four are obvious. The fourth — the gain — is Kalman’s entire contribution, and the recursion that produces it is the only hard object in the chapter.

The Kalman filter — one-step predictor form
x^(t+1t)=Fx^(tt1)+K(t)e(t)state equation, plus a correctiony^(tt1)=Hx^(tt1)output equatione(t)=y(t)y^(tt1)the innovationK(t)=(FP(t)H+V12)(HP(t)H+V2)1the gain\begin{aligned} \hat x(t+1|t)&=F\hat x(t|t-1)+K(t)\,e(t) &&\text{state equation, plus a correction}\\ \hat y(t|t-1)&=H\hat x(t|t-1) &&\text{output equation}\\ e(t)&=y(t)-\hat y(t|t-1) &&\text{the innovation}\\ K(t)&=\big(FP(t)H^{\top}+V_{12}\big)\big(HP(t)H^{\top}+V_2\big)^{-1} &&\text{the gain} \end{aligned}
The difference Riccati equation (DRE)

P(t+1)=(FP(t)F+V1)(FP(t)H+V12)(HP(t)H+V2)1(FP(t)H+V12)P(t+1)=\big(FP(t)F^{\top}+V_1\big)-\big(FP(t)H^{\top}+V_{12}\big)\big(HP(t)H^{\top}+V_2\big)^{-1}\big(FP(t)H^{\top}+V_{12}\big)^{\top}

Two dynamic equations means two initial conditions: x^(10)=X0\hat x(1|0)=X_0 and P(1)=P0P(1)=P_0 — the two pieces of prior knowledge from §02, arriving exactly where they are needed.

The mnemonic that rebuilds both formulas

The gain and the DRE look unmemorable until you notice they are built from three repeated blocks, each of the shape (matrix) P(t)P(t) (matrix) ++ (noise covariance):

blockexpressionwhere it comes from
STATEFP(t)F+V1FP(t)F^{\top}+V_1FF and V1V_1 both belong to the state equation
OUTPUTHP(t)H+V2HP(t)H^{\top}+V_2HH and V2V_2 both belong to the output equation
MIXFP(t)H+V12FP(t)H^{\top}+V_{12}one of each — the state/output cross term
key

Two lines instead of two formulas

K(t)=(MIX)(OUTPUT)1,P(t+1)=(STATE)(MIX)(OUTPUT)1(MIX)K(t)=(\text{MIX})(\text{OUTPUT})^{-1},\qquad P(t+1)=(\text{STATE})-(\text{MIX})(\text{OUTPUT})^{-1}(\text{MIX})^{\top}

Memorise the three blocks and both formulas reconstruct themselves. Note the shape of the DRE too: it is STATE minus a correction, and the correction is built from the same object that forms the gain. Uncertainty only ever goes down relative to open-loop propagation — which is what measuring something is supposed to do.

The DRE runs without data

The DRE as a dynamical system

{P(t+1)=f(P(t))P(1)=P0\begin{cases}P(t+1)=f\big(P(t)\big)\\ P(1)=P_0\end{cases}

Written that way, one thing is conspicuous: there is no input. The DRE is a non-linear matrix difference equation that is autonomous — its trajectory depends on FF, HH, V1V_1, V2V_2, V12V_{12} and P0P_0, and on nothing that is measured. Two consequences follow, and both matter:

  • P(t)P(t) and K(t)K(t) can be computed entirely offline, before the plant is switched on. The online filter is then three cheap equations with a pre-computed gain schedule.
  • The accuracy of the estimate is known in advance. §05 makes this precise.

The equation is named for Jacopo Riccati, who studied its continuous scalar ancestor in the early 1700s; Kalman rediscovered and used the matrix difference version in 1960.

Why V2>0V_2>0 was worth insisting on

The gain inverts (HP(t)H+V2)\big(HP(t)H^{\top}+V_2\big), so the filter exists only if that matrix is invertible at every step. The argument is short:

  • HP(t)HHP(t)H^{\top} is semi-definite positive by construction, for any P(t)0P(t)\ge0. On its own it may well be singular.
  • V2>0V_2>0 is definite positive, by assumption.
  • Semi-definite plus definite is definite, and definite positive matrices are invertible. ∎

That is the whole reason §02 demanded strictness for V2V_2 and allowed slackness for V1V_1: a state direction with no noise is harmless, an output direction with no noise is not.

What the structure is doing

The block diagram is worth holding in your head, because every extension in §06 and §07 is a modification of it. The filter contains a replica of the plant — a digital twin running the same FF and HH, differing only in that it cannot see the two noises. It compares the real measurement y(t)y(t) against its own prediction y^(tt1)\hat y(t|t-1), and feeds the difference back into its state equation through K(t)K(t).

The plant — has noise, cannot be opened v₁(t) x(t+1) = Fx + v₁ true state H + v₂(t) y(t) all you have The filter — same F, same H, no noise x̂(t+1|t) = Fx̂ + K·e the replica H ŷ(t|t−1) K(t) e(t) = y(t) − ŷ(t|t−1) — the innovation the only news the measurement carries

The plant’s two noise arrows are exactly what the filter lacks; the innovation feedback is what it has instead.

why

Feedback used for estimation, not for control

The loop looks exactly like a control loop, and it is not one. Nothing here acts on the plant; the feedback path exists to keep a simulator locked onto reality. The innovation e(t)e(t) is the only channel through which measurements enter, and it carries precisely the part of y(t)y(t) that the model failed to anticipate — which is why “innovation” is the right word for it.

This idea long predates Kalman: a replica with output-error feedback is the classical state observer. Kalman’s contribution was narrower and much deeper — a closed-form optimal choice of the correction gain. Without it you are guessing, and the failure modes are symmetric:

  • K(t)K(t) too small — the filter under-exploits the information in e(t)e(t) and trusts a model it should be correcting.
  • K(t)K(t) too big — the filter over-amplifies measurement noise, and can go unstable outright.

Nor can it be tuned by hand, because K(t)K(t) is not a knob. It is an n×pn\times p matrix: for a modest n=10n=10, p=3p=3 plant that is 30 numbers, all time-varying, all coupled.

×

The filter's real weak point is V₁

The Kalman filter needs V1V_1 and V2V_2 before it can run. V2V_2 is usually available — sensor datasheets quote it. V1V_1 is genuinely hard: it lumps together internal disturbances and modelling error, and no datasheet reports those. The current trend is to estimate V1V_1 from data, which quietly turns a model-based method into one that needs a training dataset — a machine-learning technique wearing a control-theory coat.

04 · The distinction that is graded

Predictor, filter, and the step between them

x^(t+1t)\hat x(t+1\lvert t) and x^(tt)\hat x(t\lvert t) both use every measurement up to time tt. They differ in which state they estimate — tomorrow’s or today’s — and converting between them is one multiplication. The exam asks for that conversion more often than for anything else in chapter 2.3.

Q

7 questions, 27 marks, and every one of the last five sittings

“Predictor vs filter” is the most repeated part of Q2 in the archive: 7 questions, 27 marks, 7 of the 12 sittings — and it has appeared in every one of the last five (14/07/2025, 04/09/2025, 12/02/2026, 26/06/2026, 16/07/2026). It is worth 4 marks in six of those seven appearances.

The stem is nearly invariant. You are given FF, HH, V1V_1, V2V_2, V12V_{12}, told that the DRE converges to a stated Pˉ\bar P (sometimes with Kˉ\bar K supplied too), and asked for the transfer function from y(t)y(t) to x^(tt)\hat x(t\lvert t) — with filter set in bold, because the predictor answer is the trap the question exists to catch. Assessing stability of FKˉHF-\bar KH is usually bolted on as part (a).

Everything asymptotic here — where Pˉ\bar P comes from, whether the DRE converges at all — is chapter 05’s job. This section is about what you do once you have been handed Pˉ\bar P, which is exactly the position the exam puts you in.

What each estimate is

The notation x^(ab)\hat x(a|b) means: estimate of the state at time aa, using measurements up to time bb. Both objects below use the same data.

the same data — every y up to t time t−2 t−1 t t+1 no y here x̂(t | t) — the filter estimates now x̂(t+1 | t) — the predictor estimates next × F × F⁻¹ needs F invertible

Same information, different target instant — which is why one multiplication converts between them.

Predictor — one step ahead of the data

x^(t+1t)\hat x(t+1|t) estimates a state the data has not reached yet. This is the form the Kalman recursion produces natively, and the form §03 wrote down.

Filter — level with the data

x^(tt)\hat x(t|t) estimates the state at the same instant as the most recent measurement. This is what a software sensor must deliver: an estimate of now, not of next.

Route A — invert FF

The filter’s own state equation is x^(t+1t)=Fx^(tt)\hat x(t+1|t)=F\hat x(t|t): to predict tomorrow from today’s best estimate, push it through the model — the noise contributes nothing because it is zero-mean. Reading that backwards gives the conversion:

Predictor to filter, when F is invertible

x^(tt)=F1x^(t+1t)\hat x(t|t)=F^{-1}\hat x(t+1|t)

One matrix inverse, applied to the whole predictor equation. That last point is where marks are lost; see the mistake callout below.

Route B — the filter form of the recursion

When FF is singular, route A is unavailable and the filter has to be generated directly. It has its own gain:

The filter form (valid only when V₁₂ = 0)
x^(tt)=Fx^(t1t1)+K0(t)e(t)filter state equationK0(t)=P(t)H(HP(t)H+V2)1the filter gain\begin{aligned} \hat x(t|t)&=F\hat x(t-1|t-1)+K_0(t)\,e(t) &&\text{filter state equation}\\ K_0(t)&=P(t)H^{\top}\big(HP(t)H^{\top}+V_2\big)^{-1} &&\text{the filter gain} \end{aligned}

with y^(tt1)\hat y(t|t-1) and e(t)e(t) unchanged — the innovation is still built from the prediction, in both forms — and the DRE identical. Nothing about P(t)P(t) changes; only how its output is used.

×

The filter form carries a condition the predictor form does not

K0(t)K_0(t) as written is valid only when V12=0V_{12}=0. In practice V12=0V_{12}=0 almost always, so the condition is easy to forget — but exam systems are built with a shared noise source specifically to make V120V_{12}\ne0. When it is non-zero, use route A. When FF is also singular, neither shortcut applies and the general derivation is needed.

The one-symbol difference

Set V12=0V_{12}=0 and put the two gains side by side:

Predictor gain vs filter gain
K(t)=(FP(t)H)(HP(t)H+V2)1,K0(t)=(P(t)H)(HP(t)H+V2)1K(t)=\Big(\,\boxed{F}\,P(t)H^{\top}\Big)\big(HP(t)H^{\top}+V_2\big)^{-1}, \qquad K_0(t)=\big(P(t)H^{\top}\big)\big(HP(t)H^{\top}+V_2\big)^{-1}

They differ by exactly the leading FF, which is to say K(t)=FK0(t)K(t)=F\,K_0(t). This is not a coincidence — it is route A’s F1F^{-1} seen from the other side. It is also the single most testable line in the chapter, and a one-symbol slip changes the answer without changing its shape.

Worked example — the exam’s own format

Do this in 5 minutes From matrices to a filter transfer function

What you are given

F=12,H=1,V2=1,V12=0,DRE converges to Pˉ=1F=\tfrac12,\quad H=1,\quad V_2=1,\quad V_{12}=0,\qquad\text{DRE converges to }\bar P=1

Scalar, as the exam always is. Pˉ\bar P is handed over; chapter 05 explains where it came from.

Compute the asymptotic gain

Using the MIX and OUTPUT blocks with V12=0V_{12}=0:

Kˉ=FPˉHHPˉH+V2=1211111+1=14\bar K=\frac{F\bar PH}{H\bar PH+V_2}=\frac{\tfrac12\cdot1\cdot1}{1\cdot1\cdot1+1}=\tfrac14

Check stability before going further

FKˉH=12141=14F-\bar KH=\tfrac12-\tfrac14\cdot1=\tfrac14

14<1\lvert\tfrac14\rvert<1, so the filter is asymptotically stable. Do this first: an unstable FKˉHF-\bar KH means the transfer function you are about to write is not a usable one, and part (a) of the real questions asks for it explicitly.

Write the predictor as a closed-loop recursion

Substitute e(t)=y(t)Hx^(tt1)e(t)=y(t)-H\hat x(t|t-1) into the state equation to eliminate ee:

x^(t+1t)=(FKˉH)x^(tt1)+Kˉy(t)=14x^(tt1)+14y(t)\hat x(t+1|t)=(F-\bar KH)\,\hat x(t|t-1)+\bar K\,y(t)=\tfrac14\hat x(t|t-1)+\tfrac14y(t)

The pole of everything that follows is FKˉHF-\bar KH, and Kˉ\bar K is the input gain.

Transfer functions of the predictor

Reading the recursion in the zz domain:

Wyx^(tt1)(z)=Kˉz(FKˉH)=14z14,Wyx^(t+1t)(z)=Kˉzz(FKˉH)=14zz14W_{y\to\hat x(t|t-1)}(z)=\frac{\bar K}{z-(F-\bar KH)}=\frac{\tfrac14}{z-\tfrac14}, \qquad W_{y\to\hat x(t+1|t)}(z)=\frac{\bar K\,z}{z-(F-\bar KH)}=\frac{\tfrac14z}{z-\tfrac14}

The two differ by one factor of zz — one step of shift, which is all “predictor” means.

Convert to the filter — the graded step

F=12F=\tfrac12 is invertible, so apply F1=2F^{-1}=2 to the entire predictor transfer function:

Wyx^(tt)(z)=F1Wyx^(t+1t)(z)=214zz14=12zz14W_{y\to\hat x(t|t)}(z)=F^{-1}\,W_{y\to\hat x(t+1|t)}(z)=2\cdot\frac{\tfrac14z}{z-\tfrac14} =\boxed{\frac{\tfrac12\,z}{z-\tfrac14}}

Cross-check with route B

The filter gain is K0=PˉH/(HPˉH+V2)=1/2K_0=\bar PH/(H\bar PH+V_2)=1/2, and indeed Kˉ=FK0=1212=14\bar K=FK_0=\tfrac12\cdot\tfrac12=\tfrac14 ✓. Running the filter recursion instead of converting gives the same transfer function — worth doing once, so that you trust the shortcut afterwards.

×

Where marks actually go missing

  • Applying F1F^{-1} to the gain only. The conversion multiplies the whole equation, both the memory term and the input term. Halving just one of them gives a wrong pole and a plausible-looking answer.
  • Answering with the predictor. The questions bold the word filter because this is the standard slip. Read the target of the transfer function before computing anything.
  • Expecting the filter to be dynamic. When FKˉH=0F-\bar KH=0 the recursion has no memory term at all and the “transfer function” collapses to a constant. That is a deadbeat filter, not an error — and it is exactly what the 04/09/2024 paper below serves up.
2024-09-q2b2024Q02Predictor vs filtermedium4 pts
Given a system described by the following matrices: $$F=2,\quad H=2,\quad V_1=1,\quad V_2=\tfrac13,\quad V_{12}=\tfrac13$$ The solution of the ARE is $\bar P=\tfrac23$ and the resulting asymptotic Kalman gain is $\bar K=1$. Assume the DRE converges to the ARE solution. a. Write the asymptotic Kalman predictor and filter equations. b. Compute the transfer function from $y(t)$ to $\hat x(t|t)$ (**filter**, not predictor).
2026-07-q2b2026Q02Predictor vs filtermedium4 pts
Consider the system described by the following matrices: $$F=1,\quad H=-2,\quad V_1=\tfrac13,\quad V_2=\tfrac14,\quad V_{12}=-\tfrac14$$ Knowing that the DRE converges to the only solution of the ARE $\bar P=\tfrac18$, answer the following questions: a. Compute the asymptotic Kalman gain and assess the filter stability. b. Compute the transfer function from $y(t)$ to $\hat y(t+1|t)$.
Deep dive Why the filter and the predictor always share their pole

Route A converts by scaling, so it cannot move a pole. Route B builds a different recursion, and it is not obvious that the two agree. Substituting x^(tt1)=Fx^(t1t1)\hat x(t|t-1)=F\hat x(t-1|t-1) into the filter form:

x^(tt)=Fx^(t1t1)+K0(y(t)HFx^(t1t1))=(FK0HF)x^(t1t1)+K0y(t)\hat x(t|t)=F\hat x(t-1|t-1)+K_0\big(y(t)-HF\hat x(t-1|t-1)\big)=(F-K_0HF)\,\hat x(t-1|t-1)+K_0\,y(t)

so the filter’s pole is FK0HFF-K_0HF. In the scalar case that is FKˉHF-\bar KH immediately, since Kˉ=FK0\bar K=FK_0 and everything commutes — the same pole as the predictor.

In the matrix case the two poles are F(IK0H)F(I-K_0H) for the predictor and (IK0H)F(I-K_0H)F for the filter, which are not the same matrix. They do, however, have the same eigenvalues: ABAB and BABA always share their non-zero spectrum, and when FF is invertible the two are outright similar via FF. So the stability verdict from FKˉHF-\bar KH transfers to the filter unchanged, which is why the exam is content to ask for stability once and reuse it for both forms.

A system has a singular state matrix F and a non-zero cross-covariance between its two noises. You need the filtered state estimate. Which route works?

05 · What you get for free

An accuracy figure you can compute before any data

The Riccati recursion was introduced as machinery for producing the gain. Its solution turns out to be the answer to the question §01 said every software-sensing project must answer second.

The meaning of P(t)
P(t)=E[(x(t)x^(tt1))(x(t)x^(tt1))]=var[x(t)x^(tt1)]P(t)=\mathbb E\Big[\big(x(t)-\hat x(t|t-1)\big)\big(x(t)-\hat x(t|t-1)\big)^{\top}\Big] =\operatorname{var}\big[x(t)-\hat x(t|t-1)\big]

P(t)P(t) is the covariance matrix of the one-step state prediction errorn×nn\times n, symmetric, semi-definite positive. Its diagonal entries are the variances of the individual state estimates; its off-diagonal entries say how those errors are correlated.

Now combine that with the fact from §03 that the DRE is autonomous:

key

A datasheet for a sensor that does not exist yet

The DRE takes no measurements as input. So P(t)P(t) — the accuracy of the software sensor — can be computed from FF, HH, V1V_1, V2V_2, V12V_{12} and P0P_0 before the plant is switched on, before any data is collected, before the algorithm is deployed.

That is what makes the design decision in §01 tractable. You can quote the software sensor’s noise figure and compare it against a hardware sensor’s datasheet at design time, and decide whether to buy the instrument — without building either.

The output prediction error variance

P(t)P(t) measures the error on the state. The exam sometimes wants the error on the output, which is not the same thing and is a three-line derivation away.

Q

One question, 3 marks, and no new machinery

Set once, on 26/07/2024, for 3 marks: given FF, HH, the covariances and a stated Pˉ\bar P, compute var[y(t)y^(tt1)]\operatorname{var}\big[y(t)-\hat y(t\lvert t-1)\big]. It is the cheapest item in Q2 and it is pure bookkeeping — but only if you remember that the output error carries V2V_2 on top of the state error. The supplied Kˉ\bar K is a decoy: it never enters the calculation.

3 lines From state error to output error

Subtract the two output equations

y(t)=Hx(t)+v2(t)y(t)=Hx(t)+v_2(t) and y^(tt1)=Hx^(tt1)\hat y(t|t-1)=H\hat x(t|t-1), so

y(t)y^(tt1)=H(x(t)x^(tt1))+v2(t)y(t)-\hat y(t|t-1)=H\big(x(t)-\hat x(t|t-1)\big)+v_2(t)

Argue the two terms are uncorrelated

x(t)x^(tt1)x(t)-\hat x(t|t-1) is built from measurements up to t1t-1; v2(t)v_2(t) is fresh noise at time tt. For a white v2v_2 they cannot be correlated, so the variances simply add.

Read off the result

var[y(t)y^(tt1)]=HP(t)H+V2\operatorname{var}\big[y(t)-\hat y(t|t-1)\big]=HP(t)H^{\top}+V_2

Which is the OUTPUT block from §03’s mnemonic — the same object that sits in the denominator of the Kalman gain. It was never an arbitrary grouping; it is the variance of the innovation.

×

Forgetting the sensor noise

Asked for var[yy^]\operatorname{var}\big[y-\hat y\big], the tempting answer is Pˉ\bar P. It is wrong by exactly V2V_2: the output error contains the measurement noise on top of the propagated state error. And the Kalman gain is not needed anywhere in this calculation — it enters only through Pˉ\bar P, which the question already gives you.

2024-07-q2c2024Q02Output prediction error varianceeasy3 pts
Given a system described by the following matrices: $$F=-2,\quad H=1,\quad V_1=\tfrac12,\quad V_2=\tfrac15,\quad V_{12}=-\tfrac14$$ The solution of the ARE is $\bar P=\tfrac14$ and the resulting asymptotic Kalman gain is $\bar K=-\tfrac53$. Assume the DRE converges to the ARE solution. Compute the variance of the output prediction error $\mathrm{Var}\!\left[y(t)-\hat y(t|t-1)\right]$.

06 · Extensions 1, 3 and 4

Many steps ahead, a known input, a drifting plant

The basic case was deliberately stripped down. Putting the missing pieces back costs almost nothing — which is a statement about the structure of the derivation, not about luck.

The lecture numbers five extensions. Extension 2 — the filter — was promoted to §04 because it carries the exam weight, and extension 5 — the nonlinear case — is deferred to chapter 07, where the Extended Kalman Filter is the machinery behind gray-box identification. The remaining three are here.

Extension 1 — prediction kk steps ahead

Once x^(t+1t)\hat x(t+1|t) is available, going further needs no new data, so it needs no new correction: just iterate the model.

Multi-step prediction

x^(t+kt)=Fk1x^(t+1t),y^(t+kt)=Hx^(t+kt)\hat x(t+k|t)=F^{\,k-1}\hat x(t+1|t),\qquad \hat y(t+k|t)=H\hat x(t+k|t)

×

The exponent is k − 1, not k

Reaching t+kt+k from t+1t+1 takes k1k-1 applications of FF, not kk — the Kalman recursion already spent one step getting you to t+1t+1. Writing FkF^{k} is a classic slip, and it is silent: the answer has the right shape and the wrong value. Check it against k=1k=1, where the formula must reduce to x^(t+1t)\hat x(t+1|t) itself, i.e. F0=IF^{0}=I.

Extension 3 — an exogenous input Gu(t)Gu(t)

The estimate equations pick up the input term in the obvious place, and then:

key

K(t) and P(t) are completely unchanged

Adding Gu(t)Gu(t) changes neither the gain nor the Riccati equation. The reason is worth internalising because it explains what the DRE is actually tracking: Gu(t)Gu(t) adds no uncertainty. It is the perfectly known, deterministic part of the system. The Riccati recursion propagates uncertainty, and a signal you already know carries none — so the prediction error, and its covariance, are identical with or without it.

Extension 4 — a time-varying plant

For x(t+1)=F(t)x(t)+G(t)u(t)+v1(t)x(t+1)=F(t)x(t)+G(t)u(t)+v_1(t) with y(t)=H(t)x(t)+v2(t)y(t)=H(t)x(t)+v_2(t), the Kalman equations are exactly the same — replace FF, GG, HH by F(t)F(t), G(t)G(t), H(t)H(t) wherever they appear. The typical physical cause is ageing: plant dynamics that drift slowly over the equipment’s life.

This extension is also the door to the Extended Kalman Filter in chapter 07, whose whole strategy is to approximate a nonlinear time-invariant system by a linear time-varying one — precisely so that this extension applies.

The uncomfortable corollary

Even with a time-invariant plant, the Kalman filter is a time-varying system, because K(t)K(t) varies. That single observation is what chapter 05 is about: it makes stability hard to certify and forces a matrix inversion at every sampling instant, and the fix is to stop using K(t)K(t) and use its limit instead.

07 · When the assumption fails

Coloured noise and the model-extension trick

Every formula so far assumed v1v_1 and v2v_2 are white. Real disturbances frequently are not — a sensor’s own noise is often visibly correlated in time. The repair does not modify the filter; it modifies the model until the filter applies again.

Q

Asked as theory, with a worked example demanded

Set on 16/07/2026 as a 3-mark theory question: how do you handle a non-white v1v_1, described with an example of a simple first-order system. The second half of that instruction is the marking scheme — a full-credit answer names the trick, gives the recipe, and then actually carries out an extension on a concrete first-order plant. Prose alone will not score it.

Why whiteness was load-bearing

The Kalman derivation assumes the innovation is white. If v1v_1 is correlated in time, then part of “the part the model failed to anticipate” was in fact predictable from past innovations — the orthogonality argument behind the DRE fails, and the filter systematically mis-weights the model against the measurement. It still runs; it is simply no longer optimal, and worse, P(t)P(t) no longer reports the true error covariance, so its own accuracy claim becomes a lie.

The trick

A coloured noise is, by definition, white noise pushed through a filter. So model that filter explicitly, append its state to the plant’s, and the augmented system is driven by white noise once more. The standard Kalman filter then applies to the extended model unchanged — you are including the noise dynamics into the system dynamics.

Memorise this Model extension — the recipe

Identify the shaping filter

Write the coloured noise as v1(t)=Ws(z)ξ(t)v_1(t)=W_s(z)\xi(t) with ξ\xi white. The shaping filter Ws(z)W_s(z) is whatever colours it.

Put the shaping filter in state space

Convert Ws(z)W_s(z) to a state-space realisation — chapter 01’s job, and the reason this chapter needs that one as a prerequisite.

Stack the states

Form the extended state xE=[xxs]x_E=\begin{bmatrix}x\\ x_s\end{bmatrix}, with the plant on top and the shaping filter underneath.

Build the extended matrices

Assemble FEF_E, HEH_E and the new covariances V1EV_{1E}, V2EV_{2E}, V12EV_{12E} for the augmented system.

Run the ordinary Kalman filter

Apply the standard equations to {FE,HE,V1E,V2E,V12E}\{F_E,H_E,V_{1E},V_{2E},V_{12E}\}, then read the physical estimate off the first block of x^E\hat x_E. The appended components estimate the noise itself — a by-product, occasionally a useful one, but not the goal.

The first-order example the question asks for

Take a first-order plant whose process noise is an AR(1) process:

A plant with coloured process noise
{x(t+1)=ax(t)+η(t)y(t)=bx(t)+v2(t)η(t)=11cz1e(t)\begin{cases}x(t+1)=a\,x(t)+\eta(t)\\ y(t)=b\,x(t)+v_2(t)\end{cases} \qquad \eta(t)=\frac{1}{1-c\,z^{-1}}\,e(t)

with eWN(0,1)e\sim\mathrm{WN}(0,1), v2WN(0,1)v_2\sim\mathrm{WN}(0,1) and v2ev_2\perp e. The Kalman formulas cannot be applied as they stand, because η\eta is not white.

Expand the noise model back into the time domain: η(t+1)=cη(t)+e(t+1)\eta(t+1)=c\,\eta(t)+e(t+1). Define v(t)=e(t+1)v(t)=e(t+1), which is still white with the same variance, and the shaping filter becomes a first-order state equation, η(t+1)=cη(t)+v(t)\eta(t+1)=c\,\eta(t)+v(t).

Now promote η\eta to a state. With x1=xx_1=x and x2=ηx_2=\eta:

The extended system — order 2, driven by white noise

{x1(t+1)=ax1(t)+x2(t)x2(t+1)=cx2(t)+v(t)y(t)=bx1(t)+v2(t)\begin{cases}x_1(t+1)=a\,x_1(t)+x_2(t)\\ x_2(t+1)=c\,x_2(t)+v(t)\\ y(t)=b\,x_1(t)+v_2(t)\end{cases}

which in standard form is

Extended matrices and covariances
FE=[a10c],HE=[b0],V1E=[0001],V2E=1,V12E=0F_E=\begin{bmatrix}a&1\\0&c\end{bmatrix},\quad H_E=\begin{bmatrix}b&0\end{bmatrix},\quad V_{1E}=\begin{bmatrix}0&0\\0&1\end{bmatrix},\quad V_{2E}=1,\quad V_{12E}=0

The driving noise is white again, so the standard Kalman filter applies. Note where the coupling went: the 11 in the top-right corner of FEF_E is the coloured noise entering the plant, now a perfectly ordinary state interaction.

×

Two things this costs, and one shortcut that does not work

  • V1EV_{1E} is singular. Only the shaping-filter channel is driven by noise, so the top-left block is zero — semi-definite, not definite. Chapter 05’s second asymptotic theorem asks for reachability from the noise, and on an extended model that condition has to be checked rather than assumed.
  • The state dimension grows by the order of the shaping filter, and the Riccati recursion is cubic in nn. The shaping filter also has to be identified from data before any of this can start.
  • Inflating V1V_1 instead does not work. Enlarging V1V_1 accounts for the noise’s magnitude and says nothing about its time correlation. The filter stays sub-optimal and P(t)P(t) still misreports the error.

The same construction handles a coloured measurement noise, and — with unknown model parameters appended as extra states instead of a noise filter — it is exactly the mechanism behind gray-box identification in chapter 07. Learning the trick once pays three times.

2026-07-q52026Q05Coloured noise and model extensionmedium3 pts
Consider the problem of using a Kalman filter when the noise $v_1(t)$ on the state equation is not white; how can this problem be managed? Describe the solution with an example of a simple 1st-order system.

08 · In practice

The Kalman filter in MATLAB

Two functions cover the whole chapter: kalman for the filter and idare for the steady-state Riccati solution. Both are stated in a different parameterisation from the course’s, and both have a trap in the translation.

No archived question has yet asked specifically for kalman or idare. But MATLAB questions appear in 8 of the last 9 papers (see the exam analysis), the lecturer states in the exercise sessions that the exam will contain simple MATLAB questions, and these are the only two functions in the course that touch chapter 2.3 — so the cost of learning them is three lines and the downside of not is a whole question.

The two parameterisations

MATLAB does not write the noises the way the course does. It routes a single process noise ww through matrices into both equations:

courseMATLAB
statex(t+1)=Fx(t)+Gu(t)+v1(t)x(t{+}1)=Fx(t)+Gu(t)+v_1(t)x(t+1)=A^x(t)+B~u(t)+G~w(t)x(t{+}1)=\hat Ax(t)+\tilde Bu(t)+\tilde Gw(t)
outputy(t)=Hx(t)+Du(t)+v2(t)y(t)=Hx(t)+Du(t)+v_2(t)y(t)=C^x(t)+D^u(t)+H~w(t)+v(t)y(t)=\hat Cx(t)+\hat Du(t)+\tilde Hw(t)+v(t)
covariancesV1V_1, V2V_2, V12V_{12}QQ, RR, NN

Matching v1=G~wv_1=\tilde Gw and v2=H~w+vv_2=\tilde Hw+v gives the general translation:

General equivalence between the two forms
V1=G~QG~,V2=H~QH~+H~N+NH~+R,V12=G~QH~+G~NV_1=\tilde GQ\tilde G^{\top},\qquad V_2=\tilde HQ\tilde H^{\top}+\tilde HN+N^{\top}\tilde H^{\top}+R,\qquad V_{12}=\tilde GQ\tilde H^{\top}+\tilde GN

Nobody wants to compute that. The trick is to choose the routing matrices so it collapses: set G~=I\tilde G=I and H~=0\tilde H=0, and the three equivalences become simply V1=QV_1=Q, V2=RV_2=R, V12=NV_{12}=N — the course’s covariances pass straight through.

That choice is implemented by declaring the noise as an extra bank of inputs:

% dt = sampling TIME; n states, p outputs
SYS = ss(F, [G eye(n)], H, [D zeros(p,n)], dt);

[KALMAN_SYS, K, P] = kalman(SYS, V1, V2, V12, 'current');   % 'current' -> FILTER
                                                            % 'delayed' -> PREDICTOR

SYS and KALMAN_SYS are both state-space objects; K and P are the asymptotic gain and Riccati solution.

×

The flag that decides what you built

'current' returns the filter x^(tt)\hat x(t|t) and 'delayed' returns the predictor x^(t+1t)\hat x(t+1|t). Neither word is the one the course uses, both are plausible for either object, and the two results differ by exactly the factor FF from §04. Getting this backwards produces a correctly-sized, fully-functional, wrong answer — which is precisely what a short MATLAB exam question is built to detect.

The algebraic Riccati equation — idare

For the steady-state solution of chapter 05, MATLAB provides the implicit discrete algebraic Riccati equation solver. It is stated for the dual control problem, so the plant matrices go in transposed:

[P, Ktilde, EIGS] = idare(F', H', V1, V2, V12, eye(n));
K = Ktilde';        % <-- transpose back
% EIGS already contains eig(F - K*H)
×

Two transposes, and the second one is silent

Transposing FF and HH on the way in is easy to remember, because forgetting it usually errors out on dimensions. Transposing the returned gain is not: Ktilde has the right size to be used directly in a scalar or square problem, so omitting Ktilde' yields a wrong gain that runs cleanly. The returned EIGS is the eigenvalues of FKHF-KH, which hands you the stability check of §04 for free — use it as a consistency test on the gain you think you computed.

Load-bearing ideas

  • Software sensing is an economics decision first: fixed development cost against variable hardware cost, break-even at NN units, redundancy and installability bending the result. Then two technical gates — observability (feasible?) and var[xx^]\operatorname{var}[x-\hat x] (good enough?).
  • The model: v1v_1 is process noise with V10V_1\ge0; v2v_2 is measurement noise with V2>0V_2>0 strictly, and that strictness is what makes the gain’s inverse exist. V120V_{12}\ne0 whenever the two equations share a noise source — which is how every exam builds them.
  • The block mnemonic rebuilds both hard formulas: STATE =FPF+V1=FPF^{\top}+V_1, OUTPUT =HPH+V2=HPH^{\top}+V_2, MIX =FPH+V12=FPH^{\top}+V_{12}, then K=(MIX)(OUTPUT)1K=(\text{MIX})(\text{OUTPUT})^{-1} and P+=(STATE)(MIX)(OUTPUT)1(MIX)P^{+}=(\text{STATE})-(\text{MIX})(\text{OUTPUT})^{-1}(\text{MIX})^{\top}.
  • The DRE is autonomous — no data enters it. So K(t)K(t) and P(t)P(t) are computable offline, and the software sensor’s accuracy can be quoted before the sensor is built.
  • P(t)=var[x(t)x^(tt1)]P(t)=\operatorname{var}[x(t)-\hat x(t|t-1)], the state prediction error covariance; the output prediction error variance is HP(t)H+V2HP(t)H^{\top}+V_2 — the OUTPUT block, which is no coincidence.
  • Predictor to filter: x^(tt)=F1x^(t+1t)\hat x(t|t)=F^{-1}\hat x(t+1|t) when FF is invertible; otherwise the filter form with K0=PH(HPH+V2)1K_0=PH^{\top}(HPH^{\top}+V_2)^{-1}, valid only when V12=0V_{12}=0. The two gains differ by exactly the leading FF: K=FK0K=FK_0. Same DRE, same pole, different scaling.
  • Extensions are nearly free: Fk1F^{k-1} (not FkF^{k}) for multi-step; a known input changes nothing in KK or PP because it carries no uncertainty; a time-varying plant just gets time-varying matrices.
  • Coloured noise is repaired in the model, not the filter — realise the shaping filter, stack its state, re-run the standard Kalman filter, read the answer off the first block. The extended V1V_1 comes out singular, which matters in chapter 05.
  • MATLAB: G~=I\tilde G=I, H~=0\tilde H=0 makes the covariances pass through unchanged; 'current' = filter, 'delayed' = predictor; idare takes FF', HH' and returns a gain you must transpose back.

Exam radar. Two things in this chapter carry real marks. First, §04, predictor vs filter — 7 questions, 27 marks, every one of the last five sittings. Be able to go from {F,H,V1,V2,V12}\{F,H,V_1,V_2,V_{12}\} plus a supplied Pˉ\bar P to Kˉ\bar K, to FKˉHF-\bar KH, to the closed-loop recursion, to the transfer function, and finally to apply F1F^{-1} to all of it — in five minutes, without notes. Second, §02, building the covariances — 3 questions, 18 marks, and always part (a), so an error there propagates through the rest of Q2. Expand every square in full and keep the cross terms.

Behind both sits §03: if you can write the three blocks from memory, you can rebuild the gain and the DRE under pressure, and neither question can strand you. §07 is a 3-mark theory item that wants a worked first-order extension, not a description — practise writing that 2×22\times2 FEF_E from scratch.