Visual explainer
State Estimation and the Kalman Filter
Follow the recursive predict-update cycle of the Kalman filter as it fuses noisy wheel odometry with range sensor measurements to estimate robot pose.
1. Hidden Truth Behind Noisy Signals
A mobile robot traverses a 1D corridor. Its true physical position is a hidden variable governed by Newtonian mechanics. The onboard flight computer cannot directly access ; it receives only noisy wheel tick counts and jittery distance measurements.
The state vector captures the minimal set of quantities needed to predict future behavior:
Because real sensors deliver corrupted signals , raw readings cannot be trusted directly. Passing unfiltered sensor values straight into a motor controller causes erratic commands, excessive mechanical wear, and catastrophic collisions.
2. Representing Belief with Gaussians
The Kalman filter expresses its belief over the hidden state as a normal probability density function . The mean denotes the most likely position, while the variance (or covariance matrix ) captures the degree of certainty.
At time , prior calibration establishes our initial state belief:
The width of the bell curve visually conveys robot confidence. A narrow peak reflects high confidence, whereas a flat, spread distribution indicates severe uncertainty.
3. The Motion Prediction Step
When motors engage, the robot commands a forward displacement . In an ideal world, the robot would land precisely at . In reality, wheel slip and gear backlash inject process noise with variance .
The prediction equations propagate belief forward in time:
Moving always increases uncertainty in the absence of external landmarks. The prior bell curve shifts rightward to while flattening out to standard deviation .
4. The Incoming Noisy Measurement
At time , an onboard ultrasonic sensor pings a wall to measure position. Due to acoustic reverberation and electronic noise, the sensor observation model contains measurement noise with variance :
The robot now possesses two contradictory representations of reality: a motion prediction claiming () and an external sensor report claiming ().
5. The Measurement Residual and Innovation
The discrepancy between what the sensor observed and what the motion model predicted is termed the measurement residual or innovation :
The innovation variance combines the uncertainty from both domains:
A positive residual indicates that the robot is further along the track than dead reckoning suggested. The filter must determine how much of this gap is genuine motion versus spurious sensor jitter.
6. The Optimal Kalman Gain
The Kalman gain calculates the optimal mathematical weighting between prediction trust and sensor trust:
The gain acts as a dynamic blending knob:
- If sensors are exceptionally noisy (), : the filter ignores sensor updates and follows dead reckoning.
- If sensors are virtually noiseless (), : the filter discards historical predictions and snaps directly to measurements.
- With , the filter attributes of the residual to true robot displacement and to measurement noise.
7. The Measurement Update Step
The posterior mean reconciles prediction with observation by scaling the innovation through the Kalman gain:
The updated belief settles at . Rather than naively averaging and to , the filter places greater weight on the prediction because its variance () was smaller than the sensor noise ().
8. Variance Reduction and Shrinking Uncertainty
Fusing two independent probabilistic estimates guarantees that posterior uncertainty is strictly lower than either source individually:
The resulting standard deviation shrinks to . Notice that is smaller than the predicted variance () and drastically smaller than the raw sensor variance (). Combining imperfect predictions with noisy observations yields higher certainty than either source could attain on its own.
9. Tracking State Over Extended Horizons
The Kalman filter operates as an infinite recursive loop:
- Predict: Apply control inputs and add process covariance ().
- Measure: Receive raw sensor observations .
- Update: Compute gain , correct state estimate , and contract covariance .
- Recurse: Set and repeat at 100 Hz.
Over multiple time steps, the filter smoothly tracks the true vehicle trajectory, rejecting transient noise spikes while faithfully following authentic accelerations and turns.
10. Where It Breaks
Standard linear Kalman filtering guarantees optimality only under rigid assumptions: linear kinematics and zero-mean Gaussian noise. Real physical systems break these assumptions regularly:
- Sensor Glitches and Non-Gaussian Outliers: If a specular reflection causes the rangefinder to report instead of , the quadratic penalty in Gaussian estimation jerks the state estimate violently off track. Robust M-estimators or particle filters are required to reject non-Gaussian outliers.
- Filter Divergence from Covariance Collapse: If process noise is underestimated, the covariance matrix shrinks toward zero. The filter becomes overconfident ("smug"), driving and completely ignoring new sensor data while the true robot drifts away.
- Kinematic Non-linearities: Real robots rotate with sines and cosines. Linear Kalman filters cannot propagate non-linear functions directly, requiring the Extended Kalman Filter (EKF) via first-order Taylor expansion or the Unscented Kalman Filter (UKF) via deterministic sigma points.
The Quick Version
- State estimation deduces unmeasurable physical variables from noisy, indirect sensor observations.
- Robot belief is tracked as a Gaussian distribution with mean and covariance.
- Motor commands advance state predictions while increasing uncertainty via process noise.
- Sensors deliver corrupted observations characterized by measurement noise variance.
- Innovation measures the discrepancy between expected sensor readings and actual observations.
- Kalman gain balances prediction uncertainty against measurement noise for optimal blending.
- State updates shift the estimate toward the observation proportional to gain.
- Fusing prediction and measurement strictly contracts posterior uncertainty below both sources.
- Recursive predict-update loops maintain bounded tracking error across extended operating horizons.
- Non-linear kinematics and non-Gaussian sensor glitches trigger catastrophic filter divergence.