Handling magnetic interference in sensors involves understanding your environment and developing algorithms to detect interference.
A while ago, I covered a glossary of terms you would need to know related to sensors, including their requirements, calibration, output vectors, and more. I’d like to take it a step further and discuss the most common question I get about sensors and how to work around it: Usually it’s something like, “I want to use the magnetometer, but I’m not sure how to deal with magnetic interference.”
Sensor Refresh: The Basics
It’s important to understand that each sensor represents a part of the orientation puzzle, so let’s have a quick review. The accelerometer can measure the direction of gravity relative to the sensor, and thereby estimate the tilt (pitch and roll). The gyroscope determines the change in angular position by measuring the angular velocity. The magnetometer measures the strength and direction of the magnetic field, which can sometimes measure the direction of North and thereby estimate the heading (yaw).
The following suggestions are based around some general principles when using an IMU:
- You can trust the gyroscope for relative orientation changes over short periods of time.
- You can trust the magnetometer in stable magnetic environments.
- You can trust the accel when it’s being used in an application without constant acceleration.
And by “trust” these sensors, I mean you can use their output with a reasonable level of confidence.
How to Handle Magnetic Interference
One of the most common questions I receive from customers is how to deal with magnetic interference. The answer to this, as you might expect, depends on the situation. So, let’s go over a few scenarios:
Outdoor Use in a Rural Setting
If you’re using the magnetometer in a rural setting, the changes and interference in the magnetic field should be few and far between, and you should be able to use its output to acquire long-term orientation information. Fusing this with information from the accelerometer and gyroscope produces a full picture. A key thing to keep track of is sudden changes in the magnetic reading and potentially rejecting them as interference.
Outdoor Use in a City
An outdoor urban setting has lots of potential magnetic interferences, from metal pipes to large motor vehicles. In short, it’s harder to get consistent output from the magnetometer due to the number of potential interferences compared to rural settings.
Developing a robust magnetic-interference rejection algorithm is crucial, and ensuring that the magnetometer is trusted more when in stable environments is key. In those times when a magnetic environment isn’t stable, you can rely on the short-term orientation accuracy of the gyroscope and correct its orientation over time when there’s a more stable magnetic environment.
Indoor applications have just as many possibilities for magnetic interference as an urban environment. Variations exist, however, between large buildings reinforced with concrete and steel compared to smaller buildings with more wood-based construction. The former will often contend with largely unstable magnetic fields, and even when reasonably stable, it can be dramatically warped to point in a different direction from the Earth’s magnetic field.
Understanding the setting you’re in and adjusting to it is important. For instance, in an indoor application with a warped magnetic field, it may be better to judge orientation based on relative differences over absolute direction.
This solution revolves around one of the principles we discussed above. In a less-warped environment, it also holds. Trust the mag when the magnetic environment is stable. Create a magnetic-interference rejection algorithm for improved consistency. Lean on data from the accelerometer and gyroscope at times when your magnetic environment is less stable. Is this sounding similar? It should! Because the key principles are the same.
- Trust the magnetometer in stable magnetic environments
- When not in stable magnetic environments, lean on the gyroscope and accel for orientation information
- Develop a magnetic-interference rejection algorithm to help detect and ignore sudden and potentially erroneous magnetic information
Additional Magnetic Considerations (Hard- and Soft-Iron Effects)
Iron effects differ on an ideal magnetometer
A small note about mounting magnetometers on devices with nearby hard-iron effects: Hard-iron effects provide an offset to the magnetometer readings, but they don’t change the scale/sensitivity. This takes the sphere of magnetometer readings in all directions and shifts the origin.
The biggest issue with large hard-iron offsets is that you might saturate the supported range of the magnetometer with this offset. Soft-iron effects change the scale/sensitivity and skew. As a result, this can stretch, shrink, or turn the sphere into an ellipsoid (see figure).
If you’re new to sensor fusion or IMUs in general, a company such as CEVA can help. It offers a sensor fusion suite that enables companies and tinkerers alike to shortcut their design by using a number of convenient tools and sensor outputs.
CEVA has developed products with algorithms behind them to get the most out of sensors (including those tricky magnetometer situations). Calibrated sensor output, sensor fusion using various sensor combinations (AG, AM, AGM), and magnetic interference rejection help users navigate the IMU world. Additional features include dynamic calibration (adjusting sensor output over temperature and age), gesture recognition, and activity classifiers.
Published on ElectronicDesign.
You might also like
More from Sensor fusion
In order to improve functionality in next-generation devices, smart audio devices need to do more than just listen. Users are …
In this data-driven age, people are hungrier than ever for insight into their health and wellness – especially in terms …