Posted on
• Q&D Magnetometer Calibrations

The Ideal Magnetometer

From an ideal three axis magnetometer with readings X, Y and Z from orthogonal axis, we can compute the Radius R of a sphere. For easy coding let us represent the three components X, Y, and Z in a vector M=[X, Y, and Z]. This M[0] is the X axis reading, M[1] is the Y axis reading and M[2] is the Z axis reading. The radius R = Sqrt(M[0]^2+M[1]^2+M[2]^2).
For an ideal magnetometer the radius R is a constant for a given external magnetic field.
In practice each axis of the magnetometer will not be centered and may have a different gain from the other two axis. Centering consist of finding an offset value to subtract from the raw readings for each axis. Gain adjustment finds a value that makes the output of each axis equal when positioned in the same magnetic field.

Coding note

I’m using a LSM9DS1 IMU chip connected to a Pico. Since there is recent interest in the Puck magnetometer, I will try to point out where there are differences and give my best guess as to how to use this technique with a Puck.

How the calibrations are implemented

We start with a raw reading from the magnetometer. Mr[i], where Mr is the raw reading vector containing raw values for the X, Y and Z, axis. To get the calibrated reading in vector Mc, the following equation is used:
Mc[i]=( Mr[i] – Moffest[i] ) * Scale * Mgain[i],
Where Mc[i] is the calibrated vector component,
Mr[i] is the raw vector component,
Scale is used to convert ADC count to engineering units such as Gauss. (Can omit for Puck),
Mgain[i] is the gain factor for the vector component,
and i is the component index 0...2.
The raw magnetometer readings from the LSM9DS1 IMU are in ADC counts and the Scale (there are 4 different ones) is the full scale engineering units divided by 32768.
For example 4 Gauss/ 32768 = 0.0001220703125 = Scale.

The min/max Method

``````function minmax(){
this.min=[0,0,0];
this.max=[0,0,0];
this.avg=[0,0,0];
this.R=0;
this.amp=[0,0,0];
this.gain=[1,1,1];
}

minmax.prototype.process=function(A){
var i,S=[0,0,0];
this.R=0;
for(i=0;i<3;i++){
if(A[i]>this.max[i])this.max[i]=A[i];
if(A[i]<this.min[i])this.min[i]=A[i];
this.avg[i]=(this.min[i]+this.max[i])/2;­
this.amp[i]=(this.max[i]-this.min[i])/2;­
}
for(i=0;i<2;i++){
this.gain[i]=this.amp[2]/this.amp[i];
S[i]=4/32768*this.gain[i];
}
console.log("A= ",A);
console.log("max= ",this.max);
console.log("min= ",this.min);
console.log("avg= ",this.avg);
console.log("amp= ",this.amp);
console.log("Gain= ",this.gain);
console.log("S= ",S);
};
``````

For the LSM9DS1 I used the minmax class in a loop that can be stopped using a menu system.

``````    case "4"://read and display data
nn=setInterval(function () {
count++;
if(count>1000)clearInterval(nn);
}, 100);
break;if(count>1000)clearInterval(nn);
xxxx
if(W.magAvailable()){
T.process(W.m);
}//endif
``````

Due to budget I don't own a Puck yet, so this code may need some enhancement.
For a Puck the Puck.on('mag', function() { ... }); would be used something like this:

``````var T=new minmax[];
var M=[0,0,0];
var Moffset=[0,0,0];
var Mgain=[1,1,1];

function onMag(p) {
M[0]=(p.x-Moffset[0])*Mgain[0];
M[1]=(p.y-Moffset[1])*Mgain[1];
M[2]=(p.z-Moffset[2])*Mgain[2];
T.process(M);
}
``````

Running the code

The idea is to run the code and then point each end of each axis towards the magnetic pole. For my location in North America it is North and about 60 degrees below the horizon due to magnetic dip. This process is continued until the readings for each axis stop changing.

``````A=  [ 2145, 2153, -1557 ]
max=  [ 2145, 2201, 0 ]
min=  [ 0, 0, -1581 ]
avg=  [ 1072.5, 1100.5, -790.5 ]
amp=  [ 1072.5, 1100.5, 790.5 ]
Gain=  [ 0.73706293706, 0.71830985915, 1 ]
S=  [ 0.00008997350, 0.00008768430, 0 ]
``````

``````A=  [ 1883, 1919, -1572 ]
max=  [ 6327, 3363, 4486 ]
min=  [ 0, -3755, -2141 ]
avg=  [ 3163.5, -196, 1172.5 ]
amp=  [ 3163.5, 3559, 3313.5 ]
Gain=  [ 1.04741583688, 0.93101994942, 1 ]
S=  [ 0.00012785837, 0.00011364989, 0 ]
``````

At this point for the LSM9DS1, I used a different program to write the offsets (avg)to ROM. For the Puck copy the offsets (avg) to the Moffset[].

To evaluate the calibration data were collected using code like this:

``````function readall(W){
var avg=  [ 3163.5, -196, 1172.5 ];
var Gain=  [ 1.04741583688, 0.93101994942, 1];
var R1,R2,R3;
var raw=[0,0,0];
var Roff=[0,0,0];
var Rcal=[0,0,0];
var i;
if(W.magAvailable()){
//  T.process(W.m);
for(i=0;i<3;i++){
raw[i]=W.m[i];
Roff[i]=raw[i]-avg[i];
Rcal[i]=Roff[i]*Gain[i];
R1=Math.sqrt(raw[0]*raw[0]+raw[1]*raw[1]­+raw[2]*raw[2]);
R2=Math.sqrt(Roff[0]*Roff[0]+Roff[1]*Rof­f[1]+Roff[2]*Roff[2]);
R3=Math.sqrt(Rcal[0]*Rcal[0]+Rcal[1]*Rca­l[1]+Rcal[2]*Rcal[2]);
}//next i
console.log(R1,R2,R3);
}//endif
``````

The magnetometer was pointed in many different orientations as data were collected. R1 is the radius from raw data, R2 is the radius from raw data - offset, and R3 is the radius from the gain times the raw data - offset. Excel was used to perform descriptive statistics on the radius values R1, R2, and R3.

R1 R2 R3
Mean 4093.694998 3522.325582 3446.806677
Standard Error 82.29402041 33.33800845 31.38490953
Median 4348.209172 3585.501569 3508.904969
Mode #N/A #N/A #N/A
Standard Deviation 1261.543444 511.0619921 481.1215526
Sample Variance 1591491.862 261184.3597 231477.9484
Kurtosis -0.645447113 0.85299825 0.453653148
Skewness -0.525200694 -0.538526 -0.405032898
Range 5344.130082 2606.674164 2376.33701
Minimum 715.4453159 2087.480659 2163.026205
Maximum 6059.575398 4694.154823 4539.363215
Sum 962018.3246 827746.5118 809999.569
Count 235 235 235
• Result of the QD calibration of the LSM9DS1 magnetometer using the 8 Gauss scale.

The calibration results:

``````8gcal.txt
A=  [ 1055, 1059, -774 ]
max=  [ 2787, 2318, 2211 ]
min=  [ -282, -2189, -1154 ]
avg=  [ 1252.5, 64.5, 528.5 ]
amp=  [ 1534.5, 2253.5, 1682.5 ]
Gain=  [ 1.09644835451, 0.74661637452, 1 ]
S=  [ 0.00013384379, 0.00009113969, 0 ]
``````

Statistical results of using the calibrations

R1 R2 R3
Mean 2177.63886 1737.768628 1600.029522
Standard Error 37.24718705 18.20304123 9.234868336
Median 2164.406154 1697.652129 1581.39782
Mode #N/A #N/A #N/A
Standard Deviation 503.870607 246.2461775 124.9269833
Sample Variance 253885.5886 60637.17993 15606.75115
Kurtosis 1.775293165 -0.51651582 -0.552808728
Skewness -1.068292004 0.516047324 0.674115736
Range 2610.07284 992.2192807 517.1070694
Minimum 262.2422544 1337.931519 1411.795858
Maximum 2872.315094 2330.1508 1928.902927
Sum 398507.9114 318011.659 292805.4026
Count 183 183 183
cv 0.231383916 0.141702511 0.078077924

For the 8 Gauss range the use of the Gain term reduced the variance in the data.

R1 uses raw readings. R1= sqrt( X1^2 + Y1^2 +Z1^2)
R1 uses raw readings - offset
R2 uses (raw -offset) * gain
.

• Magnetometer, Turntable, Wireless, Plot Circle, Calibrate

The hardware

A magnetically agnostic turntable is used to spin a three axis magnetometer. The magnetometer readings are read by a Pico (or equivalent) and transmitted wirelessly to a web page (served by the Pico). Puck?

The webpage has the following elements:

• A slider bar that controls the radius of a circle drawn on the page.
• Radio buttons to select the magnetometer axis pair to plot X-Y, X-Z, Y-Z.
• Three slider bars for the axis offset values and boxes that display the values.
• Three slider bars for the axis gain values and boxes that display the values.
• A control to limit the size of the data buffer

As the data from the magnetometer are acquired the selected axis pair are plotted as an asteroid belt around the origin of the graph. The offset sliders are adjusted to center the asteroids. The cursor circle and the gain sliders are adjusted to visually best fit the data to a circle. The values in the gain and offset boxes are then used for the magnetometer calibration values. It is conceivable that local distortions in the magnetic field could be detected and visualized with such a system.

• In Depth Magnetometer Calibration Using Excel and Solver

( Best fit so far!)

The mathematical model

Given raw magnetometer readings X, Y , and Z,
Let Xa= X-Xoffset, Ya=Y-Yoffset, and Za=Z-Zoffset, and
The calibrated values X1, Y1, Z1 are given by:
X1=Xa*gainXX + Ya*gainXY + Za*gainXZ,
Y1=Xa*gainYX + Ya*gainYY + Za*gainYZ,
Z1=Xa*gainZX + Ya*gainZY + Za*gainZZ.
Let R1= sqrt( X1^2+Y1^2+Z1^2), and
Error = R1-Rtarget, and Error Squared = Error^2
Take the sum of the Error Squared for all the samples = SES.
Set the X, Y, and Z offsets =0,
Set gainXX, gainYY and gainZZ =1, and the other 6 gains =0;
Use solver to minimize SES while changing the offsets, and all of the gains except gainZZ

Results

r1 stats
Mean 3117.206387
Standard Error 1.005167936
Median 3119.478578
Mode #N/A
Standard Deviation 8.041343492
Sample Variance 64.66320515
Kurtosis -0.864123021
Skewness -0.291754939
Range 27.37080618
Minimum 3101.887692
Maximum 3129.258498
Sum 199501.2087
Count 64
cov 0.002579663

Magcal 4 Gauss 5 Hz 11Jan2017
error = 4129.637996

Offset Value Axis xgain ygain zgain
xoffset 638.3171635 x -0.005373179 0.092816827 0.084165352
yoffset 125.7515646 y -0.004554252 -0.103490134 0.004828644
zoffset 3341.735388 z -0.08843408 0.094803696 1

(Back to the drawing board because the X and Y gains are too small)

N x y z r x1 y1 z1 r1 error error^2
0 3453 -1701 -1738 4223.417337 442.4174201 59.33861037 -3079.535366 3111.718547 4.553628065 20.73552856
1 3381 -1643 -1723 4135.134702 441.2136312 54.80011423 -3079.90296 3111.828203 4.443971966 19.74888684
2 3355 -1693 -1711 4129.139741 440.5198375 48.34904687 -3079.615717 3111.338671 4.933504364 24.33946531
3 3407 -1633 -1731 4155.803051 441.7358587 58.51563949 -3079.954256 3112.020705 4.251470614 18.07500238
4 4665 -757 1189 4873.29406 172.7593596 -94.34721157 -3099.703419 3105.947276 10.32489947 106.6035491
5 4673 -815 1151 4881.18377 176.3410159 -95.04998877 -3099.28195 3105.749387 10.52278769 110.7290608
6 4697 -829 1165 4909.814151 175.037742 -95.08402029 -3099.268663 3105.663444 10.60873144 112.5451828
7 4643 -819 1181 4860.346798 173.8674059 -100.501382 -3099.331213 3105.830706 10.4414693 109.0242812
8 715 -815 4223 4359.95172 -74.06143648 -462.3864042 -3093.645286 3128.885974 -12.6137993 159.1079327
9 727 -813 4177 4317.039147 -70.06705543 -461.5084948 -3093.729721 3128.747844 -12.47566864 155.6423081
10 749 -785 4243 4379.529084 -76.14943373 -459.8156956 -3093.955444 3128.863932 -12.59175646 158.5523309
11 611 -807 4179 4299.838485 -69.64796033 -462.7892605 -3093.225351 3128.428969 -12.15679335 147.7876245
12 -657 -1013 833 1466.869797 234.0038399 -404.2074408 -3084.870216 3120.026554 -3.754379313 14.09536403
13 -711 -989 817 1466.673447 235.5996348 -400.3426095 -3084.622015 3119.402886 -3.130710964 9.801351141
14 -701 -999 844 1483.825461 233.2037254 -402.438937 -3084.662639 3119.532765 -3.260589446 10.63144353
15 -711 -995 795 1458.619553 237.5725101 -399.3862665 -3084.539666 3119.348496 -3.076321134 9.46375172
16 3613 481 -1543 3958.02716 414.3756879 216.5243802 -3092.44633 3127.589219 -11.31704349 128.0754734
17 3611 525 -1540 3960.624446 413.9207449 220.5440825 -3092.636235 3127.997596 -11.72542068 137.48549
18 3653 569 -1572 4017.381485 416.3245748 233.3204843 -3092.651637 3129.258498 -12.98632299 168.6445848
19 3631 489 -1555 3980.113943 415.3037456 220.6027051 -3092.421607 3127.97285 -11.70067486 136.9057922
20 3597 565 2639 4496.882809 44.24777705 -157.3892385 -3107.992798 3112.289908 3.982267156 15.8584517
21 3593 599 2606 4478.804081 47.03274985 -152.5322222 -3108.072578 3112.168586 4.103589344 16.8394455
22 3631 577 2604 4505.319744 47.10563075 -151.8534292 -3108.039993 3112.103951 4.16822427 17.37409356
23 3617 549 2634 4507.998004 44.6553519 -157.3030955 -3107.952379 3112.251011 4.021164599 16.16976474
24 -185 2581 2177 3381.584688 96.24431343 -28.19245814 -3100.266032 3101.887692 14.38448319 206.9133566
25 -145 2557 2207 3380.846492 93.4856659 -33.5947497 -3100.503284 3102.094259 14.1779165 201.0133163
26 -153 2599 2220 3421.492364 92.1877297 -27.18843576 -3100.510806 3102.000169 14.27200652 203.6901701
27 -157 2557 2228 3395.126213 91.69302836 -34.41427218 -3100.459497 3102.005972 14.26620361 203.5245653
28 431 -7 -767 879.8289607 365.0707723 -200.9031402 -3091.302457 3119.26107 -2.988894959 8.933493078
29 463 -83 -736 873.4723808 362.5034972 -211.7680404 -3091.2913 3119.669276 -3.397100785 11.54029375
30 429 17 -746 860.7241138 363.1151009 -202.6600393 -3091.582907 3119.424392 -3.152216975 9.936471856
31 427 -9 -638 767.7590768 353.6933771 -225.0636403 -3092.363668 3120.651487 -4.379311514 19.17836934
32 1387 3417 2378 4387.999772 66.21507103 124.0127614 -3108.518418 3111.695737 4.576438419 20.94378861
33 1377 3429 2382 4396.372823 65.86041548 125.5063989 -3108.495982 3111.725682 4.546493018 20.67059876
34 1457 3355 2349 4347.030596 68.68590046 117.3753027 -3108.68621 3111.659471 4.612703873 21.27703702
35 1373 3445 2338 4383.993385 69.7001397 130.3714175 -3108.419309 3111.932746 4.339428815 18.83064244
36 3471 2883 1405 4725.839079 143.4956967 207.1728909 -3111.499374 3121.688642 -5.416466456 29.33810886
37 3345 2939 1448 4682.248392 140.1150137 203.7879992 -3111.471431 3121.284388 -5.012212653 25.12227568
38 3405 2909 1461 4710.714065 138.7796075 202.3567737 -3111.575237 3121.235092 -4.962916449 24.63053968
39 3393 2931 1484 4722.866291 136.7099082 203.1705467 -3111.650454 3121.271603 -4.999427663 24.99427696
40 3143 2419 -178 3970.099999 287.3624218 256.2839073 -3104.515596 3128.302365 -12.0301897 144.7254642
41 3147 2451 -205 3994.125061 289.5829131 264.325944 -3104.45156 3129.112647 -12.84047192 164.877719
42 3135 2411 -161 3958.1646 285.9384618 252.6505205 -3104.566376 3127.926705 -11.65453029 135.8280762
43 3103 2383 -179 3916.546821 287.8297361 247.9689525 -3104.391036 3127.55148 -11.27930518 127.2227254
44 185 3641 713 3714.764461 218.8962238 253.2896075 -3099.22339 3117.251482 -0.979306912 0.959042028
45 181 3667 707 3738.916822 219.3299105 258.6135189 -3099.178072 3117.674018 -1.401843218 1.965164408
46 143 3653 733 3728.5583 217.2985647 253.6413137 -3099.071136 3117.016922 -0.744746647 0.554647569
47 153 3623 712 3695.467765 219.2385762 249.8929967 -3099.05838 3116.837324 -0.565148844 0.319393216
48 2099 -3223 2501 4587.867805 81.75220912 -486.072025 -3081.66385 3120.833466 -4.561291068 20.80537621
49 2087 -3223 2526 4596.082462 79.60583526 -487.8804985 -3081.666425 3121.062707 -4.790532247 22.94919921
50 2079 -3203 2573 4604.538956 75.40133387 -490.0864914 -3081.874321 3121.509164 -5.236989049 27.4260543
51 2129 -3179 2505 4573.150664 81.03689034 -483.7972845 -3082.113572 3120.905455 -4.633279728 21.46728104
52 -109 -2125 1255 2470.33014 198.8044841 -455.9608393 -3079.70644 3119.617808 -3.34563262 11.19325763
53 -97 -2101 1269 2456.414257 197.3926267 -456.5013745 -3080.007177 3119.904096 -3.631920504 13.19084655
54 -173 -2103 1319 2488.433041 193.3883928 -458.8260158 -3079.648536 3119.640282 -3.368107032 11.34414498
55 -153 -2117 1301 2489.517825 194.9365022 -458.1597874 -3079.610165 3119.60084 -3.328664726 11.08000886
56 333 -831 -375 970.6054811 334.6838879 -309.346388 -3088.258196 3121.705813 -5.433637378 29.52441515
57 285 -829 -326 935.2764297 330.5994221 -317.5810956 -3088.389151 3122.226975 -5.954799411 35.45963602
58 309 -877 -348 992.8313049 332.6346197 -314.3031054 -3087.92768 3121.654944 -5.382768361 28.97419523
59 253 -877 -315 965.5894573 330.017193 -320.3009077 -3087.899191 3121.958589 -5.686413856 32.33530255
60 3419 -2285 710 4173.114664 228.7731624 -252.9791429 -3087.385737 3106.169071 10.10310436 102.0727176
61 3395 -2277 684 4144.708675 231.1649708 -252.2388575 -3087.31939 3106.220002 10.05217284 101.0461788
62 3429 -2275 693 4172.998323 230.1772675 -250.3026719 -3087.413005 3106.083074 10.18910087 103.8177765
63 3451 -2273 697 4190.672858 229.6962127 -248.8553876 -3087.472054 3105.989865 10.28231054 105.72591

http://diydrones.com/forum/topics/magnet­ometer-soft-and-hard-iron-calibration

• (Found the error in the previous post, a copy and paste in Excel)

In Depth Magnetometer Calibration Using Excel and Solver

The mathematical model

Given raw magnetometer readings X, Y , and Z,
Let Xa= X-Xoffset, Ya=Y-Yoffset, and Za=Z-Zoffset, and
The calibrated values X1, Y1, Z1 are given by:
X1=Xa*gainXX + Ya*gainXY + Za*gainXZ,
Y1=Xa*gainYX + Ya*gainYY + Za*gainYZ,
Z1=Xa*gainZX + Ya*gainZY + Za*gainZZ.
Let R1= sqrt( X1^2+Y1^2+Z1^2), and
Error = R1-Rtarget, and Error Squared = Error^2
Take the sum of the Error Squared for all the samples = SES.
Set the X, Y, and Z offsets =0,
Set gainXX, gainYY and gainZZ =1, and the other 6 gains =0;
Use solver to minimize SES while changing the offsets, and all of the gains except gainZZ

Results

r1 stats
Mean 2792.675963
Standard Error 27.03157384
Median 2784.500715
Mode #N/A
Standard Deviation 216.2525907
Sample Variance 46765.18298
Kurtosis -0.287108248
Skewness -0.366464619
Range 848.6523987
Minimum 2329.127457
Maximum 3177.779856
Sum 178731.2617
Count 64
COV 0.077435619
COV% 7.74%

Magcal 4 Gauss 5 Hz 11Jan2017

offset value axis xgain ygain zgain
xoffset 1741.458318 x 0.863257581 -0.3926702 0.358295402
yoffset 150.0131291 y 0.399463789 0.673246386 0.034881236
zoffset 1234.272835 z 3.12226E-06 -3.2123E-06 1
N x y z r x1 y1 z1 r1 error error^2
0 3453 -1701 -1738 4223.417337 738.0793342 -1918.249765 -2423.600946 3177.779856 -385.1038923 148305.0078
1 3381 -1643 -1723 4135.134702 699.0937349 -1850.929269 -2432.375103 3135.461665 -342.7857013 117502.037
2 3355 -1693 -1711 4129.139741 656.6758859 -1874.382201 -2431.434845 3139.491561 -346.815598 120281.059
3 3407 -1633 -1731 4155.803051 725.5330449 -1854.406204 -2430.71061 3142.224473 -349.5485101 122184.1609
4 4665 -757 1189 4873.29406 2161.450477 -1758.630861 970.5809689 2950.708066 -158.0321025 24974.14542
5 4673 -815 1151 4881.18377 2145.18752 -1800.820391 933.4242204 2952.298147 -159.6221841 25479.24165
6 4697 -829 1165 4909.814151 2160.313252 -1819.669971 955.5349728 2981.811401 -189.135438 35772.21392
7 4643 -819 1181 4860.346798 2117.692031 -1791.733367 952.5358334 2932.959684 -140.283721 19679.52238
8 715 -815 4223 4359.95172 -1271.576393 -246.6416096 2587.291018 2893.408616 -100.7326523 10147.06725
9 727 -813 4177 4317.039147 -1260.418518 -250.0070114 2545.660325 2851.586372 -58.91040867 3470.436249
10 749 -785 4243 4379.529084 -1230.241659 -239.795069 2620.519498 2904.843999 -112.1680354 12581.66817
11 611 -807 4179 4299.838485 -1358.159609 -200.4177964 2506.307346 2857.68111 -65.00514671 4225.669099
12 -657 -1013 833 1466.869797 -2535.070208 158.8100096 -1301.196759 2853.929675 -61.25371127 3752.017145
13 -711 -989 817 1466.673447 -2572.099037 196.172165 -1335.707561 2904.873778 -112.1978142 12588.34951
14 -701 -999 844 1483.825461 -2567.461015 185.5129124 -1305.47342 2886.266092 -93.59012836 8759.112126
15 -711 -995 795 1458.619553 -2574.495888 192.1327573 -1357.916849 2916.998842 -124.3228786 15456.17813
16 3613 481 -1543 3958.02716 1747.831143 -512.0540098 -2095.162824 2776.116041 16.55992257 274.2310357
17 3611 525 -1540 3960.624446 1763.681044 -481.6458381 -2091.34464 2777.818558 14.85740514 220.7424876
18 3653 569 -1572 4017.381485 1817.514169 -468.5150427 -2106.761459 2821.578981 -28.90301747 835.3844188
19 3631 489 -1555 3980.113943 1766.565452 -513.7360638 -2100.434457 2792.221901 0.454061814 0.206172131
20 3597 565 2639 4496.882809 1767.587037 -449.232024 2084.034473 2769.36329 23.31267347 543.4807445
21 3593 599 2606 4478.804081 1777.715672 -424.7708601 2050.787254 2747.076929 45.5990339 2079.271892
22 3631 577 2604 4505.319744 1801.731251 -454.5037418 2061.635092 2775.45463 17.22133316 296.5743156
23 3617 549 2634 4507.998004 1778.460752 -467.8573541 2085.642282 2780.596497 12.07946639 145.9135084
24 -185 2581 2177 3381.584688 -691.9355777 2393.112869 337.2818337 2513.866162 278.8098011 77734.90521
25 -145 2557 2207 3380.846492 -666.9923117 2361.248051 380.7765001 2483.014669 309.6612945 95890.11729
26 -153 2599 2220 3421.492364 -657.1208526 2392.665719 392.3751488 2512.093811 280.5821522 78726.34413
27 -157 2557 2228 3395.126213 -677.3513371 2365.960026 397.4769552 2492.901845 299.7741183 89864.52203
28 431 -7 -767 879.8289607 -1193.990385 408.8758362 -2476.280838 2779.345116 13.33084684 177.7114774
29 463 -83 -736 873.4723808 -1196.725294 345.1435649 -2436.466359 2736.355939 56.32002402 3171.945106
30 429 17 -746 860.7241138 -1186.129704 425.8190224 -2455.160279 2759.716926 32.95903781 1086.298173
31 427 -9 -638 767.7590768 -1198.24194 409.0996099 -2348.783782 2668.319976 124.3559878 15464.4117
32 1387 3417 2378 4387.999772 999.057694 2338.668648 1130.68292 2783.151305 9.524658502 90.71911958
33 1377 3429 2382 4396.372823 995.2186962 2350.674294 1131.518541 2792.214909 0.461054752 0.212571485
34 1457 3355 2349 4347.030596 1034.718879 2269.440551 1124.600961 2736.006377 56.66958609 3211.441988
35 1373 3445 2338 4383.993385 998.1569491 2363.017058 1086.643459 2785.850125 6.825838565 46.59207212
36 3471 2883 1405 4725.839079 2584.769791 1160.833507 885.7439583 2968.688543 -176.0125795 30980.42815
37 3345 2939 1448 4682.248392 2498.369442 1248.011612 885.5520868 2929.775649 -137.0996855 18796.32378
38 3405 2909 1461 4710.714065 2538.181024 1204.253967 919.0033738 2955.868354 -163.1923911 26631.75652
39 3393 2931 1484 4722.866291 2536.610208 1223.777356 938.4712162 2968.627728 -175.9517649 30959.02358
40 3143 2419 -178 3970.099999 2116.265164 977.248095 -830.9618274 2474.689807 317.986156 101115.1954
41 3147 2451 -205 3994.125061 2132.500951 997.2213852 -855.4124462 2504.74375 287.9322136 82904.9596
42 3135 2411 -161 3958.1646 2106.163446 975.0034309 -817.1072405 2460.532543 332.1434204 110319.2517
43 3103 2383 -179 3916.546821 2067.354161 968.7180363 -847.549368 2435.304456 357.3715073 127714.3942
44 185 3641 713 3714.764461 50.89677217 2961.470767 -957.1747571 3112.729204 -320.0532409 102434.077
45 181 3667 707 3738.916822 57.82978161 2980.545873 -963.7010265 3133.004573 -340.3286093 115823.5623
46 143 3653 733 3728.5583 19.43358169 2986.041807 -951.8045891 3134.127521 -341.4515573 116589.166
47 153 3623 712 3695.467765 16.08217827 2961.917781 -970.2680722 3116.831037 -324.1550734 105076.5116
48 2099 -3223 2501 4587.867805 -1038.742081 -2411.268931 1277.177838 2919.655151 -126.9791875 16123.71405
49 2087 -3223 2526 4596.082462 -1049.101094 -2406.556969 1297.878293 2928.586283 -135.9103193 18471.6149
50 2079 -3203 2573 4604.538956 -1048.017732 -2389.950831 1342.709554 2934.804097 -142.1281338 20200.40643
51 2129 -3179 2505 4573.150664 -995.2679345 -2393.426209 1293.461474 2896.9104 -104.2344367 10864.81779
52 -109 -2125 1255 2470.33014 -2506.20747 -805.0245965 -721.6388134 2729.451055 63.2249088 3997.389092
53 -97 -2101 1269 2456.414257 -2486.261204 -793.5787706 -702.5021189 2702.734036 89.94192774 8089.550366
54 -173 -2103 1319 2488.433041 -2552.667552 -765.0824888 -679.802332 2750.198912 42.4770515 1804.299904
55 -153 -2117 1301 2489.517825 -2540.994949 -782.3612844 -691.1247612 2747.070794 45.60516933 2079.831469
56 333 -831 -375 970.6054811 -1607.746566 -107.3987654 -2148.135926 2685.306588 107.3693755 11528.18279
57 285 -829 -326 935.2764297 -1648.383849 -87.20426041 -2116.264343 2683.905487 108.7704759 11831.01643
58 309 -877 -348 992.8313049 -1646.839998 -128.944101 -2131.339552 2696.537937 96.13802609 9242.520061
59 253 -877 -315 965.5894573 -1695.182319 -106.9546759 -2118.404095 2715.274997 77.40096666 5990.909641
60 3419 -2285 710 4173.114664 475.4493671 -2298.082732 -8.153631469 2346.764331 445.9116326 198837.1841
61 3395 -2277 684 4144.708675 457.9268143 -2283.272592 -42.47367124 2329.127457 463.5485064 214877.2178
62 3429 -2275 693 4172.998323 488.0765277 -2295.276915 -21.22186508 2346.692392 445.9835715 198901.3461
63 3451 -2273 697 4190.672858 507.8671346 -2302.56918 -9.269603757 2357.93125 434.7447135 189002.9659

http://diydrones.com/forum/topics/magnet­ometer-soft-and-hard-iron-calibration

• Used a long cable to move magnetometer away from the table and computer with improved results.
8 Gauss range
11Jan2017
LSM9DS1 long cable

offset value axis xgain ygain zgain
xoffset 1057.176483 x 0.970972836 -0.095223453 0.017179224
yoffset 120.7727841 y 0.171154738 0.956653319 0.005190024
zoffset 549.551664 z -0.000344029 -0.000125418 1
Stat Value
Mean 1805.82288
Standard Error 2.302069588
Median 1805.330298
Mode #N/A
Standard Deviation 20.20057865
Sample Variance 408.0633778
Kurtosis 0.449741028
Skewness 0.019637359
Range 97.68571284
Minimum 1757.482648
Maximum 1855.168361
Sum 139048.3617
Count 77
COV 1.12%
N x y z r x1 y1 z1 r1 error error^2
0 481 -114 -1116 1220.578961 -1655867 -5512957.334 -4481757046 4481760743 -2241780074 5.02558E+18
1 1150 82 -1248 1699.037375 -2393599 -4101041.62 -6041270293 6041272159 -3801291491 1.44498E+19
2 1223 1763 1306 2511.87858 2783145 4445402.421 8208139517 8208141193 -5968160524 3.56189E+19
3 -497 1005 1203 1644.458269 3815848 -550325.0282 9822473543 9822474300 -7582493631 5.74942E+19
4 2030 1599 312 2602.891661 366043 3769985.976 2027116432 2027119971 212860697.9 4.53097E+16
5 1109 -301 -1253 1700.144406 -2848644 -5140973.94 -7028156509 7028158967 -4788178298 2.29267E+19
6 429 -1157 -545 1348.968124 -2266216 -7282210.964 -5081260925 5081266649 -2841285980 8.07291E+18
7 52 -1187 -15 1188.233142 -1197310 -7126541.529 -2239969012 2239980669 0 0
8 1509 892 -981 2008.757327 -1462570 -1017395.195 -3627393468 3627393906 -1387413237 1.92492E+18
9 1607 1377 -648 2213.251454 -550865 914976.1828 -1241463461 1241463920 998516748.2 9.97036E+17
10 2039 1361 -281 2467.549999 -669396 2212286.456 -919612333 919615237.6 1320365431 1.74336E+18
11 1211 1171 -923 1920.85684 -656518 -727515.6291 -1916284327 1916284578 323696091.1 1.04779E+17
12 418 1637 1422 2208.297308 3762777 2951937.793 10226948810 10226949928 -7986969260 6.37917E+19
13 352 1627 1426 2191.919022 3836897 2821260.374 10372358286 10372359379 -8132378711 6.61356E+19
14 -50 1486 -151 1494.488876 2257316 -809238.2217 4924569343 4924569927 -2684589258 7.20702E+18
15 939 1372 -793 1841.997286 101834 -470986.6254 -209753014 209753567.5 2030227101 4.12182E+18
16 1927 1686 409 2592.914576 724900 3973031.015 2885928000 2885930826 -645950157.2 4.17252E+17
17 -32 1678 235 1694.677845 2949962 338386.0304 6888765729 6888766369 -4648785700 2.16112E+19
18 1297 1908 182 2314.259493 1527991 3086982.486 4145556064 4145557495 -1905576826 3.63122E+18
19 2097 1616 454 2686.071667 475455 4160036.49 2455909180 2455912749 -215932080.7 4.66267E+16
20 -556 1068 236 1226.970252 2808457 -2082511.029 6449109003 6449109951 -4209129282 1.77168E+19
21 -466 1183 1146 1711.712885 3941057 -144274.6037 10026168448 10026169224 -7786188555 6.06247E+19
22 1754 1621 1246 2693.821264 1862825 4892237.013 6312980978 6312983148 -4073002480 1.65893E+19
23 2161 45 -951 2361.429017 -3346358 -1987850.236 -7430868391 7430869410 -5190888742 2.69453E+19
24 1370 1708 1416 2607.5314 2660189 4737898.003 8122950769 8122952586 -5882971918 3.46094E+19
25 -376 489 -587 851.5080739 837574 -4584451.155 1266377324 1266385899 973594769.5 9.47887E+17
26 1526 1354 -749 2173.244809 -601318 553490.6629 -1496994925 1496995148 742985520.5 5.52027E+17
27 408 758 -1043 1352.359789 -338112 -3326583.487 -1601564975 1601568465 638412203.2 4.0757E+17
28 2462 862 1451 2984.943718 234602 4525753.577 3288154671 3288157794 -1048177125 1.09868E+18
29 1135 1979 568 2351.018928 2287251 3624842.703 6203839725 6203841206 -3963860537 1.57122E+19
30 -611 409 1331 1520.579824 3333728 -2030604.264 8925017953 8925018807 -6685038138 4.46897E+19
31 -450 -603 1254 1462.403843 1718497 -4425703.656 5429285478 5429287554 -3189306885 1.01717E+19
32 2286 1349 901 2803.105064 428622 4545555.819 2966103310 2966106824 -726126155.4 5.27259E+17
33 598 -485 2237 2365.79754 1747250 -732208.3364 7000183420 7000183676 -4760203008 2.26595E+19
34 1100 -1207 1827 2450.464854 -315408 -2367095.8 2224668352 2224669634 15311034.96 2.34428E+14
35 2565 461 -448 2644.32411 -2702145 570664.8623 -5320722523 5320723240 -3080742571 9.49097E+18
36 -174 1541 178 1560.974375 2879685 -340738.7636 6629862586 6629863220 -4389882552 1.92711E+19
37 -700 526 1097 1403.597164 3316100 -2272732.031 8570767797 8570768740 -6330788071 4.00789E+19
38 -699 -193 940 1187.202594 2186967 -4335253.641 5968204807 5968206782 -3728226114 1.38997E+19
39 1584 1159 -782 2112.785129 -968071 107951.3846 -2304459926 2304460132 -64479463.23 4.1576E+15
40 1406 -1236 1693 2524.04061 -896372 -2140392.25 900192221 900195211.9 1339785457 1.79503E+18
41 1326 1811 -121 2247.807376 1000608 2394331.492 2649974684 2649975955 -409995285.9 1.68096E+17
42 -456 1301 749 1568.928934 3605094 -483732.4905 8815751912 8815752662 -6575771994 4.32408E+19
43 -761 437 912 1265.635809 3053439 -2904155.285 7763145551 7763146695 -5523166026 3.05054E+19
44 25 1341 -476 1423.194295 1583371 -1580481.75 3101342793 3101343600 -861362931.3 7.41946E+17
45 2116 1514 209 2610.236196 23796 3533214.309 1191667249 1191672487 1048308182 1.09895E+18
46 2183 266 1949 2938.510847 403512 3373582.734 4197506676 4197508051 -1957527382 3.83191E+18
47 969 -4 2371 2561.370336 2073630 1326705.535 7962174568 7962174949 -5722194280 3.27435E+19
48 832 -52 2327 2471.812493 2128986 901011.0785 7988609359 7988609694 -5748629025 3.30467E+19
49 2158 959 -608 2438.505485 -1736301 866958.8605 -3571057200 3571057727 -1331077059 1.77177E+18
50 1638 934 -908 2092.812462 -1480891 -572675.0196 -3540718745 3540719101 -1300738432 1.69192E+18
51 821 1310 1917 2462.728162 3428256 3629272.403 10241084758 10241085975 -8001105306 6.40177E+19
52 2220 1390 874 2761.227263 532055 4492006.001 3135161893 3135165156 -895184487.5 8.01355E+17
53 2119 1382 -198 2537.575418 -641961 2537448.933 -735938824 735943478.4 1504037190 2.26213E+18
54 -249 1355 -71 1379.516944 2430822 -1344846.092 5341571389 5341572111 -3101591443 9.61987E+18
55 47 1240 -612 1383.60146 1260401 -2020448.989 2248630642 2248631903 -8651234.314 7.48439E+13
56 -24 -44 -873 874.4375335 -641878 -5795536.348 -2150918337 2150926241 89054427.99 7.93069E+15
57 -141 -809 -407 916.52114 -934354 -7149593.281 -2221788011 2221799711 18180957.7 3.30547E+14
58 105 -1389 200 1407.247668 -1268621 -7190333.493 -2108617729 2108630370 131350298.6 1.72529E+16
59 -158 959 -583 1133.372842 1184142 -3026900.242 2067914284 2067916838 172063830.3 2.9606E+16
60 1045 1836 -175 2119.798575 1318984 1890898.208 3186098836 3186099670 -946119001.5 8.95141E+17
61 2656 329 -355 2699.741099 -2876226 546643.9099 -5551041308 5551042080 -3311061411 1.09631E+19
62 2783 418 64 2814.943872 -2414431 1675006.865 -4008488164 4008489241 -1768508572 3.12762E+18
63 -801 499 533 1083.831629 2728394 -3439629.992 6585238109 6585239573 -4345258904 1.88813E+19
64 -121 -1190 392 1258.731504 -495703 -6758716.115 -281175684 281257339.9 1958723329 3.8366E+18
65 1790 1654 1142 2691.464285 1735883 4865270.691 5921807007 5921809260 -3681828591 1.35559E+19
66 935 -1637 1115 2190.255465 -1527604 -4898399.044 -1294023939 1294034112 945946556.8 8.94815E+17
67 2392 574 1629 2950.386585 159968 3976113.502 3333381785 3333384160 -1093403492 1.19553E+18
68 1355 1923 335 2376.168975 1659256 3474806.948 4632299241 4632300841 -2392320173 5.7232E+18
69 118 838 -831 1186.05607 383324 -3269728.886 124190111 124233738.3 2115746930 4.47639E+18
70 2301 -1224 1134 2842.311207 -2670137 -1508863.429 -3341740176 3341741583 -1101760915 1.21388E+18
71 93 1625 -112 1631.507891 2307303 -152990.882 5117959913 5117960435 -2877979767 8.28277E+18
72 914 588 -1194 1614.551331 -1373273 -3142203.132 -3862053767 3862055289 -1622074621 2.63113E+18
73 1457 421 -1209 1939.528551 -2287084 -2663776.435 -5683800959 5683802043 -3443821375 1.18599E+19
74 29 -240 -861 894.2941351 -949562 -6178082.069 -2777485328 2777492361 -537511692.8 2.88919E+17
75 1035 1729 -460 2066.946056 848867 1136466.219 1824721631 1824722182 415258486.3 1.7244E+17
76 1280 1711 -378 2169.97811 618245 1642362.14 1501092802 1501093828 738886840.9 5.45954E+17
• See attached spreadsheet in ods format.
Let me know if it doesn't open OK.
I suppressed graphs to save space, if you're curious do some plots.

1 Attachment