ECG Analysis Algorithms for Smartphone Based Cardiac Monitor

A.N. Kalinichenko1, S.V. Motorina1, A.V. Uskov2
1Saint Petersburg Electrotechnical University, St. Petersburg, 5 Prof. Popova str., Russia
2Medical project CardioQVARK Cardiomonitor, Moscow, Russia

Development of the mobile communication technology makes it possible to create compact and easily available smartphone based devices that provide real-time control of human physiological parameters and also translation of registered data to medical centers where they can be reviewed by doctors. The possibility like this is especially important for the cardiac patients supervision. As in case of the mobile based devices use, the conditions of physiological signals acquisition (first of all ECG) differ much from the conditions typical for standard ECG equipment, the task of special ECG processing algorothms development becomes urgent. This work is devoted to the description of ECG analysis algorithms complex oriented to the use in mobile cardiac monitoring systems.

Smartphone based cardiac monitor.
The described algorithmic complex was developed for the use in mobile cardiac monitor CardioQVARK [1], based on IPhone series 5/5S or 6. This device represents a portable case into which smartphone is inserted. On the rear side of the case two electrodes are placed for the ECG acquisition from fingers of both arms that corresponds to the standard ECG lead I. ECG signal is acquired with sampling frequency 20000 Hz and 16-bit resolution. Bandwidth of the signal is from 0.2 Hz to 5000 Hz. Registered signal is first preprocessed in the smartphone and displayed in real-time mode at the screen. Then the signal is decimated to 1000 Hz and transferred via Internet to the cloud service where additional analysis of the signal is implemented and also the ECG and its analysis results are saved in database. The data from service are available both to the patient and to the doctor with the use of special clients application that can be installed at smartphone, clipboard computer, notebook or desktop computer.
The following main functions of ECG processing and analysis are realized in this system:
•heart rate control and measuring of RR-intervals (distances between two adjacent heartbeats);
•pacemaker spikes detection (if they are present);
•cardiac arrhythmia recognition;
•heart rate variability (HRV) parameters estimation.

ECG analysis algorithms.
Common structure of the ECG analysis process.
The algorithms of ECG processing and analysis are distributed between the mobile device and the cloud service. The part of the preprocessing procedures that is implemented in the real-time mode is realized at the smartphone while most of the ECG analysis algorithms are concentrated in the cloud service software. So in case of some algorithms modernization, most part of the ECG analysis program has to be updated only at the cloud service.
ECG processing and analysis algorithms realized at the smartphone.
If a patient has implanted pacemaker, it is very important to use a method of ECG acquisition and processing that provides the pacemaker spikes detection and visualization. As most of the modern pacemakers use bipolar mode that is characterized by very small amplitude of pacemaker spikes (typically about several millivolt and 0.2 -1 ms duration), routinely used standard ECG acquisition equipment doesn’t provide reliable detection and display of the pacemaker spikes [2, 3]. The use of very high sampling frequency 20000 Hz and wide frequency range in the described above mobile ECG monitor permits not only detection of the spikes but also estimation of their parameters.
At the first stage of the spikes detection procedure estimation of the current mean amplitude of QRS-complexes is implemented. This mean amplitude is needed for further adjusting of some thresholds used in the detection algorithm. The spikes detection procedure itself includes the following stages:
•pacemaker spikes search, based on a criteria of two steep jumps presence separated by a plateau having duration between 0.15 and 1.0 ms;
•estimation of the detected pulse parameters (duration and amplitude); 
•deleting of the spike with the use of linear interpolation;
•compensation of the signal jump (just after the spike) caused by the pacemaker electrodes polarization; this procedure is based upon polynomial approximation.
The pacemaker spike detection algorithm caused the signal delay 80 ms. Fig. 1 illustrates the spike detection process and further signal correction.

ECG Analysis LETI CardioQVARK 
Fig. 1. Illustration of the spike detection algorithm and further signal correction. Left plot: a fragment of raw signal containing a pacemaker spike (solid line) and polynomial curve used for the polarization jump compensation (descending dotted line). Right plot: the same signal fragment after the pulse deleting and the jump compensation (solid line). Dotted line shows the detected pulse restored with the use of its parameters. 

To prepare the ECG for display on the smartphone screen the signal is filtered by two digital filters: notching (removing AC interference) and low-pass (smoothing) filter. If some pacemaker spikes were detected, they are inserted in the signal as vertical lines having the high equal to the measured amplitude of the spikes (Fig. 2).
After the spikes detection procedure the signal is decimated to 1000 Hz with preliminary smoothing and then translated to the cloud service in parallel with the detected spikes parameters.

 ECG Analysis LETI CardioQVARK
Fig. 2 Raw wide-range ECG signal with sampling frequency 20000 Hz in which pacemaker pulses take place (upper plot) and the same signal after the correction of the segments containing spikes, smoothing, decimation and restoring of the detected pulses (lower plot).

ECG analysis at the cloud service.
The ECG signal with sampling frequency 1000 Hz transmitted from the smartphone is stored in the cloud service database both in original and filtered forms. The signal filtering is implemented with the use of comb filter (removing DC component, AC interference and its harmonics) and low-pass filter with cutoff frequency about 35 Hz.
The unfiltered signal with sampling frequency 1000 Hz is used then as an input for the further ECG analysis stages [4-7]. First the noise level of the signal is estimated. If the noise level is too high, the corresponding ECG fragment is excluded from the further processing. If the signal is considered as noiseless, it is filtered by adaptive AC interference filter and smoothing filter. After this preliminary filtering the signal is passed through high-pass filter with cutoff frequency 5 Hz and differentiating filter to accentuate the signal components related to QRS-complex. Absolute values of the obtained signal samples are used as an input of QRS detection procedude [4, 5] that represents a logical algorithm based on threshold rules. This algorithm is adaptive to the current ECG amplitude and to the mean current heart rate. The begining and the end points of each detected QRS-complex are then determined and also a reference point used for RR-interval estimation.
All detected QRS-complexes are grouped into clusters with the use of dynamical clusterization algorithm [4, 5] based on the following three indices characterizing the complexes similarity: 
•linear decision rule using four QRS features (duration, amplitude, square and shift relative to the baseline);
•correlation based index;
•spectrum based index.
Each of the obtained clusters is labeled as “normal”, “pathological” or “indefinite”. 
RR-interval values and results of QRS forms classification are used further for the recognition of arrhythmia (premature ventricular beats and premature supraventricular beats). Arrhythmia recognition algorithm is based on a set of empirically derived decision rules [4]. The cardiac rhythm irregularity analysis including detection of atrial fibrillation is implemented by separate algorithm based on graphical representation of some regularities in RR-intervals values and order [8].
The analysis of HRV is also based on the RR-intervals sequence and the QRS classification results. Only the intervals between adjacent “normal” QRS-complexes (so called NN-intervals) are used for the HRV parameters estimation. The NN-interval values themselves as well as heart rate control function derived from these intervals with the use of spline interpolation are used for the HRV parameters calculation. The most widely used HRV indices both in time and frequency domains are determined by this procedure [9,10].

Results and conclusion
The pacemaker spikes detection algorithm was tested with the use of real ECGs set including 83 recording, each 300 s long. Following pacing modes underwent analysis: AAA (n=6), VVI (n=11), DDD (n=66), including biventricular pacing (n=17). Total number of the verified pacemaker spikes was 37921. The algorithm correctly detected 37276 spikes (98.3 %) while showed 531 false positives (1.4 % of the total pulses number).
Standard arrhythmia database MIT/BIH [11] was used for the QRS-complex detection and arrhythmia recognition algorithms testing. QRS detection algorithm showed sensitivity 98.90 % and specificity 99.88 % while for the ventricular premature beats these indices had values 87.2 % and 92.1 % correspondingly.
Atrial fibrillation recognition algorithm was tested with the use of Atrial Fibrillation Database [11] and showed sensitivity 93.22 % and specificity 95.57 % [8]. 
Today all algorithms presented here are included into the software of mobile cardiac monitoring system CardioQVARK. The whole volume of data stored in the system database is permanently reviewed in order to reveal ECG analysis mistakes that take place in some situations. The results of this review are used for the further enhancement of the algorithms quality.

[1] CardioQVARK project site:
[2] Maya E. Guglin, Neeta Datwani, Electrocardiograms with pacemakers: accuracy of computer reading. In: Journal of Electrocardiology, Vol. 40. p. 144–146. (2007).
[3] Andersson, Hedvig; Hansen, Marco Bo; Thorsberger, Mads; Biering-Sørensen, Tor; Nielsen, Jonas Bille; Graff, Claus; Pehrson, Steen; Svendsen, Jesper Hastrup / Diagnostic accuracy of pace spikes in the electrocardiogram to diagnose paced rhythm. In: Journal of Electrocardiology. Vol. 48, No. 5. p. 834-839. (2015).
[4] Барановский А.Л., Калиниченко А.Н., Манило Л.А. и др. Кардиомониторы. Аппаратура непрерывного контроля ЭКГ. Под ред. А.Л. Барановского и А.П. Немирко - М.: Радио и связь, 1993. - 248 с. 
[5] Немирко А.П., Манило Л.А., Калиниченко А.Н. Математические методы анализа биомедицинских данных. СПб.: Изд-во СПбГЭТУ «ЛЭТИ», 2013. - 175 с.
[6] R. M. Rangayyan, Biomedical Signal Analysis: A Case-Study Approach, (IEEE Press, Wiley-Interscience, New York, 2002). 
[7] G. D. Clifford, F. Azuaje, and P. McSharry, Advanced Methods And Tools for ECG Data Analysis, (Artech House, Norwood, MA, 2006).
[8] Моторина С.В., Калиниченко А.Н., Немирко А.П. Выбор метода кластеризации для алгоритма выявления мерцательной аритмии - "Биотехносфера". № 4(40). с. 2 -5. (2015).
[9] Heart rate variability. Standards of measurement, physiological interpretation, and clinical use. Task Force of the European Society of Cardiology and the North American Society of Pacing and Electrophysiology. Eur Heart J. 17(3). p. 354-81 (1996).
[10] Баевский Р.М., Иванов Г.Г., Гаврилушкин А.П., Довгалевский П.Я., Кукушкин Ю.А., Миронова Т.Ф., Прилуцкий Д.А., Семенов А.В., Федоров В.Ф., Флейшман А.Н., Медведев М.М., Чирейкин Л.В. Анализ вариабельности сердечного ритма при использовании различных электрокардиографических систем (часть 1) Вестник аритмологии. № 24. с. 65-86. (2002).
[11] Physionet: the research resource for physiologic signals: