Exercises — Sensor fusion — complementary filter (simple), Kalman filter (optimal)
Quick symbol reminder so you never guess:
Level 1 — Recognition
L1·1 — Name the weight
The complementary filter update is With and , compute . Which sensor does this value trust more?
Recall Solution
. WHAT this means: multiplies the gyro prediction, so we trust the gyro heavily this instant. The remaining gently pulls toward the accel — enough to erase long-term drift, small enough to reject fast accel noise.
L1·2 — Read the Kalman gain
In one Kalman step the prior variance is and the measurement noise is . Compute the gain and say, in words, what a gain of that size does to a measurement.
Recall Solution
. WHAT it does: the update is , so we move 75% of the way from our prior toward the new reading . WHY so much? Because the prior () is more uncertain than the sensor (), so the sensor deserves the louder vote.
Level 2 — Application
L2·1 — One complementary step
Given , , previous estimate , gyro rate , accel angle . Find .
Recall Solution
Step A — WHAT: build . . Step B — WHY predict first: integrate the rate to guess where the angle went. Gyro prediction . Step C — Fuse: . WHAT it looks like: we mostly followed the gyro's downward swing, then the accel tugged us a hair further down (since ).
L2·2 — One full Kalman cycle
Start , , with , , and a reading . Run predict → gain → update → variance.
Recall Solution
Predict. (no motion model but the state); . WHY : uncertainty always grows between measurements. Gain. . Update. . Variance. . WHAT it looks like: the estimate leapt two-thirds of the way to the reading, and its variance dropped from to — below both the prior and the sensor. Fusion always sharpens.
Level 3 — Analysis
L3·0 — Limiting cases of : where does trust go?
Using , describe what happens to the complementary filter in the two extremes (with fixed) and .
Recall Solution
Case (or ): . WHAT it looks like: — pure gyro integration, the accel term . WHY: with ticks arriving arbitrarily fast, only a whisker of drift builds between corrections, so the smooth gyro rules and the noisy accel is ignored. This is the high-frequency / short-term regime. Case : . WHAT it looks like: — the estimate just copies the accel; the gyro prediction is discarded. WHY: over a long gap the gyro's drift has grown huge, so we throw away the stale prediction and re-anchor to the drift-free accel. This is the low-frequency / long-term regime. The knob slides you between these poles: large (relative to ) → → gyro-dominated; small → → accel-dominated. The crossover sits exactly where , giving .
L3·1 — The steady-state Kalman gain
Let the filter run forever until stops changing: call the settled value . It satisfies Take , . Find and the steady gain .
Recall Solution
WHAT we do: at steady state . Substitute the gain into with . Step 1 — assemble the fixed-point equation. Using , the updated variance is (the "" form). At steady state and , so Step 2 — clear the denominator. Multiply both sides by . WHY: to turn a fraction into a polynomial we can solve. Step 3 — expand each side. Left: . Right: . Step 4 — cancel the shared term from both sides (it appears identically), leaving a clean quadratic: Step 5 — solve the quadratic. With : . The quadratic formula gives the two roots Step 6 — pick the physically valid root. WHY we discard the root: is a variance, and a variance is a squared spread — it can never be negative. The root gives , which is impossible for a variance, so we reject it. The root is Then , and . WHAT it means: once settled, the Kalman gain is a constant — meaning a settled Kalman filter is a complementary filter with .
L3·2 — Precisions add
Two independent estimates of the same angle: one with variance , one (a measurement) with variance . Show numerically that the fused variance obeys , and compare to what naive averaging would give.
Recall Solution
Kalman way. , so . Check precision rule. , and . ✓ Naive average ( each). Averaging two independent estimates, the variance of the average is — worse than the optimal . WHY: equal weighting ignores that the first source is more precise. The optimal weight leans toward the sharper source, squeezing variance lower. Information (=inverse variance) simply adds.
Level 4 — Synthesis
L4·1 — Match a complementary to a Kalman steady state
An engineer built a complementary filter with at . She wants a Kalman filter that, at steady state, behaves identically. If her sensor has , what process noise gives a steady Kalman gain ?
Recall Solution
WHAT the match requires: . Recall from L3·1 the settled relations and . From the gain: with , so . Also . Then . WHAT it means: a Kalman filter with tiny (and ) locks to the same blend her complementary filter uses. The two filters are the same machine at steady state — Kalman just also handles the noisy start-up transient.
L4·2 — Convergence curve of
Starting from , , , list using , , . Confirm it heads toward the from L3·1.
Recall Solution
Step 1. , , . Step 2. , , . Step 3. , , . WHAT it looks like (see figure below): plunges , settling toward . The gain rides down with it. That falling curve is exactly why Kalman beats a fixed : early on it grabs measurements hard (high ), then relaxes as confidence builds.

Figure — what to observe (alt-text): A blueprint-style plot with step number on the horizontal axis and value on the vertical axis. The cyan curve with circles is the estimate variance : it starts high at and drops steeply — — flattening toward the dashed white line marked . The amber curve with squares is the Kalman gain : it starts high (near , "grabs measurements hard early") and settles toward ("relaxes as it grows confident"). What you should take away: both the uncertainty and the trust-in-measurement shrink together and level off at the steady-state value computed in L3·1 — this converged, frozen gain is precisely the fixed of a complementary filter.
Level 5 — Mastery
L5·1 — Derive the optimal gain from scratch
The estimate is a weighted correction , with prior error variance and independent measurement noise variance . Prove that the minimising the posterior variance is , and that then .
Recall Solution
Step A — WHAT: write the error. Let the true value be . Prior error has variance ; measurement error has variance , independent of . Then Step B — WHY variances add: and are independent, so their variances add with the squared coefficients: Step C — Minimise. WHY a derivative? is a smooth upward parabola in ; its lowest point has zero slope. Step D — Back-substitute. . Since , multiply by : , so WHAT it means: the "" law follows directly, and the gain is nothing more than "trust each source in proportion to its precision."
L5·2 — Complementary filter has unity DC gain
Show that and sum to for all , and evaluate each at (DC, a constant input) and as (very fast input). Interpret.
Recall Solution
Sum. for every . WHY this matters: whatever the frequency, the two paths' weights always total , so no scaling error can creep in. DC, : , . A constant angle is passed entirely by the accel path — which is drift-free, exactly what we want for long-term truth. Fast, : , . Quick wiggles pass entirely through the gyro path — smooth and noise-free short-term. WHAT it means: each sensor rules the band where it is trustworthy, and because the transfer functions sum to , a steady input keeps its exact size (unity DC gain) — no steady-state bias. This is the frequency-domain mirror of the limits in L3·0: DC ↔ (accel), high frequency ↔ (gyro).
Recall Self-test cloze — cover and recall
The complementary blend weight is ::: The Kalman gain is ::: Predict grows variance by adding ::: the process noise , giving A larger makes the filter trust the measurement ::: less (smaller ) Fusing two Gaussians makes their ::: precisions (inverse variances) add As the complementary filter trusts ::: the gyro fully () As the complementary filter trusts ::: the accel fully () Before blending angles you must ::: wrap the difference into (shortest arc) A steady-state Kalman filter is equivalent to a ::: complementary filter with fixed gain
See also: Low-pass and High-pass filters, Gaussian distribution, Bayesian estimation, State-space models, Attitude estimation (AHRS), Extended Kalman Filter, Inertial Navigation Systems.