Skip to content
Tactiverge

Textbooks/Introduction to Intelligent Systems/Chapter 6Lite (plain text) version

6State estimation and sensor fusion

Version 1 · Technically checked (automated checks only) · 4 source lessons · 8 practice items

Text
All chapters and search
  1. 1. Sense, think, act
  2. 2. Noise and filtering
  3. 3. Machine vision
  4. 4. Search and planning
  5. 5. Decisions under uncertainty
  6. 6. State estimation and sensor fusion
  7. 7. Learning from data
  8. 8. Evaluating intelligent systems honestly

Introduction

No single sensor tells a robot where it is. Wheels drift, cameras drop frames, gyros wander. Fusion combines them so the estimate is better than any one. This chapter weights readings by their reliability, blends a fast drifting sensor with a slow absolute one in a complementary filter, and builds the Kalman filter's predict–update cycle, whose gain is exactly the weight that makes the combined variance smallest.

position (cm)belief681012fused 10.2 ± 0.894weights ∝ 1/σ²: 0.8 for σ = 1, 0.2 for σ = 2solid: sensor 1 · dashed: sensor 2
Figure 6.1. Two beliefs make a sharper one. Two Gaussian beliefs about a position: 10 cm with σ = 1 cm and 11 cm with σ = 2 cm. Inverse-variance weights are 0.8 and 0.2, so the fused estimate is 10.2 cm with σ ≈ 0.894 cm, narrower than either sensor alone.

Explanation

This chapter is built from 4 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

6.1 Inverse-variance weighting

Two sensors measure the same distance. One is twice as precise. Should you trust it twice as much? Four times? All the way?

The recipe

x̂ = (z₁/σ₁² + z₂/σ₂²)/(1/σ₁² + 1/σ₂²) and σ_f = 1/√(1/σ₁² + 1/σ₂²). The fused value sits between the readings, closer to the more precise one; the fused σ is smaller than the smaller σ. Two equal sensors give σ/√2.

The fine print

It assumes both readings are unbiased, independent and have correctly known σ. A biased sensor drags the fused value with full confidence. Correlated errors (two cameras with the same calibration fault) give less improvement than the formula promises.

A consistency check

If the readings disagree by much more than √(σ₁² + σ₂²), something is wrong: a fault, a bias, a wrong σ. Real systems test the difference before fusing and reject outliers. In Kalman language this is innovation gating.

Derivation: Why inverse-variance weights are optimal
  1. Blend two independent unbiased readings: x̂ = w·z₁ + (1 − w)·z₂. It is unbiased for any w.

  2. Its variance is V(w) = w²σ₁² + (1 − w)²σ₂² (no cross term, by independence).

  3. Minimise: dV/dw = 2wσ₁² − 2(1 − w)σ₂² = 0 ⇒ w = σ₂²/(σ₁² + σ₂²) = (1/σ₁²)/(1/σ₁² + 1/σ₂²).

  4. d²V/dw² = 2(σ₁² + σ₂²) > 0, so this is a minimum.

  5. Substitute back: V_min = σ₁²σ₂²/(σ₁² + σ₂²), i.e. 1/σ_f² = 1/σ₁² + 1/σ₂². For n sensors, weights ∝ 1/σᵢ² and precisions add.

Common mix-ups

  • Fusing with a worse sensor makes the result worse.
    ✓ With correct σ's and independent, unbiased errors, adding any sensor can only help (its weight shrinks as it gets worse).
  • Twice as precise means twice the weight.
    ✓ Weight goes with 1/σ², so twice as precise means four times the weight.

Open the full lesson: Inverse-variance weighting →

6.2 The complementary filter

A gyro is smooth but drifts. An accelerometer never drifts but jitters. Could you keep the best half of each?

Two paths that add to one

θ[k] = α(θ[k−1] + ω·Δt) + (1 − α)·θ_acc. The gyro path (integrate rate) is effectively high-passed: good for fast changes. The accelerometer path is low-passed: good for the slow, long-term level. Because the two filters add to exactly one, the true signal passes through unchanged.

Choosing α

The crossover time constant is τ = αΔt/(1 − α). With α = 0.98 and Δt = 0.01 s, τ = 0.49 s: changes faster than about half a second come from the gyro, slower ones from the accelerometer. Pick τ longer than the accelerometer's jitter but shorter than the time the gyro takes to drift noticeably.

Complementary versus Kalman

The complementary filter uses a fixed blend. A Kalman filter computes its gain from Q and R and can add the gyro bias as a state and estimate it, so the drift is removed rather than just pulled back. In steady state, a scalar Kalman filter with constant gain behaves much like a well-tuned complementary filter.

Common mix-ups

  • The complementary filter averages the two sensors.
    ✓ It splits them by frequency: gyro for fast changes, accelerometer for slow ones.
  • A bigger α is always better because the gyro is smoother.
    ✓ Bigger α means a longer τ and more bias error. The best α balances drift against jitter.

Open the full lesson: The complementary filter →

6.3 The predict–update cycle

Drive a metre: your uncertainty grows. See a landmark: it shrinks. Repeat forever. That rhythm is the whole idea of a filter.

Predict

Push the estimate through the model: x⁻ = x + u (here, the commanded move) and P⁻ = P + Q. Q is the variance the model adds each step: wheel slip, gusts, anything unmodelled. Prediction always increases uncertainty.

Update

When a measurement z with variance R arrives, compute the innovation z − x⁻, the gain K = P⁻/(P⁻ + R), then x = x⁻ + K(z − x⁻) and P = (1 − K)P⁻. This is the conjugate normal update from week 13 with the prediction as prior.

Checking a filter honestly

In simulation you know the truth, so measure RMSE of x − x_true. Also check consistency: about 95% of errors should fall within ±2√P. If the truth often leaves the band, the filter is overconfident (Q or R too small); if it never comes close to the edge, it is too cautious.

Common mix-ups

  • A low RMSE proves the filter is right.
    ✓ It must also be consistent: its own σ should match its actual errors, or downstream decisions will be over- or under-cautious.
  • The update step can increase uncertainty.
    ✓ For a correct linear-Gaussian model P = (1 − K)P⁻ is always smaller than P⁻. A surprising measurement moves x a lot, but P still shrinks.

Open the full lesson: The predict–update cycle →

6.4 The Kalman gain as the variance-minimising weight

Why P/(P + R)? Not a guess, not a rule of thumb: it is the only weight that makes the error as small as possible.

Reading the gain

K → 1 when R ≪ P⁻: trust the sensor, x ≈ z. K → 0 when R ≫ P⁻: trust the prediction, ignore the reading. K is not a tuning knob you set; it is computed from the variances you believe. What you tune are Q and R.

Steady state

With constant Q and R the variance stops changing. For the random-walk model x[k+1] = x[k] + u + w, the prior variance converges to P⁻∞ = (Q + √(Q² + 4QR))/2. With Q = 0.3, R = 2: P⁻∞ ≈ 0.939, K∞ ≈ 0.319. Many embedded filters precompute this constant gain.

In more dimensions

For vector states, K = P⁻Hᵀ(HP⁻Hᵀ + R)⁻¹ and P = (I − KH)P⁻, where H maps the state to what the sensor sees. The scalar case is H = 1. The same minimum-variance argument, done with matrices, gives the same structure.

Derivation: The scalar Kalman gain
  1. Update rule: x = x⁻ + K(z − x⁻) = (1 − K)x⁻ + Kz. Prediction error e⁻ has variance P⁻; measurement error v has variance R; they are independent.

  2. Posterior error e = (1 − K)e⁻ + K·v (the true x cancels because both terms are unbiased).

  3. Its variance: P(K) = (1 − K)²P⁻ + K²R.

  4. Minimise: dP/dK = −2(1 − K)P⁻ + 2KR = 0 ⇒ K = P⁻/(P⁻ + R).

  5. Substitute back: P = (1 − K)P⁻ = P⁻R/(P⁻ + R), i.e. 1/P = 1/P⁻ + 1/R: inverse-variance weighting, again.

Common mix-ups

  • K is a gain you tune by hand.
    ✓ K is computed from P⁻ and R. You tune the noise models Q and R; the gain follows.
  • The Kalman filter is a different idea from averaging.
    ✓ Its update is inverse-variance weighting of the prediction and the measurement.

Open the full lesson: The Kalman gain as the variance-minimising weight →

Worked examples

Inverse-variance weighting: example 1

Readings 10 (σ = 3) and 13 (σ = 2). Fuse them.

Solution

Weights 1/9 : 1/4 = 4 : 9. x̂ = (4 × 10 + 9 × 13)/13 ≈ 12.08. σ_f = 6/√13 ≈ 1.66.

The complementary filter: example 1

α = 0.98, Δt = 0.01 s. Time constant? Steady-state tilt error from a 0.5 °/s gyro bias?

Solution

τ = 0.98 × 0.01/0.02 = 0.49 s. Error ≈ b·τ = 0.5 × 0.49 ≈ 0.25°.

The predict–update cycle: example 1

x = 0, P = 1 m². Drive u = 1 m with Q = 0.25 m². Fix z = 1.6 m with R = 0.5 m². Predict and update.

Solution

x⁻ = 1, P⁻ = 1.25. K ≈ 0.714. x ≈ 1.43 m, P ≈ 0.357 m² (σ ≈ 0.60 m).

The Kalman gain as the variance-minimising weight: example 1

Q = 0.3, R = 2. Find the steady-state prior variance, gain and posterior variance.

Solution

P⁻∞ = (0.3 + √(0.09 + 2.4))/2 ≈ 0.939. K∞ = 0.939/2.939 ≈ 0.319. P∞ = (1 − 0.319) × 0.939 ≈ 0.639.

Interactive figures

Figure 6.2 from Inverse-variance weightingSet σ₁ = 1, σ₂ = 2. Drag your weight w from 0 to 1 and watch the lower curve: the blend's σ dips to a minimum. Find it by hand, then press 'snap' to check. Repeat with equal σ's: where is the minimum now, and what is the fused σ?
Can't use the interactive? Read a description instead

The fusion diagram plots both sensor curves, your blend and the optimal fusion, plus a curve of blend σ against weight with its minimum marked. The readout gives the optimal weight, fused value and σ, and how far your chosen weight is from optimal.

Interactive figure (online). Description: The fusion diagram plots both sensor curves, your blend and the optimal fusion, plus a curve of blend σ against weight with its minimum marked. The readout gives the optimal weight, fused value and σ, and how far your chosen weight is from optimal.

Figure 6.3 from The predict–update cycleStep predict → update ten times in clear skies and watch the band settle to a steady width. Reset, switch on dust, and step again: note how wide the band gets during the gaps. Check after each update that the green truth line stays inside the ±2σ band most of the time.
Can't use the interactive? Read a description instead

The Kalman stepper plots truth, landmark fixes and the estimate with a ±2σ band over 20 steps. Each button press updates a text readout with the estimate, σ, truth, error and gain.

Interactive figure (online). Description: The Kalman stepper plots truth, landmark fixes and the estimate with a ±2σ band over 20 steps. Each button press updates a text readout with the estimate, σ, truth, error and gain.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 1

Sensor σ's are 2 m and 4 m. What weight does the 2 m sensor get?

Practice 2

Sensor B has a hidden +5 m bias but claims σ = 0.5 m; sensor A is unbiased with σ = 2 m. The fused estimate will be…

Practice 3

A complementary filter runs at Δt = 0.005 s with α = 0.99. What is its time constant τ, in seconds?

s

Practice 4

What happens if α = 1?

Practice 5

A filter has P = 0.4 m² after an update. Q = 0.3 m² per step. With no fixes for 6 steps, what is P, in m²?

m²

Practice 6

In simulation, the true position leaves the filter's ±2σ band on 40% of steps. The most likely problem is…

Practice 7

A filter is told R = 0 (a perfect sensor). What does it do at each update?

Practice 8

P⁻ = 4 m², R = 1 m². What is the posterior variance P, in m²?

m²
  1. Sensor σ's are 2 m and 4 m. What weight does the 2 m sensor get?
  2. Sensor B has a hidden +5 m bias but claims σ = 0.5 m; sensor A is unbiased with σ = 2 m. The fused estimate will be…
    • Close to B, and wrong by nearly 5 m, with a small reported σ
    • Close to the truth
    • Exactly halfway
    • Rejected automatically
  3. A complementary filter runs at Δt = 0.005 s with α = 0.99. What is its time constant τ, in seconds? (s)
  4. What happens if α = 1?
    • Pure gyro integration: drift is never corrected
    • Pure accelerometer: very noisy
    • Perfect fusion
    • The filter stops updating
  5. A filter has P = 0.4 m² after an update. Q = 0.3 m² per step. With no fixes for 6 steps, what is P, in m²? (m²)
  6. In simulation, the true position leaves the filter's ±2σ band on 40% of steps. The most likely problem is…
    • Q and/or R are set too small: the filter is overconfident
    • Q and R are too large
    • The filter is working perfectly
    • The truth is wrong
  7. A filter is told R = 0 (a perfect sensor). What does it do at each update?
    • Sets x = z exactly and P = 0
    • Ignores the measurement
    • Averages x⁻ and z
    • Crashes
  8. P⁻ = 4 m², R = 1 m². What is the posterior variance P, in m²? (m²)

Engineering applications

  • Drones holding level

    A drone fuses a gyro, which is smooth but drifts, with an accelerometer, which is noisy but knows where down is. A complementary filter gives a steady attitude estimate hundreds of times a second.

  • Phones finding themselves

    A phone's location blends satellite fixes, Wi-Fi and motion sensors. When the satellite signal is lost indoors, the motion prediction carries the estimate until a fix returns.

Watch

Optional verified videos. Nothing loads from YouTube until you press play.

Builds intuition for estimating what you can't measure directly when your sensors are noisy.

6 min 47 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

Shows how blending a jittery accelerometer with a drifting gyro gives a drone a steady sense of its tilt.

11 min 12 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

Explains why robots and cars combine several imperfect sensors to get a better picture of the world.

12 min 35 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

Shows the Kalman filter as the product of two probability distributions, the prediction and the measurement, which is exactly our inverse-variance derivation.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Why Use Kalman Filters? | Understanding Kalman Filters, Part 1 (MATLAB)
  • Drone Control and the Complementary Filter (Brian Douglas)
  • Understanding Sensor Fusion and Tracking, Part 1: What Is Sensor Fusion? (MATLAB)
  • Optimal State Estimator | Understanding Kalman Filters, Part 3 (MATLAB)

Chapter summary

  • Weight independent readings by 1/σ²; the fused variance is smaller than any single one.
  • A biased sensor that claims to be precise will drag a fused estimate off; weights are only as honest as the noise models.
  • A complementary filter trusts a fast sensor at short time scales and a slow one at long time scales.
  • The Kalman filter predicts with a model, then updates with a measurement using the variance-minimising gain.

Glossary

IMU (inertial measurement unit)
An IMU combines an accelerometer, which measures acceleration including gravity, and a gyroscope, which measures angular velocity; some add a magnetometer.
Encoder counts and resolution
A rotary encoder reports rotation as a count of ticks. Its resolution is the number of counts per revolution (CPR), often four times the pulses per revolution with quadrature decoding.
Odometry
Odometry estimates a robot's position and heading by adding up how far its wheels have turned since a known start.
Random and systematic error
Random errors scatter readings unpredictably above and below the true value; systematic errors shift every reading the same way.

Definitions from the Field Guide.

Project: Where is the rover?

Using the rover or two-sensor simulation, estimate position with dead reckoning alone, then with fusion. Tune the filter's noise settings, state them, and report the error over a full route, including during sensor dropouts.

Deliverables

  • The filter settings and their justification
  • Error over the route for each method
  • Behaviour during dropouts and one limitation

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • Rudolf E. Kalman (1960). "A New Approach to Linear Filtering and Prediction Problems". Journal of Basic Engineering 82(1), 35–45.
  • Sebastian Thrun et al. (2005). Probabilistic Robotics. MIT Press.

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.