# Fog-Computing-Based Heartbeat Detection and Arrhythmia Classification Using Machine Learning
## 3 System Design  
We organize the components of the end-to-end system based on the fog-computing approach in three layers given their functionality and their physical proximity to the user. In particular, we have (1) the wearable device that is always connected to the user, (2) the edge device that is located within the house premises of the user, and (3) the cloud services. Figure 2 provides a graphical representation of the three layers and the corresponding components as well as their interaction using different communication technologies such as WIFI, bluetooth low-energy (BLE) wireless connection, and LORA. The wearable device is comprised of several hardware components such as the ECG sensors, the asymmetric multicore processor, the memory unit, the network interface, the battery and possible power nano-generator. In this work, the software is responsible for (1) collecting the ECG data from the analog-to-digital converter (ADC) based on a given sampling rate, (2) processing of the signal received from the ADC to reduce the noise and amplify the signal, and (3) detecting the heartbeats and classification of arrhythmias using hardware-assisted machine learning techniques. Other aspects of the software firmware such as the encryption, storage, and retrieval of ECG recorded sessions and ECG metadata, as well as the communication with the edge devices and the cloud platform, are not within the scope of this paper. The edge-device software is installed on the patient's device (either a smartphone/tablet or a fixed device; for instance, a computer in the patient's home) and is connected to both the wearable device and the cloud services. The edge device communicates with the wearable device over a well defined API via a secure bluetooth low-energy wireless connection. It has internal storage space for storing the data collected from the ECG sensor and is capable of processing them, allowing for additional (and, typically, more elaborate) computation to that performed in the wearable device. It can also generate alerts, sent to the user either in small packages or in batch mode. As with the wearable device, data stored within the edge device are cryptographically encrypted, and message exchanges across the different layers are always performed in a secure and encrypted manner. Finally, the cloud services offer all the necessary features to facilitate authentication, authorization, access control, asynchronous notifications, data integration with electronic health records, and other services relying on privacy-preserving data integration. In this work, we focus on the software executed on the wearable device, and specifically on the processing and analysis of the data collected from the ECG sensors that are conducted either within the wearable or with the edge device. The processing and analysis of the ECG data is based on three modules:  
1. Signal-processing module --The first module is responsible for processing the signals collected from each ECG sensor lead to reduce the noise and amplify the signal (see Section 2). The goal is to have a well extracted ECG morphology, with as little information loss as possible. The module produces _ECG records_ composed of a number \(n\) of _channels_, each channel corresponding to a recording received from a specific ECG sensor lead, therefore composing an \(n\)-dimensional vector. The elements of the channels represent the amplitude of the signal at any given time, these are called _samples_. This module is executed within the wearable device. More specifically, all the signals initially pass through a _bandpass filter_ to reduce the influence of muscle noise, 60 Hz interference, baseline wander, and \(T\)-wave interference. The desirable passband to maximize the \(QRS\) energy is approximately 5-15 Hz [27]. It is implemented with a cascade of low-pass and high-pass filters to achieve a 3 dB passband from about 5-12 Hz, reasonably close to the desirable passband. Subsequently, a _derivative filter_ processes the output to provide the \(QRS\) complex slope information.