# Fog-Computing-Based Heartbeat Detection and Arrhythmia Classification Using Machine Learning
## 5 Results and Discussion
### Heartbeat Detection  
To better understand the performance of the heartbeat-detection module (HDM), we conducted a comparative evaluation with (1) the algorithm of [PERSON] (2017) (PT), as it is one of the earliest and the most established algorithm, (2) the algorithm of [PERSON], and [PERSON] (2018) (SSK), as it is also based on the KNN algorithm, and (3) on a naive algorithm implementation using the first-order difference technique (FOD), which does not require any dependencies on any algorithmic library, and thus can be supported by low-power embedded processors available in wearable devices. For each of the four algorithms, we measure the performance in terms of precision, recall, and F1 score, as defined in Section 4.2, using the ECG records of the MIT-BIH database. Note that our module, the HDM, uses 3% of the data of each recording as a training set, while the SSK module follows an inter-patient training approach and uses the complete record of patient 100 for training. In contrast, the PT and FOD modules do not require a training phase. Therefore, to make the comparison fair, all four algorithms were evaluated using the exact same input. For this reason, we used the 97% of the recordings of each patient as test set, excluding patient 100. In Table 2, we present the results of the comparative evaluation. The results indicate that HDM achieves a high level of precision, even higher than the PT algorithm, which is one of the most established algorithms in the bibliography, implying that almost all beats detected are correct. The results also indicate that HDM fails to detect only a very small number of beats, whereas the PT algorithm performs slightly better. For this reason, the resulting F1 score for HDM is slightly lower than that of PT. The results indicate that the PT module achieves a higher F1 score compared to our module. However, it is important to recall that our module is executed within the dedicated hardware core where the energy consumption is much lower in contrast to the PT algorithm that is executed within the generic core thus requiring much more power. Although the overall performance of the module proposed in this work is slightly lower than the one achieved by the state-of-the-art model, the important element to consider is that it can be executed within the dedicated core for hardware assisted pattern matching provided by the asymmetric multicore embedded processors (e.g., the NXP MPC8572E module ([PERSON] et al., 2018) and the Intel(r) Curie(tm) module ([PERSON] et al., 2018)). Given that the signal-processing module can also be implemented using hardware elements, the main cores of the embedded processors can be used for other computation and communication services required by the wearable device. Moreover, the power consumption of the HDM algorithm executed within the dedicated hardware core is extremely low, in contrast to the consumption achieved when executed in the main cores. Considering the evaluation conducted by \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Algorithm** & **Precision** & **Recall** & **F1 Score** \\ \hline
**HDM** & **0.987** & **0.921** & **0.952** \\ PT & 0.979 & 0.977 & 0.978 \\ SSK & 0.988 & 0.501 & 0.664 \\ FOD & 0.818 & 0.768 & 0.792 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Performance of the heartbeat-detection module (HDM), the Pan and Tompkins algorithm (PM), Saini, Singh and Khosla algorithm (SSK), and the algorithm based on the first order difference technique (FOD) in terms of precision, recall, and F1 score. [PERSON] et al. [49] using the Intel(r) Quark(tm) SE C1000 asymmetric multicore embedded processor operating at 32 MHz, the parallel broadcast mode of accessing the neurons of the pattern-matching engine enables the execution of the KNN algorithm in real-time--it requires about 3.2 ms to classify a sample, requiring a power of 15.24 mW. However, when HDM is executed in the x86 main core, the power consumption increases to 210.24 mW.