Skip to content

SensingNoise and Estimation

The Complementary Filter

Trust the gyro over short times and the accelerometer over long times: θ = α(θ + ω Δt) + (1 − α) θ_acc.

Not started Jump to practice

The gyro is smooth but drifts; the accelerometer is right on average but jumpy. Blend them and get the best of both.

Key idea

The complementary filter: $\theta \leftarrow \alpha\,(\theta + \omega\,\Delta t) + (1 - \alpha)\,\theta_{\text{acc}}$, with $\alpha$ close to 1, such as 0.98.
The blended angle follows quick changes like the gyro and stays anchored like the accelerometer.

Why it works

Each step mostly trusts the gyro's quick update, so the result is smooth. But each step also pulls 2% toward the accelerometer, so over a second or two any drift is pulled back out. That is why it is called complementary: one sensor covers the other's weakness.

Worked example: One step

$\alpha = 0.98$, last $\theta = 10^\circ$, gyro 20 °/s, $\Delta t = 0.01$, accelerometer 12°.
  1. Gyro guess: $10 + 0.2 = 10.2$.
  2. $0.98 \times 10.2 + 0.02 \times 12 = 9.996 + 0.24 = 10.236$.

Answer: About 10.24°.

Common mistake

Swapping the weights and trusting the noisy accelerometer most.

Hands-on: a tilt meter

Wire an IMU board to your microcontroller. Print three angles side by side: accelerometer alone, gyro alone, and the complementary blend. Tilt the board and hold it; then shake it. Which one would you trust to balance a robot?

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of Sensing and Estimation.

Sources and further reading

  • Sebastian Thrun, Wolfram Burgard and Dieter Fox, Probabilistic Robotics (MIT Press, 2005)
  • Roland Siegwart, Illah R. Nourbakhsh and Davide Scaramuzza, Introduction to Autonomous Mobile Robots, 2nd ed. (MIT Press, 2011)