MATLAB Answers

Why don't the Sensor Fusion Toolbox IMU filters consistently provide the same results?

1 view (last 30 days)
I have tried several different IMU filters available in the sensor fusion toolbox MATLAB and found that they don't return the same answer each time despite being given the same data and no settings being changed between implementations, does anyone know why that is?
The filters/fusion methods I am having issues with are: complementaryFilter, ahrsfilter, and imufilter
The way I tested them (after noticing a problem with a larger section of code I was working on) was for example:
FUSE = complementaryFilter('SampleRate', 248.0159)
[complementary1,~] = FUSE(IMU(1).acc,IMU(1).gyro,IMU(1).mag);
[complementary2,~] = FUSE(IMU(1).acc,IMU(1).gyro,IMU(1).mag);
complementary1 == complementary2;
figure, plot(ans)
IMU(1).acc, IMU(1).gyro, and IMU(1).mag are accelerometer, gyroscope, and magnetometer values I have saved in a struct. The answer from this comparison was 0. I tested it with two other filters I was also using and the ans was 1. These filters/fusion methods that were consistent were ecompass (also available in the sensor fusion toolbox) and the open-source Madgwick filter. I would like to understand why the answer is different every time for these three filters
  2 Comments
Nawsheen Tarannum Promy
Nawsheen Tarannum Promy on 26 Feb 2021
Hi Jaime, I'm using Madgwick Algorithm for processing my data that I have collected from MATLAB mobile app. Did you collect your sample from Mobile App? If so, can you please share how you connect your input with madgwick algorithm? Thanks.

Sign in to comment.

Accepted Answer

Brian Fanous
Brian Fanous on 19 Jan 2021
Edited: Brian Fanous on 19 Jan 2021
Hi Jaime
The fusion filters are generally objects which retain state from one call to the next. In your example code, the first call to FUSE() estimates the orientation in complementary1, but also updates the internal states and state covariances of the FUSE object. The next call to FUSE() will start from those new internal states and state covariances. This allows you to stream data through the filter in smaller chunks but get the same answers as if you had fed the entire datastream at once. If you'd like to get the same answers from one call to the next use the reset method on the filters:
reset(FUSE);
To restore the initial states and covariances. The ahrsfilter and imufilter are System objects for which this streaming behavior is fundamental. The filters are not true System objects but retain the same streaming design philosophy.
The ecompass algorithm is a notable exception because it is a function. It does not retain state from call to call, so it's giving you identical answers from one call to the next.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!