Professional Documents
Culture Documents
Prerequisite For HRV Biofeedback: Real-Time Detection of R Peaks
Prerequisite For HRV Biofeedback: Real-Time Detection of R Peaks
Prerequisite For HRV Biofeedback: Real-Time Detection of R Peaks
Detection of R peaks
Branko Babusiak, Stefan Borik and Michal Gala
Faculty of Electrical Engineering, Department of Biomedical Engineering
University of Zilina
Zilina, Slovakia
branko.babusiak@fel.uniza.sk
Abstract—Heart rate variability (HRV) reflects the physical individual increase their HRV. The HRVB can also be an
health and ability of the organism to handle stress situations. effective component in asthma treatment.
HRV biofeedback is a real-time training process which helps
reduce stress and asthma severity. The most important There are many methods for HRV analysis which can be
prerequisite for the HRV biofeedback is the detection of R peaks divided into two main groups: time domain methods and
in the ECG signal. This article describes in detail a real-time frequency domain methods. The time-domain analysis is
algorithm capable of R peaks detection. The algorithm is simpler and more commonly used method of HRV
implemented within a standalone C# application and measurement. The RR interval is often denoted as normal-to-
functionality thereof is demonstrated. The results indicate that normal (NN) interval in HRV terminology. Simple time–
the proposed algorithm is immune against various types of domain variables such as the mean NN interval, the mean heart
artefacts. rate, the difference between the longest and shortest NN
interval, etc. can be calculated [1]. The simplest variable is the
Keywords—ECG; peak detection; HRV; biofeedback standard deviation of the NN interval (SDNN):
( NN )
I. INTRODUCTION 1 N
2
SDNN = − NN ()
Electrocardiography (ECG) is one most prominent N i =1
i
A. Band-pass filter
The band-pass filter is used to maximize the energy of the
QRS complex in the spectrum. The main energy of the QRS
complex is approximately within the range of 5 to 15 Hz [4].
The original Pan-Tompkins algorithm uses a combination of
low-pass and high-pass filters to produce a band-pass filter.
The order and the gain of these filters was very low because of
low computational performance of computers in 1985 with
respect to real-time signal filtering [4]. Fig. 5. Output of signal differentiation.
We designed a FIR filter of order 355 and 40 dB
attenuation in the band-stop areas (Fig. 3). We chose the FIR
filter because of its linear phase characteristics and stability
thereof.
III. RESULTS
The R peak detection method described in the previous
chapter was implemented within a real-time application. The
application is developed in C# programming language. Data is
received through UART interface. The algorithm works
properly after 2 seconds from the start of data collection
because the threshold value for peak detection is calculated
from two second intervals. Therefore, the first two seconds of
Fig. 7. Output of the moving average filter. the ECG signal are not visible in the application window while
the application is receiving and processing data in the
D. Peak detection background. Once enough input data is collected for the pass-
Proper detection of R waves depends on the peak detection band filter (355 samples = filter order), the filter starts to
algorithm applied at the output of the moving average filter. produce filtered samples which are stored in the pass-band
The peak detection algorithm searches for local signal maxima filter buffer.
which cross the adaptive threshold values. The threshold value
is computed as one third of maximum value of moving average
output in the last 2 seconds and is recomputed every 20
milliseconds after buffering the first 2 seconds. Not all detected
maxima are corresponding to R peaks because of the presence
of noise, slight variations of QRS complex length and
fluctuations of the ECG signal. The T wave is sometimes
detected as false maximum because in specific cases its value
can cross the threshold value. An operative criterion should be
applied to avoid detection of false maxima. This criterion is
based on the physiological properties of the ECG signal. The
heart rate should not be over 200 BPM, meaning that R peaks
cannot be closer than 0.3s (150 samples). If neighboring peaks
are closer than 0.3s then one of the peaks is erroneously
identified and must be discarded. In such case, the lower
maximum is discarded. The peak detection principle is shown
in Fig. 8. The adaptive threshold (orange line) is computed
from 2 second interval starting from the beginning and then
recalculated every 20 milliseconds. The true local maxima are
denoted by red circles and false maxima are denoted by the
black circles – these are discarded using the mentioned
criterion.
IV. CONCLUSION
An algorithm for real-time R peak detection was developed
and presented in this article. The algorithm was implemented
within a standalone C# application and functionality thereof
was confirmed on real-time ECG data from a calm, seated
person and also on ECG data with movement artefacts and
mains noise (50 Hz). The successful detection of R peaks is
crucial for proper computation of instant heart rate (BPM) and
heart rate variability (HRV). Subsequent work will focus on the
development of the HRV biofeedback system where proper
detection of R peaks is the most important input parameter.
ACKNOWLEDGMENT
This work was supported by the Slovak Research and
Fig. 10. Detection of R peaks in ECG of a calm, seated subject.
Development Agency under the contract No. APVV-16-0190.
The subject was then asked to periodically move his hand REFERENCES
with the attached electrode. The mentioned situation is depicted
[1] Task Force of the European Society of Cardiology and the North
in Fig. 11. Even though the ECG signal (first row) has changed
American Society of Pacing and Electrophysiology, “Heart rate
significantly, peaks were successfully detected. Positions of R
waves (signal in first row) and detected peaks (third row) are variability: Standards of measurement, physiological interpretation
not synchronized, as is evident from Fig. 10 and Fig. 11. This and clinical use,” Eur. Heart J., 1996.
is due to the delay of the bandpass filter and the moving [2] A. L. Wheat and K. T. Larkin, “Biofeedback of heart rate variability
average filter. However, synchronization thereof is not and related physiology: A critical review,” Applied
important for successful detection of instant BPM. The instant Psychophysiology Biofeedback, vol. 35, no. 3. pp. 229–242, 2010.
BMP will be used as input parameter for online HRV
[3] P. M. Lehrer, E. Vaschillo, B. Vaschillo, S.-E. Lu, A. Scardella, M.
estimation in ECG recordings with defined length – the SDNN
parameter described by equation (1). Siddique, and R. H. Habib, “Biofeedback Treatment for Asthma,”
Chest, vol. 126, no. 2, pp. 352–361, 2004.
The application for real-time detection of BPM was tested
[4] J. Pan and W. J. Tompkins, “A Real-Time QRS Detection
on a Windows PC with CPU Intel Core i5 3.2 GHz (four cores)
Algorithm,” IEEE Trans. Biomed. Eng., vol. BME-32, no. 3, pp.
and 8 GB RAM. The CPU usage did not exceed 4 % while the
application was running and processing data and RAM usage 230–236, 1985.
was within 12 megabytes. Based on above mentioned facts, we [5] B. Babusiak and S. Borik, “Bio-Amplifier with programmable gain
can conclude that the designed application runs without any and adjustable leads,” in 2013 36th International Conference on
problems on today’s standard personal computers. Telecommunications and Signal Processing, TSP 2013, 2013.
[6] V. Acharya, “Improving Common-Mode Rejection Using the Right-
Leg Drive Amplifier,” 2011.
[7] J. D. Bronzino, Biomedical Engineering Fundamentals (The
Biomedical Engineering Handbook, Third Edition). 2006.