# A Smart Motor Rehabilitation System Based on the Internet of Things and Humanoid Robotics
## 4 Framework Development
### Edge Processing Layer  
As shown in Figure 2, the ES server includes the MQTT broker and a custom software stack, which performs the following tasks:  
* Receiving the vital sign data transmitted from the smart ring via BLE connection. * Receiving the time-series transmitted from each IMU-based device via MQTT subscription. * Aggregating the time-series from different IMU-based devices into time windows of size \(T_{f}\) second. * Extracting statistical features, namely **mean**, **maximum**, **minimum**, and **standard deviation**, from each time window of the IMU data, and storing them in a database, which, in our implementation, is InfluxDB ([[https://www.influxdata.com/](https://www.influxdata.com/)]([https://www.influxdata.com/](https://www.influxdata.com/)) accessed on 1 December of 2024). * Computing second-level information from the statistical features. We focus on two types of information automatically extracted from IMU data: (_i_) identification of the type of exercise routine currently performed by each patient; and (_ii_) a repetitions count for that routine. Exercise identification is performed using an independent and modular application. We have implemented several traditional and deep ML algorithms, which serve as a library of options for the system administrator to choose the most suitable one for their specific context. Section 5 provides a quantitative comparison of the classification performance of the implemented algorithms. To count repetitions, we developed a simple algorithm to estimate the number of repetitions by identifying peaks in accelerometer signals inspired by the work in [28], assuming that each peak corresponds to a moment of maximum effort during the exercise. This approach treats the problem of exercise repetition detection as a task of finding local maxima in the signal shape. To focus on the signal features that are most relevant for predicting motion, we used accelerometer data from a single device. Now, the accelerometer measures acceleration along three axes (X, Y, Z). To obtain a unified signal that captures the overall motion intensity, we computed the acceleration magnitude, which can be defined as follows, for a device \(d\), at time \(t\) and without loss of generality:  
\[a_{d}(t)=\sqrt{\text{accelerometerX}_{d}(t)^{2}+\text{accelerometerY}_{d}(t)^ {2}+\text{accelerometerZ}_{d}(t)^{2}}. \tag{1}\]  
To reduce noise in the acceleration magnitude and make peak detection reliable, we applied a moving average smoothing technique with window size \(w\). Let \(W\) be the total \begin{table}
\begin{tabular}{c c} \hline \hline
**Feature** & **Device** \\ \hline Heart Rate & Smart Ring \\ Oxygen Saturation & Smart Ring \\ Acceleration Data (x, y and z) & IMU Device \\ Gyroscope Data (x, y and z) & IMU Device \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Features collected from IoT devices for patient monitoring in I-TROPHYTS. number of windows over which smoothing can be applied, in the dataset. We define the smoothed acceleration magnitude \(\bar{a}_{d}(t)\) as the collection of points \(\alpha(w)\) at a specific time \(t\),  
\[\alpha(w)=\frac{1}{w}\sum_{j=0}^{w}a_{d}(j)\, \tag{2}\]  
\[\bar{a}_{d}(t)=\left\{ \begin{array}{c}\alpha(w_{i})\qquad\forall\,i\in[1,W] \end{array} \right\}\,. \tag{3}\]  
Finally, we detect peaks in the smoothed acceleration magnitude \(\bar{a}_{d}(t)\), using a threshold value \(\tilde{\beta}\) and a minimum peak distance criterion \(\sigma\). Let \(\lambda\) be the total number of points in the dataset; we defined \(\tilde{\beta}\) as the mean of the smoothed signal over all time points,  
\[\tilde{\beta}=\frac{1}{\lambda}\sum_{t=1}^{\lambda}\bar{a}_{d}(t). \tag{4}\]  
Let \(t_{p}\) be the time index corresponding to a peak signal, and let \(\sigma\) be the distance between two peaks signals defined as \(|\bar{a}_{d}(t_{p_{i}})-\bar{a}_{d}(t_{p_{i-1}})|\). We define a peak as the maximum local point \(p(t)\) if all the following four conditions are satisfied:  
\[p(t)=\left\{