Analytics & ML · Study deck
Complementary Filters: Sensor Trust
A gyro reacts fast but drifts.
Data Dora is your guide for this deck.

After studying this chapter
Learning objectives
You will be able to:
- separate gyro drift from accelerometer motion noise
- derive the trust roles in a complementary filter
- Explain: Real devices turn in three dimensions and may speed up in any direction.
- Explain: Under the Hood derives the update rule, tracks uncertainty, and shows where this simple blend stops being enough.
Major section
Start With the Story
Real devices turn in three dimensions and may speed up in any direction.
- The second is steady over time but shakes during motion.
- Neither gives a perfect answer alone.
- An inertial measurement unit is a small set of motion sensors.
- Its short name is IMU.
Major section
Start With the Story (continued)
Under the Hood derives the update rule, tracks uncertainty, and shows where this simple blend stops being enough.
- It trusts the fast view for quick change.
- The two parts support each other.
- A missed or uneven update changes the result.
- Vibration can disturb the gravity view.
Major section
Complementary Filter Trust
A complementary filter is a lightweight IMU fusion method that combines gyroscope integration with an accelerometer gravity reference.
- The gyroscope is responsive over short intervals, but bias and noise accumulate into drift when angular rate is integrated.
- Wearable systems also need the body-plane mapping: sagittal, coronal, and transverse planes must be tied to the sensor mounting frame.
Major section
Complementary Filter Trust (continued)
The accelerometer gives an absolute roll and pitch reference from gravity when the device is not accelerating hard, but it is noisy during vibration and linear motion.
- It trusts the gyroscope for fast changes and uses a small accelerometer correction to pull the estimate back toward the gravity reference over time.
- In the usual aircraft convention, roll is rotation about the forward x-axis, pitch is rotation about the lateral y-axis, and yaw is rotation about the vertical z-axis.
- The filter works because those errors are complementary.
Major section
Phoebe's Field Notes: Why the Complementary Filter Behaves Like a Physics Ledger
That small correction corresponds to a 0.495 s time constant and leaves 1.82° of an initial 5° drift after 50 equal updates.
- The lower comparison explains the blend: the gyro is responsive but drifts, while gravity supplies a slower tilt reference when linear acceleration is controlled.
Major section
Phoebe's Field Notes: Why the Complementary Filter Behaves Like a Physics Ledger (continued)
This connects the worked alpha calculation to the running physics ledger: every output axis must name its reference, calibration, sample period, and conditions of observability.
- Gyroscope Measures angular rate.
- Integration gives smooth short-term attitude changes but accumulates bias drift.
- Accelerometer Measures gravity plus linear acceleration.
Major section
Tune Alpha by Motion and Rate
The same idea can be applied to roll and pitch separately, or implemented in quaternion form for a full orientation pipeline.
- The alpha value is not a universal constant.
- It should be chosen from the update period, expected vibration, allowed drift, and how often the accelerometer is a valid gravity reference.
Major section
Tune Alpha by Motion and Rate (continued)
Alpha tuning is meaningless until the inputs have a healthy stationary baseline.
- A higher alpha makes the output smoother during vibration but slower to correct gyro drift.
- A lower alpha corrects drift faster but can inject acceleration and vibration into the attitude estimate.
- Axis signs vary by board and mounting.
Major section
Tune Alpha by Motion and Rate (continued)
A stationary calibrated gyroscope should sit near zero angular rate, while the calibrated accelerometer should show two axes near 0 g and the gravity-facing axis near +1 g or -1 g depending on mounting.
- Magnetometer channels should be stable in the local field but still need hard-iron and soft-iron checks before they are trusted for heading.
- The gyroscope panel wobbles inside a ±50 LSB band, and its card gives the decoder ring: 131 LSB per °/s on a ±250 °/s range.
- In: Accelerometer -- gravity on one axis only, z holds about -1g while x and y remain near 0g.
Major section
Tune Alpha by Motion and Rate (continued)
Accelerometer samples include vibration and may not represent only gravity.
- Flat and boring is the healthy signature here; the next two figures show what turns these codes into checkable physics.
- The: Compass -- stable local field, no drift panel keeps three separate offsets without a trend.
- The accelerometer includes non-gravity acceleration during maneuvers.
Major section
Tune Alpha by Motion and Rate (continued)
Calibration shrinks the ramp's slope; only an external reference — gravity, in this chapter — can keep paying it off.
- The top chart in Figure: Three stationary calibrated IMU traces for gyroscope shows Gyroscope -- near-zero angular rate, with x, y, and z close to zero.
- Gyroscope angle is obtained by integrating angular rate, commonly with a rectangle or trapezoidal numerical rule.
- The gravity correction is too slow for the observed bias and update rate.
Major section
Tune Alpha by Motion and Rate (continued)
The blend factor only makes sense after seeing what each IMU channel gets wrong over the same motion.
- The accelerometer's −16,650 LSB becomes −1.016 g at step 1 · APPLY SCALE, and only the second step, 2 · REMOVE BIAS, brings it to the clean −1.000 g the calibrated chart displayed.
- That integration also accumulates bias and white noise: a class trace can show tens of degrees of apparent angle drift over about 30 seconds even though the gyroscope itself is unaffected by earth gravity.
- Two bands in Figure: The worked roll update as a living loop carry the whole philosophy.
Major section
Tune Alpha by Motion and Rate (continued)
The: Accelerometer-derived angle remains noisy on each sample, yet gravity resets its reference so it has no matching long-term drift.
- Accelerometer tilt estimates avoid long-term drift but are noisy and sluggish when filtered, so they are best treated as roll and pitch correction evidence rather than a complete attitude solution.
- The top panel of Figure: A bias invisible in the rate chart compounds looks perfectly healthy — the rocking is symmetric and no single sample is suspicious — yet the dashed line marks its mean = −1.7 °/s, not 0.
- Gate correction when acceleration magnitude is far from 1 g.
Major section
Tune Alpha by Motion and Rate (continued)
The card also separates the two failure currencies: noise integrates into a slow random walk that grows like √t, while bias buys a straight ramp that grows like t.
- The paired chart in Figure: Same window holds the time window constant so the tuning discussion can separate accumulated bias from sample-by-sample noise.
- A larger alpha trusts the fast gyro branch for short motion; the complementary term must still pull the estimate toward the driftless gravity reference.
- Interpretation: The estimate follows the gyro's fast motion but is nudged 0.0424 deg toward the accelerometer gravity estimate during this 10 ms update.
Deck summary
Key takeaways
Real devices turn in three dimensions and may speed up in any direction.
- Under the Hood derives the update rule, tracks uncertainty, and shows where this simple blend stops being enough.
- A complementary filter is a lightweight IMU fusion method that combines gyroscope integration with an accelerometer gravity reference.
- The accelerometer gives an absolute roll and pitch reference from gravity when the device is not accelerating hard, but it is noisy during vibration and linear motion.
- That small correction corresponds to a 0.495 s time constant and leaves 1.82° of an initial 5° drift after 50 equal updates.
Retrieval practice
Recall check 1 of 2

Data Dora says: answer from memory, then check your reasoning.
Q1What complementary property makes gyroscope and accelerometer fusion useful for roll and pitch?
Show answer
Answer: B Complementary IMU fusion relies on different time-scale strengths, not duplicate measurements.
Retrieval practice
Recall check 2 of 2

Data Dora says: answer from memory, then check your reasoning.
Q2In the worked roll update, why does the estimate become 8.0776 deg instead of copying the 6.00 deg accelerometer estimate?
Show answer
Answer: A The complementary filter blends a gyro prediction with a small accelerometer correction controlled by alpha.
Print reference
Answers
Answer key.
- B · Complementary IMU fusion relies on different time-scale strengths, not duplicate measurements.
- A · The complementary filter blends a gyro prediction with a small accelerometer correction controlled by alpha.