MATLAB Answers

quat2angle different result

7 views (last 30 days)
Sven Dietrich
Sven Dietrich on 12 Nov 2020
Answered: David Goodmanson on 14 Nov 2020
Hello everybody.
I am using the quat2angle function to analyse the yaw, pitch and roll of my sensor data. For that I did a Testfile, which looks fine, but on the original data there a lot of jumps. You can see it on the plots attached. Does anybody have an idea where jumps the jumps are comming from and any suggestions to get it as smooth as the testfile?
Test Original
It should be almost the same movement... The only difference is, that the testfile was recorded in the lab and the original data on a canoe on water.
PRY = compact(quaternion(w,x,y,z));
figure ('Name','p r y')
[yaw, pitch, roll] = quat2angle(PRY);
plot(t, yaw)
ylabel('Winkel (rad)')
plot(t, pitch)
ylabel('Winkel (rad)')
plot(t, roll)
ylabel('Winkel (rad)')
axes('pos',[.6 .5 .5 .3])


James Tursa
James Tursa on 12 Nov 2020
Could be the sign ambiguity of the quaternion or a rollover of angles for the Euler Angles. Can you post a small subset of the data you are using that encompasses one of these jumps?
Sven Dietrich
Sven Dietrich on 13 Nov 2020
Yes the, ambigiuty could be. Attatched you can find a part of the the original data.
The plot does not make sens - confuses me - because I also did an animation to see the movement and this looks smooth with the same data.
James Tursa
James Tursa on 14 Nov 2020
I don't see any sign flipping in the quaternion data you posted.

Sign in to comment.

Answers (1)

David Goodmanson
David Goodmanson on 14 Nov 2020
Hi Sven,
it's pretty clear that both test and original have discontinuities because the function producing the angles, probably atan2, has range -pi to pi. That's clearest in the test roll plot, where the data drops below -pi and reappears at pi (or goes above pi and reappears at -pi). A straightforward way to fix that is to run those angles through the unwrap function.
Since the jumps are +-2*pi, keeping them or removing them makes no difference one you plug them into a trig function.


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!