Madgwick Filter
Madgwick IMU and AHRS Algorithms · Also known as: Madgwick AHRS, gradient descent attitude filter
The Madgwick Filter is a computationally lightweight attitude estimation algorithm that fuses inertial measurements (accelerometer, gyroscope) with magnetic measurements (magnetometer) to compute a quaternion orientation. Introduced by Sebastian Madgwick in 2010, the algorithm uses gradient descent optimization to minimize the error between measured and expected sensor outputs, yielding accurate, drift-free attitude estimates on embedded systems with minimal computational cost. The Madgwick Filter is now ubiquitous in consumer electronics, robotics, and aerospace systems.
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 Madgwick Filter when you need lightweight, real-time attitude estimation on resource-constrained devices (microcontrollers, mobile phones, wearables). Ideal for applications where Kalman Filter complexity is overkill. Effective indoors and outdoors, in vehicles, drones, and wearables. Deploy when you have a 9-DOF IMU and want to avoid tuning multiple Kalman Filter parameters. Use for consumer electronics, hobby robotics, and real-time control systems.
Strengths & limitations
- Minimal computational cost; implemented in < 100 lines of code; runs on microcontrollers and mobile processors.
- No matrices or complex linear algebra required; only quaternion algebra and dot products.
- Provides IMU-only (6-DOF) and MARG (9-DOF) variants; adaptable to available sensors.
- Single tuning parameter (beta) makes it easy to customize; no covariance matrices or matrix inversions.
- Heuristic, not optimal; does not minimize any formal cost function (unlike Kalman Filter).
- Performance depends critically on beta (step size); no automatic adaptation if sensor quality or motion changes.
- Magnetometer disturbance can corrupt heading; requires manual calibration; does not automatically detect or reject bad measurements.
- Large accelerations (in MARG variant) cause temporary errors as accelerometer misaligns with gravity; filter recovery is heuristic, not principled.
Frequently asked
How do I choose the beta parameter?
Beta controls the rate of gradient descent correction. Start with beta = 0.041 (the value Madgwick used). If the filter is sluggish (slow to respond to motion), increase beta (up to 0.1–0.5). If the filter oscillates or drifts, lower beta (down to 0.01). Tune empirically by watching attitude response to known motions.
What is the difference between IMU (6-DOF) and MARG (9-DOF) variants?
IMU variant uses accelerometer and gyroscope only; it provides roll and pitch but yaw drifts without a reference. MARG variant adds magnetometer for absolute yaw; it provides stable 3-DOF attitude but is sensitive to magnetic distortion. Use IMU for short-duration flights; use MARG for stationary or slow navigation.
Can I run Madgwick Filter on a 32-bit microcontroller?
Yes. The algorithm is very efficient; ARM Cortex-M4 can run it at 200+ Hz. Even 8-bit microcontrollers (with floating-point libraries) can manage 50+ Hz. Performance depends on clock rate and floating-point support. With fixed-point arithmetic, it scales to much slower processors.
How do I detect magnetic disturbance?
Monitor magnetometer magnitude; Earth's field is ~50 micro-Tesla; larger deviation indicates distortion. Compare compass heading (from magnetometer) with heading from gyro integration; large disagreement signals disturbance. Mitigation: temporarily ignore magnetometer updates during disturbance, or reduce its weight (lower beta_m in some variants).
Sources
- Madgwick, S. O. H., Harrison, A. J. L., & Vaidyanathan, R. (2011). Estimation of IMU and MARG orientation using a gradient descent algorithm. IEEE International Conference on Rehabilitation Robotics (ICORR), 1–7. link ↗
- Madgwick, S. O. H. (2010). An efficient orientation filter for inertial and inertial/magnetic sensor arrays. Report x-io Technologies, University of Bristol, UK. link ↗
- Sabatini, A. M. (2006). Quaternion-based extended Kalman filter for determining orientation by inertial and magnetic sensing. IEEE Transactions on Biomedical Engineering, 53(7), 1346–1356. DOI: 10.1109/TBME.2006.875664 ↗
How to cite this page
ScholarGate. (2026, June 3). Madgwick IMU and AHRS Algorithms. ScholarGate. https://scholargate.app/en/aerospace/madgwick-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
- Mahony FilterAerospace↔ compare
- Quaternion AttitudeAerospace↔ compare