VIEW THIS AS

Auto mode follows the Route Engine until you choose a viewpoint.

YOU ARE HERE

ROUTE CHECK

CONNECTED TO

WHAT NEXT

Use the canonical route for this room, or HELP if you are unsure.

How Artificial Intelligence AI Works | How Kalman Filters Track Noisy Measurements

Did you know? A phone’s location dot can jump slightly even when the phone has not moved. A classroom robot can record a distance of 10.2 metres in one reading and 9.8 metres in the next. Real sensors are useful, but their measurements contain noise. How can a computer combine an imperfect prediction with an imperfect new observation?

One well-established answer is the Kalman filter, a recursive state-estimation method widely used in engineering, tracking and robotics. It does not need to start over with every new measurement: it carries forward an estimate and an estimate of uncertainty, predicts what should happen next, then corrects that prediction when a new measurement arrives.

Quick answer: define a state → predict its next value → predict uncertainty → obtain a new measurement → compare measurement with prediction → calculate a Kalman gain → update both the state estimate and its uncertainty → repeat. The filter is not a truth detector. Its reliability depends on sensible motion and noise models.

Kalman filtering in 30 seconds

  • State: the quantity being estimated, such as position, velocity or an instrument bias.
  • Prediction: what the motion or process model expects before the latest observation.
  • Measurement: what a sensor actually reports; it may differ from the unknown true state.
  • Covariance: a mathematical description of estimate or noise uncertainty; variance is its one-dimensional form.
  • Process noise (Q): the variability not fully explained by the system’s evolution model.
  • Measurement noise (R): variability associated with the observation system.
  • Innovation or residual: the difference between an incoming measurement and its predicted value.
  • Kalman gain: the weighting used to correct an estimate with new evidence.
  • Predict–update loop: the repeated structure of filtering as measurements arrive.

A toy example: finding a true position from a noisy reading

Imagine a stationary classroom cart. Our predicted position for the current step is 10 metres, with estimated variance P = 4 square metres. A new sensor measurement reports 14 metres, with measurement-noise variance R = 4 square metres.

These are intentionally simple fictional numbers. The predicted estimate and measurement have equal uncertainty, so a sensible correction places the updated estimate halfway between the two values.

For a one-dimensional measurement of the same state, the Kalman gain is K = P / (P + R). Here K = 4 / (4 + 4) = 0.5.

The innovation is z − x = 14 − 10 = 4 metres. The corrected estimate is x_new = x + K(z − x) = 10 + 0.5 × 4 = 12 metres.

The updated variance becomes P_new = (1 − K)P = 0.5 × 4 = 2 square metres under this scalar model. This does not mean the cart is known to be at exactly 12 metres; 12 is still an estimate.

Step 1: Separate state, estimate and measurement

The true state of the cart is what we wish to know but do not directly observe without error. The estimate is the model’s best current numerical representation under its assumptions. The measurement is a sensor output.

Confusing these three produces a common mistake: assuming the latest reading is the truth and the older estimate is an irrelevant guess. Both sources may be useful, and both may be wrong.

Step 2: Make the noise units consistent

In a scalar position model, estimate uncertainty P and sensor noise R are both variances, measured in the square of the position unit. If position is measured in metres, P and R have units of square metres.

The value 4 square metres corresponds to a standard deviation of 2 metres. A numerical variance is not interchangeable with a standard deviation. Entering 2 where a program expects variance 4 changes the filter’s weighting.

In multivariable filters, covariance matrices also contain off-diagonal terms describing how errors in different state quantities vary together.

Step 3: Predict the next state

A motion model may say that a cart’s next position is its current position plus velocity multiplied by elapsed time. For constant velocity v and step duration Δt, a basic prediction is position_next = position_now + vΔt.

If we deliberately model the cart as stationary, the predicted position remains unchanged from one step to the next. That assumption is convenient for our arithmetic but may be unrealistic for a moving object.

Prediction is based on a model, not evidence that the real world obeyed it. A turn, collision, skipped step or unmodelled acceleration can cause the state to depart from the prediction.

Step 4: Predict uncertainty as well as the state

Even when a model predicts the same position, confidence should not automatically remain unchanged forever. Unknown forces and process disturbances can make uncertainty grow between observations.

In our one-dimensional random-walk teaching example, P_prior = P_previous + Q. With a corrected variance of 2 square metres and process variance Q = 2 square metres across the next step, the predicted variance is 4 square metres.

The general multivariable equation uses the state-transition matrix: P_prior = F P_previous Fᵀ + Q. F describes how the state evolves; the transpose is part of propagating covariance correctly.

Step 5: Read a new measurement and calculate the innovation

Suppose at the next step the predicted position is 12 metres and the sensor reads 13 metres. The innovation is 13 − 12 = 1 metre.

The residual is not just an error to erase. It provides information about how the sensor evidence differs from the model forecast, and it can reveal a sensor bias or process mismatch if its behaviour becomes systematically unusual.

In the general case, the measurement model H predicts what the sensor would read from the state. The innovation is y = z − Hx_prior, not necessarily z minus the entire state vector.

Step 6: Compute the Kalman gain again

At the start of our second update, predicted variance is 4 square metres and sensor variance remains 4 square metres. The gain is again K = 4 / (4 + 4) = 0.5.

Update the estimate: 12 + 0.5 × 1 = 12.5 metres. Update the variance: (1 − 0.5) × 4 = 2 square metres.

We now have a series of estimates: 12 metres after the first reading and 12.5 metres after the second. We are not averaging all sensor readings equally; the filter repeatedly balances the evolving prediction uncertainty against observation uncertainty.

Step 7: What happens if the sensor is less trustworthy?

Return to the first estimate of 10 metres with predicted variance 4 square metres, but now suppose the sensor’s variance is R = 16 square metres rather than 4.

The gain becomes K = 4 / (4 + 16) = 0.2. A measurement of 14 metres changes the estimate only to 10 + 0.2 × 4 = 10.8 metres.

That smaller correction is not stubbornness. The filter is giving less weight to a reading whose noise model says it is comparatively imprecise. If R is incorrectly made huge, the filter can also become dangerously slow to react to genuine changes.

Step 8: What happens if the prediction is less trustworthy?

Suppose predicted variance is 16 square metres and sensor variance is 4 square metres. The gain becomes K = 16 / (16 + 4) = 0.8.

Starting from the same predicted position of 10 metres, a sensor reading of 14 metres now produces 10 + 0.8 × 4 = 13.2 metres.

In this case the model considers its prediction comparatively uncertain, so the new sensor exerts more influence. This is why tuning Q and R cannot be reduced to making one number small just to obtain smoother-looking plots.

Step 9: Recognise the difference between Q and R

Q represents uncertainty introduced while moving the state forward, including unmodelled acceleration or process disturbances. R represents the observation system’s measurement uncertainty.

A filter with Q too small may act as if its motion forecast is nearly perfect and resist genuine changes. With Q too large, it can chase sensor noise. If R is too small, it trusts noisy measurements too much; if R is too large, it underweights valuable sensor evidence.

These parameters should be grounded in instrument behaviour, process variability and held-out error checks where possible.

Step 10: Why the Kalman gain is not a fixed average

Our two toy updates happened to produce a gain of 0.5. In realistic filters it varies with predicted covariance, sensor covariance and measurement geometry.

The filter is not simply calculating ‘half old, half new’ forever. Its weighting changes as uncertainty changes. Multivariable gain K is a matrix that can update one state component using evidence about another.

The FilterPy linear KalmanFilter documentation exposes the state-transition matrix F, covariance P, process-noise covariance Q, measurement covariance R and measurement matrix H used in the predict–update loop.

Step 11: How position and velocity can be estimated together

For a tracking task, a state vector may contain position and velocity: x = [position, velocity]ᵀ. When the step duration is Δt, a constant-velocity state transition can be written with the two-by-two matrix F = [[1, Δt], [0, 1]].

If the sensor measures only position, the measurement matrix can be H = [1, 0]. The observation carries information about position directly and may indirectly refine the velocity estimate through covariance and repeated updates.

This is a simplified physical model. Turning, accelerating and changing sampling intervals require appropriate modifications.

Step 12: Why a filter may smooth a jittery location dot

If a sensor alternates slightly around a plausible motion path, a model-based prediction supplies continuity and the measurement supplies correction. The estimate may fluctuate less than the raw readings while still responding to genuine motion.

But smoothing is not a promise of greater truth. A filter that is too reluctant to change can lag behind a moving object. A plausible-looking curve is not evidence that the position estimates are accurate.

The correct evaluation checks known reference positions, residual patterns and uncertainty calibration rather than visual elegance alone.

Step 13: Missing readings are not the same as zero readings

A sensor may fail to report a measurement at one time step. This is different from reporting the value zero.

In an ordinary predict–update filter, if a reading is missing, the prediction can proceed without the measurement update. Uncertainty generally grows according to the process model until useful evidence returns.

Filling missing observations with arbitrary zeros can pull the estimated position towards zero even when the physical cart is nowhere near it.

Step 14: Detect model surprises without inventing certainty

When the innovation is unexpectedly large relative to the predicted measurement uncertainty, the new reading may be an outlier, the motion model may be wrong or the system may have changed abruptly.

Checking the normalised innovation is more meaningful than using the raw difference alone because one sensor’s normal variation may be much larger than another’s.

Do not discard every surprising measurement automatically. A genuine turn, sudden acceleration or equipment failure may be precisely the event a monitoring system must discover.

Step 15: What assumptions make the classical filter useful?

The ordinary linear Kalman filter uses a linear state-transition and observation model, with uncertainty represented through means and covariances. Under correctly specified linear-Gaussian assumptions it provides optimal minimum-variance estimation in the conventional sense.

When important relationships are nonlinear or error distributions have heavy tails, the ordinary formulation may perform poorly. There are extensions, but each changes assumptions and approximations.

Even under a well-specified model, a filter’s covariance measures uncertainty as modelled. It does not account automatically for every unknown human mistake or unseen environmental hazard.

Step 16: Extended and unscented variants

An extended Kalman filter (EKF) commonly linearises nonlinear motion or measurement functions around a current estimate using derivatives. This can be useful, but linearisation error can become significant in difficult regimes.

An unscented Kalman filter (UKF) propagates a selected set of sigma points through nonlinear functions rather than relying on the same first-order linearisation.

The FilterPy ExtendedKalmanFilter reference is one starting point for studying these implementations. Neither method automatically makes an incorrect physical model safe.

Step 17: Kalman filtering versus hidden Markov models

An HMM often describes movement among discrete hidden states and uses transition and emission probabilities to explain observations. A Kalman filter commonly estimates a continuous numerical state such as position and velocity under a state-space model.

Both make predictions and update beliefs using sequential data, but their representations and inference mathematics differ. The best method depends on whether the hidden dynamics and observations fit the stated assumptions.

Do not assume that one algorithm is a universal replacement for the other.

Step 18: Where you may encounter Kalman filters

Robot tracking: combining a motion model with camera, wheel encoder or other sensor evidence.

Navigation: estimating changing positions and velocities from noisy measurements when the modelling choices are appropriate.

Industrial monitoring: tracking physical quantities over time while representing uncertainty.

Computer vision: smoothing and predicting object trajectories between detections.

Teaching: demonstrating how variance and weighted corrections help interpret imperfect measurements.

Step 19: How to test one responsibly

First check data units and timing. Then compare its estimates with an independent trusted reference rather than judging the result only against the same sensor it was trained to trust.

Plot and inspect innovations across time, assess whether uncertainty intervals contain realistic proportions of reference outcomes, and evaluate what happens during dropout, unusual motion and sustained bias.

Compare with a simple baseline, such as using the latest reading or a straightforward moving average. Extra mathematical complexity only earns its place when it improves the required performance.

Step 20: Five common mistakes

  • ‘The sensor is always right.’ No. Measurements include uncertainty and sometimes systematic bias.
  • ‘The Kalman gain is always 0.5.’ No. It depends on current predicted and measurement uncertainty.
  • ‘Variance and standard deviation are interchangeable.’ No. One is the square of the other.
  • ‘A smooth path must be correct.’ No. An overconfident filter can produce a neat but delayed or biased result.
  • ‘One filter handles every nonlinear system.’ No. Classical, extended and other filters have different conditions and limitations.

Try it: change the uncertainty

  1. Start with a predicted position of 10 metres and predicted variance 4 square metres.
  2. Use sensor reading 14 metres with variance 4. Calculate K = 0.5, then update position to 12 and variance to 2.
  3. Keep the predicted position 10 and variance 4, but raise sensor variance to 16. Calculate K = 0.2 and the new estimate 10.8.
  4. Now set predicted variance to 16 and sensor variance to 4. Calculate K = 0.8 and the new estimate 13.2.
  5. Explain what changed across all three calculations: not the reading or the original predicted position, but the model’s trust in each source.
  6. Discuss a limitation: if the true object abruptly accelerates, how could a weak motion model produce poor estimates despite these correct sums?

Frequently asked questions

What is a Kalman filter in AI?

It is a recursive state estimator that predicts a state, compares new sensor evidence with that prediction and updates the estimate and its uncertainty.

Does a Kalman filter learn like a neural network?

Not in the same way. A conventional Kalman filter performs probabilistic recursive estimation from an explicit state-space model; its parameters may be calibrated or learned separately.

What does Kalman gain mean?

It describes how the new measurement correction influences the state estimate, based on uncertainty and the measurement model.

What is the difference between Q and R?

Q represents process-model uncertainty added as the state evolves. R represents measurement-system uncertainty.

Does it always produce the true location?

No. It produces an estimate conditional on the specified dynamics, observations and noise assumptions. It can be biased or wrong if these assumptions fail.

Can secondary students understand it?

Yes. Begin with the one-dimensional weighted correction and basic variance, then build towards equations, vectors and covariance matrices.

Your one-minute takeaway

A Kalman filter uses the same repeating logic every step: predict, quantify uncertainty, observe, measure the difference and update. The gain determines how strongly evidence corrects the forecast. Its strength is disciplined reasoning with imperfect data; its limit is dependence on an accurate enough model of the world.

Trusted reading and connected articles

Discover more from eduKate Singapore

Subscribe now to keep reading and get access to the full archive.

Continue reading