Monitoring Atrial Fibrillation Using PPG Signals and a Smartphone

Atrial fibrillation (AF) is a common type of cardiac arrhythmia. AF is associated with increased rates of death and hospitalizations. It is also related to a degraded quality of life and reduced exercise capacity. Ageing increases the risk of developing AF, as well as hypertension and obesity. Continuous ECG monitoring is required in patients with previously diagnosed AF. Studies have also demonstrated that daily ECG monitoring increases the successful detection of silent AF among older adults. In this sense facilitating AF monitoring using portable devices such as Smartphones will increase patients life quality and could help to an early diagnosis. With this in mind in this work we present a proposal to detect AF using pulsatile photoplethysmogram (PPG) signal from a fingertip using the built-in camera lens in a smartphone. We developed an algorithm intended to sense paroxysmal AF considering resource utilization capabilities in order to be used in mobile devices with constrained. Keywords—Smartphone; Sensors; Arrhythmia; Atrial fibrillation.


Introduction
Atrial fibrillation (AF) is a common heart rhythm disorder that has gained clinical importance [1] . AF incidence levels have increased mainly due to the nature of its risk factors, such as age, diabetes, alcohol and tobacco consumption, to name a few [2]. Scientists predict that AF will affect from 6 to 12 million people in the US in 2050 and from 9 to 17 million people in Europe in 2060 [4] [5]. Most AF symptoms are persistent and include palpitations, chest pain, shortness of breath, and lightheadedness, among others. Moreover, AF can lead to a brain stroke or a heart attack. AF can be detected by continuously monitoring the patient. In this sense, electrocardiography (ECG) is the most common form of monitoring patient's heart rate [3]. Several portable ECG have been developed and also have been used with smartphones as external sensors. On the other hand, photoplethysmography (PPG) sensors are today embedded in many mobile devices such as smartphones. The simplest PPG sensor includes a LED and a photodetector that get in contact with the skin surface to monitor cardiac activity. Due to their popularity, PPG sensors are often studied to measure their efficacy in terms of heart rate variability (HRV) assessment [6]- [10]. Following this trend, this work develops an algorithm for atrial fibrillation detection using PPG signals. The main goal is to implement an AF monitor system on a mobile device (i.e. smartphone) to facilitate AF monitoring while simultaneously increasing patient comfort.

Detecting and Monitoring Atrial Fibrillation
AF causes patient heartbeat to be rapid and irregular due to disorganized signals from the heart's electrical signals. In AF, the upper chambers of the heart (right and left atrium) may beat as often as 300-700 times per minute [11]; such high levels are part of a component known as the F wave. The European Society of Cardiology (ESC) distinguishes five types of AF based on the presentation and duration of the arrhythmia [12]: • First diagnosed AF is that identified by the first time in a patient, irrespective of its duration and/or the presence and severity of AF-related symptoms. • Paroxysmal AF is self-terminating, usually within 48 hours; however, some episodes may last for up to seven days. This seven-day point is clinically important, as AF periods lasting longer are not considered to be paroxysmal AF episodes. • Persistent AF is said to exist when an AF episode either lasts longer than seven days or requires termination by either chemical cardioversion (i.e. using drugs) or direct current cardioversion (DCC). • Long-standing persistent AF is present when an AF episode has lasted for a year or more after adapting a rhythm control strategy. • Permanent AF occurs when the presence of the arrhythmia is accepted by the patient (and the physician). As a result, rhythm control interventions are, by definition, not pursued in patients with permanent AF.
An AF diagnosis requires monitoring patient heart rate using an ECG sensor to detect the typical characteristics of the arrhythmia as listed below: • No distinct P waves, but fine baseline F wave oscillations are present.
• Varying morphology of the QRS complex.
• Inconsistent and unpredictable R-R intervals (i.e. abnormal heart rhythm) Arrhythmia episodes that last for 30 seconds or more may indicate AF; however, the diagnosis must be confirmed by the ECG test. In this case, it is important to ensure the necessary conditions to not compromise the ECG signal. Such conditions include reducing noise and preventing F wave filtrations. This can be usually achieved through digital filters. Likewise, when working with ECG signals, it is important to identify the following aspects before making any classification decision [11] [12] [13]: • Heart rate variability • Number of f waves • Amplitude of the QRS complex • Amplitude of the T waves • High frequency components • Low frequency components Once AF is diagnosed, further ECG monitoring may help to define the correct treatment. Similarly, multiple studies have confirmed that daily ECG monitoring increases the successful detection of silent, asymptomatic, and paroxysmal AF among older adults [14] [15]. Such results highlight the importance of continuous ECG monitoring for timely AF detection and treatment. In parallel, wearable sensors and monitoring systems are now available to the general public and can be a key to the early detection and successful treatment of AF. For instance, smartphones now rely on PPG sensors that, along with an algorithm, can effectively diagnose AF. However, up to date, the clinical community lacks a formally approved PPG-based method for AF detection.

State of the Art
Nowadays, several works suggest using smartphones to detect some types of arrhythmia. In [16] a smartphone application that detects irregular pulse using an iPhone 4S was developed. Namely, the application makes use of the iPhone's camera to obtain pulsatile time series recordings, which were later analyzed using two statistical methods: root mean square of successive RR difference (RMSSD/mean) and Shannon entropy (ShE). In the end, the two methods turned out to be significant in terms of AF detection. In [17], the authors employed an iPhone 4S camera to record patient pulse. Then, their algorithm takes into account pulse rise and fall times to detect AF. The proposal is able to monitor heart rate and calculate its variations, which are then analyzed using t-tests to either accept or reject a diagnosis. Similarly, the method is particularly useful for detecting bigeminy, trigeminy, and/or unpredictable heartbeat that may lead to AF. Finally, in [18], the authors proposed an initiative that records patient facial videos; then, the video images are processed on a computer using the Kanade-Lukas-Tomasi (KLT) algorithm and a series of digital filters. The goal is to obtain heart rate parameters, including heart rate variations. It is a non-intrusive solution, but it is not wearable.
As the above-mentioned works indicate, some arrhythmias can be detected by merely monitoring heart rate; however, detecting AF is usually a much more complex task. In this sense, our work proposes a mobile-device proposal than includes an algorithm for AF detection that takes into account two rhythm conditions: high frequency components (more than 300 beats per minute, bpm) and abrupt heart rate changes (more than 100 bpm). Similarly, our proposal seeks to be portable, code-line saving, and of rapid processing in such a way as to be able to be embedded in a mobile device. This characteristic would increase the proposal's accessibility to the general public and would allow patients to carry on with their daily lives without necessarily being bothered by fixed vital signs monitoring mechanisms.

Design and Implementation
We propose a portable and non-invasive solution that analyzes PPG signals obtained from a sensor embedded in a smart device. A general diagram of the proposal is depicted in Figure 1. According to Figure 1, following a doctor´s order, the patient uses the AF monitoring solution periodically. It mainly consists of a mobile system that includes the following components: A monitoring layer (sensors), a resource manager, and a process and diagnostic layer which rely on a new algorithm to detect AF. First, the patient must be at rest to activate the system and take his heart rate. The system will verify that the patient's average heart rate does not exceed 100 bpm, ensure the frequency variations are not significant, and discard the presence of highfrequency components ranging from 300 to 700 bpm. This solution can adapt to the battery and processing capabilities of the device on which it is installed, the network status, and the place where AF monitoring occurs. If the application detects a critical picture where PPG signal characteristics demonstrate the presence of AF, the patient's physician is notified. At the resource manager battery and memory regulate the functioning of the PPG sensor. If the device on which the application is installed has low battery or memory, the PPG sensor works with 4,000 samples, otherwise the sensor requires 7,000 samples. The monitoring layer comprises the embedded monitoring sensors. The three parameters monitored by the solution are listed as follows: PPG signal -used to obtain patient cardiovascular signals; Network status: as a part of the mobile context, the network status determines the best way (either SMS or push notification) to alert the patient's physician in the case where the application detects a critical picture of AF; Location -This parameter allows the application to adjust its recognition threshold to identify a high heart rate. For instance, if the patient is in a place of intense physical activity, the application must increase its recognition threshold to avoid AF misdiagnosis. To detect AF using frequency variation of a PPG signal we designed a new algorithm described in the next section. To implement the algorithm, it is necessary to use a device with characteristics like those of a Samsung Galaxy 6 smartphone. These characteristics include CPU speed: 1.5GHZ and RAM capacity: 3 GB. Similarly, the following sensors are necessary: an accelerometer, a barometer, a fingerprint sensor, a gyroscope, a geomagnetic sensor, a Hall Effect sensor, a heart rate sensor, a proximity sensor, and an RGB light sensor.

4.1
Algorithm to detect AF using PPG PPG signals cannot be treated in the same form as ECG signals. Besides being able to detect the aforementioned characteristics of AF, PPG signals can identify the presence of F waves as well as the absence of P waves. Our proposal analyzes PPG signals to detect AF. Namely, our algorithm has the following characteristics and is shown in figure 2: • The first stage involves adapting the signal. The first 1,000 collected samples are removed to discard the wrong sensor data, as the sensor requires a training period. • The signal captured by the sensor is discontinuous and appears on a slope as the samples are taken; therefore, the second stage involves removing the offset to adjust the signal on a coordinate axis. • To remove noise without compromising the high-frequency components, a smoothing filter can be used. The PPG signal of a patient with AF has a frequency component higher than 300 bpm; hence, it is important to denoise the signal. • The minimum values must be calculated to identify the location of each wave valley. Because of the signal's waveform, it is easier to calculate the valleys than to calculate the peaks. • The location of each valley is used to calculate the heart rate. In other words, the difference between two valley locations is calculated to find the time period. Then, for each period, the inverse of this result is calculated. • If most calculated frequencies differ more than 5 bpm a Fast Fourier Transform is applied in search of high frequency component greater than 300 bpm.

Fig. 2. Algorithm to detect AF
(Equivalent to F waves), if this component is significant in intensity compared to the central frequency, then AF is detected.
The following section describes the algorithm's crucial stages: Offset removal: One method for removing the offset is to find the line of the best fit by using the least squares method. Figure 3 illustrates the change in the data that was taken by the PPG sensor once the procedure to remove the offset is applied. The 4) Calculate the y-intercept of the line by using the formula expressed as (2) where and are the means of the x and y coordinates of the data points, respectively. (2)

5) Use the slope and the y-intercept to form the equation for the line of the best fit.
Once the line is obtained, its points are subtracted from the corresponding data points.
Smoothing filter: It is important to denoise the signal without affecting the heart rate and the AF frequency component (greater than 300 bpm). The use of an embedded PPG sensor has less noise sources than that of a wireless connected one. The most important noise source in the embedded PPG sensor is the patient movement during the data input.
An exponentially weighted moving average (EWMA) filter was used to de-noise the signal. EWMA filters can significantly reduce the white noise while preserving the waveform of the original signal, with the amount of noise that is reduced being equal to the square root of the number of data points. Furthermore, the filter was easy to build and did not require a large window. The general formula obtained for the EWMA filter was similar to a convolution and in expressed as (3): By using different values for α, we defined α = 0.6 to denoise the signal without compromising the final results.
where n=1 → 7000 x(n)= data point without offset y(n)=result point without noise

Minimum function values:
The valleys from the resulting signal were narrower than the peaks. Consequently, the minimum values in the windows of 70 samples were identified to detect the valley frequencies in a heart rate range; what mattered was the position of the minimal value (signal valleys), and not the signal amplitude. Mathematically, the minimum value was found after deriving the general quadratic expression ax2 + bx + c, making it equal to 0, and solving it to find the value of x. When the value of y was positive, the minimum value lay on the x axis. In the case of discrete data, the data were compared to find the minimum value in the assigned time window.

Fig. 4. Algorithm to detect AF
iJOE -Vol. 16, No. 3, 2020 It was necessary to detect the difference between the heart frequencies; therefore, any valley frequency difference of higher than 5 bpm indicated the existence of AF.

Results and Discussion
To assess the detection efficiency of our algorithm, we compared it with other alternatives. Namely, we compared the average frequency detected by our algorithm with the average frequency detected by the Pan-Tomkins algorithm and the Samsung Health solution during two minutes of data (12,000 samples). The Pan-Tomkins algorithm is commonly associated with AF detection and QRS detection using ECG signals [19]. This algorithm has been widely validated in the medical community.
The Pan-Tomkins's tests were conducted on a personal computer on MATLAB. Moreover, we conducted tests on a Samsung Galaxy S8 Plus smartphone using a corresponding native application (i.e. Samsung Health) to measure heart rate, whereas our proposed algorithm was programmed on Android. Table 1 summarizes the heart rate data obtained from a 35-year-old patient. For one hour, we collected the data with the sensor embedded in the Samsung smartphone. Every dataset was composed of two minutes of data and was exported to a CSV file. As Figure 6 depicts, all the CVS files were processed by our algorithm on a Toshiba Satellite S55t laptop computer, with an Intel Core ™ i7 processor and a 12 Gb RAM. Implementing the Pan-Tomkins algorithm on MATLAB requires 632 code lines, whereas the algorithm proposed in this work was implemented with 254 lines. Moreover, executing the Pan-Tomkins algorithm on MATLAB takes 1.454212 s, whereas executing the proposed algorithm took 0.058409 s. In conclusion, the proposed algorithm was lighter and faster to implement on a mobile device. Table 1. Average heart rate (bpm) frequency estimation from 7,000 samples.

Samsung Health App
Pan-Tomkins Proposed Algorithm  69  77  75  64  55  68  67  76  81  63  73  67  66  72  70  61  80  76  66 76 73 We also compared the algorithm results with a FDA approved sensor. We used the Kardia sensor that uses an ECG signal. Table 2 shows the results comparison between our algorithm and the Kardia Alive Core sensor with two minutes of data (i.e. 12,000 samples). The data were collected from a healthy, sedentary, 35-year-old patient. As table 2 highlights, in most of the cases, the estimations made by our algorithm are like those made by the sensor, even though the Kardia sensor uses an ECG signal. However, calculating frequency variations is not enough to detect AF, since it can be confused with atrial flutter (AF). Therefore, it is important to work with the PPG signal of a patient with AF.

Experiment to detect frequency components higher than 300 bpm
The presence of F waves in an ECG signal denotes AF, as these waves have a frequency component higher than 300 bpm. Therefore, if a given PPG shows a frequency component higher than 300 bpm, it is possible to detect AF. For this experiment, the algorithm was tested in a Samsung S8+ smartphone obtaining 2-min frequency readings from PPG signals of nine volunteers, three of them with AF antecedents. The process of the data was made in the smartphone to deliver the results that are shown in Figure 5. The high-frequency component detection stage was executed prior to the algorithm for calculating the heart rate as follows: The same windows were used as those for which the signal valleys were detected; then, we applied an algorithm for Fast Fourier Transform (FFT) designed by Columbia University [20]. Some of the results were graphed to aid interpretation, and in those that indicated the presence of AF, the highfrequency component was present in most of the windows.
As Figure 6 depicts, the Fourier transform does not indicate the presence of a significant component higher than 300 bpm; yet, Figure 6 clearly depicts these components with an amplitude of 3 × 106, despite having examined different segments of the signal.
We repeat the tests with 9 volunteers, some of them without AF antecedents as shown in Table 3. We could observe that the proposed algorithm could detect AF successfully in the case of the patients with AF. In addition, the heart rate and the presence of AF results obtained by the algorithm were compared with the Kardia Alivecore and Samsung Health App results.

Energy and memory saving on implementation
As mentioned previously, the basis of an AF diagnosis is whether a person's heart rate is higher than 100 bpm, has different intervals between heart beats, and has a high-frequency component. The recognition of these characteristics is possible to implement using smart devices. However, implementing an FFT algorithm after the heart rate and frequency variability calculation consumed a high amount of process and energy of the device. To prevent this problem, it was necessary to identify when to undertake FFT and when not to do so. The FFT calculation was considered unnecessary if the heart rate of the person was between 60 and 100 bpm, or if the time period between the heart beats was constant. This was also helpful in enabling the algorithm to detect results other than whether the patient was healthy or had AF; for example, the algorithm could detect bradycardia if the heart rate was lower than 60 bpm, or other forms of arrhythmia if the heart rate was higher than 100 bpm and the period between the heart beats was not constant.

Conclusion
In this work we proposed a solution to detect and monitor AF using a smartphone. We confirmed the functionality of our AF detection platform both at an optimal battery level and a low battery level. In addition to the proposed algorithm's ability to detect AF episodes, the algorithm also provided an efficient solution in terms of its processing capabilities. It is possible to implement this AF detection solution on devices with low processing capabilities and memory, as it does not require large datasets, complex algorithms to be processed, or a continuous Internet connection. The main design-related advantage is that our AF detection solution can analyze PPG signals without looking for trends or similar patterns in the waveform, unlike other applications such as Samsung Health. Finally. AF was characterized by the significant heart rate variations of greater than 5 bpm between the valleys, as well as a high-frequency component of greater than 300 bpm, which could be detected by a Fourier transform; the consideration of these additional characteristics in the proposed algorithm enabled a successful diagnosis. This AF detection solution can offer patients the chance to lead a less sedentary life and to monitor their health status constantly from anywhere.