An E ﬃ cient Algorithm for Cardiac Arrhythmia Classiﬁcation Using Ensemble of Depthwise Separable Convolutional Neural Networks

: Many algorithms have been developed for automated electrocardiogram (ECG) classiﬁcation. Due to the non-stationary nature of the ECG signal, it is rather challenging to use traditional handcraft methods, such as time-based analysis of feature extraction and classiﬁcation, to pave the way for machine learning implementation. This paper proposed a novel method, i.e., the ensemble of depthwise separable convolutional (DSC) neural networks for the classiﬁcation of cardiac arrhythmia ECG beats. Using our proposed method, the four stages of ECG classiﬁcation, i.e., QRS detection, preprocessing, feature extraction, and classiﬁcation, were reduced to two steps only, i.e., QRS detection and classiﬁcation. No preprocessing method was required while feature extraction was combined with classiﬁcation. Moreover, to reduce the computational cost while maintaining its accuracy, several techniques were implemented, including All Convolutional Network (ACN), Batch Normalization (BN), and ensemble convolutional neural networks. The performance of the proposed ensemble CNNs were evaluated using the MIT-BIH arrythmia database. In the training phase, around 22% of the 110,057 beats data extracted from 48 records were utilized. Using only these 22% labeled training data, our proposed algorithm was able to classify the remaining 78% of the database into 16 classes. Furthermore, the sensitivity ( S n ), speciﬁcity ( S p ), and positive predictivity ( P p ), and accuracy ( Acc ) are 99.03%, 99.94%, 99.03%, and 99.88%, respectively. The proposed algorithm required around 180 µ s, which is suitable for real time application. These results showed that our proposed method outperformed other state of the art methods.


Introduction
ECG signals can be easily acquired by putting one's finger on the sensor for about 30 s [1]. There are at least two types of important information contained in the ECG signal, including those related to health or biomedical [2][3][4] and those related to the person identification or biometrics [5][6][7]. Due to its convenience, many ECG classification algorithms have been developed, including handcraft [4,8,9] and machine learning [10][11][12][13][14][15] methods. The handcraft method is rather difficult to utilize on non-stationary signals, such as ECG, while machine learning methods normally require high computational resources. Due to its high accuracy, the machine learning method is preferable compared to the handcraft method. However, an efficient algorithm is required to minimize the computational requirements while still maintaining its high accuracy.
If the feature extraction and classification stages are done separately, SVM can be used and optimized using particle swarm optimization (PSO) [10]. As presented in [10], after supervised training was conducted using 500 beats, the model can classify 40,438 test beats into five classes with accuracy of 89.72%, outperforming the other methods such as kNN or radial basis function (RBF). Nevertheless, the quality of this classification can still be improved in terms of increasing the number of classes and/or accuracy. For example, discrete orthogonal Stockwell transform (DOST) could be used during feature extraction followed by principal component analysis (PCA) to reduce feature dimensions [13]. As shown in [13], after supervised training was conducted on 23,996 beats, the remainder 86,113 test beats could be classified into 16 classes with better accuracy of 98.82%.
Another promising method for improving efficiency is by combining both feature extraction and classification stages using MLP [26] and CNN [27]. For example, in [27], a neural network model containing three layers of CNN and two layers of MLP was proposed. The input of this model is a raw ECG beat signal containing 64 or 128 samples centered on the R-peak. While the number of ECG beats used for training is kept at minimum at 245 and the testing beats is set to 100,144, it can achieve accuracy of 95.14% to classify five classes. In [28], autoencoder was utilized with a rather good result but it needs to fairly evaluate the performance with and without denoising. Moreover, the deep networks configuration could be further optimized to reduce computational time.
Although many researches have been conducted, an efficient algorithm for cardiac arrhythmia classification is still required. Therefore, the objective of this paper was to simplify the overall process to lower the computational cost, while maintaining high accuracy. A neural network model presented in [27] was adopted and modified to now classify 16 classes as in [13]. The performance of our proposed algorithms was evaluated using number of classes, prediction stages, and accuracy.

1D Convolutional Neural Network and Its Enhancement
In this paper, we use two stages of ECG classification, namely beat segmentation and classification. For classification purposes, CNN could be used as stated in [27,29]. Although CNN hyperparameters such as number of filters, filter size, padding type, activation type, pooling, backpropagation, still have to be done intuitively or by trial and error, there are still some techniques that can be used to reduce the amount of trial and error attempts to achieve the best results. Further enhancement to the CNN could be done using All Convolutional Network (ACN) [30], Batch Normalization (BN) [31]. Depthwise Separable Convolution (DSC) [32], ensemble CNN [33], which are further elaborated in this section. Out of various methods for CNN enhancement, DSC has the greatest effect on decreasing training time, while ensemble CNN enables further improvement on the classification rate.
ACN is used to replace pooling layer with stride during convolution. Pooling or stride is used for downsampling as CNN output parameters are less than the input parameter. In our case, the CNN input parameter is set to 256, while the output parameter is set to 16. Normally, the last or output layer of CNN uses the SoftMax activation function to determine the output class based on its highest probability. To reduce the number of layers, pooling layer could be replaced with stride during convolution [30].
Input normalization is required to solve internal covariate shift, i.e., the change in the distribution of network activations due to the change in network parameters during training. Without normalization, this will slow down the training iteration or even stop the iteration before reaching adequate accuracy. To solve this issue, BN can be conducted for each training mini-batch [31]. To reduce computational cost, BN could be conducted during the convolution process before nonlinear activation, such as rectified linear unit (ReLU). On the other hand, DSC could be used to reduce the number of parameters and floating points multiplication operation, with negligible performance degradation [34]. DSC could be performed on one layer or a group of layers of CNNs.
Another thing that must be considered in designing the CNN model is the implementation of the Flatten layer before the Fully Connected (FC) layer. Even though Flatten technically can be replaced by the AveragePool layer, these two techniques differ in terms of execution time and the final results obtained. The Flatten process does not require any further calculations, it only changes the arrangement of parameters in the last layer, while AveragePool must perform arithmetic operations to get the average value of each group in the last layer according to its position. The next effect of Flatten causes more neurons connected to FC, in comparison to the number of neurons produced by AveragePool which is obviously related to the number of arithmetic operations at the FC layer. It should be noted that the number of neurons in the Flatten layer represents all local features on the last layer without having to be combined in the average value.

1-D CNNs
As described in [27,29], during the forward propagation, the input map of the next layer neuron will be obtained by the cumulation of the final output maps of the previous layer neurons convolved with their individual kernels as follows: where conv1D(·, ·) is 1-D convolution, x l k is the input, β l k is the bias of the k-th neuron at layer l, s l−1 i is the output of the i-th neuron at layer l − 1, ω l−1 ik is the kernel (weight) from the i-th neuron at layer l − 1 to the k-th neuron at layer l. Let l = 1 and l = L be the input and output layers, respectively. The inter backpropagation delta error of the output s l k can be expressed as follows: where rev(·) flips the array, and conv1Dz(·, ·) performs full convolution in 1-D with K − 1 zero padding. Lastly, the weight and bias sensitivities can be expressed as follows:

All Convolutional Network
All Convolutional Network (ACN) [30] is utilized by removing the max pooling layer and replacing it with convolutional stride. As a result, the computational cost will be reduced, as it removes several layers as well as reducing the floating point operation on the convolution operation. For example, conv stride = 1 continued with max pooling 2 could be replaced with one layer, i.e., conv stride = 2 with an almost similar result.
Let f denote a feature map produced by some layer of a CNN, while N is the number of filters in this layer. Then p-norm subsampling with pooling size m (or half-length m 2 ) and stride r applied to the feature map f is a 3-dimensional array s( f ) with the following entries: where g(h, w, i, j, u) = (r · i + h, r · j + w, u) is the function mapping from positions in s to positions in f representing the stride, p is the order of the p-norm ( p → ∞ represents max pooling). If r > m, pooling regions do not overlap. The standard definition of a convolution layer c applied to the feature map f is given as: where θ are the convolutional weights, σ(·) is the activation function, typically a rectified linear activation ReLU σ(x) = max(x, 0), and o ∈ [1, M] is the number of output features of the convolutional layer. From the two equations, it is evident that the computational cost will be reduced.

Batch Normalization
Batch Normalization (BN) is intended to avoid non-linear saturation or internal covariate shifts causing a faster learning process [31]. The Batch Normalization allows much higher learning rates and reduces dependence on the initialization process. It can also act as a regularizer to reduce the generalization error and to avoid overfitting without the implementation of dropout layer. To reduce computation, the Batch Normalization is carried out directly after the convolution and before ReLU. ReLU before BN can mess up the calculations due to the non-linear nature of ReLU. Suppose we have network activation as follows: where ω and β are learned parameters of the model, and g(·) is the nonlinear activation function such as sigmoid or ReLU. Since we normalize ωu + β, the bias β can be ignored since its effect will be cancelled by the subsequent mean subtraction. Therefore, Equation (7) is replaced with: where the BN transform is applied indenpendently to each dimension of x = ωu, with a separate pair of learned parameters.

Depthwise Separable Convolution
In addition to the implementation of BN, the convolution part can also be further optimized, for example by using depthwise separable convolution (DSC) to reduce the computational costs by reducing the number of arithmetic operations while preserving the same final results [32,34,35]. This technique is applied with changes in filter sizes 3, 1, and 3, respectively. In addition to DSC, the size of the stride in the third convolution should be set to be greater than one, for example 2, 3, or 4, allowing the downsampling process to be implemented within the convolution process, instead of on a special layer such as the MaxPool layer [30]. DSC [34] splits the convolution into two calculation stages, i.e., depthwise and pointwise, as follows:

Proposed Ensemble of Depthwise Separable Convolutional Neural Networks
Traditional methods of ECG classification are varied in stages, including four, three, and two. The four stages are beat detection morphology feature extraction, feature dimension reduction, and classification, as stated in [13,36]. The three stages are beat detection, feature detection, and classification [10]. Moreover, the two stages of classification are beat detection and classification [27,37], in which the feature extraction stage is combined with classification. In [38], one stage was used for arrhythmia detection using 34 layer CNNs. However, it cannot be directly compared to our proposed algorithm as they used a different database with 12 heart arrhythmias, sinus rhythm, and noise for a total output of 14 classes. This paper proposes a two-stage ECG beat detection, as one patient might experience a normal beat and another arrhythmia beats as described in the MIT-BIH database. Furthermore, as will be explained in Section 5, the beat detection and segmentation require minimum computational time while improving the classification process. In this section, beat detection and segmentation, and ensemble of Depthwise Separable CNNs consists of around 34,719 train parameters with 21 layer CNNs are explained.

Beat Detection and Segmentation
In this paper, beat detection, QRS detection, or R-peak detection are performed based on analysis of gradient, amplitude, and duration of the ECG signals similar to [39]. R-peak detection of ECG signals can be done through wavelet transforms with a detection accuracy of more than 99% [39,40]. R-peak detection was performed on 48 records of the MIT-BIH database. With a 360 Hz sampling rate, each record contains 650,000 samples or a duration of 30 min [41]. Each sample is a conversion of a range of 10 mV using an 11-bit ADC [41]. Figure 1 shows examples of ECG pieces of 3000 samples or 8.33 s from the 2nd, 18th, and 36th records. The RR intervals on ECG chunk from the 2nd and 36th files tend to be uniform, while the RR interval on the ECG chunk from the 18th file looks more diverse. Hence, the R-peak detection and the RR interval measurement affect the beat segmentation process. Appl. Sci. 2020, 10, x FOR PEER REVIEW 6 of 17 Figure 1. The ECG chunk contains 3000 samples from 3 files, i.e., the 2nd, 18th, and 36th files. The vertical axis is the voltage in mV, while the horizontal axis is time with a scale of 500 samples or 1388 s. The text on the horizontal axis contains the type of beat, and its R-peak position, for example, /: 1608, means that the beat is Paced Beat (see Table 1) with R-peak position at the 1608th sample from 650,000 samples in the 2nd file.
In this paper, after R-peak detection, beat segmentation starts from , in which is the RR-interval right before the detected R-peak, while is the RR-interval right after the detected R-peak. This automatic segmentation window is necessary to ensure that there is only a single beat or R-peak in each segment. The maximum number of samples taken for each segment is 256 points which is equivalent to a duration of 256/360 s or 711 ms. The MIT-BIH database used a sampling rate of 360 Hz, so the 256 sample segment size will be more than adequate as the typical RR interval is around 500 ms [42]. Figure 2 shows the example of our proposed automatic beat segmentation. In our segmentation method, if the RR-interval is too short, or there is more than one R-peak at the segment, then zeropaddings are performed to keep the segment size to 256 samples with only one R-peak. If required, this segment size could be downsampled to 128 or even 64 samples to further reduce the computational cost. However, there will be a slight decrease in the classification accuracy. More experiments are conducted on the sample sizes and its accuracy in the next section. Figure 1. The ECG chunk contains 3000 samples from 3 files, i.e., the 2nd, 18th, and 36th files. The vertical axis is the voltage in mV, while the horizontal axis is time with a scale of 500 samples or 1388 s. The text on the horizontal axis contains the type of beat, and its R-peak position, for example, /: 608, means that the beat is Paced Beat (see Table 1) with R-peak position at the 1608th sample from 650,000 samples in the 2nd file.
In this paper, after R-peak detection, beat segmentation starts from 1 4 L i to 3 4 R i , in which L i is the RR-interval right before the detected R-peak, while R i is the RR-interval right after the detected R-peak. This automatic segmentation window is necessary to ensure that there is only a single beat or R-peak in each segment. The maximum number of samples taken for each segment is 256 points which is equivalent to a duration of 256/360 s or 711 ms. The MIT-BIH database used a sampling rate of 360 Hz, so the 256 sample segment size will be more than adequate as the typical RR interval is around 500 ms [42]. Figure 2 shows the example of our proposed automatic beat segmentation. In our segmentation method, if the RR-interval is too short, or there is more than one R-peak at the segment, then zeropaddings are performed to keep the segment size to 256 samples with only one R-peak. If required, this segment size could be downsampled to 128 or even 64 samples to further reduce the computational cost. However, there will be a slight decrease in the classification accuracy. More experiments are conducted on the sample sizes and its accuracy in the next section.

Ensemble CNNs
Each segmented ECG beat can be replicated into three beat sizes, i.e., 64, 128, and 256 samples. The 64 and 128 samples were the downsampled version of the original 256 beats segmented automatically as explained in Section 3.1. In total, we have three CNN configurations with a difference only in layer 1 (input size), i.e., 64, 128, and 256. After the training and testing phase, the three outputs from three CNNs were ensembled using the averaging method.
Using ensemble CNN by averaging, it can improve further the accuracy by reducing the variance [33]. In our proposed algorithm, we calculate the average of all tensor SoftMax from 3 CNNs as shown in Equation (13)

Ensemble CNNs
Each segmented ECG beat can be replicated into three beat sizes, i.e., 64, 128, and 256 samples. The 64 and 128 samples were the downsampled version of the original 256 beats segmented automatically as explained in Section 3.1. In total, we have three CNN configurations with a difference only in layer 1 (input size), i.e., 64, 128, and 256. After the training and testing phase, the three outputs from three CNNs were ensembled using the averaging method.
Using ensemble CNN by averaging, it can improve further the accuracy by reducing the variance [33]. In our proposed algorithm, we calculate the average of all tensor SoftMax from 3 CNNs as shown in Equation (13) and Figure 3. Let l = L denote the last layer of the CNN model, and s L k is the output of the k-th neuron at the output layer, and let m = 1, . . . , M denotes the number of CNNs to be ensembled. The final output of the ensemble CNN using averaging can be calculated as follows: Appl. Sci. 2020, 10, x FOR PEER REVIEW 8 of 17 of the -th neuron at the output layer, and let = 1, … , denotes the number of CNNs to be ensembled. The final output of the ensemble CNN using averaging can be calculated as follows:

Implementation and Experimental Setup
This section discusses the ECG datasets from the MIT-BIH arrhythmia database, the computational platform used for simulation, and the proposed ensemble CNN algorithm.

MIT-BIH Arrhythmia Database and Computing Platform
In this paper, ECG datasets from the MIT-BIH arrhythmia database [41] are used for the performance evaluation of our proposed ensemble CNN algorithms. This database is the widely used database for testing classification performance. It contains 48 records, in which each contain twochannel ECG signals for 30 min duration selected from 24 h recording of 47 patients. The database consists of 19 types of ECG beats, in which 16 of them are related to cardiac arrhythmia.
From the total MIT-BIH database, we only used around 110,157 ECG beats out of 112,647 total beats which were categorized into 16 classes as shown in Table 1. These beat samples were then further divided into 23,999 beats for training and 86,158 beats for testing. As described in Figure 2, the total of 110,157 beats was also replicated with zero padding. Therefore, there are two sets of experimental data, with and without zero padding.

Implementation and Experimental Setup
This section discusses the ECG datasets from the MIT-BIH arrhythmia database, the computational platform used for simulation, and the proposed ensemble CNN algorithm.

MIT-BIH Arrhythmia Database and Computing Platform
In this paper, ECG datasets from the MIT-BIH arrhythmia database [41] are used for the performance evaluation of our proposed ensemble CNN algorithms. This database is the widely used database for testing classification performance. It contains 48 records, in which each contain two-channel ECG signals for 30 min duration selected from 24 h recording of 47 patients. The database consists of 19 types of ECG beats, in which 16 of them are related to cardiac arrhythmia.
From the total MIT-BIH database, we only used around 110,157 ECG beats out of 112,647 total beats which were categorized into 16 classes as shown in Table 1. These beat samples were then further divided into 23,999 beats for training and 86,158 beats for testing. As described in Figure 2, the total of 110,157 beats was also replicated with zero padding. Therefore, there are two sets of experimental data, with and without zero padding. The proposed algorithm was implemented in Python with Tensorflow with GPU [43] and Keras libraries [44]. The experiments were performed on a computer with Intel Core i7-7700 CPU with a total of eight logical processors, memory of 8 GBytes, graphic card Nvidia GeForce GTX 1060 6 GB DDR5, using Microsoft Windows 10 64 bits operating system. The experiments on the training and testing time using this computing platform is elaborated further in Section 5.

Depthwise Separable and Ensemble of Depthwise Separable CNN Models
Using a heuristic approach and optimization, the proposed CNN model contains 21 layers. Figure 4 shows the comparison between the CNN model with and without depthwise separable CNN in terms of structure and number of train parameters. As shown in the figure, the total train parameters are less with the implementation of depthwise separable. Hence, the training time will be faster for depthwise separable CNN. Table 2 shows the depthwise separable CNN model summary along with its total parameters' calculation. The proposed algorithm was implemented in Python with Tensorflow with GPU [43] and Keras libraries [44]. The experiments were performed on a computer with Intel Core i7-7700 CPU with a total of eight logical processors, memory of 8 GBytes, graphic card Nvidia GeForce GTX 1060 6 GB DDR5, using Microsoft Windows 10 64 bits operating system. The experiments on the training and testing time using this computing platform is elaborated further in Section 5.

Depthwise Separable and Ensemble of Depthwise Separable CNN Models
Using a heuristic approach and optimization, the proposed CNN model contains 21 layers. Figure 4 shows the comparison between the CNN model with and without depthwise separable CNN in terms of structure and number of train parameters. As shown in the figure, the total train parameters are less with the implementation of depthwise separable. Hence, the training time will be faster for depthwise separable CNN. Table 2 shows the depthwise separable CNN model summary along with its total parameters' calculation.    The depthwise separable CNN as described in Table 2 was used to improve the training time, while the ensemble of depthwise separable CNN, as depicted in Figure 5, was used to improve further its classification accuracy. The input layer size is 256 representing the raw ECG beat waveform, while the output layer size is 16 representing the number of classes as described in the MIT-BIH database (see Table 1). There is a group of layers repeated three times, i.e., layer 5 to 9, layer 10 to 14, and layer 15 to 19. These five layers contain three convolution layers with filter size of 5, 1, and 5, respectively. Layer 5 to 7 is configured according to the DSC algorithm. Moreover, layer 2, 7, 12, and 17 were using stride 4 to replace the function of pooling layer according to the ACN algorithm. Suppose that we use an ensemble of three DSC, the total number of parameters will be three times larger, i.e., 34,719 train parameters, which is still less than the train parameters without DSC, i.e., 47,600. As is discussed in Section 5, the use of ensemble improves its accuracy. The depthwise separable CNN as described in Table 2 was used to improve the training time, while the ensemble of depthwise separable CNN, as depicted in Figure 5, was used to improve further its classification accuracy. The input layer size is 256 representing the raw ECG beat waveform, while the output layer size is 16 representing the number of classes as described in the MIT-BIH database (see Table 1). There is a group of layers repeated three times, i.e., layer 5 to 9, layer 10 to 14, and layer 15 to 19. These five layers contain three convolution layers with filter size of 5, 1, and 5, respectively. Layer 5 to 7 is configured according to the DSC algorithm. Moreover, layer 2, 7, 12, and 17 were using stride 4 to replace the function of pooling layer according to the ACN algorithm. Suppose that we use an ensemble of three DSC, the total number of parameters will be three times larger, i.e., 34,719 train parameters, which is still less than the train parameters without DSC, i.e., 47,600. As is discussed in Section 5, the use of ensemble improves its accuracy.

Results and Discussion
This section elaborates beat segmentation and detection, the training process, experiments on the CNN model with and without DSC, the experiments on zero padding and various ensemble configurations, and benchmarking with other algorithms.

Results and Discussion
This section elaborates beat segmentation and detection, the training process, experiments on the CNN model with and without DSC, the experiments on zero padding and various ensemble configurations, and benchmarking with other algorithms.

Experiment on ECG Beat Segmentation and Detection
The ECG beat segmentation and detection algorithm described in [39] were implemented in the computing platform described in Section 4. We evaluated the algorithm on the 48 records of the MIT-BIH database. The experiment was repeated 10 times for each record and then the average time was calculated. The experimental result showed that, on average, it requires around 26 µs to detect and segment one ECG beat with zero padding. This result justified the use of two stage ECG classification as proposed in this paper, as the segmentation time is minimal compared to the improvement achieved in the classification stage. Figure 6 shows the training history for 1000 epochs using the CNN model as described in Table 2 and for the training data described in Table 1. There is a gap of accuracy around 1.5% between training and testing. The accuracy curve for validation shows that the best accuracy can be achieved at epoch of 50. The training accuracy has convergent tendency reaching almost 100% with fluctuation around 99.7%. This result is achieved for a zero-padding input size of 256. Figure 6 shows the training history for 1000 epochs using the CNN model as described in Table  2 and for the training data described in Table 1. There is a gap of accuracy around 1.5% between training and testing. The accuracy curve for validation shows that the best accuracy can be achieved at epoch of 50. The training accuracy has convergent tendency reaching almost 100% with fluctuation around 99.7%. This result is achieved for a zero-padding input size of 256.  Table 2. The blue curve is the classification accuracy of the training data. The orange curve is the classification accuracy of the testing data. There is a visible gap around 1.5% between the two curves.

Performance Measures
We used the performance measure of sensitivity, specificity, positive predictivity, and accuracy as shown in Figure 7 and described in [45]. Sensitivity is the rate of correctly classified classes among all classes. Specificity is the rate of correctly classified nonevents among all events. Positive predictivity is the fraction of real events in all detected events. Finally, the accuracy is the percentage of correctly predicted classes.  Table 2. The blue curve is the classification accuracy of the training data. The orange curve is the classification accuracy of the testing data. There is a visible gap around 1.5% between the two curves.

Performance Measures
We used the performance measure of sensitivity, specificity, positive predictivity, and accuracy as shown in Figure 7 and described in [45]. Sensitivity is the rate of correctly classified classes among all classes. Specificity is the rate of correctly classified nonevents among all events. Positive predictivity is the fraction of real events in all detected events. Finally, the accuracy is the percentage of correctly predicted classes.  Table 3 shows the experimental result for CNN models with and without depthwise separable algorithms as described in Figure 4 for the input size of 256 samples. The total parameters were 47,600 and 11,573 for without and with DSC algorithm, respectively. The training time for 1000 epochs and the accuracy of both CNN models were comparable. This could be due to the use of GPU during training, in which a faster training time was not apparent in the result. When CPU only was used during training, a faster training time was evident for the CNN model with DSC. Nevertheless, the smaller parameters in the CNN model with DSC provided a faster computation time during the classification stage compared to the model without DSC. Therefore, the CNN model with DSC is used in our next experiments. Zero padding in ECG beats was required due to there being a possibility that the distance  Table 3 shows the experimental result for CNN models with and without depthwise separable algorithms as described in Figure 4 for the input size of 256 samples. The total parameters were 47,600 and 11,573 for without and with DSC algorithm, respectively. The training time for 1000 epochs and the accuracy of both CNN models were comparable. This could be due to the use of GPU during training, in which a faster training time was not apparent in the result. When CPU only was used during training, a faster training time was evident for the CNN model with DSC. Nevertheless, the smaller parameters in the CNN model with DSC provided a faster computation time during the classification stage compared to the model without DSC. Therefore, the CNN model with DSC is used in our next experiments. Zero padding in ECG beats was required due to there being a possibility that the distance between RR intervals is less than 256, as well as to avoid more than one R-peak being detected in one segment (see Section 3.1). Furthermore, zero padding has a positive impact on the performance, in terms of sensitivity, specificity, positive predictivity, and accuracy, as evidenced in Table 4. The best performance is highlighted in bold. As shown in Table 4, our proposed ECG segmentation of 256 samples with zero padding has the highest performance. Hence, zero padding is used in our next experiments.  In the ensemble configuration, the CNN model was trained separately. For example, the [256 256 256] ensemble is trained three times. Therefore, the training time is increased by three times with increased accuracy. As expected, the classification stage (testing time) will be increased around three times as well but within the range of 150 µs. Hence, we can conclude that the proposed two stage ECG classification requires around 180 µs for QRS detection and classification using the computing platform described in Section 4.1.

On the Effect of Depthwise Separable CNN
For more detailed evaluation, the [256 256 256] ensemble confusion matrix is shown in Table 6. The performance assessment of each class using the [256 256 256] ensemble configuration can be seen in Table 7, in which the ECG class is sorted from the largest to the smallest available samples in the MIT-BIH database. As can be seen from the table, fewer samples of data cause inaccurate classification.
In conclusion, the [256 256 256] ensemble achieves the best performance in terms of sensitivity, specificity, positive predictivity, and accuracy.  Truth  0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15   N  0  63,521 4  13  70  2  79  11  36  3  44  6  2  0  1  0  3  L  1  22  5211  0 Table 8 shows the benchmarking results with another 10 algorithms, in terms of number of classes (some of the algorithms did not classify all 16 classes), methods, number of prediction stages, and accuracy. In terms of accuracy, refs. [46] and [47] have the closest but still a lower accuracy than our proposed algorithm, i.e., 99.61% and 99.80%, respectively. Note that, ref. [46] only performs classification for eight classes, while [47] only performs classification for four classes, while we perform classification for sixteen classes. Hence, it is evident that our proposed algorithm with the [256 256 256] ensemble of CNNs outperforms the other algorithms. Particularly, we managed to classify all 16 classes from the MIT-BIH database, while reducing the number of stages to two (lower computational cost), and achieving highest accuracy.

Conclusions
In this paper, we presented an efficient algorithm for cardiac arrhythmia classification using the ensemble of depthwise separable convolutional neural networks. First, we optimized the beat segmentation by taking ECG samples centered around the R-peak. Second, we used all convolutional network, batch normalization, and depthwise separable convolution, to achieve the best accuracy while reducing the computational cost. Finally, we ensembled three depthwise separable CNNs by averaging three CNNs of 256 sample input size. Performance evaluation showed that our proposed algorithms achieved around 99.88% accuracy in 16 classes classification. The proposed two-stage ECG classification required around 180 µs, which can be implemented in a real time application. Future work will include the implementation of the current CNN on GPU to speed up its training, as well as to vary the input segment for various patients, the use of different databases, the use of other optimization methods, and the implementation in clinical application validated by a cardiologist.