## 3 DoFs Angles Estimation
### Sensor Fusion and Orientation Estimation  
The sensor node orientation can be estimated either by integrating the angular velocities or by processing the accelerometer measurements and estimating the gravity vector. However, to avoid the accumulative errors due to the integration of the gyroscope measurements and to minimize the noise in the orientation vector derived from the accelerometer signal, both estimators are implemented and fused over a complementary filter [40, 41]. Although, there are improved versions of the complementary filter [42, 43, 44], we used this simpler version, which concludes to satisfactory results regarding the experimental test cases, while it also provides quick and accurate performance [45]. In the sequel, the estimation and filtering procedure that concludes to the calculation of links orientation is presented in detail. The simplest method to extract the orientation angles of an IMU-based sensor node is by integrating the measurements of its gyroscope adopting the first-order approximation of Taylor series:  
\[ \begin{split}\phi[n]=\phi[n-1]+\frac{\delta\phi_{g}[n]}{\delta t }T\\ \theta[n]=\theta[n-1]+\frac{\delta\phi_{g}[n]}{\delta t}T\\ \psi[n]=\psi[n-1]+\frac{\delta\psi_{g}[n]}{\delta t}T\end{split}  \tag{3}\]  
where \(\phi\), \(\theta\) and \(\psi\) are the roll, pitch and yaw rotations around \(y\)--the longitudinal, \(x\)--the transverse and \(z\)--the vertical axes of the sensor, and \(T\) is the sampling period. In our implementation the value of T is constant, but filtering with variable sampling periods can also be adopted. The rates of Euler angles that are presented as coefficients in Equation (3), are given by the first-order differential equations [30] as:  
\[ \begin{bmatrix}\frac{\delta\phi_{g}}{\delta t}\\ \frac{\delta\phi_{g}}{\delta t}\\ \frac{\delta\phi_{g}}{\delta t}\\ \end{bmatrix} = \begin{bmatrix}\frac{\delta\phi_{g}\delta\theta_{g}}{\delta t}& 1&\frac{\phi_{g}\delta\theta_{g}}{\delta t}\\ \frac{\delta\phi_{g}}{\delta t}&0&-\frac{\delta\phi_{g}}{\delta t}\\ \frac{\delta\phi_{g}}{\delta t}&0&\frac{\phi_{g}}{\delta t}\\ \end{bmatrix}\begin{bmatrix}G_{x}\\ G_{y}\\ G_{z}\\ \end{bmatrix}  \tag{4}\]  
where \(G_{x}\), \(G_{y}\), \(G_{z}\) are the measurements of the gyroscope for \(x\), \(y\) and \(z\) axis, respectively and \(s\) and \(c\) represent sine and cosine of the corresponding angle. The transformation from the raw gyroscope measurements with respect to the sensor body axis coordinate system to the fixed coordinate system is derived from the direction cosine matrix shown in Equation (4). This relation allowed to update the orientation of the upper limb link with time, improving also its accuracy, compared to the previous implementation [29], where we used the raw gyroscope measurements in the calculations. Using the raw measurements, we get the angular velocities with respect to the moving body frame and not the fixed 3-dimensional global frame that is defined. This is the reason which restricted us from testing successively the full range of the motions, which were presented in our previous work, and instead we presented the half range of motions, compared to the results that we will present in the sequel, in Section 4. The parameters \(\phi_{a}\), \(\theta_{a}\) and \(\psi_{a}\) are the orientation Euler angles that are estimated from the accelerometer measurements. Due to the discrete integration (Equation (3)), the errors and the sensor noise result to the angular error, known as drift. These orientation angles can be retrieved by identifying the direction of the gravity vector for a \(R_{y}(\phi)R_{x}(\theta)R_{z}(\psi)\) configuration [46] as:  
\[ \begin{split}\phi_{a}&=\text{atan2}\bigg{(}\frac{A_{x }}{A_{z}}\bigg{)}\\ \theta_{a}&=\text{atan2}\bigg{(}\frac{A_{y}}{\sqrt{A_ {x}^{2}+A_{z}^{2}}}\bigg{)}\end{split}  \tag{5}\]  
where \(A_{x}\), \(A_{y}\), \(A_{z}\) correspond to accelerometer measurements over \(x\), \(y\) and \(z\) axis.