The Extended Kalman Filter and Gray-Box Identification
Two ideas that turn out to be one. Linearising a nonlinear model at every step gives the extended Kalman filter; promoting an unknown physical parameter to a state lets the same filter identify it. The second trick forces the first — appending a parameter to the state multiplies two unknowns together, so a linear plant stops being linear the moment you try this.
01 · Extension 5
The extended Kalman filter
Chapter 04 listed five extensions to the basic Kalman filter and deferred the fifth. Here it is — and unlike the other four, it is not free.
The plant is now nonlinear in the state:
with and of class or better — differentiable, which is the only property the construction actually needs. Something like with qualifies.
The strategy is unchanged: run a replica of the plant and correct it with the output error. The only open question is what the gain should be, and there are two candidate answers.
Option 1 — a nonlinear gain
The correction block outputs , with itself a nonlinear function of the innovation. The most intuitive and natural answer — and it discards the entire linear theory.
Option 2 — a linear time-varying gain
The block outputs , exactly as before, with recomputed each step. Less intuitive, and it re-uses almost all of the Kalman theory. This is what the EKF does.
Linearise, then apply what you already have
The gain and the Riccati recursion keep their usual shape; only and become time-varying:
with given by the same STATE − MIX·OUTPUT⁻¹·MIXᵀ expression, and the two matrices obtained as Jacobian matrices, recomputed at every sampling instant:
The EKF turns extension 5 into extension 4
The whole idea in one sentence: approximate a nonlinear time-invariant system by a linear time-varying one, so that chapter 04’s fourth extension — which cost nothing at all — applies.
Note where the Jacobians are evaluated: at , the predicted state, not the filtered one and certainly not the true state, which is unknown. The linearisation is taken about the best guess available at the moment it is needed.
Take the latest prediction
Start from , carried over from the previous iteration.
Linearise about it
Evaluate the two Jacobians at to get and .
Update the Riccati recursion and the gain
Feed and into the DRE to get , and into the gain formula to get .
Advance the estimate
Compute from the correction equation, and loop.
What you gave up
There is no steady state, and therefore no shortcut and no guarantee
The EKF is nonlinear and time-varying, so the whole of chapter 05 does not apply: no algebraic Riccati equation, no , no , no asymptotic theorems. Two consequences follow, and neither is small.
- Asymptotic stability is impossible or very difficult to guarantee. There is no to test. In practice only extensive empirical validation is available — you run it on a lot of data and hope.
- The computational load is high. , , and must all be recomputed at every sampling instant, where a steady-state linear filter would use one precomputed constant.
Despite that, the EKF is used heavily in real applications — with reservations exactly where the missing guarantee matters most: safety-critical systems (velocity estimation inside ABS) and mission-critical ones (a rover on Mars).
02 · End to end
Designing a filter for a real plant
Every worked example so far arrived with , and the covariances already supplied. Getting them is four steps, and only the last one is genuinely hard.
The problem: a mass–spring–damper with known stiffness , mass and friction coefficient . The input is the applied force ; the measured output is the position . Estimate the velocity in software.
The obvious answer, and why it is not the right one
Differentiate the position numerically and low-pass the result. The filter is needed because numerical differentiation amplifies high-frequency noise — but it introduces phase shift, which can be critical inside a control loop.
It is not optimal. A Kalman filter gives an estimate that is both less noisy and less phase-shifted, because it is using a model of how position and velocity are related rather than treating the signal as an arbitrary time series.
Step 1 — build the white-box model, in continuous time
Newton’s second law on the mass:
A linear second-order ODE. Physical white-box modelling comes naturally in continuous time, so start there and convert later. Split it into two first-order equations by taking the two natural mechanical states — position and velocity:
Step 2 — discretise
Euler forward, with the sampling time — say 10 ms. Substituting and rearranging gives a discrete-time model whose matrices are
This is an approximation, and is the knob that controls how good it is.
Step 3 — add the noise
The model so far is deterministic; the Kalman filter needs the stochastic version. Add to the state equation and to the output:
Step 4 — choose the covariances
The only genuinely open step, handled empirically:
- — there is no reason for the process and measurement noises to be correlated here.
- — from the position sensor’s datasheet, or by measuring its noise directly.
- — the hard one. Simplify by assuming it diagonal, , which turns an unknown into two scalars to be tuned.
Where the hard step went
Chapter 04 flagged as the Kalman filter’s real weak point, and this is where the flag is redeemed. Modern practice treats and as meta-parameters estimated from a dataset in a black-box way: collect a training set and minimise the state estimation error over them.
Which is worth noticing for what it is. A model-based method, at its very last step, reaches for a machine-learning technique — the same convergence chapter 06 approached from the other side.
03 · The problem
Known structure, unknown parameters
The Kalman filter was built to estimate states. It turns out to estimate physical constants too, with no new theory at all — a side benefit that chapter 04 promised and this section collects.
Two stems, three sittings — and nothing since July 2024
Gray-box identification has been set twice with distinct stems, spanning three sittings: “explain how the Kalman filter can be used to solve grey-box identification problems” (15/07/2023 and again, identically, 25/06/2024) and “describe what offline grey-box identification is, with two example input signals” (26/07/2024). Three marks each.
It is also the module’s fading topic: it has not appeared in any of the seven sittings since 26/07/2024. Read that as a reason to know it rather than to drill it — the recorded weight is low and the trend is downward, but a 3-mark theory question is cheap to secure and both stems are answerable from this chapter and the next section.
The setting. A model is available, built white-box from physics:
with and known functions containing a few unknown parameters — and has physical meaning: a friction coefficient, a mass, a time constant. Given a dataset and , estimate .
This is the precise definition of gray box
Not “partly known” in a vague sense. The structure is fully known and a handful of physical constants are not. Place it against the rest of the module:
| structure | parameters | physical meaning | |
|---|---|---|---|
| chapters 02–03, black box | unknown | fitted | none |
| chapter 04, white box | known | known | full |
| this chapter, gray box | known | a few unknown | full |
The payoff is that the identified numbers mean something — which is exactly what chapter 06’s black-box sensor could not offer.
The trick, stated
Append a state equation for and stack it under the physical state. An unknown parameter has been reclassified as an unknown state, and the entire Kalman machinery — built for states — now estimates it. No new theory; a change of bookkeeping.
04 · The trick
Promoting parameters to states
The appended equation looks trivial and is not. Each of its three features — the constant dynamics, the marginal stability, the added noise — is doing work, and one of them is the chapter’s most commonly missed point.
The core relation is — the equation of a constant quantity, which is right, because constant parameters are what we are estimating. Adding the noise makes it a random walk.
Marginally stable, and that is fine
The appended mode sits at : simply stable, not asymptotically stable. That is not a defect to be repaired. Chapter 05 showed the filter’s stability lives in , not in , and the lecture states plainly that marginal stability here is not a problem for the Kalman filter.
Why the fictitious noise is there — the most missed point in the chapter
The parameter really is constant, so is not a claim that it fluctuates. It is a deliberate design device.
Without it, the parameter channel has no process noise, its error covariance collapses towards zero, and the filter concludes it already knows perfectly. It then trusts its initial condition and stops searching — the estimate freezes on whatever was guessed at , no matter what the data says.
Injecting keeps from collapsing, which keeps the gain on that channel alive, which keeps the estimator willing to move. Setting “because the parameter is constant” is the single most reliable way to get a confident wrong answer.
One knob
The assumptions are the usual ones — with and — and is then collapsed, hard:
All the structure of becomes a single tuning knob , and it controls a trade-off with two clean ends:
| convergence | steady-state variance | |
|---|---|---|
| large | fast — the estimate climbs to the true value quickly | large — it then rattles around it |
| small | slow — the estimate creeps up over many samples | small — it settles tightly |
Which end to pick, and the case that settles it
The right choice depends on the length of the dataset — a short record cannot afford slow convergence — and on whether the parameter is genuinely constant.
If it is time-varying and the filter runs always-on, you want the larger value, because the estimator must keep chasing. The lecture’s example is the mass of fuel in a rocket: that “parameter” drops continuously through the flight, and a filter tuned for a constant would lag it badly.
Two estimates for the price of one — within limits
Run the extended filter and it delivers and simultaneously, from the same measurements. That is genuinely free, and it invites over-reach.
Do not ask too much
The number of unknowns you can identify is bounded by the number of things you actually measure. Compare the sensors-versus-unknowns budget:
| sensors | states | parameters | ratio | verdict |
|---|---|---|---|---|
| 3 | 10 | 15 | hopeless | |
| 3 | 5 | 2 | realistic |
Extending the state is cheap to write and expensive to afford. The formal version of this check is observability of the extended system — and identifiability is structural, not statistical: if two parameters only ever appear as a product, no quantity of data will separate them. A filter given more unknowns than it can support still runs, and produces confident nonsense.
You extend the state with an unknown constant parameter and set its fictitious process-noise variance to zero, reasoning that the parameter genuinely does not change. What happens?
05 · The consequence
State extension makes the model nonlinear
The trick has a hidden cost, and it is the reason this chapter carries the extended Kalman filter rather than referring to it.
Same move, same consequence, every time: one more state, one more product, one linearisation per step.
Take §02’s mass–spring–damper and change one thing: the friction coefficient is now unknown. So , and state extension promotes it to a third state :
with , from the sensor, and .
Look at the second equation
It contains the product — an unknown state multiplied by another unknown state. The system has become nonlinear.
The original plant was perfectly linear. Nothing about the physics changed; the nonlinearity was manufactured by the trick itself, and it is unavoidable, because a parameter that multiplies a state in the original model will multiply that state again once it is promoted.
So gray-box identification via state extension is almost always an EKF problem, never a plain KF one. Answering the exam question with “run a Kalman filter on the extended model” and stopping there is the single most-missed point in the topic.
Two extensions, one pattern
This is the second time in the module that appending states to make a problem tractable has cost something structural. Chapter 04 extended the state with a noise shaping filter and the extended came out singular, which put chapter 05’s second theorem in question. Here the extension costs linearity, which puts all of chapter 05 out of reach at once.
Both are worth remembering as a general lesson: state extension is a cheap thing to write down and its price is always paid somewhere in the hypotheses.
Once that is accepted, the extended model is ready: run the EKF on it and it returns the physical states and the friction coefficient together, online, from position measurements alone.
06 · The alternative
Offline identification by simulation error
There is a second route to the same parameters — more intuitive, entirely classical, and far more expensive.
Set once, and it wants example inputs
“Describe what offline grey-box identification is and make two examples of input signals which can be used for the identification dataset” — 3 marks, 26/07/2024. The second clause is half the marks: an answer that explains batch optimisation and never names a signal is incomplete.
Treat the physical model as a simulator : pick a candidate , drive the model with the recorded input, compare its output against the recorded one, and minimise the simulation-error optimisation index:
where is the output of the simulator driven by — and writing it that way makes the cost visible.
Why this is extremely more expensive than the filter
Every candidate requires a full simulation of the model over the whole dataset, and that simulation sits inside a non-convex outer optimisation which will evaluate many candidates.
The Kalman route gets the same parameter as a by-product of one forward pass over the data. That is the honest comparison, and it is not close.
Choosing the input
Both routes need data that actually contains information about , which is the requirement chapter 02 called persistent excitation: the input must excite every mode the unknown parameters influence, across the band where the model has to be accurate. Otherwise is flat in some directions and those parameters are simply not identifiable.
Multi-sine or swept sinusoid (chirp)
A sum of sinusoids, or one whose frequency sweeps the band of interest. Gives precise control over which frequencies get excited and how much energy each receives, and keeps amplitude inside actuator limits — chapter 03’s schedule applies directly.
PRBS — pseudo-random binary sequence
A deterministic, repeatable two-level signal with an approximately flat spectrum over a wide band. Excites everything at once, is trivial to generate, drives on/off actuators natively, and delivers maximum energy for a bounded amplitude.
A step is not an identification input
It is the reflex answer and it is wrong. A step excites essentially one region of the spectrum, so it pins down the static gain well and the dynamics badly. Whatever else the experiment does, the plant must also stay inside its linear operating region, the actuators must not saturate, and an unstable plant must be tested inside a stabilising loop — chapter 03’s closed-loop identification.
Deep dive Choosing between the two routes
They are not ranked; they fail differently.
State extension is recursive and cheap, runs online, tracks a drifting parameter, and delivers states and parameters together. It requires the fictitious noise and its tuning knob, it is bounded by the sensors-versus-unknowns budget, and it drags in the EKF with all of §01’s missing guarantees.
Simulation-error optimisation uses the whole dataset at once, needs no fictitious noise, and is not restricted to models a Kalman filter can handle — any simulator will do. It cannot track a drifting parameter, it is not recursive, and it is enormously more expensive.
The practical split: online, drifting, cheap points to state extension; offline, constant, awkward model points to batch optimisation.
Load-bearing ideas
- The EKF keeps the linear gain structure and recomputes , as Jacobians evaluated at , the predicted state. It converts a nonlinear time-invariant problem into a linear time-varying one — chapter 04’s extension 4, which was free.
- What that costs: no steady state, so no ARE, no , no asymptotic theorems; stability can only be validated empirically; and every step recomputes four matrices. Used widely anyway, warily in safety- and mission-critical settings.
- Designing a filter for a real plant is four steps: white-box ODE in continuous time → state space → Euler discretisation → add noise, then choose , from a datasheet, and diagonal with its entries tuned (today, from data — a machine-learning step inside a model-based method).
- Gray box means the structure is fully known and a few physically meaningful parameters are not — distinct from black box (structure unknown, parameters meaningless) and white box (all known).
- State extension: append and stack under . The parameter becomes a state and the ordinary machinery estimates it.
- The fictitious noise is a design device, not a modelling claim. Without it collapses, the gain on the parameter channel dies, and the estimate freezes on its initial guess. collapses to one knob : large = fast and noisy, small = slow and clean; large is right for a genuinely drifting parameter.
- Budget the unknowns against the sensors. More parameters than the measurements support gives a filter that runs and lies. Identifiability is structural — parameters appearing only as a product are never separable.
- The catch: extending the state multiplies unknown by unknown (), so a linear plant becomes nonlinear and the EKF is required. Same pattern as chapter 04’s coloured-noise extension, which cost a singular .
- The alternative is batch simulation-error optimisation: intuitive, no fictitious noise, any simulator — but one full simulation per candidate inside a non-convex search, and no tracking. Inputs must be persistently exciting: multi-sine/chirp or PRBS, never a step.
Exam radar. Two 3-mark theory stems, three sittings, nothing since July 2024 — the module’s fading topic, and cheap to secure. For the first stem, be able to go: gray-box setting → state extension → why the fictitious noise exists → trade-off → and the extended model is nonlinear, so EKF. That last clause is what most answers omit. For the second, define offline batch optimisation against the recursive route, then name two concrete inputs and say what persistent excitation buys.