Atrial Fibrillation Detection Algorithm Based on Manual Extraction Features and Automatic Extraction Features

Atrial Fibrillation is a common arrhythmia. RR interval irregularity and P wave disappeared and replaced by continuous f-wave is the two important ECG manifestations of atrial fibrillation. RR interval irregularity can also be reflected in other types of arrhythmia, P Wave or f wave is a weak signal, its feature point detection is difficult and shape features are difficult to grasp. Therefore, this paper proposes a method combining manual extraction features and neural network extraction features for atrial fibrillation detection. Experiments were performed using the MIT-BIH atrial fibrillation database. The ECG signals were first processed into equal-length data, and then the 180 dimensional time-frequency domain features were manually extracted and combined with the improved 128 dimensional features extracted by the neural network. The extracted feature input integration model, the sub-model includes Decision Tree, Random forest, GBDT, XGBoost, LightGBM.In the final experiment, the stacking model was used. The accuracy, accuracy, recall rate, F1 and AUC were 99.1%, 98.9%, 98.9%, 98.9%, and 99.4%. This method is better than the single model, which provided a very good measure for detecting atrial fibrillation.


Introduction
The aggravating trend of aging population and the factors that cause atrial fibrillation increase, the prevalence rate increases. Atrial fibrillation can be divided into: paroxysmal atrial fibrillation, persistent atrial fibrillation and permanent atrial fibrillation. Paroxysmal atrial fibrillation is extremely prone to develop permanent atrial fibrillation. In addition, some patients with atrial fibrillation have no obvious clinical symptoms, resulting in unconscious exposure of these patients to the risk of various critical illnesses, when clinical symptoms appear or sudden illness At times, it has often led to cardiovascular lesions, which greatly affect the health of patients. Therefore, early detection and prediction of atrial fibrillation and appropriate treatment to reduce the occurrence and pathology of atrial fibrillation have important clinical and social significance.
At present, the research on atrial fibrillation detection is usually limited in applicability. Various automatic detection of atrial fibrillation algorithms have been developed, from random forests [1], decision trees [2], support vector machines [3], convolution neural network [4][5][6] and recurrent neural network [7].According to the characteristics of ECG and its performance, the automatic detection algorithm of atrial fibrillation can be divided into atrial activity analysis, RR interval or a combination of the two [8].The early methods mainly used manual extraction of features, and the characteristics of the research are relatively few. In recent years, in order to improve the accuracy of recognition, more and more features are selected, and generally have better robustness. In the analysis of ECG data, a lot of research on feature extraction is carried out. The feature extraction technology based on expert knowledge is a special process. In the field of ECG signal analysis, such as RR interval, mean heart  [10][11][12].More than 150 features were considered in [13].
With the development of neural networks, more and more researches have begun to use neural networks to automatically extract features and classification. In particular, convolutional neural networks have received extensive attention in multi-dimensional signal processing with their powerful capabilities. R. Girshick [14] proposed a neural network classification algorithm to solve the automatic identification classification by establishing a multi-layer neural network model, and the accuracy and adaptability were greatly improved. Z. Deng [15] proposed a classification method of electrocardiogram arrhythmia based on deep two-dimensional convolutional neural network .Each ECG beat is converted into a two-dimensional grayscale image as the input data of the CNN classifier, and has a better effect than the other CNN models AlexNet and VGGNet. The classifier was evaluated using an electrocardiogram recording of the MIT-BIH arrhythmia database. Rymko J [16] first used DCNN for atrial fibrillation. With proper training, the convolutional layer of DCNN can learn to extract specific features. Pourbabaee B [17] Combine cnn-based feature learning mechanisms with other standard classifiers, support vector machines, and multi-layer perceptrons). Compared with the end-to-end CNN structure used for feature extraction and classification tasks, the multi-layer perceptron can improve the accuracy of patient detection, but the algorithm has the convergence of the patch and the global minimum, and the initial weight setting. Insufficient randomness. Schwab P [18] The RNN extended by the Attentional Mechanism enables it to infer which heartbeats the RNN focuses on to make decisions. Through the use of the attention mechanism, the model can maintain a high degree of interpretability while improving the performance of classification recognition. Ziyang H [19] established a lightweight neural network, LiteNet, which uses deep learning algorithm design to diagnose arrhythmias. Compared to other deep learning models with considerable precision, LiteNet requires less memory and lower computational cost. The Stanford University Machine Learning Group led by Rajpurkar P [20] used the DNNS to classify ECG data to diagnose 14 types of arrhythmias, and the network uses the time series of the original ECG signals as input, but does not have ECG signals. With heart beat as input, the model outputs a new forecast every second. However, this method requires the collection of massive data, and requires a senior expert to mark the heart beat. Guo Junwen [21] proposed a wearable ECG acquisition and arrhythmia detection system based on CAPSNET, but this paper only carried out classification and identification of five ECG signals, which did not detect AF signals.
Although many methods of machine learning have been used for atrial fibrillation detection, the accuracy of recognition is not high. Therefore, based on feature extraction, the accuracy of classification recognition is further improved by training integrated models.

Feature Extraction
The database used in the experiment was the MIT-BIH atrial fibrillation database. The MIT-BIH AF database has a total of 25 records; each record is about 10h, containing two lead signals. The information is stored in three files: hea header file, dat data file, atr\qrs annotation file, data. The frequency is 250HZ.The 00735 and 03665 signals do not contain dat files, so the data set of this experiment does not use these two files. The database contains four types: AFIB (atrial fibrillation), AFL (atrial flutter), J (junctional Yibo), N (other), atrial flutter and atrial fibrillation are two arrhythmias that are closely related to atrial function, each other Mutual transformation and independent of each other, the two are easy to confuse, and the data in the data boundary between the Yibo and the atrial flutter are relatively small, so this experiment only distinguishes between atrial fibrillation signals and non-other AF signals. The specific method is to divide all denoised data into the same length first, considering the timeliness and accuracy of data analysis. In this paper, all types except atrial fibrillation are marked as non-atrial fibrillation with a data length of 4s.The total amount of data is 212,375, and the type of atrial fibrillation accounts for about 40% of the total data.

Manual Extraction Features
The characteristics of the atrial fibrillation signal are not easily distinguished from the characteristics of other signals. Although the features extracted by the neural network can also achieve a good recognition effect, it is often difficult to achieve high precision. Based on the automatic extraction of features from the original neural network, the experiment newly added features to ensure the validity and extensiveness of the features. The commonly used parameters of ECG signals are sometimes domain parameters, frequency domain parameters and time-frequency domain parameters, and focus on extracting the characteristics of ECG signals from nonlinear angles such as symbol dynamics, phase space, Poincare and recursive graphs. parameter.
We perform waveform recognition of R wave, Q wave, S wave, P wave and T wave from each ECG record. QRS waveform detection and feature point positioning are the key points in ECG detection. The main method of QRS waveform detection algorithm It can be from frequency domain analysis, neural network, principal component analysis, support vector machine, and so on. By referring to a large number of literatures, this paper uses the signal-time domain-based differential threshold method proposed by Pan and Tompkins [22] to be simple and practical. Manually extracted 180-dimensional ECG signal features. The extracted features can be divided into the following categories: A. Statistical characteristics include the mean, median, variance, interval range, slope, kurtosis, maximum peak-to-variance ratio of the ECG signal segment, and also calculate the RR interval and ' RR interval. The above values and probability density estimates of the RR interval. In addition, the RR interval is also used. The number of peaks on the probability density of the RR interval and the energy change between the RR peaks. The calculation formula of the mean value of ECG signals: Among them i x for the amplitude corresponding to the sampling point of the ECG signal, n is the total number of all samples in the RR interval. The calculation formula of the variance of ECG signals: The calculation formula of RR interval slope:   The calculation formula of the variance of ' RR interval: The symmetry of the RR interval, the distribution center feature, and the variation of the adjacent RR interval are respectively reflected.
B. Morphological features are derived from the PQRST points detected in the ECG waveform. The QT interval (QT for short) includes ventricular depolarization and repolarization activation time, representing the total time course of ventricular depolarization and repolarization processes, which is the time from the start of the QRS wave to the end of the T wave. These features include the median, range and variance of the corrected qt interval , the QR and QRS widths, the slope of the QR, RS, and ST intervals, the depth of the q and s points relative to r, the amplitude difference of the tr wave, The ratio of the number of p waves to the number of r waves.
C. Heart rate variability (HRV) is a smile variation characteristic between successive heartbeat beats. HRV is an important reference index for studying cardiovascular diseases. HRV analysis methods mainly include time domain analysis, frequency domain analysis, and time-frequency analysis. Method and nonlinear analysis. Some features related to HRV are also included in our analysis. The time domain feature includes the percentage of heartbeats of the adjacent N normal RR intervals greater than X milliseconds as a percentage of the total heart rate (pNNX), and the logarithm of consecutive N intervals exceeding X milliseconds, PNNX (where X is Between 20 and 500 ms).The standard deviation of all normal RR intervals (SDNN), the mean of all normal RR intervals (NNVGR), the standard deviation of the mean of all normal RR intervals (SDANN), and the standard deviation of the difference between all normal RR interval lengths ( SDSD) and the root mean square value (RMSDD) of the difference between every two adjacent normal RR intervals. The frequency domain feature mainly calculates the power spectrum by the welch method.
D. signal processing features include through FFT (Fast Fourier transform) and DWT(Discrete wavelet transformPerform feature extraction to calculate power, band power, Shannon entropy, signal to noise ratio, and so on.
E. Other features include the use of Poincare's heart beat interval, the characteristics of approximate entropy and sample entropy based on atrial fibrillation detection, and the coefficient of variation of RR and RR interval differences.

Automatic Extraction Features
The neural network feature can automatically extract features. This experiment is based on the CNN network. The network structure is shown in the figure below. The number of fully connected layers is set to 128, that is, 128-dimensional features are extracted, and the previously extracted 180-dimensional features are extracted. The features are combined to form a new 308-dimensional feature set.

Experimental Process
In this paper, we extract the various ECG features and use the integrated model to improve the results of machine learning. Compared with a single model, this method can produce better prediction performance. The decision tree algorithm implements feature selection by generating a decision tree and branches of the decision tree. The nodes of the tree represent features, and the branches of the tree are feature subsets.

Figure 2. Experiment Flow Chart
Stacking is a layered model integration framework. Taking two layers as an example, the first layer is composed of multiple base learners, the input is the original training set, and the second layer model is retrained by using the output of the first layer base learner as a training set to complete The stacking model often uses a partitioning method similar to K-fold cross-validation for the original training set. The base model of Stacking selects decision tree, random forest, GBDT, xgboost, lightgbm, so the accuracy is the highest.
In the stacking model, we use 5-fold cross validation for the original training set, which is recorded as fold1, fold2, fold3, fold4 and fold5 respectively. At this time, we use the data of fold2-fold5 to train base model 1 and predict fold1, which is the meta feature of fold1 generated by base model 1; similarly, we use the data of fold1 and fold3-fold5 to train base model 1 and predict fold2, which is the meta feature of fold2 generated by base model 1; and so on, we get the whole original training of base model 1. The meta feature generated by the training set. In the same way, we use the same method to generate meta features for other base models, thus forming a complete set of meta features for the second level model training. Finally, we fit the base model to all the training sets.

Experimental Results
The evaluation of the experimental results was evaluated by accuracy, accuracy, recall, and f1. The experimental results are shown in the figure.
Accuracy: Where TP is to predict the positive class as a positive class, TN is to predict the negative class as a negative class, FP is to predict the negative class as a positive class number, and FN is to predict the positive class as a negative class. The random forest method is not suitable in this experiment, and the accuracy is only 73.4%. Compared with the random forest, SVM improves the accuracy to a certain extent, but still fails to achieve good results. If only a single convolution neural network and decision tree are used, the accuracy can reach 96%. In this paper, stacking model does not need too much This experiment compares the results directly with neural networks or a single classifier. The integrated learning model stacking is more accurate than other methods. As the most prominent aging heart disease, atrial fibrillation has never left the researcher's field of vision. Especially under the current conditions of medical advancement, the monitoring and diagnosis of atrial fibrillation has also put forward new requirements. In this paper, the MIT-BIH atrial fibrillation database was used to test the atrial fibrillation. It can be seen from the experimental results that the correct rate of detection is over 99%, indicating that the method is feasible.