# IMU sensor fusion: imufilter command reduces number of samples

8 views (last 30 days)
Aishwarya Rao on 26 Mar 2023
Answered: Paul on 27 Mar 2023
Hi Everyone.
I have collected the accelerometer and gyroscope data from IMU and want to find an angle estimate from it. I am using the 'imufilter' command with decimation factor 2. I find that the number of samples reduce after I convert the quaternion obtained into euler angles. Is there any way I can retain the sample size and get accurate angle estimate? How to do it numerically?
##### 2 CommentsShow 1 older commentHide 1 older comment
Aishwarya Rao on 27 Mar 2023
Edited: Aishwarya Rao on 27 Mar 2023
Here is the code for attached data
dd = importdata('sampledata.csv'); %%% Import the data
acc = dd.data(:,1:3); %%% Acceleration data XYZ
vel = dd.data(:,5:7); %%% Velocity data XYZ
aca = (pi/180).*acc;
vca = (pi/180).*vel; %%% deg to rad per sec or sec^2
Fs = 370;
decim = 2;
fuse = imufilter('SampleRate',Fs,'DecimationFactor',decim);
q = fuse(aca,vca);
x = eulerd(q,'XYZ','frame'); %%% quaternion to euler
The dimensions of each vector is 33334. I am getting final sample size as 16667. And the angles are around 128 radians which is weird.

Jack on 26 Mar 2023
Hi,
When you convert the quaternion obtained from the imufilter command to Euler angles, you are essentially converting from a four-dimensional representation to a three-dimensional representation. This conversion can lead to a loss of information, which is why the number of samples is reduced.
To retain the sample size and get accurate angle estimates, you can avoid converting the quaternion to Euler angles and instead directly use the quaternion representation. Quaternions are a more efficient and numerically stable way of representing orientation than Euler angles.
You can use the quaternion function in MATLAB to create a quaternion object from the four values of the quaternion obtained from the imufilter command. Once you have the quaternion object, you can use the eulerd function to compute the Euler angles directly from the quaternion. This approach will allow you to retain the original sample size and avoid the loss of information that occurs when converting to Euler angles.
Here's an example code snippet to illustrate this approach:
% Set the decimation factor
decimationFactor = 2;
% Create an imufilter object
imuFilter = imufilter('SampleRate', imuData.SampleRate, 'DecimationFactor', decimationFactor);
% Process the IMU data
[orientations, angVelocities] = imuFilter(imuData.Acceleration, imuData.AngularVelocity);
% Convert the quaternion to Euler angles directly using the quaternion object
q = quaternion(orientations);
[roll, pitch, yaw] = eulerd(q, 'ZYX', 'frame');
In this example, imuData is a structure containing the accelerometer and gyroscope data, and decimationFactor is the decimation factor used for the imufilter command. The quaternion function is used to create a quaternion object from the orientations obtained from imufilter. The eulerd function is then used to compute the Euler angles directly from the quaternion object.
Aishwarya Rao on 26 Mar 2023
I have already done the same procedure which you suggested. But it doesn't work for me. Is there any alternative? Can I directly operate on euler angles without using quaternions?

Paul on 27 Mar 2023
Hi Aishwarya,
Because the decimation factor is 2, shoudn't it be expected that there be half as many output samples as there are input samples? Why not use a (default) decimation factor of 1?
Why multiply the acceleration data by pi/180? Are the units already m/s^2?
Presumably the vel data is actually angular velocity? Are you sure the units aren't already in rad/sec?

### Categories

Find more on Coordinate Transformations in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!