A person holds his phone and rotates it in space in a sequence. I am able to obtain a sequence of quaternions from the phone's motion sensors representing the rotation of the phone from the phone coordinate system to the world coordinate system.
A second person holds his phone and again rotates it in a sequence. I want to determine if the second person is rotating in the same sequence as the first person. I learned that I can use Dynamic Time Warping to compute a similarity score, however, my problem is a little more difficult. I do not know if the second person is facing the same direction as the first person when rotating his phone.
The following graph depicts the phone's coordinate system.

The following graph depicts the world coordinate system

As an example with a sequence of $1$, the first person is facing north. He holds the phone flat (screen pointing up), with the top side of the phone pointing away from his body. In this case, the phone's coordinate system coincide with the world's coordinate system. I get an identity quaternion. The second person is facing west, and he holds the phone in the same way. Because the phone's coordinate system is $90$ degrees around $Z$ off from the world coordinate system, I get a quaternion of $(0i, 0j, 0.7k, 0.7)$, which is basically a rotation of $90$ degree around $Z$.
From the person's perspective, both hold the phone in the exact same orientation. The question is that how do I find the angle of rotation around $Z$ such that it minimizes the differences between the two quaternion sequences? In this example, I want the algorithm to say this is an exact match.
Even though the example uses a sequence of $1$, I really want to match a longer sequence of rotations.
I am only interested in rotation similarity, and do not care about translation in space. I also consider a phone facing up to be different from a phone facing down.
I thought about decomposing a quaternion into a rotation around $Z$ and another quaternion without the $Z$ component, but I think the decomposition is not unique. Any other ideas what I can do to check if the two sequences of rotations are similar, subject to a constant rotation around $Z$?
If both people carry the phone in the same orientation, then the curves will be similar, regardless of the direction (N.S.E.W)
The problem will come if the two people hold hold the phone in different orientations, for example phone pointing up vs phone pointing down etc. THIS is the problem to solve.
One trick to solve this is to combine all directions $(X,Y,Z)$ into a single time series. This single time series will be invariant to phone orientation.
One caveat: Combining three axis is trivial in outer space, but here on earth there is a constant $-9.8Ms^2$ acceleration shared between the three axes. Many phones can do a "trick" to remove this for you automatically (so, at rest on your desk, the three axes are all zero).
The conversion to 1d can cause ambiguity between two different motions in a handful of cases, but in practice it works VERY well.
How can you compute DTW on a fast moving stream? The problem has been solved here http://www.cs.ucr.edu/~eamonn/UCRsuite.html
I recommend reading http://www.cs.ucr.edu/~eamonn/SDM_RealisticTSClassifcation_cameraReady.pdf
You must z-normalize both time series before comparison
You should limit the warping window (Ratanamahatana, C. A. and Keogh. E. (2004). Everything you know about Dynamic Time Warping is Wrong. )