# Performance Enhancement of Consumer-Grade MEMS Sensors through Geometrical Redundancy
## 2 Theoretical Background
### Sensing Axes Alignment  
In order to correctly combine data acquired from different sensors, their spatial orientation must be referred to a common reference frame. Different approaches (direction cosines, Euler rotation angles or quaternions) can be exploited to transform a vector from one coordinate system into another. All rotations involve a transformation matrix or Direction Cosine Matrix (DCM), usually referred to as \(C_{b_{i}b_{i}}^{b_{i}}\), where \(b_{i}\) is the starting reference of the \(i\)-th sensor body frame, while \(b_{r}\) is the body reference frame of destination.  
The transformation matrixes are defined by a sequence of three rotations comprising [PERSON]'s angles \(\phi\) (roll), \(\theta\) (pitch), \(\psi\) (heading) [19]. The [PERSON]'s angles are three anglesintroduced by [PERSON] to describe the orientation of a rigid body. Indeed, the relative orientation between two any Cartesian frames can be described by [PERSON]'s angles. The advantage of [PERSON]'s angles consists of the fact that they allow us to easily understand the orientation of a body with respect to a certain reference system. However, the main disadvantage is their propensity to singularity. Therefore, the most effective way to parametrize the transformation matrix is to use the quaternion method [5].  
The quaternion representation is based on [PERSON]'s rotational theorem, which states that the relative orientation of two coordinate systems can be described by only one rotation about a fixed axis [20]. Therefore, the quaternion is defined by a rotational axis and a rotation angle [20]  
\[q=\left[q_{0}\;q_{x}\;q_{y}\;q_{z}\right]^{T}=\left[\begin{array}{c}cos \left(\frac{\Theta}{2}\right)\\ \left|\left|\overrightarrow{e}\right|\right|sin\left(\frac{\Theta}{2}\right) \end{array}\right] \tag{5}\]  
where \(\left|\left|\overrightarrow{e}\right|\right|\) is the normalized rotational axis and \(\Theta\) is the rotation angle.  
The optimal transformation matrix of the sensing axes of each sensor can be determined by minimizing the loss function:  
\[J(A)=\sum_{i=1}^{n}w_{i}\left|\dot{\mathbf{u}}_{B}^{i}-A\dot{\mathbf{u}}_{R}^{i} \right|^{2} \tag{6}\]  
where \(A\) is the transformation matrix, \(\dot{\mathbf{u}}_{B}^{i}\) is the vector measurements in the body system, \(w_{i}\) is the weight of \(i\)-th \(\dot{\mathbf{u}}_{B}^{i}\) and \(\dot{\mathbf{u}}_{R}^{i}\) is the vector in the reference coordinate system.  
The loss function could be rewritten in terms of quaternion using an algorithm based on [PERSON]'s [20] method:  
\[J^{\prime}(q)=q^{T}Kq \tag{7}\]  
where the matrix \(K\) is defined as follows:  
\[K=\left(\begin{array}{cc}S-1\sigma&Z\\ Z^{T}&\sigma\end{array}\right) \tag{8}\]  
Matrix \(S\), scalar \(\sigma\) and the vector \(Z\) are given by:  
\[B=WV^{T} \tag{9}\]  
\[S=B^{T}+B \tag{10}\]  
\[Z=(B_{23}-B_{32},\;B_{31}-B_{13},B_{12}-B_{21})^{T} \tag{11}\]  
\[\sigma=tr(B) \tag{12}\]  
\(W\) and \(V\) are matrices having as entries the normalized components of frame versors is in the body and reference coordinates system, respectively:  
\[W_{i}=\sqrt{w_{i}}\dot{\mathbf{u}}_{B}^{i};\;V_{i}=\sqrt{w_{i}}\dot{\mathbf{u}}_{R}^{i} \tag{13}\]  
The result is an eigenvectors problem; in particular, it can be demonstrated [20], the quaternion associated with the optimal rotation is an eigenvector of matrix K. Therefore, the loss function in Equation (7) is a maximum if the eigenvector corresponding to the largest eigenvalue is chosen [20].  
Finally, the formula described in [20] was used to obtain the corresponding optimal transformation matrix.