A Wearable Heartbeats Classification System Based on A New Method: Selective-Mask Artificial Neural Network

— The electrocardiograph (ECG) signal is an essential biomedical human body signal that shows heart activity and can diagnose cardiovascular diseases. Many researchers investigate heartbeats detection and classification based on ECG to achieve a high-performance method. The main problem with improving performance is increasing the computation, such as in many existing methods. In this paper, a new artificial neural network (ANN) method named Selec-tive-Mask Artificial Neural Network (SMANN) is proposed to improve the performance with low computational processes. Furthermore, A new mixture of features from reused the QRS-detection stage features and the others features from the RR-interval and between-RR are used to decrease the computation for features extraction. The proposed method performance evaluation is based on the MIT-BIH Arrhythmia Database using MATLAB program for software evaluation moreover a hardware implementation. The proposed method’s promising results show high accuracy of 99.9224 %, and the total classification errors for the SMANN are 80 comparing with the 583 errors for the same data with traditional ANN. The method with low error assists the clinical decision-maker in diagnosing the long-time ECG signals or the real-time monitoring. It was implemented as a prototype wearable system using Node-MCU with the internet of things (IoT). The system can operate online patient monitoring and offline for heartbeats detection and classification.


Introduction
Globally, the major diseases that cause death are cardiovascular, with 31 % of all worldwide deaths, almost eighteen million deaths caused by cardiovascular diseases. In 2030, the number may reach 24 million because of the global growing populations [1]. Peoples die each year due to cardiovascular disease; arrhythmias are among the primary forms of these diseases [2]. Arrhythmia is a heartbeat abnormality with too fast, too slow, or irregular rhythm [3], [4], and it can be detected and classified by electrocardiograph (ECG) signal [5], [6]. The ECG is the tool for measuring the heart's electrical signal in time sequence. It is a simple and non-invasive tool that provides valuable health information about the heart [7]. Numerous studies for classification have been developed in recent decades. Detecting and classifying arrhythmias is an important topic in biomedical fields because it provides details regarding cardiovascular disease [8]. The ECG beats should be processed to find any cardiac anomalies. However, the long-time ECG signal processing from the hospital monitoring system or wearable healthcare for online monitoring is a big challenge for an individual, and it takes a very long time [9].
Automated arrhythmia classification provides excellent suitability for doctors and helps the patients for monitoring their conditions. Typically, it is not achievable in many regions because of financial and medical services issues. Reducing the demand for physicians and care providers encourages the need for a low-cost, safe, and automatic framework for wearable healthcare monitoring devices [9]. On the other hand, real-time or long-time monitoring systems are concerned with a single-lead ECG signal to allow the patients to have a natural life [10]. There are many challenges for arrhythmia classification: the selected section may not show the arrhythmia, the ECG signal is not constant like the ECG signal variability depending on age or gender, large data may cause classification errors, and the noise for ECG signal [9].
There are two main types of heartbeats classification techniques. The first type processes the raw ECG signal for a certain period (like 5 sec or 10 sec) and extracts the features according to this period. The second uses the beat or beats by beats from the ECG signal, and the extracted features depend on the beat's detection. The QRSdetection algorithms detect these beats. The arrhythmia classification algorithm based on QRS-detection is more popular than the ECG processing without beat detection [11]. The most presented classification methods depended on the highest energy waves (QRS) using the detection algorithm for ECG-segmentation [3], [8], [10], [12]- [26]. In contrast, [11], [27] presented an algorithm based on long-time ECG-signal analysis classification without QRS detection.
Different ECG databases like the MIT-BIH database are widely used for training, testing, and evaluating the performance of existing methods. The MIT-DIH arrhythmia database contains variable ECG signals, and variable arrhythmia types make this database used by many researchers [28]. It consists of 15 heartbeats types. The present methods classified the heartbeats into different types. Some methods classified only two types such as the atrial fibrillation and normal beats only [5], [20], normal and supraventricular beats as first-class (SVEB+) and the second-class ventricular ectopic and the fusion beats as (VEB+) [10], and normal and abnormal beats [12], [21], [22]. Whereas [3], [13]- [16], [18], [26], [29] designed to classify the database according to Association for the Advancement of Medical Instrumentation AAMI [Standard ANSI/AAMI/ISO EC57, 1998-(R)2008] [30]. Based on AAMI, the MIT-BIH arrhythmia database beats are categorized into five main types, as shown in Table 1. Finally, the methods [11], [17], [19] classified all types of the MIT-BIH arrhythmia database.
High accuracy and high complexity methods used different approaches such as deep neural networks [22] and deep-recurrent-neural-network with Long Short-Term Memory [20], one-dimensional convolutional neural network [3], [13], [29] and twodimensional convolutional neural networks [31]. Moderate accuracy and moderate complexity method presented a deep convolutional neural network based on features [12]. Also, a neural network used Long Short-Term Memory and Recurrent Neural Network [21] was proposed. Low complexity and moderate performance methods were presented like the Echo State Network [10], Artificial Neural Network [25], and Empirical Mode Decomposition [27]. High accuracy and moderate computation model used a Multilayer Perceptron Neural Network [16]. Low computational and moderate performance techniques presented dual fully connected neural networks [32]. On the other hand, High accuracy and low-computational techniques were presented, such as [11], [17], [26], and will be compared with the proposed method. Many methods have been proposed with high classification performance, but it is not easy to implement with their high computation. The big challenge for wearable (low computation) applications is improving the performance without adding more complexity [33]. Artificial neural network (ANN) is an essential machine learning technique for classification and recognition problems [34]. Adding more hidden layers, extracting new features, and increasing the number of neurons per layer are fundamental ways to improve the classification for the ANN. On the other hand, this improvement will add more computation with more complexity for the classifier. The main objective is designing and implementing a wearable device for heartbeats detection and classification at real-time monitoring and diagnosis using a new method named Selective-Mask Artificial Neural Network (SMANN). The method is high accuracy, low computation, and implementable. The SMANN will give the ANN a new dimension (selective or parallel) instead of the serial dimension for deep learning methods. SMANN does not consist of multi-layers like deep learning, high multiplication processes like convolutional, or tree with ANN used multi-design networks for each tree branch. Furthermore, this method is differed from ensemble neural networks [35] by using a single network with multi masks, and the inputs for each mask are divided based on its properties.
In section 2, the proposed method based on SMANN in detail will demonstrate. Then, the method performance is evaluated based on the software and the prototype system hardware using the database with results and discussion in section 3. Finally, the conclusions are summarized in section 4.

The Proposed Method
The proposed method can be divided into three main parts: QRS-detection, Features Extraction, and classification, as shown in Figure 1. The QRS-detection prepares the ECG signal by filters and heartbeats detection. The features are extracted from the QRS morphology, the between-RR, and the RR-interval. A new classification method is proposed based on ANN, and it is SMANN. Furthermore, the proposed method is implemented as a prototype heartbeats detection and classification system using Node-MCU with IoT for real-time monitoring and a microSD-card for an offline patient data logger after the evaluation using MATLAB.

QRS-Detection
A QRS-detection algorithm detects the heartbeats for the ECG signal. The algorithm constraints are real-time, low computation, and high accuracy. The QRS-detection algorithm in [7] is used as a detection method because the detection features are mixed with new features extracted before the classification stage. A (150 samples) moving average window filters the ECG signal to remove the noise and smooth the signal, as shown in equation (1).
Where: (Ef) The Filtered ECG signal and (E) The original ECG signal.

The Features Extractions
A new mixture features method is applied to achieve the purpose of the heartbeat classifier because the essential part of any classifier is the features extracted to enhance the performance. The features are divides into three-part. First, the QRS-complex has the most features for the ECG signal because, in the ECG signal processing operations, the QRS-complex is the highest energy part for the ECG signal. These are fourteen features extracted from the QRS shape using the detection algorithm in [7]. Second, the between-RR features are extracted four features from the ECG signal nearby the QRScomplex. The between-RR features are calculated from equations (2)(3)(4)(5), and Figure 2 shows these features.
Third, the RR-interval features are shown the regularity of the heartbeat and the heart rate. It determines the RR-before, RR-after, RR-after-average, RR-before-average, different RR, and the heart rate as six RR-interval features. The RR-interval features are calculated from equations (6-11), and Figure 2 shows these features.
• f19: RR before • f20: RR after • f21: The average of f19 • f22: The average of f20 • f23: The different RR after the average • f24: The average heart rate Where: bn: The heartbeat number. tQ: The Q wave time for the (bn) heartbeat. tR: The R wave time for the (bn) heartbeat. tS: The S wave time for the (bn) heartbeat. fs: The sampling frequency.

Classification
The human brain solves many problems using a logical operation depending on select the region of the problem to be solved. This logical brain operation can be used in machine learning to improve performance by using selective operation to separate the problem and its solutions. The ANN is one of the essential machine learning techniques for classification and recognition problems. A new method has been proposed based on a multi-range ANN. The new ANN proposed method named Selective-Mask ANN (SMANN) depends on the selection for the problem range to find the solution in this range. So, the input data are divided into multi-range based on a knowledge base.
The ANN weights and biases matrices are produced from training the network by the database. Different features are extracted from the database using different methods. These features are the inputs for training the ANN to classify these inputs. After training, the network weights and biases matrices are applied for all input features from the database. Single weights and biases matrices are produced from training for each network layer and applied for classification. Adding more features, using a new technique for extracting these features, and changing the network design, like adding more layers, are the procedure to improve the network performance. All these procedures are increasing the computation with improving the performance.
A knowledge base is created depending on the dominant inputs to divide the data with the same properties. This knowledge base is a starting basis for the ANN before the supervision learning or training. So, the ANN will not start to learn from zero. In the ECG signal, the heart rate and the heartbeat regularity are the two most properties that can divide the data into subtypes. The subtypes of heartbeats regularity are: regular and irregular, and the subtypes of heartrate are: normal, low, and high. The normal heart rate is from 60-120 bpm, the low heart rate is lowest than 60 bpm, and the high heart rate is the highest than 120 bpm. Figure 3 shows six ranges for the ECG database: regular-(normal, low, high), irregular-(normal, low, high). These subtypes numbers in Figure 3 according to the MIT-BIH arrhythmia database.

Fig. 3. The MIT-BIH arrhythmia database subtypes
The weight and bias matrices for the ANN can be called the mask for this network. The SMANN is produced multi masks for the same problem and same ANN design based on separating the features extracted from the database by the dominant properties to be selective. It applies each mask for the inputs (features) based on the selective property. Figure 4 shows a general diagram of the SMANN method for a single hidden layer and can be expanded for more hidden layers. weights and a one-dimension matrix for biases, as shown in Figure 4 with a different color. The SMANN has several distinct characteristics: • The mask dimension (hidden mask (m, n) or output mask (s, m)) for each layer is fixed for all inputs. • The number of hidden layers design should be constant.
• Based on the SMANN designer: ─ For all selective properties, the number of inputs (n), hidden neurons (m), and outputs (s) can be fixed using fixed masks. ─ Some inputs, hidden, and outputs neurons can be eliminated using zeros values for rows or columns of weight and bias matrix corresponding to the selective mask for any selective property.
In this paper, a feed-forward SMANN is designed with a single hidden layer. The hidden layer has 48 hidden neurons (m) and 24 input features (n). Also, the number of the masks is 6 (r): regular-normal, regular-low, regular-high, irregular-normal, irregular-low, and irregular-high. The outputs are five classes: N, S, V, F, and Q.
For all (l: 1-5 (s)) output neurons using one of the selective masks (k: 1,2, or 6 (r)).  s=5). The outputs of the hidden neurons are calculated from equations (12,13), then the classifier output is calculated from equations (14,15) to find the final classes from one of the five beats types. All equations are calculated for a single mask (k: 1,2, or 6 (r)) at a time, depending on the selective input features properties. The (k) value is a constant for each selective input; the (i) and (j) are all values to calculate the overall network equations to find the SMANN output for a single mask with constant (k). For this design, the classifier is low computational based on the low process.

The ANN and SMANN Evaluation
The MIT-BIH arrhythmia database is widely used because it consists of a variable ECG signal that is suffered from different types of noise. So, it is used for method performance evaluation. The database consists of two channels, 48 records with an 11bit resolution at 360 sampling rates. These records contain a variable QRS type variable heartbeats (15-classes) and variable noise. Because of this variability, this database is suitable for evaluation.
In this work, the number of heartbeats is 103,192 from 45 records excepted the records 102, 104, and 114 that are not included. The 45 records are lead-II ECG-signal. According to the knowledge base, these heartbeats are divided, as shown in Figure 3. According to the AAMI, five classes are 88,490 (N), 7,143 (V), 3,888 (Q), 2,876 (S), and 795 (F). The regularity property is extracted from the R and R time of the four RRbefore beats and one RR-after beat. So, this property is extracted from the RR-interval features. The heart rate is extracted directly from the average heart rate features (f24), as shown in equation (11).

Software Evaluation
The new method (SMANN) is performance evaluated and compared with the traditional ANN performance evaluation. First, the traditional ANN method with all input features without any selection is evaluated using the 103,192 heartbeats from 45 records. Second, the SMANN with selective input features is evaluated using the same heartbeats from the same records. These heartbeats are divided into six selective properties to train the SMANN and produce six masks for each selective property.
The parameters: true-positive (TP), true-negative (TN), false-total (FT), false-negative (FN), and false-positive (FP) were calculated to evaluate the performance. The FT is the most important parameter because a patient is diagnosed with the wrong heartbeat class. The performance is evaluated based on the overall Accuracy (Acc), Recall (Rec), Precision (Pre), and F1. The following equations (16)(17)(18)(19)(20) were calculated for both ANN and SMANN based on each class. The equation results are presented in Tables 2 and 3.
The equations (16)(17)(18)(19)(20) were calculated for the 103,192 beats to evaluate the algorithm performance and compare the results with the other methods. The method was trained, tested, and evaluated in a 2.6 GHz Intel Ci7 computer using 64-bit MATLAB 2020B. The proposed method's promising results show an Acc of 99.9224%, overall Rec of 99.9224%, and overall high Pre of 99.9222% (The overall Rec and Pre are the average weighted values). The total errors (FT) for the proposed method based on SMANN is 80 comparing with the 583 errors for the same method with traditional ANN. This low error leads to durability for diagnosing the patient's heartbeats and assists the clinical decision-maker for long-time or real-time ECG signals. Table 4 are summarized the evaluation performance comparison of the proposed method with other not a high computational algorithms using the same MIT-BIH arrhythmia database. The proposed method performance is better than the other methods, as the results described. These results are promising according to the accuracy and low computational.

Device Hardware Implementation
The Node-MCU (ESP8266) stands for Microcontroller Unit firmware development hardware. It is used for IoT projects because of the high performance, deep sleep, 128 KB RAM, and 4MB of flash memory than storing the data and programs. After the software evaluation, the proposed method was implemented using the Node-MCU and the same database to evaluate the resources, speed, and performance. Figure 5 shows the prototype system (using Olimex-EKG and Node-MCU) at run time with the mobile application and computer. For hardware evaluation, the data are used from the same 103,192 beats, and overall processing data are displayed by the computer using the serial port. At the same time, the diagnostic report (patient report) is uploaded to the mobile application through the IoT. The patient report consists of the detection and classification information. The report summarized the patient's ECG heart rate (HR), average HR, maximum and minimum (HR), the beats count of each one for the five diagnostic types (N, V, S, F, and Q), and the current beat class. At the same time, the patient report and the ECG original samples are stored in the device using the microSD-card for backup and offline analysis. The mobile application displays the patient report in real-time and controls the ON/OFF device through the IoT connection. Furthermore, actual cases were connected to the system using the Olimex-EKG, and the patient report results were promising for real-time heartbeats detection and classification.  Table 3, except for some missing results due to initialization of the program at starting. The implementation running times were calculated, and the average delay times for the first QRSdetection is 664 samples (1.84 s). The average time for the first classification is 2404 samples (6.678 s), and the average QRS-detection and classification delay are calculated with an average of 237 samples (0.658 s).
The proposed system based on the new method has several distinct characteristics: ─ The same features for the QRS-detection are reused for classification because it contains the most beats shape features. ─ The SMANN implementation is easy with multi masks (matrices); it is like the ANN with a new dimension for selective inputs. ─ The features are extracted according to a simple mathematical calculation, as shown in the previous equations. Serial port output System ─ Low computation method is implemented in wearable devices and IoT. ─ The device executes all processes except displaying the report using the mobile application. The processes include reading the ECG samples, detecting the QRS, classifying these heartbeats, sending the patient report, and storing the ECG samples with the report in a microSD-card. The device can work with and without an internet connection because the internet is used to display the patient report for real-time monitoring, and the device performs all other processes, as shown in Figure 6. ─ The ECG samples are stored and processed by the device, and the patient report is the only data uploaded for mobile applications using IoT. So, the device can work offline to store the patient ECG and report in the microSD-card.

Conclusion
The proposed system was designed based on a new method SMANN to improve the performance with low computation. The SMANN is an ANN design with multi masks for each layer. Each mask is applied to a corresponding input property. The input property is created from the knowledge base for the input data. The inputs for the network are features extracted from the ECG signal after filtering and QRS-detection. The features for QRS-detection are used for classification with adding new features. Moreover, this mixture of features is extracted based on the simple operation to reducing the processes.
The system was evaluated using MATLAB and implemented using the Node-MCU. The method was evaluated with high accuracy of 99.92 %, low errors of 80 errors only for the SMANN, and 583 errors for the exact data of the traditional ANN without selective inputs. Each classification error refers to a patient heartbeat error diagnosing. This number should be as low as possible for the healthcare application. A promising result for the proposed method compared to the existing methods. The implemented system is reliable compared with the MATLAB results based on errors and speed. For the device, the average delay time of heartbeat detection and classification is 0.658 Sec. The system can work online or offline because the device performs all processes using the microcontroller resources. The microSD-card is storing the patient report and the ECG samples for offline analysis.