Mahony Filter
Mahony Complementary Filter for IMU and AHRS · Also known as: Mahony AHRS, complementary observer attitude filter
The Mahony Filter is a complementary observer-based attitude filter that fuses gyroscope, accelerometer, and magnetometer measurements to estimate quaternion orientation. Developed by Robert Mahony and colleagues in 2008, the filter combines gyroscope rate integration with corrective feedback from vector measurements (accelerometer, compass) using proportional-integral control principles. The Mahony Filter provides similar performance to Kalman Filters but with simpler implementation and lower computational cost, making it ideal for resource-constrained systems and real-time control.
Read the full method
Sign in with a free account to read this section.
Method map
The neighbourhood of related methods — select a node to explore.
When to use it
Use Mahony Filter for attitude estimation on embedded systems when Kalman Filter is too complex or costly. Ideal for quadrotors, multirotors, and aircraft autopilots. Deploy when you want a physically-motivated, easily-tuned alternative to Madgwick (which uses gradient descent). Suitable for real-time control loops requiring low latency and stable estimates. Use when you understand proportional-integral control and can tune K_p, K_i.
Strengths & limitations
- Physically intuitive; based on control theory (PI feedback); easier to understand and debug than gradient descent.
- Explicit gyroscope bias estimation; the integral term learns and corrects sensor bias over time.
- Two tuning parameters (K_p, K_i) have clear physical meaning (proportional and integral gain) unlike beta in Madgwick.
- Similar computational cost to Madgwick; lightweight and suitable for embedded systems.
- Tuning K_p and K_i requires understanding of control theory and empirical experimentation.
- Performance sensitive to tuning; poor choice of gains can cause oscillation or sluggish response.
- Integral term can cause wind-up; large, sustained errors accumulate and cause overshoot; mitigation needed.
- Like Madgwick, magnetometer disturbance affects heading accuracy; requires calibration and possibly disturbance detection.
Frequently asked
How do I tune K_p and K_i?
K_p is the proportional gain (typically 0.5–2.0); higher K_p means faster correction but risk of oscillation. K_i is the integral gain (typically 0.01–0.1); it controls bias correction rate. Start with K_p=1.0, K_i=0.1. Increase K_p if the filter lags behind maneuvers; decrease if it oscillates. Increase K_i if bias drift is significant; decrease if integral wind-up occurs.
What is integral wind-up and how do I prevent it?
Integral wind-up occurs when the integral term grows unboundedly during sustained error (e.g., magnetometer disturbance). When the error finally clears, the filter overshoots. Prevent by saturating the integral term (bound it between limits) or by conditional integration (only integrate when error is small).
What is the difference between Mahony and Madgwick filters?
Mahony uses PI feedback with explicit bias estimation; Madgwick uses gradient descent. Mahony is based on control theory; Madgwick on optimization. Both have similar computational cost. Mahony typically has faster bias convergence; Madgwick is simpler to implement. For attitude-only (no bias), they perform similarly.
Can Mahony handle large accelerations?
During large accelerations, accelerometer measures inertial acceleration + gravity, causing pitch/roll error. The Mahony Filter assumes accelerometer points downward; large accelerations violate this. Some implementations use acceleration magnitude thresholding to reduce accelerometer weight during maneuvers, improving robustness.
Sources
- Mahony, R., Hamel, T., & Pflimlin, J. M. (2008). Multirotor aerial vehicles: Modeling, estimation, and control of quadrotors. IEEE Robotics and Automation Magazine, 19(3), 20–32. link ↗
- Mahony, R., Hamel, T., & Pflimlin, J. M. (2012). Multirotor aerial vehicles: Modeling, estimation, and control of quadrotors. IEEE Robotics & Automation Magazine, 19(3), 20–32. DOI: 10.1109/MRA.2012.2206474 ↗
- Valenti, R. G., Dryanovski, I., & Xiao, J. (2016). Keeping a good attitude: A quaternion-based orientation filter for IMUs and MARGs. Sensors, 15(8), 19302–19330. DOI: 10.3390/s150819302 ↗
How to cite this page
ScholarGate. (2026, June 3). Mahony Complementary Filter for IMU and AHRS. ScholarGate. https://scholargate.app/en/aerospace/mahony-filter
Which method?
Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.
- AHRSAerospace↔ compare
- Madgwick FilterAerospace↔ compare
- Quaternion AttitudeAerospace↔ compare