Skip to content

Magnetic Interference

Bjarne Hansen edited this page Jan 26, 2021 · 2 revisions

Magnetic Disturbances

Even if an effective calibration is performed at the time of sensor installation, it is almost inevitable that at some point magnetic disturbances will occur in the vicinity, thus diminishing the sensor accuracy. These disturbances can include things like: new ferromagnetic objects brought into the area; new electrical wires; compasses, speakers, laptops placed nearby; etc. It is preferable to know when a magnetic disturbance is occurring so that it can be remedied. either by removing the object or performing a new calibration.

Detecting Magnetic Interference

Close review of the sensor fusion code and NXP's Application Note AN5019 Magnetic Calibration Algorithms suggested several indicators of reliability of the magnetic readings. Assuming that one already has a good calibration in use, then monitoring the Measurement Noise Covariance Matrix (array variable fQv6x1 in fusion.c) seems to work well. Specifically, fQv6x1[3] corresponds to the magnetic noise covariance for the current sensor reading, and is used by the fusion algorithm in determining how much weight to assign to the magnetic reading when calculating the orientation.

The magnetic measurement noise covariance is a float value. Some testing (below) suggests that when the time-average over 1 second of this value rises above 0.00056 there is significant magnetic interference.

Test Method

The sensor was connected to an ESP8266 d1_mini programmed to output several key values every 100 ms. These values were:

  • the B field magnitude in uT assumed by the calibration parameters
  • the B field inclination (dip below horizontal) in degrees of the present sensor reading
  • the magnetic measurement noise covariance as calculated by the fusion algorithm

The sensor was powered up and handheld at least 50 cm from the nearest metal and at least 1 m from the nearest magnet. For the first 60 seconds it was rotated arbitrarily to acquire enough readings to perform a calibration. It was then held stationary for about 30 s, followed by 30 s of moderate motion (pitch, roll, and yaw of about 30 degrees). Then for the next 30 s a pen known to have a steel barrel was brought within 5 cm of the sensor and moved arbitrarily in various orientations. The pen was removed and replaced by a 5 mm dia rare earth magnet, which was moved in the vicinity of the sensor at a distance of about 10 cm. Finally, the magnet was removed and the sensor manipulated moderately by hand for 30 s, followed by holding the sensor stationary for the rest of the test.

Results

Calibration was successful, as evidenced by the B field magnitude of about 49 uT contained in the calibration parameters. Three steps are visible in the B plot, corresponding to the completion of the 4-, 7-, and 10-element calibration routines.

The magnetic inclination angle of about 70 degrees is as expected, and is one possible indicator of magnetic disturbances provided that the threshold of determining a disturbance allows a swing of about +/- 5 degrees from the average undisturbed value.

The magnetic noise covariance is a more powerful determinant of whether interference is occurring. This was visualized easiest by plotting a 1 s time-average of the log of the noise covariance value. This parameter remained less than -3.25 during all the un-interfered periods, and rose markedly higher when subjected to interference by the pen and the magnet. If one assumes a threshold of -3.25, this would correspond to an actual noise covariance value of 0.00056; if this parameter rises above this level one can assume that magnetic interference is present.

Results are shown here: Key Parameters reported by sensor during Magnetic Disturbances

Further Testing

A test reporting the compass heading simultaneous with the above magnetic parameters, while the sensor is subjected to a disturbance, would be useful to confirm that the thresholds at which the parameters indicate interference correspond with actual distubrances in the compass heading.

Clone this wiki locally