Hexa Scholar

The Kalman filter

A tabletop sensor beside a small cart partly hidden by a cloudy gold cover.
A tabletop sensor sits beside a cart partly hidden by a cloudy cover.

The question

A cart rolls out of sight and its sensor readings jitter. How would you estimate where it is now?

Adjust a filter and check it against the cart’s hidden path.

  1. 1 SeeTune a filter for a hidden path.
  2. 2 TryChange the sensor’s noise variance.
  3. 3 ProveDerive the update from a Gaussian density.
  4. 4 ApplyUpdate a forecast and handle missing readings.
Before you start · 3 quick checks on variance, persistence and conditioning

Two ideas before you start

2 ideas

The cart moves and the sensor reads

The state disturbance moves the cart. The measurement error offsets the reading from the cart’s position.

A state disturbance changes the cart’s actual position. A measurement error changes what the sensor reports.

Exact definition

At equally spaced steps \(t\), \(X_t\) is the hidden position and \(Y_t\) is the reading. The game uses a random walk with state disturbance \(W_t\) and measurement error \(E_t\).

\[\begin{aligned}X_t &= X_{t-1}+W_t,\\ Y_t &= X_t+E_t.\end{aligned}\]

The disturbances are independent across time and of each other and the initial state. They are Gaussian with mean zero and constant variances \(Q\gt 0\) for \(W_t\) and \(R\gt 0\) for \(E_t\). The fixed offsets in this diagram illustrate one step.

An estimate has a center and a spread

The estimate stays at the center while its uncertainty band gets wider or narrower.

A filter carries both a position estimate and a measure of how uncertain that estimate is. The center can stay put while the band changes.

Exact definition

Write \(m_t\) and \(P_t\) for the conditional mean and conditional variance of \(X_t\) after reading \(Y_t\) and all earlier readings. The uncertainty band here runs from \(m_t-\sqrt{P_t}\) to \(m_t+\sqrt{P_t}\). Its half-width is the conditional standard deviation, measured in position units. The variance itself has squared position units.

Under the matching Gaussian model, the band describes the distribution of the state at each step given the readings up to that step. It can miss the true position. The model gives no promise that a whole path will stay inside it.

Refresher: what carries over from other lessons

In the AR(1) model, a coefficient \(a\) multiplies the preceding state before independent noise is added. The model here uses the random-walk case \(a=1\) for the game. The filter works with a distribution for the hidden state, since the sensor sees a noisy reading in place of the state itself.

Conjugate priors explains how a normal prior and a Gaussian reading give a normal posterior. Here the previous posterior first has to move forward in time. The resulting forecast distribution is the prior for the next reading.

Stationarity concerns the distribution of a process over time. A filter’s error variance is a different quantity. A driftless random walk with independent increments of fixed positive variance has increasing state variance, even when the filter’s error variance settles.

1 See

Tune the filter while the cart is hidden

The initial position is Gaussian with mean zero and variance \(R\). The filter starts with that same distribution and is given the correct sensor variance. Changing the ratio changes its assumed state variance. Each estimate uses only the sensor readings through its own step.

2 Try

Change the sensor and keep the forecast

Take a Gaussian forecast with mean \(m\) and positive variance \(V\). Two independent-error sensor models report the same reading \(y\), which differs from \(m\). Each sensor’s error is centered Gaussian with positive variance.

3 Prove

Derive the gain and the updated variance

Scalar Gaussian update

Given the previous readings, let the forecast for \(X\) be Gaussian with mean \(m\in\mathbb R\) and variance \(V\gt 0\). Observe \(Y=X+E\), where \(E\) is independent of the state and past readings, and Gaussian with mean zero and variance \(R\gt 0\). For every real reading \(y\), the conditional distribution of \(X\) is Gaussian with mean \(m+K(y-m)\) and variance \(P=VR/(V+R)\), where \(K=V/(V+R)\).

Choose the algebra that turns the prior and the likelihood into one Gaussian. Let \(x\) be a possible state value. Up to an additive constant in \(x\), the log posterior has the form \(-Ax^2/2+Bx\). The proof identifies the coefficients and reads the new mean and variance from the square.

4 Apply

Which part of the cycle do you need?

Use the forecast, the measurement update, or both. Give a decimal within the absolute error shown. Each problem has hints and a worked solution.

Key point Label each variance before using it. A forecast variance includes fresh state noise. A posterior variance reflects which readings were available and how much sensor noise the model assigns to them.
Level Intermediate Prerequisites Variance, conditional distributions, and the AR(1) model Time About half an hour

Further reading