I obtain sensor data from an AR headset, which outputs the user's head orientation as quaternions. When I inspected the raw data, I saw that there are several significant jumps in the consecutive quaternion samples, especially for qw and qy components as shown below.
Since I want to use some machine learning algorithms on this data, continuity is important. To get rid of the flips, I followed the advice in this answer and flipped the sign of all quaternion components, if qw < 0. This is valid because q and -q denote the same rotation, assuming q is a unit quaternion. With this approach, most of the flips are gone:
However, I noticed that this created another jump for qy at around t=25000 where the magnitude of qy is very close to 1.0. Checking the specific samples where the jump occurs, I converted the quaternions values to Euler angles (yaw, pitch, roll) to get a better understanding:
e1 = [175.84487617, 4.24149047, 170.7215615]
e2 = [175.0441748, -0.47157242, 169.98347392]
It is clear that the angles are very similar except for the zero-crossing in the pitch value which seems to cause the flip in qy. Do I have to live with these discontinuities that occur at the borders of the range or is there a way to make quaternions fully continuous?