Accelerometer and Magnetometer calibration

To calibrate the acelerometer and the magnetometer, we measure the earth’s magnetic field components and the gravity field components in various positions of the sensor/stick. We assume these fields to be constant (constant magnitude, constant direction) in an earth fixed coordinate system. We further assume some idealizations:

  • homogenous fields
  • no magnetic distorsion
  • no linear acceleration measured during calibration
  • sensors are orthogonal to each other
  • no cross-talk between sensors
  • sensors are ideal linear
  • etc.

Errors induced by deviations from these idealizations are tolerable for our purposes.

The (magnetic or gravitational) field vector \overrightarrow{f}=\left[f_x \quad f_y \quad f_z \right]^T is calculated from the sensor signals \left[x \quad y \quad z \right] by applying offset and gain values:

$$\overrightarrow{f}=\left[f_x \quad f_y \quad f_z \right]^T=\left[g_x\cdot(x+o_x)\quad g_y\cdot(y+o_y)\quad g_z\cdot(z+o_z)\right]^T$$

Scaled to a unit vector this field vector is always of length 1 for all rotational positions. All measured vectors lay on a sphere with radius 1:



This leads to an ellipsoid description in “standard form”:


This quadratic euqation can be expressed as a “general” axis-aligned ellipsoid equation (The ellipsoid’s pricipal axes are aligned with the sensors x-y-z-axes):

General ellipsoid:


Both equations (standard form and general form) are equivalent and can be transformed into each other (by completing the squares)



We define a “radius”


and get Offsets and Gains from the parameter of the general ellipsoid:


$$o_x=\frac{D}{A}\quad o_x=\frac{E}{B}\quad o_z=\frac{F}{C}$$


$$g_x=\sqrt{\frac{A}{R^2}} \quad g_y=\sqrt{\frac{B}{R^2}} \quad g_z=\sqrt{\frac{C}{R^2}}$$

The general ellipsoid form is used to get the ellipsoid parameters from measuring the sensor values x,y,z and x^2,y^2,z^2 for different sensor positions. This can be done by solving a linear least square minimization:


The determined paramters A, B, C, D, E, F can easily be converted into gain and offset values as described above.


To get the required data for the magnetometer calibration, the sensor is moved in a figure-8 while continuosly measuring. It’s sort of 3D-eight, more like poi players do the 3-beat-weave, to get data from as many rotational positions as possible.

To record data for the accelerometer calibration, the sensor is measured in some (at least six) different static positions. The sensor must not be moved during the measurements to avoid mixing of the gravitational field vector with linear acceleration.

magnetometer calibration
Example for a magnetometer calibration: uncalibrated data (blue) and calibrated data (red) with minimized distances to unit sphere

Gyroscope calibration

To calibrate the gyroscope sensors, we do a fixed angle movement between two known positions for each gyroscope axis seperately. To do so, we use a 3D-printed bracket together with a UCF204 pillow block where we can rotate the sensor 90° from stop to stop. The gyro offsets are calculated from the mean values measured during the sensor is in static positions. The gyro gains are calculated by integrating the offset-corrected gyro signal to get rotational positions.


\overline{p_1}, \overline{p_2} : mean position values (integrated gyro) at static stops

UCF204 based 90°-mover with 3D-printed bracket
gyroscope calibrator
gyroscope calibrator

Example calibration data

example gyroscope calibration data