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*](https://electronics.stackexchange.com/a/22271/102305) 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](https://i.stack.imgur.com/OXIDo.gif)](https://i.stack.imgur.com/OXIDo.gif)

**above:** After paying a zillion dollars for a very nice phone, I feel like an idiot doing this (from [support.google.com/maps](https://support.google.com/maps/answer/6145351?hl=en)) 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](https://i.stack.imgur.com/weykT.png)](https://i.stack.imgur.com/weykT.png)

**above:** Screen shot from this [nice discussion](https://www.nxp.com/docs/en/application-note/AN4246.pdf) of the principles and mathematics behind magnetometer based compass calibrations. [Here is another](http://www.sensorsmag.com/sensors/motion-velocity-displacement/compensating-tilt-hard-iron-and-soft-iron-effects-6475).