Learning LabExplorable explanations
← All artifacts
Signals

Kalman Filter: Tracking Through Noise

Track a moving target through noisy measurements. Watch the predict step grow uncertainty and the update step shrink it, and drag the noise sliders to see the covariance ellipse breathe.

kalman-filterestimationcovariancetracking
LiveInteractive · drag, toggle, run it
Signals · State Estimation

Kalman Filter: Tracking Through Noise

A target moves along the dashed green path. A sensor reports only its position, and every reading is corrupted by noise. The filter keeps a belief about position and velocity, then alternates two moves: predict where the target should be, and correct that guess against each new reading. The result, in terracotta, stays close to the truth even though it never sees it directly.

step t
0
mode
update
estimate x
40.0, 0.0
velocity
0.00, 0.00
measurement
dropped
trace(P)
180.00
true pathmeasurementsestimate

The shaded terracotta ellipse is the filter's 1-sigma position uncertainty, drawn from the eigenvectors of the 2x2 position block of the covariance P. Each update pulls it tighter. Turn on "drop measurements" and the ellipse swells with every predict-only step, because nothing is left to correct the growing drift.

Tuning the two noises

R says how much you distrust the sensor; Q says how much you distrust the constant-velocity assumption. Raise R and the filter leans on its own prediction, so the estimate is smooth but slow to react when the target turns. Raise Q and the filter trusts each fresh reading, so it tracks turns quickly but jitters with the noise. The Kalman gain K is exactly the lever between them: it lands wherever the ratio of these two uncertainties puts it.

Predict

Where should it be next?

x = F x
P = F P Fᵀ + Q

F moves position by velocity times dt and leaves velocity alone. Projecting P through F and adding Q always grows the uncertainty: prediction alone can only lose information, which is why the ellipse breathes outward during a measurement gap.

Update

Correct against the reading

K = P Hᵀ (H P Hᵀ + R)⁻¹
x = x + K (z − H x)
P = (I − K H) P

H pulls position out of the state. The gain K weighs the surprise z minus H x by how much the filter trusts the reading versus its own belief. Folding that correction in always shrinks P, which is the ellipse snapping tighter on every update.

Is it actually helping?

Estimate error versus raw error

Press Play or Step to gather readings. With measurements dropped, there is nothing to score against.

What is real here: the state is [x, y, vx, vy] with matrices F, Q, H, R as shown. Every predict and update runs the full matrix algebra in plain JavaScript, the innovation covariance is inverted in closed form because H selects position, and the ellipse comes from the actual eigen-decomposition of P. Only the target trajectory and the Gaussian sensor noise are synthetic.