Mike Is Making Stuff sticker

Complementary Filter Tuning for Six-Axis IMU Drift

By Mike · Published October 6, 2026 · Updated October 9, 2026

A six-axis IMU gives you a gyroscope and an accelerometer, and neither one tells the truth by itself. The gyroscope measures rotation rate beautifully in the short term but its estimate drifts over time as small errors accumulate. The accelerometer senses gravity's direction reliably in the long term but is corrupted in the short term by every linear acceleration of the vehicle. The complementary filter fuses them by trusting each sensor where it is strong: gyro for fast changes, accelerometer for slow truth. Tuning that trust is the whole job.

Complementary Filter Tuning for Six-Axis IMU Drift

The two sensors' complementary weaknesses

Integrate the gyroscope's rotation rate to get angle, and the angle is precise over seconds but wanders over minutes, because the gyro's small bias error integrates into a growing angle error. This drift is relentless and temperature-dependent; no affordable MEMS gyro holds its bias well enough to navigate on integration alone.

The accelerometer, meanwhile, measures the vector sum of gravity and the vehicle's own acceleration. When the vehicle sits still, that vector points down and gives an absolute tilt reference with no drift. The moment the vehicle accelerates, the vector tilts away from gravity and the tilt estimate is wrong, sometimes wildly. Accelerometers are truthful on average and liars in the moment; gyroscopes are truthful in the moment and liars on average. The filter exploits exactly this complementarity.

How the complementary filter blends them

The filter maintains an angle estimate updated in two steps each cycle. First, it advances the estimate using the gyroscope: new angle equals old angle plus gyro rate times the time step. Then it corrects the estimate toward the accelerometer's tilt measurement by a small fraction, the filter gain. The gain sets the trust balance: a tiny gain means the estimate follows the gyro almost exclusively and corrects toward the accelerometer very slowly; a larger gain pulls the estimate toward the accelerometer quickly.

Equivalently, the filter behaves as a high-pass on the gyro and a low-pass on the accelerometer, with the crossover frequency set by the gain. Fast motions come from the gyro; slow trends come from the accelerometer. Understanding it as a crossover makes tuning intuitive: you are choosing the frequency below which you trust the accelerometer and above which you trust the gyro.

Choosing the time constant

The gain is often expressed as a time constant, tau, the time over which the accelerometer's influence asserts itself. A tau of around one to a few seconds is a common starting point for balancing robots and small vehicles: short enough that gyro drift gets corrected before it matters, long enough that brief accelerations do not yank the estimate around. The exact value depends on the vehicle's dynamics: a twitchy racing quad needs a shorter tau than a slow rover, because its relevant motions are faster and its accelerations are more violent.

Tune empirically. Hold the vehicle still and watch the estimate: it should settle to the true tilt and stay there, which verifies the accelerometer correction is working. Then move it through its normal motions and watch for the estimate lagging behind fast rotations (tau too long, gain too small) or jumping with every acceleration (tau too short, gain too large). Adjust until the estimate tracks fast motion crisply while ignoring the vehicle's own accelerations.

Handling the yaw problem

The accelerometer senses gravity, which gives pitch and roll but says nothing about yaw, rotation around the vertical. A six-axis IMU has no absolute yaw reference, so the yaw estimate is pure gyro integration and drifts without bound. The complementary filter cannot fix this because there is nothing to complement the gyro with.

For applications needing stable yaw, the options are a magnetometer (making it a nine-axis system), an external heading reference, or designing the control to tolerate yaw drift. Do not waste tuning effort trying to make the complementary filter hold yaw; the information simply is not in the sensors.

Sample rate and numerical care

Run the filter at a consistent, known sample rate, and use the actual measured time step rather than an assumed one, since loop timing jitter introduces its own integration error. A few hundred hertz is plenty for most vehicles; the filter is computationally trivial, so the cost of a fast loop is negligible. Calibrate the gyro bias at startup while the vehicle is still, and consider tracking slow bias changes during operation for long-running systems.

Trust the gyro for the fast stuff, the accelerometer for the slow truth, set the crossover to match the vehicle's dynamics, and accept that yaw needs its own sensor. Tuned this way, the humble complementary filter delivers orientation estimates that rival far more complex algorithms for most robotics work.

Related Guides

← Back to Resources