{'fraction_non_alphanumeric': 0.03637031594415871, 'fraction_numerical': 0.020573108008817047, 'mean_word_length': 4.598457583547558, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
QRS peak detection for heart rate monitoring on Android smartphone

In this study, Android smartphone is used for heart rate monitoring and displaying electrocardiogram (ECG) graph. Heart rate determination is based on QRS peak detection. Two methods are studied to detect the QRS complex peak; they are Peak Threshold and Peak Filter. The acquisition of ECG data is utilized by AD8232 module from Analog Devices, three electrodes, and Microcontroller Arduino UNO R3. To record the ECG data from a patient, three electrodes are attached to particular body’s surface of a patient. Patient’s heart activity which is recorded by AD8232 module is decoded by Arduino UNO R3 into analog data. Then, the analog data is converted into a voltage value (mV) and is processed to get the QRS complex peak. Heart rate value is calculated by Microcontroller Arduino UNO R3 uses the QRS complex peak. Voltage, heart rate, and the QRS complex peak are sent to Android smartphone by Bluetooth HC-05. ECG data is displayed as the graph by Android smartphone. To evaluate the performance of QRS complex peak detection method, three parameters are used; they are positive predictive, accuracy and sensitivity. Positive predictive, accuracy, and sensitivity of Peak Threshold method is 92.39%, 70.30%, 74.62% and for Peak Filter method are 98.38%, 82.47%, 83.61%, respectively.


Introduction
Today, heart disease is one of the dominant causes of death in the world [1]. At least 6 million deaths were caused by heart disease in 2002, and increasing to 7.4 million deaths in 2012 [2]. To prevent more death from this disease, special attention is needed, one of them is early heart disease diagnosis. One of the diagnostic techniques for heart disease is Electrocardiogram (ECG) [3][4][5].
Electrocardiogram is a representation of heart's electrical activity [6]. This electrical activity can be recorded by placing some electrodes on the particular body's surface [7]. The abnormalities of the heart can be seen on this recorded graph of ECG [8].
Lately, the advances in electronics technology and the development of digital signal processing techniques; many ways have been developed to recognize the heart abnormalities automatically through ECG signals [9]. Lou et al. (2013) have developed a wireless health monitoring system based on the smartphone operating system. The system is capable of measuring, analyzing, storing various physiological parameters of the patient [10]. Compared to monitors on Personal Computer (PC) or Personal Digital Assistant (PDA), smartphones are smaller and easier to carry, have the ability to communicate remotely and other advance functions [11].
Another ECG function is the measurement of heart rate. Heart rate is a number of complete pulsation of the heart when cardiac muscles contract and relax in one minute. In the ECG, one pulsation is referred as two R peaks or QRS complex peak of ECG waveform [12]. To detect QRS complex peak in the ECG waveform, many algorithms have been developed [13][14][15]. This work contributes to developing QRS complex peak detection and heart rate monitoring system based on Android smartphone.

ECG Monitoring System
This ECG monitoring system consists of the AD8232 ECG Kit for recording cardiac activity, Arduino UNO R3 to process data that is obtained from AD8232 Kit, Bluetooth HC-05 is used for transmitting data from Arduino to Android, SDCard module to store data read by Arduino, and Android smartphone to display the ECG graph and heart rate. Small bio potential signals such as EKG can be read by the AD8232 module because this module has 1100 times amplification [16]. Besides that, AD8232 module can filter the signal when there are disturbance and interference due to body movement [17]. Recorded signal form AD8232 module is decoded by Arduino UNO R3 into analog data and processed to find the QRS complex peak. Then, the data is converted into voltage value (mV) and is stored into memory card using SDCard module. Furthermore, the data will be sent to Android smartphone using Bluetooth HC-05. Heart rate is calculated in the Arduino UNO R3. The function of Android smartphone is displaying ECG data into graph and represent the heart rate. Android Studio is used for building the application [18]. Figure 1 shows block diagram of this ECG monitoring system.  Figure 2 (a) shows algorithm of QRS complex detection using Peak Filter method. This method consists of three main processes; Linear High Pass Filter, Non-Linear Low Pass Filter, and Decision Making. The high pass filter can be written as equation (1) which is using M-point moving average filter and an ideal delayed system by group delay of (M+1)/2 samples. M value can be 5 or 7 [14].

QRS Complex Peak Detection
Low pass filter can be written into equation (2), which is constructed by point to point simple squaring operation and moving window integration. According to Pan and Tompkins (1985), the value of K is 30 for sampling rate 200 Hz [13]. In the decision-making process, adaptive threshold is utilized. Thresholding scheme can be formulated as equation (3) to (5).
(5) PEAK is new local maximum detected in the wave feature, α is referred as "forgotten factor", where 0 ≤ α ≤ 1. γ is a weighting factor; used for the peak value contribution to the adjustment of the threshold determination, empirically its values are ranged from 0.15 to 0.2 γ [14]. shows algorithm of QRS complex detection using Peak Threshold method. A data point (x n ) will be considered as QRS complex peak if the subtraction result of the current data point (xn) and previous data point (xn-1); then current data point (xn) and its next data point (xn+1), is positive. Besides that, the current data point's value is more than threshold value. The determination of the QRS complex in this method can be illustrated in Figure 3 and can be written as,   (11) Where Acc is accuracy, Se is sensitivity, P is positive predictive, Tp is the number of QRS complexes detected correctly, Fp is the number of non-QRS complexes detected as QRS complexes, and Fn is the number of undetectable QRS complexes.

Heart rate
The number of QRS complex peak (R wave) that occur in one minute is used for heart rate (HR) calculation which the unit is beat per minute (bpm). To calculate HR in real time, following equation is utilized, 60,000 For example, if one of the beats (from R to R or from QRS complex peak to another peak) takes 750 ms, then in one minute (60*1000 = 60000ms), there is (800000/750 = 80bpm) 80 beats. This 80bpm is the heart rate against time [20].

Result and Discussion
The Android application has several main functions; they are displaying data in graphical form, displaying heart rate, and recording data that has been received from Arduino. Figure 4 shows the application interface of Android smartphone while receiving ECG data and heart rate from Microcontroller Arduino UNO R3. In this study, the determination of QRS complex use two methods; Peak Threshold method and Peak Filter method. The determination of this QRS complex is used for calculating the patient's heart rate in one minute or bpm. In this monitoring system, the determination of QRS complex is done in Arduino. Then, Arduino will send a parameter to Android when the program in Arduino detects the QRS complex via Bluetooth HC-05. To calculate the heart rate in real time, equation (12) is utilized.
Where the R-R interval represents the time from R peak (QRS complex peak) to the next R peak. The QRS complex detection algorithm for the Peak Filter method is shown in Figure 2 (a). In this QRS complexes detection method, ECG data is continuously processed by Linear High Pass Filtering (HPF), Non-Linear Low Pass Filtering (LPF), and Decision Making. The function of the HPF is to assert the QRS complex and suppress the source of low-frequency noise on ECG signals, e.g. P and T waves. Therefore, the selection of the variable M value of the equation (1) in this HPF must be carefully considered. Different M value will result in different frequency of HPF responses, and lead to different QRS detection performance [14]. According to Chen (2003), the exact M value is 5 or 7 [14]. In this study, the value of M is 5.
In LPF, the number of samples (N) in the moving window is very important. The window width should be approximately equal to the possible area of the QRS complex. According to Pan, for a sampling rate of 200 Hz, the value of N is 30 [13]. In Decision Making, adaptive thresholding schemes on the wave features that is generated from the non-linear LPF stage (z [n]) is utilized for detecting the QRS Complex. Where, when z [n] is greater than Threshold; z [n] is the peak of the QRS complex, and vice versa. The adaptive threshold value will always be updated according to equation (5). The forgetting factor, α; is a correction factor in the determination of the adaptive threshold and γ is the weighting factor used for determining the contribution of the peak value to the threshold adjustment [14]. Figure 5 shows QRS complex peak detection with Peak Filter method from a patient.  The QRS complex detection algorithm with Peak Threshold method is shown in Figure 2 (b). In this method, Arduino will store three analog ECG data in the form of arrays; x [n], x [n-1], and x [n + 1], then with equations (6), (7), and (8) The peak of the QRS complex can be determined. If the QRS complex is not found or have been found in those three arrays, the data will be shifted. So  determination of QRS complex again. Figure 6 shows QRS complex peak detection with Peak Filter method from a patient.
To evaluate the performance of QRS complex peak detection method, three parameters are used; they are positive predictive, accuracy and sensitivity. Accuracy shows the number of correctly detected QRS complexes compared with the number of detected pulses. In this system, the accuracy value is influenced by false negative and false positive where false negative is the number of undetectable QRS complexes and the false positive is the number of non-QRS complexes detected as QRS complexes. Sensitivity shows the sensitivity of the system in detecting QRS complex correctly. The sensitivity value is affected by true positive and false negative where true positive indicates the number of QRS complexes detected correctly. Positive predictive shows correctly detected QRS complexes compared to non-QRS complexes but are detected as QRS complexes. Table 1 shows positive predictive, accuracy and sensitivity of the Peak Threshold method and Peak Filter method. The low value of the QRS detection performance in the Peak Threshold method is caused by the peaks of the QRS complex's value is less than the threshold value that is specified in the program. So, the peak of the QRS complex cannot be detected, as seen in figure 6. This is because of equation (8) is not fulfilled.