Basics of 6DOF and 9DOF sensor fusion

May 05, 2017


Basics of 6DOF and 9DOF sensor fusion

Inertial and magnetic sensors are becoming quite pervasive. When driving our cars or as simple pedestrians, most of us would have a hard time finding our way around without the navigation applications they support. Our smartphones rely on electronic compasses (eCompasses) built on inertial and magnetic sensor technology to determine direction, and with the help of GPS and maps, guide us blindly through the urban maze.

The eCompass is built on a very sensitive 3-axis magnetometer that strives to measure the Earth’s geomagnetic field. It is associated with a 3-axis accelerometer whose main purpose is to provide a horizontality reference to the Earth’s magnetic field vector, similar to how a mechanical magnetic compass must be kept horizontal for its needle to rotate freely and point toward the North Pole.

The combination of these two sensors provides six measureable data points, often referred to as six degrees of freedom (DOF), for a “tilt-compensated” eCompass. The key benefit of this two-sensor combination is that it delivers the North direction regardless of how a user holds their smartphone or tablet (in a flat or vertical position, in portrait or landscape orientation, for example). A six DOF eCompass can further provide device attitude and heading in 3D space by simply measuring the Earth’s gravity and geomagnetic field, provided those two vectors are not collinear (such as at the Poles). This is how sky map applications can point at visible stars and teach you the constellations.

Whereas off-the-shelf accuracy of accelerometers is satisfactory, magnetometer measurements are susceptible to distortion and errors that can impact calibration and correction in the final environment. Indeed, even if the magnetometer has been thoroughly calibrated by the vendor, once mounted in an end product it will suffer local magnetic field perturbations such as hard-iron and soft-iron distortion, mainly due to the presence of magnetic materials in the vicinity of the sensor. Magnetic interferences can be up to 20x larger than the Earth’s geomagnetic field of interest, so they absolutely have to be cancelled out.

One notable field magnetometer calibration procedure is the “figure 8” gesture that personal devices instruct their users to perform. Here, calibration is performed in the environment by simply leveraging the various natural orientations of a user’s device, either through direct manipulation of the device or indirectly through the user’s movements. Most accurate calibration algorithms are based on fitting the scatter plot of actual magnetometer measurements to an ellipsoid, after which correction parameters are used to transform the ellipsoid into a sphere.

Once properly calibrated, the 6DOF eCompass is able to deliver accurate orientation of the device. Moreover, the sophisticated ellipsoid-to-sphere fitting calibration algorithm can run in the background and regularly update correction parameters to track changes such as ambient temperature. Nevertheless, the 6DOF eCompass still suffers a few weaknesses:

  • Accelerometer measurements reflect the Earth gravity vector only when at rest. Whenever the device is moving, linear acceleration is also captured, which can corrupt the horizontality estimate for tilt-correction.
  • Despite being calibrated, magnetometers are still highly sensitive to time-varying magnetic disturbances. Any changing “magnetic environment” will cause a measurement distortion that cannot be recovered.
  • Output data from both sensors is usually low-pass filtered to remove measurement noise (especially for the magnetometer) and reduce perturbation impact. This results in lags in system response, as computed orientation can be heavily smoothed out.

To alleviate 6DOF shortfalls, a 3-axis gyroscope can be added, creating a 9DOF, or “gyro-stabilized,” eCompass solution. The gyroscope provides the system with an independent measurement of instantaneous rotation speed, which complements the 6DOF computed orientation angles. Still, gyroscopes have an annoying “zero-drift offset” drawback, as a strictly motionless gyroscope will provide a residual rotation speed offset instead of the theoretical zero degrees per second. It is important to correct this error because the rotation speed measurement error will accumulate over time through integral calculus that is matched with the 6DOF rotation angle estimate.

Similar to how the 6DOF accelerometer/magnetometer data is low-pass filtered, the 3DOF gyroscope data could be high-pass filtered in order to remove the unwanted DC offset. As a matter of fact, those offsets are even estimated thanks to dedicated data processing using an extended Kalman filter. A comprehensive and instructive way to tackle 6DOF and 9DOF sensor fusion rudiments is experimenting with Freescale’s Sensor Fusion Toolbox, which can be downloaded at

Thanks to the third sensor and sensor fusion algorithms, the 9DOF tilt-compensated and gyro-stabilized eCompass is now gathering the best data from all three sensors, identifying and compensating for the flaws of some with the strengths of the others. It provides an accurate, low noise, smooth but responsive estimate of the device orientation angles, rotation speed, linear acceleration, Earth gravity, and geomagnetic fields; delivers sensor calibration error information; and is more resilient to magnetic interferences. The outcome greatly exceeds the sum of individual sensors’ contributions, which is the essence of sensor fusion.


Analog & Power