Deep Neural Network Based Real Time Multi-Class Arrhythmia Classication in IoT-Cloud Platform

. An arrhythmia is a condition which represents irregular beating of the heart, beating of the heart too fast, too slow, or too early compared to a normal heartbeat. Diagnosis of various cardiac conditions can be done by the proper analysis, detection, and classification of life-threatening arrhythmia. Computer aided automatic detection can provide accurate and fast results when compared with manual processing. This paper proposes a reliable and novel arrhythmia classification approach using deep learning. A Deep Neural Network (DNN) with three hidden layers has been developed for arrhythmia classification using MIT-BIH arrhythmia database. The network classifies the input ECG signals into six groups: normal heartbeat and five arrhythmia classes. The proposed model was found to be very promising with an accuracy of 99.45 percent. The real time signal classification and the application of internet of things (IOT) are the other highlights of the work.


Introduction
The electrical activities of the human cardiac system are obtained from the electrocardiogram (ECG) signals using surface electrodes. A typical ECG signal consist of peaks and waves of different amplitudes and frequencies and the analysis of these signals plays an important role in heart disease diagnosis such as arrhythmia. In general ECG signal contains six different frequency components. Careful analysis of these components is to be carried out for qualified diagnosis and treatment. According to the Association for the Advancement of Medical Instrumentation (AAMI) [2], five kinds of cardiac diseases can be defined from the ECG signals viz: unknown beats (Q), normal (N), ventricular (V), supra-ventricular (S) and fusion of normal and ventricular beats (F). An irregularity in the rate or rhythm of the heartbeat is known as arrhythmia. During this condition, the heart can beat too fast (tachycardia) or too slow (bradycardia). Most arrhythmia are of not that harm, but at some extend they can be serious or even life-threatening. An irregularity in the rate or rhythm of the heartbeat is known as an arrhythmia. During an arrhythmia, the heart can beat too fast (tachycardia) or too slow (bradycar-2 dia). Around 2000, an enormous number of methods are proposed to deal with the matter of ECG beat classification. Artificial Neural Networks (ANN) are parallel comparable systems inspired by the biological neural networks. Deep learning is part of a broader family of machine learning methods based on ANN. A deep neural network (DNN) may be a sort of ANN with multiple layers between the input and output layers.
Cloud storage is a paradigm of computer data storage in which the digital data is stored in rational pools. Organizations and individuals buy or lease storage capacity from the providers to store user, organization, or application data.

Literature Review
During an arrhythmia, inconsistent blood flow can cause damaging effects to various organs of the human body especially, the brain and heart. In the daily life of a patient, arrhythmia is found to occur intermittently. If the patient is undergoing bedside monitoring or wearable healthcare monitoring, the corresponding manual inspection and analysis of the ECG signal recordings for a long period is tedious and time consuming. Therefore, the ECG signals can be analyzed and interpreted using computer assisted methods in medical applications. So, a Holter device is employed to capture these infrequent events and to record long term ECG data. Therefore, automatic recognition of abnormal heartbeats from a huge amount of ECG data is a salient and crucial task.
This paper is an extension of work done by Akhila Naz K.A et al [1]. The proposed DNN model with 3 hidden layers exhibit an accuracy of 99.45. In this paper the real time signal classification and the application of IoT in viewing the result from the DNN is proposed.
A reasonable amount of research has been dedicated to the advancement of automatic heart-beat classification by R.J. Martis et al and M.Llamedo et al. [2]- [3]. The works can be broadly classified into two categories, namely, 'intra-patient' and 'interpatient', also called 'class-oriented' and 'subject-oriented' respectively [3]. According to C.Ye et al. and M.Arif et al., both subsets of data can have part of the ECG recordings when the intra-patient paradigm separates the entire data-set into training and testing subsets, considering only the beat labels [4]- [5]. With this strategy, the classifiers usually produce bleak results. In clinical practice, the classification efficiency declines due to the variations among the individuals was shown by G.Garcia et al. [6].
Chazal et al. proposed an inter-patient automatic heartbeat classification while both the sub-sets i.e training and testing subsets were developed using different ECG recordings so that the variation from different individuals would be taken into ac-count and the classifier would clearly manifest the generalization ability [7]. It was found that one single lead classifier obtained an efficiency of 83 percent which was found to be the maximum accuracy. The specificity values were also found to be high with a value of 88.1 percent, but the sensitivity values were very low. Additionally, a patient specific automatic heartbeat classification was also proposed by Chazal et al. wherein 3 training a global classifier was done initially and to attune this global classifier, a local classifier was used [8].
Another approach proposed by M.H Hu et al. involved a fully mechanized configuration approach known as GE classifier [9]. The accuracy, sensitivity and specificity of this approach was 75.3 percent, 69.6 percent and 76.6 percent, respectively. A partially automatic mixture of expert's approach was utilized to arrive at these results. Apart from frequency domain, feature analysis of the ECG signals also provides appreciable perception of the signals. These analyses can be done by various signal processing methods like Wavelet Decomposition (WT) [2], [5], [10], Principal Component Analysis (PCA) and Independent Component Analysis (ICA) [5]. Various other classifier methods based on feature extraction methods are also carried out [8], [9], [11]  In DNN, the network is feed forward, which means there is no looping back of the data from the output layer. Initially, the DNN creates a cluster of virtual neural networks and assigns random numerical values, or 'weights', to connections (nodes) between them. The weights and inputs are multiplied and return an output whose value is between 0 and 1.
M.M. Al Rahhal et al. proposed a novel approach based on deep learning for active classification of ECG signals were a softmax regression layer is added on the top of the resulting hidden representation layer yielding the so-called DNN [12]. Here method for ranking relies on the DNN posterior probabilities to associate confidence measures such as entropy and Breaking-Ties (BT) to each test beat in the ECG record under analysis.
Aniruddha.J.Joshi et al. showed that the problem of class imbalance which is rife in biomedical signals have been overcome by a Holder-SVM detection algorithm using a novel hybrid arrangement of binary and multi-class SVMs with highest accuracy [13]. By integrating a 16-layer convolutional neural network (CNN), recurrent cells and attention module, a DNN model obtaining both spatial and temporal fusion of information from ECG signals has been developed by Qihang Yao et al. [14]. Another algorithm having four weighted hidden layers with biases in MLP, and a four-layer CNN has been developed by Shalin Savalia et al., which map ECG signals to different arrhythmia classes with a considerable accuracy has been proposed [15]. In this model, bigeminy features were easily mistaken for normal, FAV, VT, AF, and AFIB signals, which would lead to false positives. Therefore Deep learning becomes the most promising direction for cardiac abnormality detection.
A DNN for the heartbeat classification composed of 7 hidden layers and has been built empirically by G.Saninano et al. [16]. Along with the MITBIH dataset certain features has also been also extracted and given as the input to the classifier model. The model classifies the heartbeats into normal and abnormal beats.
The proposed system has a deep neural network classifier of three hidden layers for classifying arrhythmia into normal and five abnormal classes with promising efficiency parameters.
The cloud management can be access by the medical staff and a client user who wants to get the analyzed data, primarily through the web server. At first the web server will send the commands and request to the master server node. Master node 4 server controls the resource slave node server. After that, the slave node is responsible for the data storage. It can store the large amount of data for computing and returning the results to the master server [17]. Dimitra Azariadi et al proposed the cloud based ECG monitoring for diagnostic accuracy and cloud computing allows the analysis of data manageable in order to make improvements in personalized healthcare [18]. An algorithm for ECG analysis based on Discrete Wavelet Transform and classification based on Support Vector Machine for heartbeat diagnosis with highest accuracy and implemented it on an IoT-based embedded platform has been discussed by Zhe Yang et al [19].
ECG data are gathered using a wearable monitoring node and are transmitted directly to the IoT cloud using WiFi. Both the HTTP and MQTT protocols are employed within the IoT cloud so as to supply visual and timely ECG data to users. Nearly all smart terminals with an internet browser can acquire ECG data conveniently, which has greatly alleviated the cross-platform issue. This idea has been mentioned by Jose Granados et al [19]. Internet of Things (IoT) platforms applied to health promise to supply solutions to the challenges in healthcare systems by providing tools for lowering costs while increasing efficiency in diagnostics and treatment [20].

Proposed System
This section gives an overview of MIT-BIH arrhythmia database, signal processing steps implemented and the proposed DNN. Fig.1 shows the block diagram of the proposed system.

MIT-BIH Arrhythmia Data-Set
MIT-BIH arrhythmia database is a dataset compiled from ECG recording done for 24 hours carried out on 47 subjects. Subjects included 25 men, of ages ranging from 32 -5 89 years and 27 women of ages ranging from 23-89 years. The MIT-BIH arrhythmia database ECG records consists of two leads which were developed from different electrodes. The modified limb leads II (MLII) and VI, obtained by placing the electrodes on the chest, are the most common leads in the database. Initially, ECG data used as the input for the network where randomly chosen from the MIT-BIH dataset itself. This data where used for training and testing of the proposed model.

Real Time Signal Acquisition
Data acquisition is the process of sampling signals that measure real world physical conditions and converting the resulting samples into digital numeric values that can be manipulated by a computer. Three lead monitoring can be applied for use with both static and telemetry cardiac systems. The three lead systems are attached to electrodes which are applied to specific locations of the patient body. The AD8232 is an integrated signal conditioning block for ECG and other bio potential measurement applications. The real time signal acquisition is performed using AD8232 ECG modules and the three leads with electrodes as shown in Fig.2.

Signal processing
A new dataset, starting from the MIT-BIH arrhythmia database, has been created by applying the following processing steps to the ECG signals. The Python programming language has been used for all these processing, which were carried out on the VI lead of each subject of the MIT-BIH arrhythmia database.
Denoising. Patient movements or respiration may cause possible interference in power line and baseline variations which in turn can result in errors in the detection of ECG peaks. Such interference's can be removed by denoising. The ECG signals are usually manipulated by various kinds of noise signals, namely artifacts [15]. These 6 artifacts hinder the ready removal of the information of interest from the raw signal. The denoising section has been carried out using a band pass filter of frequency range [0.8 Hz -48 Hz]. This frequency range has been set based on baseline wander for the lowest frequency and power line interference for the highest frequency.
Peak Detection. Peak detection phase is useful in determining the ECG signal peaks that are of interest. Governing the positions of all peaks of interest found in the ECG signal is done by peak detection. The sectioning of the ECG signals is represented by P-wave and T-wave positions for the extraction of time-based features since the R-wave peak detection is used. The position of the ECG signal peaks which are of interest is obtained by applying a function wfdb () to the ECG signal. This is done by the Waveform Database Toolbox. This technique provides an easier way of QRS detection especially the R-wave detection since the structural form and high amplitude of QRS wave can be easily distinguished from the other parts of the ECG signals. Each R-peak detection corresponds to a single heartbeat. The Pan and Tompkins algorithm is used for QRS detection. In the proposed method only the R-peaks are detected, thereby the output annotation file contains annotations that indicate the Rwave peak.
Signal segmentation and Normalization. Signal Segmentation is done to categorize the ECG signal into single beats that will be classified as normal and different types of arrhythmia. After locating the R peaks, the ECG signals are then segmented into single heartbeats. A window of length 150 is used for segmentation. Then the signals are made more normal or regular by re-scaling into segments of same number of points and amplitude for easier mathematical computation. The signal is generally reduced into their canonical forms for easier mathematical processing.

The Proposed DNN
Generally for prediction, a DNN consists of an input layer for the raw descriptors X (i), an output layer and L hidden layers, (three or more). An overview of the proposed DNN is given in Fig.3. In detail, the proposed DNN has been developed using the Keras with Tensor-Flow back-end in the Python programming language. Performed in a wide set of trials, this DNN has been built empirically. The number of hidden layers, corresponding number of neurons that make up each layer, the activation function, the number of learning steps are the parameters that has been manually configured in each trial and the changes were noted. The classifier model accuracy is eradicated on the testing set for each manual configuration. After this arduous manual phase, the best classification performance was obtained with a DNN composed of three hidden layers, i.e. 300, 500 and 300 neurons, respectively. This DNN Classifier makes all the neural layers based on the activation function called ReLU which is an abbreviation for 'Rectified Linear Unit'. Mathematically, it is defined as Eq. (1) and visually, it looks like the following Fig.4. y = max (0, x).
(1) The aim of machine learning and deep learning is to make the predicted output as much as accurate as that of the actual output. This is also called as a Cost function(C) or the Loss function. The cost function used is Sparse Categorical Cross-entropy. This function is used when the classes are mutually exclusive (e.g. when each sample belongs exactly to one class) otherwise categorical cross-entropy is used, where one 8 sample can have multiple classes or labels. The formula for sparse categorical crossentropy (s -samples, c -classes, s in c -sample belongs to class c), p-probability is given in Eq. (2). f = -{log p(s \in c)} The goal is to find an optimal weight value to minimize the cost function and ensuring that the algorithms achieve accurate recognition of the model. To achieve this, different weight values are used by carrying out multiple iterations. This helps to finding the minimum cost. This process is called gradient descent. Gradient descent is mainly done to reduce the cost function. The direction of increase is along the gradient hence, the minimum point can be obtained moving in the opposite direction of the gradient. To minimize the loss function, the weighted parameters need to be updated. This is done by optimizers. Loss function informs the optimizer about the direction of its movement along the terrain to reach a global minimum, which is at the bottom of the curve, Eq. (3) defines the minimization of loss function.
where is the weight parameter, is the learning rate and J ( ) is the gradient of weight parameter .
The optimizer used within the network is Adamax type. Adamax is a variant of the Adam optimizer that uses the infinity norm, while the Adam optimizer itself uses the L2 norm for optimization. The softmax function is often used in the final layer of a neural network-based classifier. The training of such networks is done under a log loss or cross-entropy domain which gives a non-linear variant of multinomial logistic regression.
At the softmax regression layer, six nodes are employed for classification purpose, i.e. the ECG signals are classified into normal and five classes of arrhythmia. The labels denoting the six different classes are N -normal, L -left bundle block, R -right bundle block, V -ventricular block, A -atrial blocks and a -other arrhythmia. All the other types of arrhythmia are categorized in the class 'a'.

The Cloud data storage and accessibility
The Internet of Things (IoT) can be a system of interrelated computing devices, mechanical and digital machines, objects, animals or people who are given unique identifiers (UIDs) and also the flexibility to transfer data over a network without requiring human-to-human or human-to-computer interaction. Here the ECG data's from different locations are often stored within the developed cloud platform and may well be needed classification at any point of it slow. Node-MCU module is utilized because the processing further because the interfacing platform of information acquisition module, cloud and so the DNN model. 9 4 Results and Discussion

The Dataset
The MIT BIH dataset consist of a series of ECG data's named as a number list, that is . Each of these 48 records possess a duration of slightly more than half an hour [21], [22]. For each subject of the MIT-BIH database, the four pre-processing steps mentioned in the signal processing section, has been performed. These data are then randomly shuffled and then 80 percent of the data is used for training of the model and the remaining 20 percent for testing of the model. The length of the whole data used in modelling the proposed system is 1, 02,885 and thereby the length of the data used for training is 82,308 in which 65,846 beats are used for actual training and 16,462 beats are used for validation. The size of the remaining 20 percent of the actual data used for testing is 20,577.
Eventually, real time raw ECG data were collected from randomly selected people of different ages from 22 to 60. The ECG electrodes and AD8232 ECG module were used for the raw ECG sample collection.

Real Time Signal Acquisition
The real time ECG data were acquired using the AD8232 ECG module and the data's and waveforms are visualized in the COM ports of Arduino IDE. In order to view the output data's and waveforms initially Arduino board was connected with the ECG module. Fig.5. shows the mentioned outputs.

Dataset Preprocessing
The original signal of the subject 100 is taken as an example and is shown in Fig.6. The input signal is then allowed to undergo denoising processes using band-pass filter followed by a baseline removal. The peaks in the filtered signal are detected using waveform database toolbox. These signals are then normalized and segmented into beats by setting windows of definite length to the both sides of the detected peaks. Fig.6 shows the results obtained at each of the signal processing stages, i.e.: original signal, filtered signal, peak detected signal, segmented and normalized signal.

Deep Neural Network
A DNN model to classify six classes of arrhythmia has been developed. Classifier model designing was completed because of a number of trial and error methods. In each trial, the improvement in model has been manually configured by changing the number of hidden layers, nodes of hidden layers and the learning steps. The developed classifier has three hidden layers, along with the neuron arrangement of [300, 500 and 300], the learning and decay rate as 0.01 and 0.001 respectively with an Adamax optimizer. The output layer consist of softmax regression layer and the losses are calculated using categorical cross entropy function. Hundred number of epochs 11 are used for the training and testing process above and below this range various anomalies like over-fitting, under-fitting and other accuracy problems were encountered. The network layers and the parameters are described in Table 1. The accuracy and error graphs obtained after the 300 epochs, using the mentioned parameters for the proposed network is shown in Fig.7. In machine learning, especially in stratified classification, an error matrix known as confusion matrix is calculated, how an algorithm performs on a test dataset for which the true values are known is depicted by a table called Confusion Matrix. Confusion matrix helps in easy identification of one class being commonly mislabeled as another class. Confusion matrix is used for the computation of performance measures of classes. The confusion matrix for the developed model is shown in Fig.8. The performance matrix has been computed and the accuracy, sensitivity, and specificity of each of the classes obtained is shown in Table 2. From this data, the overall efficiency of the entire model is calculated by calculating the average of the accuracy, sensitivity, and specificity of all the classes and the values obtained are 99.45 percent, 93.16 percent and 99.35 percent respectively. To demonstrate the quality of the DNN in terms of accuracy, sensitivity, and specificity, comparative analysis was carried out on the same dataset using eleven other well-known classifiers [15].
Comparative analysis for multi-class arrhythmia classification denoted that the proposed DNN model achieved the accuracy, sensitivity and specificity values at 99.45, 93.16 and 99.35 percent respectively. To the best of our knowledge no other works have reported a multi class arrhythmia classification using deep neural network with the obtained accuracy level. Table 3 shows the results of the accuracy obtained for different algorithms used in multi class arrhythmia classification. Overall Accuracy CNN+RNN+LSTM [36] 81.5 Levenberg-Marquardt,Bayesian-Regularization [37] 93.8 Random Forest [38] 98.03 CNN [39] 98.30 Proposed DNN model 99.45

Adafruit IO
The output values of the Arduino monitor as well as the network are then send into Adafruit IO through WIFI connection and the data's are viewed in the IO platform. For sending these data's into Adafruit IO, Node-MCU board are used. Initially the board and the server is made connected using WIFI. Then the output data obtained from the ECG module is transmitted to the server through Node-MCU board.
In the Adafruit IO server page, two feed are created first. One for uploading the original ECG data values and the other for uploading the results of the classifier model. The first feed was named as "ecg" and the second one as "result". Since a full ECG waveform is formed in 8 seconds, and as each ECG beat contain 150 bits/values, initially while uploading the data to Adafruit IO, for one second only one bit of the whole data were uploaded and waveform was not visible. In order to get the whole signal information as like it is, the data's were uploaded as arrays, were each array were of size 75, in which it constitute have the number of actual data while the remaining half is occupied with commas. Therefore eight arrays of were appended and at one second each arrays containing 38 bit of information and 37 commas were uploaded. So after each eight seconds the data for a full ECG wave is uploaded and the 14 can be viewed as data itself. Since the data's are uploaded as array, waveform displayed will not be of the required type due to speed and time limitations while uploading.
After uploading the data in the feed, these data's are collected to the classifier model using python programming and the beats are classified accordingly. The classifier output is then send into the second feed named "result". Finally a dashboard is created in string type to view the status of outputs in the mentioned feeds in a single window. Figure 9 shows the dashboard created.

Conclusions and future work
In healthcare, biomedical and bioinformatics fields, classification is currently one of the emerging research topics, especially for arrhythmia detection. In this proposed system, a novel approach based on a DNN for the automatic classification of multi class arrhythmia been developed. The comparative analysis with several other classification methods shows that DNN networks are having highest accuracy, sensitivity and specificity for classifying the heart-beats in to normal and five classes of arrhythmia. The proposed model can differentiate the normal ECG beats from five classes of arrhythmia with promising accuracy, sensitivity, and specificity values of 99.45, 93.16 and 99.35 percent respectively, which indicates the efficiency of the proposed model is very promising. The real time signal acquisition and cloud based data accessibility's are the important highlights of the proposed system. Cloud based arrhythmia classifier will be a great boon for people around the world, instead of visiting a cardiac specialist and waiting for long hours to get the feedback for their checkup results separately.   Output data obtained in COM serial monitor and plotter of Arduino IDE.

Figure 6
The original signal of subject 100 of the MIT-BIH database and its ltered, peak detected and segmented form.

Figure 7
Accuracy and Loss of the network with dropout layer and Ada-max optimizer with a learning rate of 0.01. Classi er result viewed in the dashboard.