Finding the closest function describing a "magnetic line" (given magnetic readings)

112 Views Asked by At

I'm collecting data from a smartphone magnetometer while I move a magnet along a straight line (a slider). I am collecting the values of the magnetic field strength along the three axes.

I would like to find a function that could describe the movement of the magnet from the start point to the end point of the slider. I would like to do this using only the start and the end points values. I divided the slider in seven equidistant points and then recorded the value of the magnetic field in each position.

   x,         y,           z       position
-39.55,     -51.19,      -32.67     0
-26.01,     -41.83,      -32.95     0.17
-19.94,     -34.08,      -33.28     0.34
-16.43,     -26.62,      -32.72     0.51
-15.98,     -22.6,       -33.07     0.68
-15.93,     -20.72,      -32.96     0.85
-16.85,     -18.87,      -33.11     1

If I consider only the x column and the position column, the function should behave as closest as the following:

f(-39.55) = 0 f(-26.01) = 0.17 f(-19.94) = 0.34 f(-16.43) = 0.51 f(-15.98) = 0.68 f(-15.93) = 0.85 f(-16.85) = 1

My first thought was to use a line, so f(h) = |h - start| / |end - start| but the results were far from the behaviour I want

f(-39.55) = 0 f(-26.01) = 0.6 f(-19.94) = 0.86 f(-16.43) = 1.01 f(-15.98) = 1.03 f(-15.93) = 1.04 f(-16.85) = 1

I want to find a better function but I do not know what other type of functions to use. The chosen function should at least have the values as follow: f(start)=0 f(middle)=0.51 f(end)=1

The real problem is that I can't read the values in all the points every time the slider is being used (if the smartphone is moved all the values will change and the calibration phase will require to re-read the start and the end points). My idea was to find a good function and use all the stored values (the ones in between the start and the end) to check if the chosen function is correct.

What other type of function could I use to have this behaviour? Is there a better technique? Should I really get more middle-values in order to have a “decent” approximation?

Another idea I had was to use interpolation but I think I need at least the value in the middle point other than the start and end ones to have something meaningful. What kind of interpolation would be best? The problem in this case is that interpolation should use only the values of the point at the beginning and at the end (and if necessary the one in the middle).

1

There are 1 best solutions below

2
On

If I properly understood, you are looking for a model $$P=f(x,y,z)$$ to be adjusted on the basis of $n$ data points $(x_i,y_i,z_i,P_i)$. To me the problem is that $n$ is quite small.

As a simple attempt, I ignored the possible contribution of $z$ and tried $$P=a+bx+cy+dxy$$ which is just bilinear with respect to $x$ and $y$. Based on the data given in the post $$P=-0.120818-0.133217 x+0.0282536 y-0.00182842 x y$$ which is not too bad. The errors on $P$ values are $$\{0.0002,-0.0030,0.0099,-0.0061,-0.0291,0.0376,-0.0094\}$$ May be, this could give you some ideas.