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.
Tilt is recovered from gravity's projections: two shadows on the body axes, one atan2 call, no integration anywhere.
Tilt is recovered from gravity's projections: two shadows on the body axes, one atan2 call, no integration anywhere.
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.
  • 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.
  • The filter works because those errors are complementary.

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

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 gyro reacts fast, but its error grows with time.
  • The magnetometer gives a heading check for yaw.
  • GyroscopeMeasures angular rate.
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)

AccelerometerMeasures gravity plus linear acceleration.

  • Gravity gives the filter a slower check on roll and pitch when other motion is small.
  • The lower pair shows why the filter needs both a fast path and a steady reference.
  • Using a nominal dt when the loop is jittery.
Scale first, bias second: one stationary sample per sensor walked from integer code to checkable physical target.
Scale first, bias second: one stationary sample per sensor walked from integer code to checkable physical target.
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.
  • Alpha tuning is meaningless until the inputs have a healthy stationary baseline.

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)

The: Compass -- stable local field, no drift panel keeps three separate offsets without a trend.

  • 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.
  • Gyroscope angle is obtained by integrating angular rate, commonly with a rectangle or trapezoidal numerical rule.
  • The accelerometer includes non-gravity acceleration during maneuvers.
One angle step is one trapezoid of area under the gyro rate curve — and the rectangle rule overpays by a visible sliver.
One angle step is one trapezoid of area under the gyro rate curve — and the rectangle rule overpays by a visible sliver.
iotclass.org

Major section

Tune Alpha by Motion and Rate (continued)

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 chart in Figure: Three stationary calibrated IMU traces for gyroscope shows Gyroscope -- near-zero angular rate, with x, y, and z close to zero.
  • 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.
  • Gate correction when acceleration magnitude is far from 1 g.
Three stationary calibrated IMU traces for gyroscope, accelerometer, and compass
Three stationary calibrated IMU traces for gyroscope, accelerometer, and compass
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.

  • 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.
  • 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.
  • The gravity correction is too slow for the observed bias and update rate.
A bias invisible in the rate chart compounds into fifty-one degrees of angle error in thirty seconds of integration.
A bias invisible in the rate chart compounds into fifty-one degrees of angle error in thirty seconds of integration.
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.

  • Calibration shrinks the ramp's slope; only an external reference — gravity, in this chapter — can keep paying it off.
  • 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.
  • The: Accelerometer-derived angle remains noisy on each sample, yet gravity resets its reference so it has no matching long-term drift.
Same window, same motion, opposite failure modes -- exactly why a complementary filter blends the two instead of trusting either alone.
Same window, same motion, opposite failure modes -- exactly why a complementary filter blends the two instead of trusting either alone.
iotclass.org

Major section

Tune Alpha by Motion and Rate (continued)

A larger alpha trusts the fast gyro branch for short motion; the complementary term must still pull the estimate toward the driftless gravity reference.

  • The ratio cancels the strength of gravity, and no gyro rate is integrated, so gyro bias cannot accumulate as angle drift here.
  • When that magnitude leaves 1 g, the same trigonometry runs happily on the wrong force — which is precisely the failure the validity-gate section below is built to catch.
  • 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.
The worked roll update as a living loop: a fast gyro path weighted 0.98, a slow gravity correction weighted 0.02, and a feedback edge that never rests.
The worked roll update as a living loop: a fast gyro path weighted 0.98, a slow gravity correction weighted 0.02, and a feedback edge that never rests.
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.
  • That small correction corresponds to a 0.495 s time constant and leaves 1.82° of an initial 5° drift after 50 equal updates.
  • AccelerometerMeasures gravity plus linear acceleration.
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 accelerometer provides absolute yaw heading, while the gyro only measures temperature drift.
CThe gyro is strong for short-term motion but drifts, while the accelerometer gives a noisy long-term gravity reference.
DThe gyro never drifts over time, so the accelerometer is only a backup display reference.
Show answer

Answer: C 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?

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

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

iotclass.org

Print reference

Answers

Answer key.

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