Complementary filter
More actions
A complementary filter is an estimation technique that combines two measurements of the same quantity whose errors lie in different frequency ranges. One measurement is passed through a low-pass filter and the other through the matching high-pass filter, chosen so that the two transfer functions add up to one; the signal itself then passes through undistorted while each sensor's dominant noise is suppressed.[1] In virtual reality (VR) and augmented reality (AR) hardware it is used for orientation tracking with an inertial measurement unit: the gyroscope supplies smooth, fast but drifting rotation estimates, and the accelerometer (and sometimes the magnetometer) supplies noisy but drift-free references that slowly pull the estimate back.[2]
Walter Higgins described the complementary filter in 1975 as a simple technique "often used in the flight control industry" and showed that it is a steady-state Kalman filter (a Wiener filter) for a certain class of filtering problems.[1] Engineers at Oculus VR used a complementary filter to correct gyroscope drift in the head tracking of the Oculus Rift Development Kit, choosing it for "simplicity of implementation and adjustment based on perceptual experiments".[3] Nonlinear versions formulated on the rotation group, such as the filter of Mahony, Hamel and Pflimlin, were developed for attitude estimation with low-cost IMUs, and later comparisons treat them alongside the Madgwick and Kalman filters.[4][5]
How it works
Frequency-domain principle
In Higgins's formulation, two noisy measurements x and y of a signal z are combined. If the noise in y is mostly high frequency and the noise in x is mostly low frequency, y is passed through a low-pass filter G(s) and x through its complement 1 - G(s), which is a high-pass filter. With error-free measurements the output equals the true signal exactly. The filter can also be rearranged so that G(s) acts only on the difference y - x, that is, only on the measurement errors. Complementary filter designers do not use any statistical description of the noise; the filter is obtained by a simple frequency-domain analysis.[1]
Higgins's example is an aircraft vertical-velocity estimator. A vertical accelerometer signal is integrated to give one velocity estimate, whose high-frequency noise is attenuated by the integration, and a barometric vertical-velocity measurement gives another. The barometric signal is low-pass filtered with G(s) = 1/(τs + 1) and the integrated accelerometer signal is high-pass filtered with τs/(τs + 1). Higgins notes that the time constant τ was usually between 2 and 6 seconds and was adjusted during simulation or flight testing. Second-order versions estimate position and velocity together from acceleration and position measurements.[1]
Orientation from an IMU
Integrating a gyroscope's angular velocity gives a smooth orientation estimate, but small biases and noise accumulate, so the estimate drifts over time. An accelerometer at rest senses gravity and therefore gives an absolute estimate of tilt (pitch and roll), but this estimate is noisy, and an accelerometer reading cannot reveal rotation about the vertical axis (yaw).[2] Stanford's EE 267 course notes describe the two error types as complementary: a low-pass filter on the accelerometer estimate removes its noise, a high-pass filter on the gyroscope estimate removes its drift, and the two are combined. For a single rotation angle the notes give the update as a weighted sum of the previous estimate advanced by the gyroscope reading and the angle computed from the accelerometer, with a user-chosen blending weight α that can be tuned to the sensors.[2]
Texts differ on which term the weight multiplies. In Steven M. LaValle's Virtual Reality, the gain α multiplies the drift-free estimate and is chosen close to zero (the example given is α = 0.0001), so the absolute sensor has a gradual effect while the gyroscope dominates over short times. LaValle writes that the gain must be high enough to correct drift but low enough that the user does not perceive the corrections. When the absolute sensor reports at a lower rate than the gyroscope (for example a camera at 60 Hz and a gyroscope at 1000 Hz), the most recent reading is reused until a new one arrives.[6]
In three dimensions the filter is usually written with quaternions. Rather than averaging two orientations directly, the estimated drift error is expressed as a rotation about an axis, and on each update the gyroscope-integrated orientation is rotated by a small fraction of that error angle.[6][2] Tilt error and yaw error can be corrected separately with different gains.[6]
Relation to Kalman filtering
Higgins wrote the 1975 paper partly because both Kalman and complementary filtering were being considered for the Space Shuttle reentry and landing navigation system. He showed that Kalman filters as used in navigation systems are themselves based on the complementary filtering principle, and that a complementary filter with suitable fixed gains is identical to a steady-state Kalman filter for the idealized problems he analysed. He concluded that the complementary filter is simpler because it needs less computation, and left open how much accuracy fixed gains cost in real problems, where noise is not white and the equations are higher order.[1]
LaValle notes that the gain could be chosen "optimally" with a Kalman filter, but that this optimality holds only for a linear stochastic system, which human body tracking is not. He adds that the choice among filtering methods usually matters less than calibration, sensor error models and the dynamical model of the particular setup, and that VR performance requirements are mainly perceptual.[6]
The two ideas also meet in Kalman filters built in a complementary configuration. Eric Foxlin's 1996 paper at the IEEE Virtual Reality Annual International Symposium described a "complementary separate-bias Kalman filter" for an inertial head tracker. Its second prototype of the MIT Inertial Tracker combined small solid-state rate gyroscopes with a two-axis fluid inclinometer and a two-axis fluxgate compass and weighed 3.5 ounces; Foxlin wrote that the simple ad hoc drift correction used in the previous prototype was not accurate enough, and presented the Kalman-based fusion scheme as achieving a lower mean squared orientation estimation error than that method.[7]
Nonlinear complementary filters
Robert Mahony, Tarek Hamel and Jean-Michel Pflimlin formulated complementary filters directly on the special orthogonal group SO(3), the space of 3D rotations, in a 2008 paper in IEEE Transactions on Automatic Control. The work targets low-cost IMUs with high noise and time-varying biases, poses the filter as a deterministic observer, and proves almost global stability of the observer error. It presents a direct complementary filter, a passive complementary filter, and an explicit complementary filter that uses only accelerometer and gyroscope outputs, is suited to embedded hardware and estimates gyroscope bias online. The filters were demonstrated on a robotic test bed and a radio-controlled unmanned aerial vehicle.[4] A 2021 comparison describes the Mahony filter as a complementary filter extended with a proportional-integral controller acting on the error between the accelerometer-based and gyroscope-based orientations.[5]
Sebastian Madgwick's 2010 orientation filter uses a quaternion representation and an analytically derived gradient-descent step to compute the direction of the gyroscope error from accelerometer and magnetometer readings. Madgwick's report describes Mahony's complementary filter as an efficient and effective solution whose performance had been validated only for an IMU, and it adopts Mahony's integral feedback approach for gyroscope bias compensation. The report gives costs of 109 scalar arithmetic operations per update for an IMU and 277 for a magnetic, angular rate and gravity (MARG) array.[8] Büscher and colleagues describe the Madgwick filter as loosely based on the concepts of the complementary filter.[5] In 2020 Madgwick and co-authors published an "extended complementary filter" (ECF) for full-body MARG orientation estimation. According to the abstract, it combines the computational efficiency of classic complementary filters with improved accuracy compared with popular optimization filters; benchmarked against the gradient-descent algorithm (GDA), it converged 30% faster than standard alternatives, and was more robust to magnetic interference in pitch and roll and to fast yaw changes; it was used in a wearable stroke rehabilitation system with real-time avatar feedback.[9]
Roberto Valenti, Ivan Dryanovski and Jizhong Xiao proposed a quaternion complementary filter in 2015 whose correction step computes the orientation algebraically from gravity and magnetic field observations. It separates the tilt quaternion from the heading quaternion so that magnetic disturbances do not affect roll and pitch, and it works with both IMU and MARG sensors. The authors evaluated it on public datasets recorded during flights of a micro quadrotor.[10]
Use in VR and AR
Oculus Rift Development Kit
LaValle, Anna Yershova, Max Katsev and Michael Antonov of Oculus VR described the head tracking of the Oculus Rift Development Kit at the 2014 IEEE International Conference on Robotics and Automation. The headset's sensor board carried an STMicroelectronics 32F103C8 ARM Cortex-M3 microcontroller, an InvenSense MPU-6000 gyroscope and accelerometer, and a Honeywell HMC5983 magnetometer; observations were reported at 1000 Hz, although the magnetometer readings changed only at 220 Hz.[3] An April 2013 iFixit teardown of the development kit identified the same microcontroller and MPU-6000 on a tracker board "optimized for a 1000 Hz refresh rate".[11]
The tracker integrated gyroscope readings as quaternions (dead reckoning) and then corrected the accumulated drift in two parts. For tilt, the accelerometer vector was rotated into the world frame and compared with vertical; because linear head acceleration corrupts this vector in the short term, samples that differed sharply from previous measurements were discarded, and the filter relied on the fact that the average over many samples approaches gravity. The complementary filter then rotated the gyroscope estimate by a small fraction α of the tilt error about the tilt axis. The authors wrote that α "should be large enough to correct all drift, but small enough so that the corrections are imperceptible to the user", and they measured tilt correction against an OptiTrack motion-capture system.[3] Yaw drift was corrected the same way with a separate small gain, rotating only about the vertical axis, after a magnetometer calibration step: a calibrated reading recorded early in use, before much drift had accumulated, served as a reference, and later readings taken near the same orientation revealed the yaw drift. Several reference points scattered over the space of orientations extended this check. The paper treats true north as irrelevant because the headset is not used to navigate across the Earth, and notes that indoor magnetic fields and nearby ferrous materials distort the measurements.[3] The same paper presented separate predictive tracking methods to reduce effective latency.[3]
Smartphone VR on the web
The open-source WebVR Polyfill, which let WebVR content run in browsers without native WebVR support, fused smartphone gyroscope and accelerometer data with a complementary filter. Boris Smus described the approach in a November 2015 post: the gyroscope drives the orientation updates while the accelerometer's long-term accuracy corrects the drift, and the magnetometer is left out because, in his words, drifting away from true north "is often fine" in VR.[12] In the project's cardboard-vr-display component, the filter source file (copyright 2015 Google) describes a "simple complementary filter" fed by the browser's devicemotion event, and the default options set the filter coefficient to 0.98 (0 meaning accelerometer only and 1 gyroscope only) with a 40 ms prediction time. From version 1.0.4 the component prefers the browser's RelativeOrientationSensor and falls back to its own fusion on devicemotion data.[13][14]
Teaching and camera fusion
Gordon Wetzstein's notes for Stanford's EE 267 virtual reality course teach the complementary filter for 3-DOF orientation tracking, implemented on the VRduino board (a Teensy 3.2 microcontroller with an InvenSense MPU-9250 IMU). The notes show that an accelerometer alone tracks pitch and roll but not yaw, and that the quaternion complementary filter computed on the microcontroller is streamed to the host computer for rendering.[2] LaValle's textbook extends the same correction to camera-based tracking: a camera can supply the yaw reference, and for position the filter corrects doubly integrated accelerometer estimates of position and velocity with drift errors measured from camera pose solutions arriving at a much lower rate than the IMU.[6]
Performance and limitations
The basic filter depends on assumptions that head-mounted displays do not always meet. An accelerometer measures gravity plus the linear acceleration of the head, so its tilt estimate cannot be trusted over short intervals, and magnetometers measure the sum of the Earth's field and indoor fields that can nearly cancel it.[3] Fixed gains also cannot adapt to changing noise in the way a Kalman filter does, a trade-off Higgins already raised in 1975.[1]
In practice the accuracy gap has often been small. Büscher, Gis, Kühn and Haubelt compared an extended Kalman filter, the Madgwick filter, the Mahony filter and a complementary filter (blending weight 0.97) on an ARM Cortex-M0+ microcontroller, using a camera reference for ground truth. They found no meaningful difference in orientation error between the algorithms (apart from a 16-bit fixed-point Kalman implementation, which performed worse), and because the Kalman filter needed roughly three times the computation time of the others, they did not recommend it for hardware-restricted environments.[5]
| Algorithm | Average execution time per sample | Average error (degrees, without the z-axis) |
|---|---|---|
| Extended Kalman filter | 3.963 ms | 1.557 |
| Madgwick filter | 1.142 ms | 1.657 |
| Mahony filter | 0.758 ms | 1.588 |
| Complementary filter | 0.782 ms | 1.489 |
See also
References
- ↑ 1.0 1.1 1.2 1.3 1.4 1.5 Walter T. Higgins Jr. (1975-05). "A Comparison of Complementary and Kalman Filtering". IEEE Transactions on Aerospace and Electronic Systems, vol. AES-11, no. 3. pp. 321-325. doi:10.1109/TAES.1975.308081. https://doi.org/10.1109/TAES.1975.308081. Retrieved 2026-10-15.
- ↑ 2.0 2.1 2.2 2.3 2.4 Gordon Wetzstein. "EE 267 Virtual Reality Course Notes: 3-DOF Orientation Tracking with IMUs". Stanford University. https://web.stanford.edu/class/ee267/notes/ee267_notes_imu.pdf. Retrieved 2026-10-15.
- ↑ 3.0 3.1 3.2 3.3 3.4 3.5 Steven M. LaValle, Anna Yershova, Max Katsev, Michael Antonov (2014). "Head Tracking for the Oculus Rift". 2014 IEEE International Conference on Robotics and Automation (ICRA). pp. 187-194. doi:10.1109/ICRA.2014.6906608. https://msl.cs.illinois.edu/~lavalle/papers/LavYerKatAnt14.pdf. Retrieved 2026-10-15.
- ↑ 4.0 4.1 Robert Mahony, Tarek Hamel, Jean-Michel Pflimlin (2008). "Nonlinear Complementary Filters on the Special Orthogonal Group". IEEE Transactions on Automatic Control, vol. 53, no. 5. pp. 1203-1218. doi:10.1109/TAC.2008.923738. https://doi.org/10.1109/TAC.2008.923738. Retrieved 2026-10-15.
- ↑ 5.0 5.1 5.2 5.3 Nils Büscher, Daniel Gis, Volker Kühn, Christian Haubelt (2021). "On the Functional and Extra-Functional Properties of IMU Fusion Algorithms for Body-Worn Smart Sensors". Sensors, vol. 21, no. 8, article 2747. doi:10.3390/s21082747. https://pmc.ncbi.nlm.nih.gov/articles/PMC8069451/. Retrieved 2026-10-15.
- ↑ 6.0 6.1 6.2 6.3 6.4 Steven M. LaValle (2020). "Virtual Reality, Chapter 9: Tracking (online edition)". lavalle.pl (book published by Cambridge University Press). https://lavalle.pl/vr/vrch9.pdf. Retrieved 2026-10-15.
- ↑ Eric Foxlin (1996). "Inertial Head-Tracker Sensor Fusion by a Complementary Separate-Bias Kalman Filter". Proceedings of the IEEE 1996 Virtual Reality Annual International Symposium (NASA Technical Reports Server copy). pp. 185-194. doi:10.1109/VRAIS.1996.490527. https://ntrs.nasa.gov/api/citations/19960028781/downloads/19960028781.pdf. Retrieved 2026-10-15.
- ↑ Sebastian O. H. Madgwick (2010-04-30). "An efficient orientation filter for inertial and inertial/magnetic sensor arrays". x-io Technologies (internal report). https://x-io.co.uk/downloads/madgwick_internal_report.pdf. Retrieved 2026-10-15.
- ↑ Sebastian O. H. Madgwick, Samuel Wilson, Ruth Turk, Jane Burridge, Christos Kapatos, Ravi Vaidyanathan (2020). "An Extended Complementary Filter for Full-Body MARG Orientation Estimation". IEEE/ASME Transactions on Mechatronics, vol. 25, no. 4. pp. 2054-2064. doi:10.1109/TMECH.2020.2992296. https://spiral.imperial.ac.uk/entities/publication/29a705a0-2f4a-41dc-b44a-ea467951416e. Retrieved 2026-10-15.
- ↑ Roberto Valenti, Ivan Dryanovski, Jizhong Xiao (2015). "Keeping a Good Attitude: A Quaternion-Based Orientation Filter for IMUs and MARGs". Sensors, vol. 15, no. 8. pp. 19302-19330. doi:10.3390/s150819302. https://doi.org/10.3390/s150819302. Retrieved 2026-10-15.
- ↑ "Oculus Rift Teardown". iFixit. 2013-04-10. https://www.ifixit.com/News/oculus-rift-teardown. Retrieved 2026-10-15.
- ↑ Boris Smus (2015-11-05). "Sensor fusion and motion prediction". smus.com. https://smus.com/sensor-fusion-prediction-webvr/. Retrieved 2026-10-15.
- ↑ "cardboard-vr-display (README, src/options.js and src/sensor-fusion/complementary-filter.js)". GitHub, Immersive Web. https://github.com/immersive-web/cardboard-vr-display. Retrieved 2026-10-15.
- ↑ "WebVR Polyfill". GitHub, Immersive Web. https://github.com/immersive-web/webvr-polyfill. Retrieved 2026-10-15.