12
\$\begingroup\$

Most cell phones offer digital compass functionality which uses a 3-axis magnetometer chip for data. Phones (some more than others?) frequently require the user to "recalibrate", which involves rotating the phone in a "swirly" or other pattern to populate readings over some fraction of a sphere representing the various orientation with respect to the local field.

The discussion in this answer to Magnetometer ∞ shaped calibration as well as the 3D plots of data give an excellent overview of what is happening mathematically. Roughly speaking, six parameters - a gain and an offset for each of the three axes - are fit to a dataset collected over a cloud of data points that at cover at least a chunk of that sphere.

I've done this myself with a magnetometer attached to an Arduino and fitting offline. The low cost chip I used seemed to drift a lot (being careful to do this outdoors and away from more obvious sources of error or gradients like nearby ferrous materials or other possible fields). I noticed that the offsets seemed to be contributing as much to the drift as the gains, if not more.

Question: What exactly is drifting within the magnetometer sensors in newer, high-end cell phones that still requires frequent recalibration? Is it simply temperature? If so, why wouldn't the magnetometers be internally temperature stabilized? Is it too hard to do in analog and the magnetometers don't have any ability to calculate offsets?

image

above: After paying a zillion dollars for a very nice phone, I feel like an idiot doing this (from support.google.com/maps) while balancing on a bicycle on a busy street corner, or enjoying some beautiful view on a hike. My iPhone makes me go through a much longer, silly video-game-like task before it will even begin to tell me anything useful. I cary a normal compass sometimes because it just simply works.

image

above: Screen shot from this nice discussion of the principles and mathematics behind magnetometer based compass calibrations. Here is another.

\$\endgroup\$
7
  • \$\begingroup\$ I'll hazard a guess that hall sensors in a smartphone operate at a fraction of current which lab-grade sensors use (amperes and tens of amperes), so they have bad SNR to begin with. Having all that iron and nickel nearby (and the magnets in the speakers) further complicate matterss. In such case, long-term thermal compensation wouldn't do much good, so the only way is to calibrate the sensor in the exact conditions in which it will be used. \$\endgroup\$ Commented Aug 1, 2016 at 13:13
  • \$\begingroup\$ @DmitryGrigoryev I thought they were magnetoresistive devices - you are saying that they are Hall effect sensors? (Here's an example of one I used stand-alone with the Arduino: HMC5883L It's a few years old, but it says that it is "among the most sensitive and reliable low-field sensors in the industry." The point about the ferrous materials in the phone is interesting. \$\endgroup\$
    – uhoh
    Commented Aug 1, 2016 at 13:17
  • \$\begingroup\$ @DmitryGrigoryev so the chips do not drift significantly - you are saying it is only other ferrous and/or magnetic components in the phone? The chips (used in high-end phones) are stable? \$\endgroup\$
    – uhoh
    Commented Aug 1, 2016 at 13:25
  • \$\begingroup\$ I don't know, that's why I only wrote a comment, not an answer. Sorry. \$\endgroup\$ Commented Aug 1, 2016 at 13:56
  • 1
    \$\begingroup\$ There are some great answers to this question, but none seem to explain why it’s so common that they are 180° off. \$\endgroup\$
    – gerwitz
    Commented Oct 13, 2023 at 11:19

2 Answers 2

15
\$\begingroup\$

3 Axis magnetometers have 3 channels all of which have an offset and gain. The offset changes with temperature and can change over time and are an unknown constant (especially the gains on each channel). This is caused by the sensor and the analog electronics that get the signal into the ADC. Not only are you calibrating the Magnetometer but the Accelerometer and\or Gyro as well. This is because all of the data from the sensors is fed into a Kalman filter which is a statistical filter. In short it updates its state based on the best information from the sensors. It's easy to calibrate if you have different information. It is easier (but not necessary) to calibrate 2 axes at a time so most phone calibration routines have you conduct two axis motions.

For information on drift and calibration in magnetic sensors see this. Kalman filters are interesting and also when applied to Degree of Freedom (DOF) sensors. Other sensors (not just the magnetometer) are subject to drift.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks! So is it the offset mostly that's changing rather than the gain? Why (actually) would it change with temperature - is it the analog electronics on on the chip (which could presumably be temperature compensated) or the manetoresistive device itself? \$\endgroup\$
    – uhoh
    Commented Aug 3, 2016 at 0:12
  • 2
    \$\begingroup\$ Both change with temperature and there are also magnetoreisistive effects that can change if exposed to a big magnetic field. Offsets look like axis drift over time. The phone calibration mostly calibrates all the sensors and the kalman filter, and also calibrate the magnetometer \$\endgroup\$
    – Voltage Spike
    Commented Aug 3, 2016 at 20:50
  • \$\begingroup\$ OK I'd never considered that the Kalman filter for the compass needed to be regularly recalibrated, that's interesting! Can you help find some supporting information somewhere for that, and for the "magnetoresistive effects that can change"? I think you are really zeroing in on a good solid answer! \$\endgroup\$
    – uhoh
    Commented Aug 3, 2016 at 23:41
  • \$\begingroup\$ You might want to stress that the existence of an unknown gain constant is not the problem for a compass - but the fact that they are different in each direction is. Actually, the way those sensors are built leads to one direction with a gain that is completely different to that in the other two directions. \$\endgroup\$
    – asdfex
    Commented Apr 17, 2021 at 16:06
0
\$\begingroup\$

Well, while the earth's magnetic field is fairly constant short term, the environment that you are moving through may not be.

Every electrical current in the vicinity is generating a magnetic field around it. Much of this electromagnetic field generation is AC, switching direction 60 (or 50) times a second. When the power is being carried in pairs of wires routed close together (in the same wireway/conduit, for instance) the fields in the two wires tend to cancel each other. DC currents, however can and do flow through the earth, and this can affect the local magnetic field. (The ground potential between buildings can be large enough to damage electronic devices connected between buildings, which is why optical isolation is recommended for these instances.)

Every ferrous object in the vicinity can locally "warp" the earth's magnetic field. Lamp posts, steel-frame building, sheet-metal buildings, iron rebar, etc., can all affect the local measurement of the earth's magnetic field.

Even iron ore deposits under your feet can locally alter the earth's magnetic field somewhat.

Because of all the potential local interference to the earth's magnetic field, it is not uncommon to require recalibration when moving through it. And, if you recalibrate in an area of interference, when you move out of that area, you'll need to recalibrate again....

\$\endgroup\$
3
  • \$\begingroup\$ I see what you mean. Those things affect both the direction and the magnitude of the local field. While calibration can't do anything about the direction of the local field being affected, the change in the magnitude (e.g. from 0.3 to 0.4 gauss) would require recalibration due to other components in the phone that interact with the field. Thanks! \$\endgroup\$
    – uhoh
    Commented Aug 1, 2016 at 22:19
  • 13
    \$\begingroup\$ I do not feel this is the correct answer at all. The need for calibration has to do with MEMS changing offsets and linearity. If this answer was correct then also the "old needle compass" would need recalibration (well, they do need fine calibration and the like, not at all the kind of calibration phones` compass needs...). And by the way the orientation ("declination") of the earth magnetic fields canges of a few degrees per century... \$\endgroup\$ Commented Sep 18, 2017 at 11:20
  • \$\begingroup\$ @Caterpillaraoz I've switched. \$\endgroup\$
    – uhoh
    Commented Oct 13, 2023 at 11:32

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