Some colleagues of mine are working on developing a new and exciting computer-assisted hip replacement system and needed to be able to track the orientation of the pelvis during the procedure for alignment of the prostheses. This is typically achieved using an IMU, or intertial motion unit; A small board that typically has a 3-axis accelerometer, 3-axis gyroscope, and a 3-axis compass.
Accelerometers are terrible for measuring orientation during small time intervals because of their noise, but if you average them over a long period of time, they’re quite accurate. Conversely, gyroscopes are great over small time intervals but they tend to drift over time. The best way to tackle these issues is by fusing the sensors together.
Some people claim that you can do this using a rather efficient and simple combination filter, which uses part of the signal from the gyroscope (a) and part of the signal from the accelerometer (1-a) to eliminate the noise and the drift. For this particular IMU, the Phidgets 1044, I couldnt’ get that working. The signal would still drift, often more than 5 degrees a minute. Orthopaedic surgeons strive to implant prostheses into people with sub-mm and sub-degree accuracy, so this clearly wasn’t going to work for a procedure that can take anywhere from 12 minutes to an hour to perform.
Enter the Kalman Filter, a piece of mathematical wizardry that is frequently applied to IMUs. So why don’t they all come with these algorithms? Because the filter needs to be tuned to the specific application, so a “one size fits all” approach just isn’t feasible.
After many hours of math and fighting with MATLAB, I finally had a working 3-axis Kalman filter implementation.
The above figure shows the Roll (blue) Pitch(green) and Yaw(red) angles of the IMU sitting on my desk. Over 30 minutes, the solid lines, the angles determined by the gyro, can drift more than 40 degrees. The slightly furry lines are the angles determined by the accelerometer. Let’s take a closer look at the Pitch.
Here we can see the solid line, representing the angle from the Gyro drifting off to inaccuracy. Also shown is the dotted line, the angle from the accelerometer, and the lovely, stable, demonstrably less noisy dashed line from my Kalman filter.
Here we can see it responding to a change in orientation, coping with the noisy accelerometer signal, and the offset from a drifted gyroscope.
And here we can see it coping with me hammering on my desk, similar to many actions performed during a hip replacement.
This was a fun learning opportunity and I’m looking forward to meeting with the group in the coming weeks to fine-tune the response of the filter, and integrate it into their system.
If you’re looking to write your own Kalman Filter for an IMU and Roll/Pitch/Yaw angles, some of the best resources I’ve found are:
Phidgets Compass Primer
Freescale Semiconductor’s AN4248 Datasheet