Analytics & ML · Study deck

Complementary Filters: Sensor Trust

A gyro reacts fast but drifts.

Data Dora is your guide for this deck.

datafusioncomplementary
Data Dora, the module guide, in a scene from this chapter.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.

Why it matters

The filter works because those errors are complementary.

Anatomy fixes the axis convention for a chest-worn IMU — and decides which angles gravity can referee.
Anatomy fixes the axis convention for a chest-worn IMU — and decides which angles gravity can referee.
iotclass.org

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.
iotclass.org

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.
For complementary IMU fusion, the gyro-plus-accelerometer path estimates roll and pitch; yaw must be backed by magnetometer or external heading evidence, or labeled as drifting.
For complementary IMU fusion, the gyro-plus-accelerometer path estimates roll and pitch; yaw must be backed by magnetometer or external heading evidence, or labeled as drifting.
iotclass.org

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.
iotclass.org

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.

Key terms

Flat and boring
Flat and boring is the healthy signature here; the next two figures show what turns these codes into checkable physics.
Alpha tuning
Alpha tuning is meaningless until the inputs have a healthy stationary baseline.
A motionless IMU still speaks in integer codes: bias offsets, one pinned gravity axis, and a steady magnetic field.
A motionless IMU still speaks in integer codes: bias offsets, one pinned gravity axis, and a steady magnetic field.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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?

ABoth sensors report identical attitude with matching noise, so fusion only averages duplicate readings.
BThe gyro is strong for short-term motion but drifts, while the accelerometer gives a noisy long-term gravity reference.
CThe accelerometer provides absolute yaw heading, while the gyro only measures temperature drift.
DThe gyro never drifts over time, so the accelerometer is only a backup display reference.
Show answer

Answer: B Complementary IMU fusion relies on different time-scale strengths, not duplicate measurements.

iotclass.org

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?

AAlpha is 0.98, so the update mostly follows the gyro prediction and applies only a small accelerometer correction.
BThe accelerometer is used only to initialize roll, leaving later updates to integrate the gyro rate without correction.
CAlpha sets the filter's response time, so the gyro rate can be blended without multiplying it by the sample interval.
DAlpha 0.98 gives the accelerometer the larger weight, pulling the estimate toward its reading from the previous roll.
Show answer

Answer: A The complementary filter blends a gyro prediction with a small accelerometer correction controlled by alpha.

iotclass.org

Print reference

Answers

Answer key.

  1. B · Complementary IMU fusion relies on different time-scale strengths, not duplicate measurements.
  2. A · The complementary filter blends a gyro prediction with a small accelerometer correction controlled by alpha.
iotclass.org