# Heart DT: Monitoring and Preventing Cardiac Pathologies Using AI and IoT Sensors
## 4 Testbed Setup of Heart DT
### ECG Datasets and Pre-Trained CNN Model Description  
The dataset used for training the neural network was derived from the combination of two public datasets: the MIT-BIH Arrhythmia Dataset [35; 36] and the MIT-BIH Atrial Fibrillation Dataset [37]. The first dataset contains ECG recordings of 47 subjects for a total of 48 ECG recordings each lasting 30 min. The recordings refer to different types of cardiac pathologies: normal sinus rhythm (N), paced rhythm (P), atrial fibrillation (AFIB), ventricular bigeminy (B), and sinus bradycardia (SBR). The recordings were digitized at 360 samples per second over a range of \(\pm 10\) mV.  
The second dataset consists of 25 ECG recordings of subjects with atrial fibrillation, in particular, AFIB, AFL, J (AV junctional rhythm), and N (used to indicate all other rhythms). Each recording has a duration of 10 h, and the signals were sampled at 250 samples within an interval of \(\pm 10\) mV.  
The combination of the two datasets is performed by preanalyzing the data, since the recordings, for each dataset, were made at a different sampling frequency (\(f_{s}\)). Therefore, to combine the data, the original sequences were resampled at a frequency of \(f_{s}=1\) kHz.  
Regarding the heart disease classes, the only class that the two datasets have in common is AFIB. To combine the two datasets uniformly, the N class related to MIT-BIH atrial fibrillation and the AFIB class related to MIT-BIH arrhythmia was removed altogether. Thus, the resulting classes from the combination of the two datasets are the following:  
* N: normal sinus rhythm;
* P: paced rhythm;
* AFIB: atrial fibrillation
* B: ventricular bigemy;
* SBR: sinus bradycardia;  
Figure 3: Single ECG signal.  
Subsequently, to train the neural network, each ECG recording is divided into 2 s segments for each class. Considering that a resampling of the ECG sequences has been performed, the input of the neural network consists of 2 s segments (equivalent to 2000 samples).  
The number of 2 s ECG sequences for each class is as follows:  
* N class, with 31,570 ECG recordings;
* P class, with 3608 ECG recordings;
* B class, with 1804 ECG recordings;
* SBR class, with 902 ECG recordings;
* AFIB class, with 150,157 ECG recordings;
* AFL class, with 2932 ECG recordings;
* J class, with 164 ECG recordings.  
For the data, 70% (learning dataset) is used as input to the network for training, while the remaining 30% (testing dataset) is used to test the accuracy of the previously trained model. The architecture of the CNN network used in this study is detailed in the papers by [PERSON] et al. [4; 5]. This network consists of 5 layers, and for each hidden layer, the network includes a 1D convolution layer, batch normalization, RELU layers, and pooling layers. For the output layer, we also have the softmax layer. Once extracted, the ECG recordings are sent to the CNN network for classification of cardiovascular diseases (CVDs) into the seven previously defined classes. The resulting model, which performs well as illustrated by [PERSON] et al. [5], can be used for inference on real ECG data recorded from any type of wearable IoT sensor, after a short preanalysis of the data.