22 views (last 30 days)

Show older comments

Hello everyone,

I am using the Sensor Fusion and Tracking Toolbox. I have raw data from accelerometer and gyroscope.. I imported them to matlab and logged them to imufilter in order to estimate the orientation. ( i want to compare the results of matlab with my own algorithm for gettting the orientation)

However, The quaternions estimated from the toolbox have an unexpected behavior.

the i (x-axis) values are switched with the w values (the real part). So for example , the initial quaternions are someting like 0.0023 + 0.99i -0.001k + 0.001j.

and going along the data set .. it seems they are so similar to my orientation output except that the values of i and w components are switched. I wanted to know why ? or what i am doing wrong. Thank you

Update: I have now transformed the quaternions to normal vectors using (compact) and I noticed the following when I compared the results from the toolbox and results from my alogrithm (assuming Q = [w,x,y,z]) :

- The scalar w component is at i (x) and has an inversed sign
- The x compnent is at w position with the same sign
- The y component is at the z position with an inversed sign
- The z component is at the y position with the same sign

James Tursa
on 7 Feb 2020

See this link for a discussion of the MATLAB quaternion convention:

Jim Riggs
on 29 Nov 2019

There are two different ways that are commonly used to represent quaternions.

Q = [a,b,c,d] with d being the scalar part, and a,b,c being the vector part.

or

Q = [a,b,c,d] where a is the scalar part and b,c,d represent the vector part.

Matlab currently uses the latter representation; a is the scalar, and b,c,d are the vector coponents. Make sure that your code is the same.

Brian Fanous
on 11 Dec 2019

Hensham

There are a few issues that might be going on. First, if you are using the NED convention of the imufilter, then you have to make sure that your input sensor data is also using that convention (i.e. on a flat surface your accelerometer z-axis gives a positive value, clockwise rotations give positive values from the gyroscope, etc). There’s a demo to illustrate that here:

The other thing to be aware of is what the quaternion output of imufilter means. The imufilter gives a quaternion q that will take a quantity in the parent (global) frame to the child (sensor) frame, when used with a frame rotation. That is

x_sensor = framerotate(q, x_global).

Ensure the library you are using is doing that as well.

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

Start Hunting!