Using magnetic field readings for linear gesture recognition

I am thinking about using a permanent magnet as an input device for my smartphone. I have been reading some papers about it, but I really want to understand how things work. Using the integrated compass I can read the field strength along three axes. Given these readings, what property of the magnetic field could I use for gesture recognition?

To do anything I have to save the magnetic field strength along the three axes when no magnets are close to the smartphone. Then compare it with other readings.

When I place a magnet close to the smartphone in a particular position the readings will change. I can tell if the magnet is in that position when I read the same values along the three axes. This is because the magnet changes the "overall" magnetic field read by the magnetometer.

I can simulate a click when a magnet in a particular position is twisted/curled because the angle of the polar coordinates changes of about 180 degrees. This is because magnets have a north and south pole, so twisting it changes the pole and as a consequence the angle of the polar coordinates.

I would like to simulate a movement along an axis (like a slider). I can tell if I am at the beginning or at the end of it by comparing the magnetic field strength to the ones previously detected in those positions. How can I tell if I am in the middle or in any other point? The obvious solution would be to save the readings in all those points but I hope there is something about the magnetic field I am missing. Is there a law or a correlation between the points I can use?

These are some readings I recorded of seven equidistant points along the x axis:

     x,      y,      z
-39.55, -51.19, -32.67
-26.01, -41.83, -32.95
-19.94, -34.08, -33.28
-16.43, -26.62, -32.72
-15.98, -22.6,  -33.07
-15.93, -20.72, -32.96
-16.85, -18.87, -33.11


The best thing I have thought so far is to approximate the movement with a linear function but things doesn't work that well (for example the 4th and 7th position have almost the same value along x but they are in two different positions so I can't tell which one is the end and which the middle). This is one example, depending on where I am I can find myself with very different problems. How should I cope with it? Magnetic field is less strong as the magnet gets away from the magnetometer; what kind of function can describe this situation?

• This is an interesting problem. Out of curiosity, is this for personal use or for some sort of school project? Aug 5, 2015 at 14:29
• You may want to research theremins and see how they work and if their operating principles can be applied to what you're thinking about. (en.wikipedia.org/wiki/Theremin)
– Fred
Aug 5, 2015 at 14:30
• I am thinking to write my final dissertation about it but I would like to be sure it is actually doable in a reasonable amount of time before starting it. Thank for the Theremin advice, I'll read it hoping it will give me some ideas. Aug 5, 2015 at 14:45
• Using a single sensor this would be very difficult. 3 sensors notionall work for position and even then there are issues. Magnetic field is inverse cube law at a good distance but closer to inverse square law near a pole and "just wierd" very near a pole. Look at diagrams of magnetic fields near magnets. Adding 'magnetic' material badly changes things. Aug 6, 2015 at 12:33
• @RussellMcMahon thanks for the answer, could you point me to some website or book to find something more "theoretical" about your explanation? I would like to understand it as best as I can (I study computer science so it's not really my area). Anyway I found this video youtu.be/_sSgp0hD-jk?t=1m38s and the relative paper, they do what I want to do but in their paper they simply say that for the slider they use a linear approximation (I guess they made assumption not stated in their paper). Aug 8, 2015 at 17:18