I want to calibrate my compass, which is installed on a board which inherits a GPS module. Because the GPS antenna is up-side-down the compass is 180° inverted. The easiest way to correct the problem would be to invert the rotation matrix 180°.

However I got interested how a general approach to calibrate a compass would look like. I found some approaches like this. They seem to collect magnetometer readings an project them on a sphere. But what is actually the point in this?

Does someone know how a general calibration algorithm of a 3D magnetometer looks like?


1 Answer 1


We always need a reference for calibration to which we calibrate our sensor. For example in case of 3D accelerometer we use gravity as a reference which is assumed vertically downwards at a place.

For magnetometer calibration we use Earth's magnetic field as a reference. But we dont know the direction of resultant magnetic field vector at the place unlike gravity in case of accelerometer. Hence we need to implement sphere fitting calibration method in order to calibrate our magnetometer.

This method is explained in this blogpost as well as this blogpost. You can also download a tool which can calibrate if you feed the data. You can also have a look at implementation in C here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.