Why don't the Sensor Fusion Toolbox IMU filters consistently provide the same results?
3 views (last 30 days)
Jaime Hislop on 19 Jan 2021
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;
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
Brian Fanous on 19 Jan 2021
Edited: Brian Fanous on 19 Jan 2021
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:
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.