# Lightweight Ensemble Network for Detecting Heart Disease Using ECG Signals
## 3 Methodology
### Proposed ECG Signal Classification Method  
An algorithm combining MobileNetV2 and BiLSTM was developed for classifying arrhythmia data. MobileNetV2 classified the arrhythmia data, and BiLSTM maintained the sequence data to improve the performance of the arrhythmia classification model. A diagram of the MobileNetV2-BiLSTM algorithm for classifying arrhythmia data is shown in Figure 6.  
The data ratio was the highest with 283 NSR data and the lowest with 103 LBBB data. The balance data may cause overfitting problems, because the number of data is insufficient. To solve this problem, data were added using the matching pursuit algorithm in this study. Figure 5: Scalogram was used to investigate the frequency characteristics of the ECG signals. A higher voltage of the signal corresponded to a clearer scalogram result. **(a)** ECG signal; **(b)** scalogram of the ECG signal. Figure 6: Diagram of the proposed algorithm. The input data consisted of four classes, and a MATLAB-based digital filter was used for preprocessing. The matching pursuit algorithm was used for data augmentation. MobileNetV2-BiLSTM was applied in the data classification process. The matching pursuit algorithm was developed to decompose signals in order to understand their characteristics. During the decomposition of the signal to be analyzed, the time and frequency domains are simultaneously considered by applying the wavelet transform or Fourier transform. When a signal is added, the matching pursuit algorithm first determines the length of the signal to be added. Subsequently, a signal that most closely reflects the original signal is generated. At this time, the minimum square error (MSE) is used. A smaller MSE corresponds to a higher degree of similarity to the original signal. In the above formula, \(g_{0}\) represents a basic signal, and \(a_{0}\) represents a signal with a minimized MSE. R(\(t\)) represents the signal remaining after the original signal is decomposed using \(g_{0}\). A matching pursuit function can be applied to the original signal to generate several signals with small MSE values. MobileNetV2 extracts random features from the input data. Figure 7 shows the MobileNetV2-BiLSTM structure. The input size was 227 \(\times\) 227 \(\times\) 3. The data size was changed to 114 \(\times\) 114 \(\times\) 32 by applying a stride of 2 \(\times\) 2 in the first convolutional layer. BN and ReLU functions were applied, and subsequently, depth-wise convolution (3 \(\times\) 3 \(\times\) 1), BN, the ReLU function, and convolution were applied to reduce the amount of computation. MobileNetV2 contains 16 blocks, and all the blocks were implemented in the same manner, as shown in Figure 8.  
Because sequence data processing is difficult with general neural networks, a special recurrent neural network was used for BiLSTM. Each LSTM layer has three gates that transmit or control data and can learn by considering the gradient decay problem. LSTM obtains the information of all the cells over time. However, data cannot be learned after the cell in which the current learning is in progress. BiLSTM is an improved version of LSTM, in which forward propagation and backpropagation are used to learn information implied in the past and future, respectively. Consequently, this model can handle time-series data more efficiently. Figure 9 shows the structure of the BiLSTM model. Figure 7: MobileNetV2-BiLSTM structure for classifying data. ECG data are input to BiLSTM through a convolution operation and classified in the FC layer. MobileNet V2 and BiLSTM were combined by Matlab-based Network designer. The first LSTM layer was used to calculate the sequence information at the current time. The second layer was used to read the same sequence in the reverse direction and add reverse sequence information to extract meaningful features of the input data. The output value between the LSTM layers was transmitted to not only the adjacent unit but also the input of the next LSTM layer.