# How does compass calibration work?

I am wondering how compass calibration works / why e.g. drawing an 8 or rotating the phone to all 3 axis works (or at least shall work) - I mean I would understand the calibration process, if an application would say me: Point to north, then press that button down there, but you can start at basically zero knowledge for the app, just by rotating your phone! How is that done? Also, do I need to enter a special calibration mode or can I draw these figures (like the 8) directly in Google Maps? How does Google Maps know that I am not just really moving the phone but want to calibrate the compass? Thanks for any hint!

• Flagged as dupe, please don't post two separate questions for the same problem. Edit your existing question with new information; android.stackexchange.com/questions/30328/… – pzkpfw Oct 3 '12 at 21:59
• Moving an object through a magnetic field can induce an electric current, which I'm guessing is being measured in this case. The figure 8 ensures that the phone is moving along every possible vector in a 2D plane, which ought to allow it to distinguish north from south. I think. As for Maps sensing it, that one's easy -- what other time do you make such an absurd motion with your phone? It's quite different from normal movements and ought to be simple to detect. – Matthew Read Oct 3 '12 at 22:00
• @bigbadonk420 This is not a duplicate, it's a completely different question. – Matthew Read Oct 3 '12 at 22:01
• Technical information: electronics.stackexchange.com/questions/22144/… – bwDraco Nov 16 '13 at 0:00

Compass calibration works by detecting the magnetic field intensity of earth. But sometimes due to strong interference from other electronic devices like transformers, compass sensor may get wrong idea about the magnetic poles of earth and can point in wrong direction.

So to ensure that, it asks users to recalibrate compass by rotating in figure-8 direction so that it can judge the magnetic intensity in all directions. From that data, it deduces the actual poles of earth.

• This is actually a wrong answer. Calibration can only cancel out the distortions coming from objects affixed to the device (thus rotating with the device during calibration). If the objects are in the environment, the phone will observe a fixed magnetic field and it will have no idea how far away from true North it's directed. – Marko Topolnik Nov 28 '18 at 19:03

The purpose of calibration is to figure out how to compensate for how the components in your phone (screws, speaker magnets, etc.) interfere with the measured magnetic field.

The calibration process is based on the fact that you can separate the internal and external contributions to the magnetic field by looking at how the field changes as the phone is rotated. For example, in one orientation the magnetic field from the magnet in the speaker will add on to the Earth's field; but when the phone is oriented in the opposite direction, the two fields will partially cancel out.

As you wave the phone around, the magnetometer records how the magnitude of the measured field changes and uses this to calibrate the x, y, and z magnetic field sensors. See geometrikal's answer to a similar question for more details on this process. Note that this calibration does not let you compensate for the influence of other external objects (e.g., your refrigerator) on the magnetic field.

Regarding the implementation in Google Maps: I believe that Google Maps has no control over the compass calibration because there is no such functionality in the Android API. The magnetometer is probably calibrating itself continuously, and Google Maps is just asking you to rotate your phone so that the magnetometer can collect the data it needs to get an accurate calibration.

In other words, you can calibrate your compass any time the magnetic field sensor is being used just by waving your phone – there is no "calibration mode".

• But how does the android OS decide when to change it's calibration values, i response to movement or at regular intervals or both? – Hamish_Fernsby Jan 25 '18 at 16:41
• Android must just maintain a history of readings and keep applying the hard-iron correction on them. This is even specified in the documentation. – Marko Topolnik Nov 28 '18 at 19:08

At any point in space, the magnetic field strength and direction is the net effect of all the magnetic field sources affecting that point. The earth's magnetic field is one of them. Magnetized screwdrivers, cars, refrigerator magnets, etc. all produce fields. Fields are also produced by current flowing through wires. It's like pouring water into a glass from multiple sources. Once it's in the glass, you can't tell where it came from.

There is no instrument that can determine the "actual poles" of the earth by measuring the magnetic field at a point. What the phone can do, however, is sense the point where the phone axis is parallel to the N/S magnetic force line and determine which end of the phone is north-pointing. If you do your dance far away from objects that might be magnetized, like cars and steel fences, the field the phone is measuring may be primarily the earth's field and hence the phone compass will be properly calibrated. If you then put the phone into a magnetized car, however, it will point the wrong direction for north. The steel in every car is magnetized to one degree or another.

High-precision compasses such are used on aircraft and serious maritime vessels actually have tiny correction magnets that are adjustable with screws for N/S and E/W errors. They are calibrated after installation by turning the vehicle onto known headings (a compass rose painted by a surveyor on a taxiway far from metal buildings, for example) and fussing with the magnets until the compass error is minimized. Then the residual errors are recorded on a "compass correction card" for use in correcting the indicated readings. Search "compass correction card" to see the images.

In theory, the GPS could be used to calibrate the compass when walking or driving since the instantaneous GPS track is accurate. I have not heard of this being done, though it possibly is common. It would work even in a magnetized car. However, in an airplane or a ship, this wouldn't work because the vehicle's heading is to one degree or another usually crabbed slightly into the wind and the GPS has no knowledge of this.

• This doesn't seem to tell how and why the common calibration procedure in Android works. – Ruslan Jul 19 '19 at 13:27

I've tested the compass fields measurments provided by Android phone and found out, that if I rotate the phone by 180 degrees, the field doesn't change to exactly opposite, which must be the case if the sensors are correct. This might be due inner magnetism of the phone details or sensor reading inacuracy.

If you don't compensate for that and just use reading as is and try to calculate the North direction, you'll find out that they are incorrect: rotating phone by 90 degress around vertical axis doesn't lead to rotating measured magnetic field by the same angle (that is true for any angle, it's just easier to check it with 90 degrees).

So the aim of calibration is to develop compensation formula which will transform wrong readings from magnetic sensor to more realistic values, from which we can calculate the correct bearing. My guess is that it is looking for optimal shift of zero for each axis which will give the result magnetic vector length independent on the phone orientation (that must be the case in ideal situation but is not the case when the zero is shifted on any axis).