# Coordinate system transformation in motion capture files

I am trying to align two motion capture files from different sources. The motion capture file consist of a skeleton specified as a hierarchy of joints. Each joint i.e. "shoulder" has three pieces of data: rotation order (XYZ), a translation plus direction from a parent joint (the bone vector) and an axis, which is a 3-tuple of rotations $(X, Y, Z)$ that describe the transformation from the parent coordinate system to the local coordinate system. For each frame, a local rotation 3-tuple $m_x, m_y, m_z$ is specified which describes how the bone vector changes from frame to frame.

To calculate the position of a particular bone for a single frame, I calculate:

$M = M_x \times M_y \times M_z$ where $M_x$, $M_y$, $M_z$ are the rotation matrices correspond to $m_x$, $m_y$ and $m_z$.

$L = C^{-1} \times M \times C$, where $C$ is the multiplication of 3 $X$, $Y$, $Z$ rotation matrices corresponding to the bone axis.

This is done for each bone in the hierarchy (i.e shoulder -> clavicle -> spine -> root) and multiplied together to get the global rotation matrix for a particular bone. The bone vector is then multiplied by this rotation matrix to get the $x, y, z$ position.

The problem is now I have two motion capture files with corresponding joints: say, shoulderA and shoulderB. Since the joint axes are different, the local per-frame rotations are also different, which means I can't use the frame data for file B for skeleton A. I would like to "refer" shoulderB to shoulderA, so I'm wondering how I can change the per-frame rotations to do so.