School/✦ Research Engineer/Week 17
Tuning a two-state filter: position and bias
Your wheels lie by 1.5 cm every second, always in the same direction. Could the filter learn that lie and subtract it?
About 45 min · 3 goals · Checked by automated tests
1.Why should I care?
Real sensors have biases that change slowly. Adding the bias as a state lets the filter estimate and remove it, which is how spacecraft keep gyros honest between star fixes and how the fusion lab's Kalman filter beats the complementary one.
- ◇ Augment a state with an unknown sensor bias and write the two-state model.
- ◇ Explain how a filter can estimate a state no sensor measures directly.
- ◇ Tune Q and R by experiment and diagnose over- and under-confident filters.
2.Discover
In the fusion lab choose the Kalman filter and a clear nonzero odometry bias. Watch the estimated bias converge. Then raise the dropout rate: does the position error during blackouts stay small because the bias has been learned? Compare with the complementary filter on the same seed.
Explorer 03 — Sensor fusion
Two imperfect sensors, one better estimate
A camera gives absolute position but loses sight of the target; odometry never drops out but drifts. Combining them gives an estimate better than either alone.
- True position
- Camera reading
- Odometry dead-reckoning
- Fused (Kalman)
- ±2σ uncertainty
- Camera dropout
Camera · absolute, drops out
Long-run share of time with no view, in bursts of about 1.2 s (occlusions).
Odometry · relative, drifts
A constant error in measured speed: its position estimate drifts by bias × time.
The Kalman filter weights each sensor by its stated noise, tracks its own uncertainty, and estimates the odometry bias while the camera can see.
Show
Root-mean-square error vs truth · lower is better
- Camera aloneholds last reading in dropouts7.9 cm
- Odometry alonedead reckoning from start15.1 cm
- Kalman filterfused estimate0.9 cm
- Fused, in dropoutsonly samples with no camera1.1 cm
Camera coverage 60 %. Camera error only over frames it saw: 2.9 cm (≈ its σ).
State
Seed 7. The camera saw the target 60 % of the time in 4 dropouts. Error (RMSE): camera alone 7.9 cm holding its last reading, odometry alone 15.1 cm, kalman filter 0.9 cm (1.1 cm during dropouts). Fusion is 88 % better than the better single sensor. Estimated odometry bias 1.53 cm/s (true 1.50).
Seed 7. The camera saw the target 60 % of the time in 4 dropouts. Error (RMSE): camera alone 7.9 cm holding its last reading, odometry alone 15.1 cm, kalman filter 0.9 cm (1.1 cm during dropouts). Fusion is 88 % better than the better single sensor. Estimated odometry bias 1.53 cm/s (true 1.50).
How to read this
Time runs left to right over 20 seconds. The thin solid line is where the object really is. Crosses are camera readings; hatched columns are dropouts where the camera sees nothing. The dashed line is odometry integrated from the start: smooth, but it wanders away as its bias accumulates. The thick line is the fused estimate, with a shaded ±2σ band showing how uncertain the Kalman filter believes it is. The band widens during each dropout and snaps back when the camera returns.
This mirrors Tactiverge's research question: when vision drops out, can local sensing such as force and joint feedback carry the estimate until it returns?
Assumptions & limitations
- One dimension, a smooth known trajectory and a single object: real tracking is 3-D, with orientation, multiple objects and data association.
- Noise is white Gaussian with the σ you set, and the Kalman filter is told the true σ values. Real filters must be tuned against noise they can only estimate.
- Odometry error is a constant bias plus white noise; real drift also comes from slip, scale-factor error and temperature.
- Dropouts are random bursts, independent of where the object is. Real occlusions often happen exactly when the task gets hard, for example when a gripper covers the object.
- The camera has no latency and runs at the same 20 Hz as odometry; real cameras are slower and delayed, which the filter would have to compensate for.
- Figures are from one seeded run of 401 samples; change the seed to see how much the numbers vary by chance.
Can't use the interactive? Read a description instead
The fusion lab reports position error and, for the Kalman filter, the estimated bias as numbers; the expected behaviour (bias converging, small error during blackouts) is described in the instruction.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
Which measurement makes BOTH position and odometry bias observable in this model?
4.Predict
The camera only ever measures position. Can a filter still estimate the odometry bias?
Guess first. Being wrong here is how the surprise works.
5.Understand
Augment the state
State x = [p, b]ᵀ: position and odometry bias. Odometry reports d = Δp_true + b·Δt + noise, so the prediction is p ← p + d − b·Δt and b ← b (a random walk). In matrix form A = [[1, −Δt], [0, 1]], with the odometry reading as input, and the camera measures H = [1, 0].
Observability
A state is observable if its effect eventually appears in the measurements. The bias pushes the position prediction away from the camera fixes at a steady rate, so over several fixes the filter can separate it from random noise. During a long blackout nothing new is learned, but the learned bias keeps being subtracted.
Tuning Q and R
Start R from the sensor's measured noise. Q is harder: it encodes how much the model can be wrong per step (slip, bias wander). Q too small: sluggish, overconfident, truth leaves the ±2σ band. Q too large: jumpy, noisy estimate. Tune on simulated runs with known truth, check consistency, and never tune on the same runs you report.
Explain it another way
If your watch gains a minute every day and you check it against the radio each morning, after a few days you know the gain and can correct for it even on days you miss the radio.
The pair (A, H) is observable when the matrix [H; HA] has full rank. Here [[1, 0], [1, −Δt]] has rank 2 for Δt > 0, so position and bias are both observable from position fixes.
Process noise for the bias random walk: Q_b = σ_b²Δt. A tiny Q_b says 'the bias barely changes', so the filter averages over many fixes; a larger Q_b lets it track a wandering bias at the cost of noisier estimates.
Spacecraft attitude filters routinely carry three gyro bias states. After a few star-tracker fixes, gyro-only coasting during an eclipse or manoeuvre is far more accurate than raw integration.
Worked example 1
Δt = 0.1 s. Write A for state [p, b] when the prediction subtracts the bias from odometry.
p⁺ = p + d − 0.1·b, b⁺ = b. So A = [[1, −0.1], [0, 1]] acting on [p, b], with d as the input.
Common mix-ups
- You can only estimate what you measure.
✓ A good model links hidden states to measured ones; observable hidden states can be estimated. - Tuning on your test runs is fine.
✓ That overfits Q and R to those runs. Tune on separate seeds, then report on held-out ones.
6.Watch
→ Listen for the idea that the filter estimates the full state, including parts you cannot measure, from a model plus partial measurements.
A university lecture that places the Kalman filter in state-space control: estimating the full state from noisy, partial measurements.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
A filter's position estimate lags behind sudden real slips and the truth often leaves its ±2σ band. The fix is to…
Practice 3
The filter learns a bias of 1.5 cm/s. During a 40 s camera blackout, how much position drift does subtracting it remove, in cm?
Practice 4 · a fresh version every time
A rover's estimate is x = 5 m with variance P = 2 m². It drives u = 3 m (process noise Q = 2 m²), then a landmark fix reads z = 10 m with R = 1 m². After predict and update, what is the new estimate x, in m?
8.Apply it
Pre-register a small tuning study in the fusion lab: three Q settings, five seeds each, metric RMSE, decision rule 'lowest mean RMSE, ties broken by consistency'. Run it on seeds 1–5, then report the chosen setting's RMSE on seeds 6–10.
9.Reflect
10.Go further
Research mode: limits and open questions
A fair tuning protocol is part of an honest comparison: give every estimator the same tuning budget on separate training seeds, then report on held-out seeds.
Concepts: Kalman filtering · States and state-space models · Sensor fusion