Kalman filter: infer hidden states
A sensor cannot always reveal every state directly.
Compute one scalar measurement update and explain why a noisy sensor receives less weight.
An observer corrects a model prediction with measurements. A Kalman filter chooses that correction from the estimated uncertainty in each source.
Review the previous lesson: LQR: decide what a good balance costsFirst, picture it
A camera can tell where a cart is now; comparing positions over time hints at its velocity, but noisy measurements make direct differentiation jittery. An observer combines a model prediction with new measurements.
Build the idea step by step
A Kalman filter repeats two steps. First use the model and known input to predict state and uncertainty. Then compare the predicted measurement with the new sensor reading and correct the state. The correction is larger when the prediction is less certain relative to the sensor. A variance measures the spread of an error; a covariance also describes how errors in different states vary together. These uncertainties are assumptions that must fit the data, not declarations that the estimate is true.
Read the equations
For a scalar direct measurement with independent prediction and measurement errors, update the prediction toward the measurement. The full filter first predicts the state and its uncertainty using a model.
What the symbols mean
- estimate before and after this measurement update
- prediction-error variance, in squared state units
- measurement-error variance; not the input cost in LQR
- Kalman correction weight in this scalar example
- measured state value
The scalar example uses a direct measurement and independent zero-mean errors. A full filter also updates uncertainty between samples. In the lab's Kalman-only lesson, control still uses simulated true state so estimation can be inspected separately.
Combine a position prediction and a sensor
Predict a position of 10 metres with error variance 4 square metres. A sensor reports 12 metres with variance 1 square metre.
The sensor is more precise in this example. Move 80% of the way from prediction to measurement.
If the sensor variance rises to 16, keep the same prediction and measurement but use weight 0.2. The estimate is now 10.4 metres. A lower stated variance is a model assumption, not proof that a sensor is correct.
More detail and model assumptions
Predict first, then correct
A sensor may report cart position and pole angle but not both velocities. A model predicts the next state from the previous estimate and applied force. The filter then compares predicted measurements with actual ones; this innovation corrects the estimate. It is an observer, not a second physical controller.
Process covariance Q says how uncertain the motion model is; measurement covariance R says how noisy the sensors are assumed to be. Larger R relative to Q usually shifts weight toward the model and smooths noisy readings, but can slow response to real changes. The tuning values are assumptions to test, not facts established merely by moving sliders.
Compare estimate with truth carefully
The simulator exposes its true state for teaching, so you can plot true angle, noisy measurement and filtered estimate together. A real device generally does not provide hidden truth; it needs independent validation or calibrated sensors. Inspect both angle and angular velocity, because a smooth angle estimate can still hide a poor velocity estimate.
In the Kalman-only Lab preset, the observer changes displayed estimates while the baseline feedback still uses its own available state. The next LQG lesson closes feedback through the estimate, which makes observer tuning affect the applied force.
Connect the example to the lab
Hold injected sensor noise fixed; increase assumed R. The estimate often looks smoother, but may react later to a real kick.
Observe the hidden velocitiesMake a prediction before moving a control.
- PREDICTWhat happens if you trust a noisy sensor less?
- CHANGE ONE THINGPin the Kalman-only run, then increase assumed sensor variance R with the same noise seed.
- OBSERVECompare measured, estimated and true angle, then compare estimated angular velocity.
- EXPLAINDescribe the smoothing-versus-delay tradeoff without claiming the estimate is always closer.
A Kalman estimate is not ground truth. Wrong models, biased sensors and non-Gaussian disturbances can defeat the ideal assumptions.
Check your understanding+
What changes when assumed sensor variance R increases?
The filter trusts a measurement less relative to its model prediction, subject to the full covariance dynamics.Why the next lesson follows
We can now combine an LQR controller with a Kalman state estimate. That combination is LQG.