# Foot-Mounted Inertial Measurement Units-Based Device for Ankle Rehabilitation
## 2 Materials and Methods
### Inertial Sensor
#### 2.1.2 Estimation of the Inertial Measurement Variable  
An MPU-6050 device was chosen for developing the rehabilitation device due to its commercial availability in local stores and low price. The MPU-6050 consists of six degrees of freedom (6 DOF), which combine a three-axis accelerometer and a three-axis gyroscope. The main characteristics of this component are 16-bit digital analog converters (ADC), and that the component can communicate by both SPI and I2C bus, which makes it easy to access the measured data. On the other hand, the accelerometer range can be set to \(\pm\)2 g, \(\pm\)4 g, \(\pm\)8 g, and \(\pm\)16 g, and the gyroscope range can be set to \(\pm\)250\({}^{\circ}\)/s, \(\pm\)500\({}^{\circ}\)/s, \(\pm\)1000\({}^{\circ}\)/s, and \(\pm\)2000\({}^{\circ}\)/s; for the best resolution, ranges of \(\pm\)2 g and \(\pm\)250\({}^{\circ}\)/s were selected. \[z_{ff}=\hat{z}_{ff}/\left\|\hat{z}_{ff}\right\|^{2} \tag{2}\]  
During the calibration procedure, at the foot flat position, the foot is at rest, and \(z_{ff}\) is nearly vertical. Then, \(y_{f}\) is calculated as follows:  
\[\hat{y}_{f}=z_{ff}\times x_{s}, \tag{3}\]  
\[y_{f}=+\hat{y}_{f}/\left\|\hat{y}_{f}\right\|^{2}\text{ for a left foot,} \tag{4}\]  
\[y_{f}=-\hat{y}_{f}/\left\|\hat{y}_{f}\right\|^{2}\text{ for a right foot} \tag{5}\]  
Similarly, \(x_{f}\) is calculated as follows:  
\[\hat{x}_{f}=z_{ff}\times x_{s}\times z_{ff}, \tag{6}\]  
\[x_{f}=\hat{x}_{f}/\left\|\hat{x}_{f}\right\|^{2} \tag{7}\]  
For each foot exercise, a strap-down integration of the angular velocity \(\omega\) is started that produces the rotation matrix \(R_{ff}(t)\). By transforming \(x_{f}\) to the reference frame, we calculate the pitch angle \(\alpha\):  
\[\alpha(t)=\frac{\pi}{2}-\sphericalangle\left(z_{ff},R_{ff}(t)x_{f}\right), \tag{8}\]  
\[=\arcsin(z_{ff}^{T}R_{ff}(t)x_{f}),\in\left[-\frac{\pi}{2},\;+\frac{\pi}{2}\right] \tag{9}\]  
Similarly, we calculate the roll angle \(\beta\):  
\[\beta(t)=\frac{\pi}{2}-\sphericalangle\left(z_{ff},R_{ff}(t)y_{f}\right), \tag{10}\]  
\[=\arcsin(z_{ff}^{T}R_{ff}(t)y_{f}),\;\in\left[-\frac{\pi}{2},\;+\frac{\pi}{2}\right] \tag{11}\]  
The IMU provides two information sources that allow the estimation of the angular position \(\theta\) of the IMU local coordinate system. The first is through the three-axis accelerometer signals \(\mathbf{g}=\) (gx, gy, gz), which measure the vector of the acceleration of gravity, and trigonometric relations are used to calculate one estimation for the angular position \(\theta\). The second is through the three-axis gyroscope, which measures the angular velocity \(\omega\), whose numerical integral with respect to time gives an approximation of the angular rotation since the beginning of the integration, and is used to compute a second estimation for the angular position \(\theta\). These means that in the first source, information is highly noisy due to the accelerations caused by vibrations that can occur in rehabilitation procedures. This makes it unreliable in short periods, but this same source is reliable on average over a longer period of time. The second source of information is very reliable in short periods, but accumulates offset errors as time progresses. For this reason, the MPU-6050 incorporates a digital motion processor (DMP), which is an internal processor that executes MotionFusion algorithms to combine the accelerometer and gyroscope data together to minimize the effects of the errors that are inherent in each sensor, avoiding having to compute the filters by an external processor. The DMP computes the results in terms of quaternions; it can also convert the results to Euler angles, and perform other filtering computations with the data as well [36]. The DMP eliminates the need to perform computationally expensive calculations on the Arduino side. The problem is that there is little information available on the inner workings of the DMP. This problem was addressed by using a library created by [PERSON] [37].