2.2.3. Second Stage: Measurement of Angle

The quaternions for the forearm, upper arm, and reference from the first stage were denoted by *qFA*, *qUA*, and *qR*, respectively.

$$q\_{FA} = \begin{bmatrix} q\_{F0} & q\_{F1} & q\_{F2} & q\_{F3} \end{bmatrix} \tag{15}$$

$$q\_{UL} = \begin{bmatrix} q\_{U0} & q\_{U1} & q\_{U2} & q\_{U3} \end{bmatrix} \tag{16}$$

$$q\_R = \begin{bmatrix} q\_{R0} & q\_{R1} & q\_{R2} & q\_{R3} \end{bmatrix} \tag{17}$$

If the upper arm is completely static, it is possible to calculate the joint angle from the initial and final quaternion of the forearm sensor. However, as the upper arm sensor may move with the movement of the forearm, the actual angle between the upper arm and forearm can be found by using the quaternion of two sensors placed on the forearm and upper arm. Considering this, the quaternion corresponding to the angle (*θ*1) between these two sensors was found using Equation (18).

$$q\_{\rm LIF} = q\_{\rm LIA} \times q\_{\rm FA}^{\*} = \begin{bmatrix} q\_{\rm LIF0} & q\_{\rm LIF1} & q\_{\rm LIF2} & q\_{\rm LIF3} \end{bmatrix} \tag{18}$$

The angle (*θ*1) between the forearm and upper arm sensors was obtained from the quaternion *qUF* using Equation (19).

$$\text{Angle } (\theta\_1) = \left[ \text{At} \\ \text{an2} \left( \left( 1 - (q\_{\text{UF2}}^2 + q\_{\text{UF3}}^2) \right) , \ 2 \left( q\_{\text{UF0}} q\_{\text{UF3}} + q\_{\text{UF1}} q\_{\text{UF2}} \right) \right) \right] \times 57.3 \tag{19}$$

Moreover, the impact of the movement of the upper arm could be found by using Equation (20).

$$q\_{\rm UFR} = q\_{\rm UF} \times q\_{\rm R}^\* = \begin{bmatrix} q\_0 & q\_1 & q\_2 & q\_3 \end{bmatrix} \tag{20}$$

The more precise joint angle (*θ*2) was obtained from the quaternion *qUFR* using Equation (21).

$$\text{Joint Angle, } \theta\_2 = \left[ \text{Atom2} \left( (1 - (q\_2^2 + q\_3^2)), \, 2(q\_0 q\_3 + q\_1 q\_2) \right) \right] \times 57.3 \tag{21}$$

## 2.2.4. Filtering

An accelerometer can accurately calculate roll and pitch angles for a stationary object on Earth. If the sensor moves, acceleration will alter rotation computation. Additionally, the adjacent magnetic fields' impact causes the magnetometer's results to be inaccurate. Therefore, filtering is quite important, and this particular design filters the final angle. The data filtering process was carried out using a fourth-order Butterworth filter.

#### **3. Results and Discussion**

The effectiveness of the proposed algorithm is evaluated and discussed in this section.

## *3.1. Joint Angle Measurement*

The performance of the proposed joint monitoring algorithm was first tested to obtain the elbow joint angle of the rigid body using two sensors, one in the forearm and another in the upper arm, shown in Figure 3.

The forearm sensor was moved for five consecutive trials, while the upper arm sensor attached to the rigid body was in a static posture. Each time, the forearm was moved around 40◦, and the respective joint angle was around 140◦. Through the use of the WitMotion software, the raw motion data from the accelerometer, gyroscope, and magnetometer was recorded and gathered. The accelerometer, gyroscope, and magnetometer raw data were collected at 10 samples per second. Following that, the accelerometer and magnetometer sensor data were subjected to a second step of calibration. Then the accelerometer, gyroscope, and magnetometer data were used to calculate quaternion for both sensors, and after that, the joint angle created by the rigid body was calculated using Equation (19). Two electro-goniometers (EGs) were attached with the forearm and the upper arm of the rigid body to measure the joint angle at the same time (shown in Figure 1c) and the angle calculated using the two EGs was considered as the reference value. The WitMotion software itself calculated the orientation of the sensors using the KF. The joint angle from the proposed algorithm (PA) and calculated from the KF outcomes of WitMotion software (WM) for two sensors were compared with the measurement of joint angle from two EGs.

The performance of the proposed algorithm (PA), using two sensors, was evaluated with respect to the angle measurement value of the EGs and the angle measured from the KF outcomes of WitMotion software (WM) in terms of root mean square error (RMSE), which are presented in Table 3. Figure 4 shows joint angle graphical representations obtained from the proposed algorithm with two sensors and WitMotion outcomes for five different trials. In this case, the RMSEs for PA and WM were 0.26◦ and 0.43◦, respectively. It can be seen

that the proposed joint angle measurement system using two sensors and the Madgwick filter gives a more accurate estimation in this case.

**Figure 3.** Joint angle (two sensors).

**Table 3.** Angle measurement comparison (RMSE in degrees) between the proposed algorithm (PA) and WitMotion (WM).


**Figure 4.** Measured angle from proposed algorithm (PA) and WitMotion (WM) using two IMUs.

In the subsequent case, three sensors were used for more precise measurement of the joint angle between the forearm and the upper arm. The forearm of the body was also moved for four separate trials, where the forearm was moved by approximately 30◦, 45◦, 60◦, and 90◦ in these four trials, respectively, and the upper arm was moved by 30◦ in every trial. During the movement of the forearm of the rigid body, shown in Figure 5 (also shown in Figure 1c), the upper arm remained in a stationary position. After the predefined movement of the forearm, the movement of the upper arm was executed. In each trial, the forearm and the upper arm were moved five times, and with the rotation of the upper arm, the final rotation of forearm was shifted to 60◦, 75◦, 90◦, and 120◦ in the four trials, respectively. Thus, in these trials, the joint angles between the forearm and the upper arm were approximately 150◦, 135◦, 120◦, and 90◦.

**Figure 5.** Joint angle (three sensors).

In each case or trial, the angle between the forearm and upper arm was calculated from the data of the two EGs attached to the forearm and upper arm of the rigid body. The angle calculated with the EGs was considered to be the reference value. Additionally, the raw data from the accelerometer, gyroscope, and magnetometer were collected and used as the input of the proposed algorithm (PA) after executing the calibration process. Three sensors provide three orientations in quaternion form, and using Equations (15)–(21), the more accurate joint angle between the forearm and upper arm was calculated.

In the first trial, at first the forearm was moved by about 30◦, and then the upper arm was moved by about 30◦. Thus, the angle was approximately 150◦ between the forearm and upper arm. The angles calculated from the EGs, PA, and WM are presented in Table 4, and Figure 6 shows joint angle graphical representations obtained from the PA and WM for the first trial. In the second trial, the forearm was moved by about 45◦, and then the upper arm was moved by about 30◦. Thus, the angle was approximately 135◦ between the forearm and upper arm. The angles calculated from the EGs, PA, and WM are presented in Table 5, and Figure 7 shows joint angle graphical representations obtained from the PA and WM for the second trial.


**Table 4.** RMSE (◦) of the joint angle (first trial).

**Figure 6.** Measured angle using proposed algorithm (PA) and WitMotion (WM) (first trial).


**Table 5.** RMSE (◦) of the joint angle (second trial).

**Figure 7.** Measured angle using proposed algorithm (PA) and WitMotion (WM) (second trial).

In the same way, the outcome of the third and fourth trials is given in Tables 6 and 7, respectively, and graphically represented in Figures 8 and 9, respectively. In the third trial, the forearm was moved by about 60◦, and then the upper arm was moved by about 30◦. Additionally, in the fourth trial, the forearm was moved by about 90◦, and then the upper arm was moved by about 30◦.


**Table 6.** RMSE (◦) of the joint angle (third trial).

In these four trials, the RMSEs for the PA and WM were calculated with respect to the joint angle calculated using EGs, and all the results were compared. The calculated RMSEs for the joint angle using the PA were 0.46◦, 0.10◦, 0.18◦, and 0.03◦, respectively, and for the WM, the RMSEs were 1.19◦, 1.97◦, 1.40◦, and 0.29◦, respectively. The comparison of the RMSE between the PA and WM showed that the proposed joint angle measurement system using the Madgwick filter gave a more accurate estimation for all the trials. Moreover, the RMSE resided within the clinically acceptable threshold of 5◦ in all cases. There are two spikes during each motion of all the trials, which was only mentioned in Figure 6. This problem was developed as different sensor units' data alter differently while in motion. The experiments were conducted under the same environmental conditions, and the same posture was used for this experiment. Table 8 shows a performance comparison between several existing studies and the proposed algorithm, and for this comparison table, articles only with artificially developed structures were considered.


**Table 7.** RMSE (◦) of the joint angle (fourth trial).

**Figure 8.** Measured angle using proposed algorithm (PA) and WitMotion (WM) (third trial).

**Figure 9.** Measured angle using proposed algorithm (PA) and WitMotion (WM) (fourth trial).


**Table 8.** Performance comparison.
