Photoplethysmogram peaks detection based on moving window integration and threshold for heart rate calculation on android smartphone

We present a photoplethysmogram peaks detection and heart rate calculation on android smartphone. Photoplethysmogram signal is obtained and extracted from a video stream of fingertip that is taken from smartphone camera. Then, photoplethysmogram peak is detected based on moving window integration and threshold. The heart rate value is calculated from the detected peak. We design an Android Application for processing photoplethysmogram data and calculating the Heart Rate. The photoplethysmogram signal and detected peak could be saved in smartphone’s storage and uploaded to the existing database. Peak detection and peak to peak time interval calculation are successfully conducted. The performance of the peak detection is calculated in terms of accuracy, sensitivity, and positive predictive. Positive predictive, accuracy, and sensitivity of peak detection are 99.19%, 92.45%, 93.17%, respectively.


Introduction
Smartphone becomes one of widely used devices. People bring it almost everywhere and every time. Smartphone has smaller size and easier to carry compared to Personal Computer (PC) and Personal Digital Assistant (PDA). In addition, smartphone has capability to connect to the Internet. Therefore, it can be used for long distance communication and storing data or any file to the existing database. Nowadays, smartphones are used in health field, especially in the mobile health sector. In recent study, smartphone is used for detecting abnormality of cardiovascular by monitoring basic vitals such as blood pressure, blood oxygen pressure, pulse rate, heart rate variability, etc. [1][2][3]. One of the most important parameters that can detect the abnormality of cardiovascular is pulse rate [4]. Many methods can be used to obtain pulse rate from the human body. One of them is using photoplethysmogram (PPG) [5][6][7][8][9].
PPG is a measurement technique consisting of two components. They are light source and light sensor, such as photodiode. A light source illuminate skin surface and the light sensor measures the intensity of light reflected by the skin. Based on the Beer-Lambert law, the intensity of the light measured by light sensor is inversely proportional to change of vascular blood volume [10][11]. The 2 maximum value of measured light intensity is reached during diastole period, which the arterial blood volume at its lowest. Otherwise, the minimum value of measured light intensity is reached during systole period, which the arterial blood volume at its highest.
PPG can also be obtained and extracted from a video stream of fingertip taken from smartphone camera. The finger is placed so that it covers the smartphone camera and its LED. PPG extraction from fingertip is approached by using a predefined region of interest (ROI) in each frame of video stream for a certain color channel and then averaging the pixel values within ROI to convert two-dimensional video signal into one dimensional signal [12].
The extracted PPG signal is processed to find its peak. Heart rate is calculated using time interval between two consecutive detected peaks [13]. Several algorithms are developed to find the peak of PPG signal. Jiang et.al. use adaptive thresholding with inverted triangular area for real-time peak detection of photoplethysmogram [10]. Kavsaoğlu et.al. use adaptive segmentation method to find peak values correctly [14]. In this method, firstly the PPG signal is separated into segments with sample size. Then, by comparing with maximum points in these segments, the peak points in this signal are detected.
In this study, we present a PPG peaks detection and heart rate calculation on android smartphone. PPG signal is obtained and extracted from a video stream of fingertip that is taken from smartphone camera. Then, PPG peak is detected based on moving window integration and threshold. The heart rate value is calculated from detected peak. Furthermore, the PPG signal and detected peak can be saved in smartphone's storage and uploaded to the existing database for further research.

System design
PPG signal is obtained and extracted from a video stream of fingertip that is taken from smartphone camera. The position of camera, LED, and finger is shown by Figure 1. We design an Android Application for processing PPG data and calculating the Heart Rate. The Android application is also capable to save and record PPG signal and its detected peak into text file. Then, the text file can be stored into internet database. The block diagram of this system is shown in Figure 2.  od to detect peak of PPG is based on moving window integration and adaptive threshold. The algorithm of this method is shown in Algorithm 1. This method is easy to be implemented and has low computational cost. The process of peak detection is described as follow.
Baseline drift removal -To remove the baseline drift of the PPG signal, the signal is fitted in low order polynomial [15], and then the PPG signal is subtracted by its polynomial value. Moving window integration -the moving window integration is used for emphasizing the systolic peak area and beat area. It operates by averaging a number of input signal ( ) to get each output signal ( ). The moving average equation is given by, Adaptive threshold -This stage is used for obtaining and by converting teach output point of moving average into 1 and 0 as , the value of [16] is obtained from the following equation, = .
( ) where, the threshold is updated every 4 seconds during taking video stream and obtaining PPG signal. Algorithm 1. Peaks detection.

Performance of peak detection method
The performance of peak detection is calculated based on three parameters. The parameters are described by the following equation, where is accuracy, + is positive predictive, is sensitivity, undetected peak is denoted as , is number of false detection, and is the number of peak which is detected correctly.

Heart rate measurement
To calculate the heart rate, we use time interval between two consecutive peak of PPG signal. Heart rate is calculated based on the following equation,

Findings and argument
The Android application displays PPG signal that is obtained from extraction of video stream, Figure  3(a) shows the application interface when it displays the PPG data. Other than that, Android application has capability to save the PPG signal into text file (.txt) in storage, and then upload and store it to database. We can store data in a NoSQL cloud database, Firebase. The data will remain available when the application goes offline or when the file in the Android device is lost. To upload the data into the database, user have to register and login to the Firebase. Figure 3(b) and 3(c) show the register and login application interface. The database is shown in figure 4.  In the peak detection, the number of samples, N, in the moving window integration is important. N describes the width of integration window. Generally, the width of the window should be around the possible widest peak width [17][18]. If the N is too narrow, it will produce several peaks in the output waveform. If N is too wide, it will merge two consecutive peaks. Figure 5 shows the correlation of N and its output waveform. For our sampling rate 24 samples/s, the width of window integration is 8. Peak detection and peak to peak time interval calculation are successfully performed using algorithm 1. Heart rate calculation is based on this peak to peak time interval as shown in equation (7). Every 4 seconds, heart rate and peak to peak interval is displayed in Android application. Figure 6 shows PPG Graph and peak detection that is obtained from recorded file from Android device. The performance evaluation of the peak detection algorithm is calculated based on accuracy, sensitivity, and positive predictive. Accuracy describes the proportion of correctly detected pulse with the total number of peaks. Sensitivity shows how good the algorithm at detecting peak. It is the proportion of detected peak that are correctly detected by the algorithm. Numerical value of sensitivity is proportional to the false positive of detection results [19]. Positive predictive shows correct detected PPG peak compared to non-peak but detected as peak. 5 records are used for testing the performance of  Table 1 shows the accuracy, sensitivity, and positive predictive of peak detection from each record. Positive predictive, accuracy, and sensitivity of peak detection are 99.19%, 92.45%, 93.17%, respectively. Based on this result, the algorithm is reliable to detect the peak of PPG in Android.

Conclusion
We design a photoplethysmogram peaks detection using moving window integration and threshold for heart rate calculation on Android smartphone. Photoplethysmogram signal is obtained and extracted from a video stream of fingertip taken from smartphone camera. The PPG signal can be saved in smartphone's storage and uploaded to the existing database for further research. Peak detection and peak to peak time interval calculation are successfully performed. The performance of peak detection is calculated in terms of accuracy, sensitivity, and positive predictive. Positive predictive, accuracy, and sensitivity of peak detection are 99.19%, 92.45%, 93.17%, respectively.