 Research
 Open Access
 Published:
A novel lowcomplexity postprocessing algorithm for precise QRS localization
SpringerPlus volume 3, Article number: 376 (2014)
Abstract
Precise localization of QRS complexes is an essential step in the analysis of small transient changes in instant heart rate and before signal averaging in QRS morphological analysis. Most localization algorithms reported in literature are either not robust to artifacts, depend on the sampling rate of the ECG recordings or are too computationally expensive for realtime applications, especially in lowpower embedded devices. This paper proposes a localization algorithm based on the intersection of tangents fitted to the slopes of R waves detected by any QRS detector. Despite having a lower complexity, this algorithm achieves comparable trigger jitter to more complex localization methods without requiring the data to first be upsampled. It also achieves high localization precision regardless of which QRS detector is used as input. It is robust to clipping artifacts and to noise, achieving an average localization error below 2 ms and a trigger jitter below 1 ms on recordings where no additional artifacts were added, and below 8 ms for recordings where the signal was severely degraded. Finally, it increases the accuracy of templatebased false positive rejection, allowing nearly all mock false positives added to a set of QRS detections to be removed at the cost of a very small decrease in sensitivity. The localization algorithm proposed is particularly wellsuited for implementation in embedded, lowpower devices for realtime applications.
Introduction
Automatic QRS detection is a basic and widely used technique in the analysis of electrocardiographic (ECG) recordings and a significant amount of research effort has gone into developing automatic algorithms with high sensitivity and positive predictive value (PPV) (Köhler et al. 2002). However, despite being able to correctly detect the presence of QRS complexes, most algorithms fail to provide their precise location. In fact, standards for evaluating the performance of QRS detectors are often not strict enough. For example the ANSI/AAMI EC57 norm (EC57:1998/(R)2008 AS (1998)) recommends a margin of 150 ms when evaluating QRS detections. In a recording where the subject has an average heart rate of 60 beats per minute (bpm), this margin corresponds to 15% of the average length of a beat. This criterion is clearly meant as a guideline for evaluating the detection performance. Although it may suffice in applications where the correct detection of QRS complexes is more important than their localization, there are many areas in which the detection of small transient changes in heart rate is crucial.
For example, in the field of sleep research, Catcheside et al. (Catcheside et al. 2001) reported how the heart rate increases by approximately 14% within two seconds of the onset of arousalinducing tones during sleep. This was further confirmed by Bangash et al. (Bangash et al. 2008) who observed an increase of 10% (during REM sleep) and 15% (during nonREM) three seconds after an arousalinducing tone, followed by a decrease of 15% (REM) and 25% (NREM) five seconds after the tone onset.
Another example comes from the area of QRS morphology analysis in highresolution ECG. If the localization of QRS complexes before signal averaging^{a} is not precise enough, the resulting signal will suffer from a lowpass filtering effect which may hide relevant highfrequency lowlevel potentials (Breithardt et al. 1991; Jané et al. 1991). Since these potentials can help, for instance, in the analysis of ventricular late potentials in patients recovering from myocardial infarction, guidelines have been proposed describing the desired precision of QRS localization in terms of trigger jitter (standard deviation of the localization error), which should be below 1 ms (Breithardt et al. 1991).
A third area in which the precise localization of QRS complexes is of paramount importance is in heart rate variability (HRV) analysis. HRV analysis is a widely used technique to assess different aspects of the autonomic nervous system (ANS) and has been shown to be clinically relevant for many different applications, such as a predictor of cardiovascular disease and mortality (Thayer et al. 2010), to assess possible ANS dysfunctions in patients with chronic obstructive pulmonary disease (Volterrani 1994), and for screening of sleep disorders and evaluation of sleep quality (Stein and Pu 2012). HRV time series are usually computed from the intervals between consecutive QRS complexes and it is recommended that the ECG is sampled at high enough sampling rates (250500 Hz or higher) to guarantee a small trigger jitter in the localization of the R wave fiducial point, needed for the accurate estimation of HRV parameters (Task Force of the European Society of Cardiology and the North American Society of Pacing and Electrophysiology 1996).
Several localization methods have been proposed to address the issue of precise QRS localization. However, most either depend on the sampling rate of the original ECG (such as crosscorrelation and normalized integralsbased methods (Jané et al. 1991)), are too sensitive to noise or to signal clipping (such as thresholdbased methods (Jané et al. 1991)) or are computationally complex and not adequate to realtime applications (such as interpolation and curve fitting (Bragge et al. 2005)). Other techniques such as vectorcardiographic loop alignment, depend on the recording of multiple ECG leads (Sörnmo 1998). The increase in the computational power of modern computers allows techniques such as crosscorrelation localization to overcome limitations in regard to the sampling rate by simply upsampling the ECG signal. However, this step renders these algorithms unsuitable for lowpower, embedded processors for wearable or even implantable devices. Furthermore, templatebased localization algorithms such as crosscorrelation are not adequate for realtime processing since they require a template to first be built from QRS complexes before localization can finally take place.
The objective of this paper is to propose and evaluate a postprocessing method for precise localization of QRS complexes in singlelead ECG recordings. The proposed method, henceforth referred to as the slope algorithm, should address the following requirements:

Complexity  the algorithm should have low complexity, O(n), to enable realtime processing with modest hardware requirements and integration in lowpower embedded devices.

Trigger jitter  the algorithm should yield at least the same trigger jitter as the more computationally complex crosscorrelationbased method in high resolution ECG, and better trigger jitter at lower sampling frequencies, to enable a high localization precision in ECG recorded with lower sampling frequencies.

Localization error  the algorithm should have low average localization error, below 10 ms (1% of the average length of a beat for a recording where the average heart rate is 60 bpm), to enable applications (such as sleep arousal detection) which depend on the detection of small transient changes in interbeat interval length.

Robustness  the algorithm should be robust to the presence of noise and movement artifacts, to enable its application in recordings performed in uncontrolled (nonlaboratory) conditions; in addition, the algorithm should handle signal clipping, a common occurrence in recordings during sleep (Redmond and Heneghan 2006).

Agnostic  the algorithm should be agnostic to the QRS detection algorithm used, and perform equally well regardless of the method.
Additionally, it will be shown how template matching can be used to reduce the number of false positive detections and that the localization step performed by this postprocessing algorithm is essential for that purpose. Template matching can be used, for instance, to exclude false positive detections which lead to erroneously short estimates of interbeat intervals, or to exclude beats with aberrant QRS morphology before averaged complexes are analyzed (Sörnmo 1998).
Methods
One of the main problems of most QRS detectors is that in the presence of noise, movement artifacts or signal clipping, they do not provide precise estimates of the location of the peaks. Consequently, a postprocessing localization step is usually performed to obtain a more precise location of detected complexes (Köhler et al. 2002).
QRS Detection
The localization algorithm described in this paper can be used after any of the vast number of QRS detectors reported in literature (Ferreira et al. 2013; Friesen et al. 1990; Köhler et al. 2002). For the purpose of evaluating its performance, three popular detectors described in literature were used: the HamiltonTompkins (HT) detector (Hamilton 2002; Hamilton and Tompkins 1986), an envelopebased detector by Nygårds and Sörnmo (NS) (Nygårds and Sörnmo 1983) and a filter bankbased detector by Afonso, Tompkins et al. (AT) (Afonso et al. 1999).
Filtering
Before the signal is processed, baseline wander is first removed with a linear phase highpass filter using a Kaiser window of 1.016 sec, with a cutoff frequency of 0.8 Hz and a sidelobe attenuation of 30 dB (van Alsté et al. 1986). The coefficients of the impulse response were determined by computeraided filter design with the software Matlab R2012b (The MathWorks Inc., Massachusetts).
Localization
The level of noise, the amount of artifacts and the possible presence of signal clipping, common in recordings during sleep, all have a significant impact in the localization performance of most QRS detectors. Consider the example of a QRS complex with a motion artifact which distorts the R peak, as illustrated in Figure 1a (highlighted with a circle). Although most QRS detectors will correctly identify the presence of this complex, they will usually yield an incorrect location, usually the local maximum.
This common type of problems is first addressed by observing that the QtoR and RtoS amplitudes of a QRS complex are normally much larger than the amplitude of measurement noise. They are usually also larger than the amplitude of artifacts which do not distort the shape of the complex beyond the point that the R wave is no longer distinguishable (Friesen et al. 1990). Note that this might not hold in the presence of intense body movements. However, it is arguable whether the QRS detectors used before postprocessing would be able to detect the presence of such peaks anyway.
Because the R waves are very steep, signal differentiation usually gives the ascending and descending slopes as local maxima and minima, respectively. This simple approach has been widely used (Köhler et al. 2002), and remains the basis of some of the most popular algorithms to date (Hamilton and Tompkins 1986; Pan and Tompkins 1985). However, it suffers from some drawbacks, notably in the presence of artifacts which cause sudden, drastic changes in the signal amplitude. In such cases it often occurs that the local maxima of the differentiated signal for these artifacts is larger than the maxima which correspond to the actual slopes of the R wave (Figure 1a). This problem can be solved simply by observing that QRS complexes have a predictable length: in the absence of a medical (cardiac) condition, they last in average about 0.08 seconds (Rangayyan 2001). Instead of differentiating the ECG signal on a sampletosample basis, a larger step can be used to more accurately calculate the slope of the tangent to the signal (Figure 1b). Local maxima and minima will indicate the beginning of the slopes which are simultaneously steep and have at least a given duration. The intersection of the tangents to these slopes yields the location of the R wave peak (Figure 1c). The slope algorithm is formally described as follows:

1.
Differentiate the filtered ECG signal with a step size Δ to obtain s'
$$s\text{'}\left[n\right]=\frac{s\left[n+\mathrm{\Delta}\right]s\left[n\right]}{\mathrm{\Delta}}$$(1) 
2.
For each base peak location p _{ i } estimated by a QRS detector:

a.
Find the location of the local maximum ${\widehat{p}}_{i}$ in a window centered around p _{ i } ,
$$\widehat{p}=\underset{n\in {P}_{i}}{arg\phantom{\rule{0.12em}{0ex}}\mathrm{max}\phantom{\rule{0.12em}{0ex}}s\left[n\right]}$$(2)with
$${P}_{i}=\left[{p}_{i}\frac{W1}{2},\phantom{\rule{0.12em}{0ex}}{p}_{i}+\frac{W1}{2}\right],$$(3)where W corresponds to the expected length (in samples) of the QRS complex (0.08 sec).

b.
Find the location of the local maximum and the local minimum of s ' in a window respectively before and after ${\widehat{p}}_{i},$
$${M}_{i}=\underset{n\in \left[{\widehat{p}}_{i}W,{\widehat{p}}_{i}\right]}{arg\phantom{\rule{0.12em}{0ex}}max\phantom{\rule{0.12em}{0ex}}s\text{'}\phantom{\rule{0.12em}{0ex}}\left[n\right]}$$(4)$${m}_{i}=\underset{n\in \left[{\widehat{p}}_{i},\phantom{\rule{0.12em}{0ex}}{\widehat{p}}_{i}+W\right]}{arg\phantom{\rule{0.12em}{0ex}}min\phantom{\rule{0.12em}{0ex}}s\text{'}\phantom{\rule{0.12em}{0ex}}\left[n\right]}$$(5) 
c.
Compute the slope and the yintercept of the tangent to the ascending slope, y _{ A }
$${y}_{A}\left[n\right]={a}_{A}\cdot n+{b}_{A}$$(6)with
$${a}_{A}=s\text{'}\left[{M}_{i}\right]$$(7)$${b}_{A}=s\left[{M}_{i}\right]{a}_{A}\cdot {M}_{i}$$(8)and to the descending slope, y_{ D }
$${y}_{D}\left[n\right]={a}_{D}\cdot n+{b}_{D}$$(9)with
$${a}_{D}=s\text{'}\left[{m}_{i}\right]$$(10)$${b}_{D}=s\left[{m}_{i}\right]{a}_{D}\cdot {m}_{i}$$(11) 
d.
Compute the location of the intersection n _{ I } between the two tangents,
$${n}_{I}=\frac{{b}_{D}{b}_{A}}{{a}_{A}{a}_{D}},$$(12)$${y}_{I}={a}_{A}\cdot {n}_{I}+{b}_{A}.$$(13)
Note that the tangent intersection n_{ I } does not necessarily correspond to the exact (integer) location of a sample in the discretized ECG. This means that the location of the peak can be computed with subsample precision and has as an important consequence, as will be shown, that the localization error is to a certain extent independent of the sampling rate of the ECG signal.
The differentiation step Δ is an important parameter in the algorithm. As explained in Appendix A, this factor should be as large as possible to minimize the localization error. However, it should not be larger than the length of the slope. In order to increase the robustness of the algorithm to clipping artifacts which cause the slopes to be shortened not only in amplitude but also in duration, a step size corresponding to approximately half of the expected length of each slope was chosen. Considering that each QRS complex lasts about 80 ms, and that each slope lasts around 40 ms, a step size of 20 ms was chosen and experimentally found to be adequate. Note that when analyzing unclipped signals this parameter can be increased in order to further reduce the trigger jitter, as explained in Appendix A; lowering the parameter increases the trigger jitter in the presence of noise. Figure 1a illustrates (in bold) the signal obtained after singlesample differentiation. The artifact at the center of the R wave introduces additional local minima which do not correspond to the descending slope of the QRS complex. Figure 1b illustrates the signal obtained after differentiating the ECG with a Δ factor of 10 samples (20 ms at a sampling frequency of 500 Hz). The maximum and minimum values now correspond to the beginning of the steepest parts of the slopes. After identifying the parameters of the tangent to the ascending and descending slopes, their intersection yields the location of the R wave peak (Figure 1c).
As explained in Appendix B, this algorithm has a complexity of O(n), lower than that of crosscorrelationbased methods.
Template matching
Template matching can be used to reduce the number of false positive detections in a recording. The template should be chosen such that it represents the morphology of the QRS complexes in an ECG recording and can be obtained by averaging the signal around the location of each peak in a window with a length equal to the median duration of the beats in each recording.
After the template is estimated, the correlation between each detected complex and the template can be computed. Under the assumption of monomorphic QRS complexes, false positive locations should have a lower correlation value (Figure 2a) than undistorted complexes. Complexes slightly distorted by noise should also yield a lower correlation value, but as long as they retain some of their characteristics the correlation should still be higher than of false positives (Figure 2b). As an example of the impact of body movement artifacts, Figure 2c illustrates the correlation obtained with complexes detected and localized in an ECG recorded simultaneously with actigraphy (Actiwatch Spectrum, Philips Electronics) during a full night. As it can be easily seen, the correlation is inversely proportional to the amplitude of the actigraphy peaks.
Evaluation
Data sets
The slope algorithm was tested in two publicly available data sets. The first comprises 18 longterm ECG recordings (lead II) of subjects with no significant arrhythmias from the MITBIH Normal Sinus Rhythm Database (MITBIH) (Goldberger et al. 2000; Moody and Mark 2001). Each recording has a sampling rate of 128 Hz and an average length of 24.3 ± 0.83 hour. This data set was chosen since it comprises full day recordings, including periods with intense motion artifacts, naturally occurring in this type of monitoring scenarios.
The second data set comprises 79 highresolution ECG recordings (lead II) of subjects annotated as healthy controls in the PTB Diagnostic ECG Database (PTBD) (Bousseljot et al. 1995; Goldberger et al. 2000). Each recording has a sampling rate of 1000 Hz and an average length of 118.9 ± 3.4 sec.
Crosscorrelation localization
As discussed, localization has been traditionally performed for the purpose of signal averaging in the area of QRS morphology analysis where it is crucial to have a low trigger jitter. One of the most successful methods uses crosscorrelation between a template (built by averaging QRS complexes detected with a QRS detector) and each complex to improve the estimated location. Since this is one of the most successful localization algorithms reported in literature, especially when used on highresolution (or upsampled) ECG signals, it will be used to establish the groundtruth locations of QRS complexes in our database and as reference to evaluate the slope algorithm.
An implementation of this method, henceforth referred to as the xcorr algorithm, is described as follows:

Remove baseline wandering using the filtering procedure described in an earlier section.

Compute a template of the QRS complexes based on the initial locations, using the template algorithm described in a later section.

For each complex, find the location which maximizes the crosscorrelation between the template and the ECG signal around the original location.

Build a new template based on the adjusted locations.

For each complex, store as the final location of its R wave peak the location that maximizes the crosscorrelation between the new template and the ECG signal around the adjusted location.
Groundtruth
The MITBIH data set includes annotated QRS locations per recording. Unfortunately these only indicate the location of the QRS complex, and not always the precise location of the R wave peak. On the other hand, the PTB data set does not include annotations with the location of QRS complexes, so these were first estimated using the HT detector. In order to obtain a groundtruth for both datasets, each recording was first upsampled to 10000 Hz, after which the xcorr algorithm was used to obtain precise locations. A similar procedure was previously used by Shaw and Savard (Shaw and Savard 1995) to obtain precise groundtruth locations in their data set.
Trigger jitter
To compare the trigger jitter obtained with the slope algorithm with the more computationally complex xcorr algorithm, both were tested on highresolution ECG recordings from the PTB database, after downsampling^{b} them to different sampling rates (500, 200, 100, and 50 Hz). To illustrate that the localization precision is not only bound by the time resolution of the signal, but also by its bandwidth which is in turn limited by the sampling rate, both algorithms were also tested after upsampling each (downsampled) recording to the original sampling rate of 1000 Hz. Note that this procedure increases the time resolution but does not change the spectral content of the signal. For each algorithm and sampling rate, the pooled trigger jitter $\sigma}_{e}^{p$ was computed as
where k is the number of recordings in the data set and ${\sigma}_{{e}_{i}}$ is the standard deviation of the localization error (trigger jitter) for all n_{ i } peaks localized within 40 ms of any groundtruth location^{c} for recording i.
Localization
In order to evaluate the robustness of the slope algorithm in the presence of artifacts and noise, the ECG signals in the MITBIH data set were degraded with clipping artifacts and Gaussian noise. Clipping artifacts were introduced to simulate saturation artifacts (Venkatachalam et al. 2011) and digital clipping. The following procedure was used:

Remove baseline wandering using the filtering procedure described in an earlier section.

Compute the median, p_{ m }, and the 99.9th percentile p_{ M } of the amplitude of the ECG.

Determine the clipping threshold ct for a given clipping factor cf
$$\mathit{ct}={p}_{m}+\left({p}_{m}{p}_{m}\right)\cdot \mathit{cf}.$$(17) 
Clip the ECG signal,
$${s}_{c}\left[n\right]=\left\{\begin{array}{cc}\hfill \mathit{ct}\hfill & \hfill \mathit{if}\phantom{\rule{0.12em}{0ex}}s\left[n\right]\ge \mathit{ct}\hfill \\ \hfill s\left[n\right]\hfill & \hfill \mathit{otherwise}\hfill \end{array}.\right.$$(18)
In order to simulate a wide range of clipping and saturation artifacts, the following clipping factors were used: 1 (no clipping), 0.6, and 0.3. The last factor is meant as a lower bound for this type of artifacts, as it is unlikely that a segment of a recording where the ECG is distorted to that degree can still allow any useful analysis.
In addition to clipping, the localization precision was tested in the presence of Gaussian noise added to the ECG signal to obtain specific signaltonoiseratios (SNR): 20 dB, 10 dB, and 5 dB. For simplicity, the noise power in the original signal was considered negligible in comparison with the added noise.
The localization precision of the slope postprocessing algorithm was evaluated with each of the three QRS detectors listed earlier on the ECG recordings of the MITBIH data set degraded with the conditions described above. For each recording, the mean and standard deviation of the localization error (distance between detected/localized peaks and the groundtruth locations) before and after postprocessing were computed.
Template matching
The impact of localization on template matching was evaluated by comparing its effectiveness in rejecting false positive detections before and after the slope algorithm was used. Mock “false positive detections” were added to the list of base QRS detections, after which template matching was applied. Complexes with a correlation below certain thresholds were rejected, and the resulting positive predictive value (PPV) and sensitivity were computed. The following procedure was used:

Use the HT detector to detect the base locations in each ECG recording of the MITBIH data set.

Add a percentage f_{ i } of randomly located false positives (‘mock false positives’) to the base list of locations. For example, a ‘mock false positive percentage’ f_{ i } of 100% means that a number of mock false positives equal to the number of original locations will be added.

Compute the median length B_{ j } between consecutive localized QRS complexes for each ECG recording j.

Compute a template as the signal average of all windows of length B_{ j } for each recording j.

Compute the correlation between the template of each recording and the ECG signal for each location on that recording.

Determine the threshold T such that the sensitivity obtained after removing locations with a correlation lower than T remains above a specified limit. Compute the corresponding PPV (post_{none}).

Use the slope algorithm to obtain a list of adjusted locations.

Compute a new template and the corresponding correlations with the adjusted locations.

Determine the thresholds T such that the sensitivity obtained after removing locations with a correlation lower than T remains above a specified limit. Compute the corresponding PPV (post_{slope}).
The choice of using a varying threshold instead of a fixed one serves the purpose of simultaneously evaluating the effect on the sensitivity and PPV of the algorithm. In turn, this allows an assessment of its performance for different scenarios where for example, sensitivity is more important than PPV, or viceversa.
Results
Trigger jitter
Figure 3 illustrates the pooled trigger jitter obtained with the slope and with the xcorr algorithms with and without upsampling, after having downsampled the original highresolution ECG signal to different sampling rates. As it can be observed, the trigger jitter obtained with the slope algorithm for (down)sampling frequencies above 50 Hz was always lower than 1 ms, even without upsampling the signal, which means that the algorithm meets the strict requirement of 1 ms specified by the guidelines for QRS localization (Breithardt et al. 1991). In contrast, the trigger jitter obtained with the xcorr algorithm increased beyond 1 ms unless the signal was first upsampled. The localization error obtained with xcorr at 1000 Hz is not zero since the groundtruth was obtained after upsampling the original recordings at 10000 Hz.
The reason why the trigger jitter increased when the signal was downsampled to 50 Hz is related to the spectral properties of the QRS complexes. As reported by Thakor et al. (Thakor et al. 1984), QRS complexes have spectral components up to 40 Hz. When the signal is downsampled below 80 Hz, these components are affected, changing the morphology of the signal and causing a decrease in localization precision.
Localization
The localization error and the trigger jitter were computed for all clipping artifact and noise conditions. The results, illustrated in Figure 4, show that the average localization error obtained after postprocessing is, overall, lower than that obtained with the original locations output by the three QRS detectors, and always below 2 ms. In addition, the trigger jitter is also lower than 8 ms and lower than of the original locations with the exception of the AT detector. However, it should be noted that the sensitivity of this detector in these conditions was very low. After postprocessing, sensitivity increased substantially, reflecting the increased precision in the localization of the complex.
To emphasize the improvement over the base HT performance, Figure 5 illustrates the trigger jitter obtained with and without slope localization after HT detection and after template matching. Varying the clipping factor for a fixed SNR of 20 dB (Figure 5, above) shows that the trigger jitter after localization (blackfilled markers) is always lower than without localization (whitefilled markers), highlighting the robustness of the algorithm to clipping artifacts. This is true for the whole range of sensitivities obtained using different thresholds with template matching. Varying the SNR without clipping (Figure 5, below) shows that with the exception of SNR = 5 dB, the trigger jitter is also always lower with slope localization, highlighting the robustness of the algorithm to noise, especially in moderate conditions. Regarding the condition SNR = 5 dB and if the analysis is restricted to complexes that are less distorted by noise (at the cost of a lower sensitivity), it is clear that below a sensitivity of 0.8 the trigger jitter with localization is also lower. Applications with strict requirements in terms of trigger jitter require this template matching step anyway to minimize the localization error. For such applications, the template matching procedure, with a complexity of O(n), does not increase the overall complexity of the slope algorithm.
These results are in line with the theoretical localization error derived in Appendix A.
Template matching
Figure 6 illustrates the sensitivity and PPV obtained after rejecting locations with a correlation value below a varying threshold for mock false positive percentages, f_{ i } = 100% and f_{ i } = 200%. In both cases, increasing the threshold leads to the rejection of an increasing number of locations and to a consequent decrease in sensitivity, since besides false positives, a few true positives are also rejected. However, despite the fact that the sensitivity decrease is extremely small, the corresponding increase in PPV is substantial. Although this is true for both post_{slope} and post_{none}, it is more pronounced for the case where postprocessing is applied.
Figure 7 illustrates the PPV obtained for different f_{ i } after rejecting peaks with correlations lower than thresholds chosen such that the sensitivity was higher than specific values. Note that even before locations are rejected, the PPV already increases after postprocessing (T = 0). This happens because some false positive locations which are close to actual peaks in the ECG are merged to the same location on the first step of the localization algorithm (equation (2)). With a sensitivity of 0.992 the PPV approaches 1 even for ${\mathit{f}}_{\mathit{i}}=\mathrm{200\%}$. With a sensitivity decrease of 0.005 (0.5%) and 0.008 (0.8%) the PPV increases by nearly 50% and 70% for ${\mathit{f}}_{\mathit{i}}=\mathrm{100\%}$ and ${\mathit{f}}_{\mathit{i}}=\mathrm{200\%}$ respectively, effectively rejecting almost all false positives added to the base locations.
Discussion and conclusions
Among the localization algorithms reported in literature, crosscorrelationbased methods were found to be among the best performing. However, the localization precision of these algorithms is intrinsically linked to the sampling rate of the recording, which is not an issue for highresolution ECG recordings, but is for recordings performed at lower sampling rates. In addition, these algorithms are computationally very expensive (O(n^{2}), see Appendix B), which makes them less suited for lowpower embedded devices; furthermore, since they typically require templates built from the entire recording, their applicability for realtime, online applications is limited. The algorithm proposed in this paper was developed with these requirements in mind. Despite its lower complexity (O(n)) it achieves comparable trigger jitter without requiring the data to first be upsampled. It also achieves high localization precision regardless of which QRS detector is used as input. Although it relies on the detection of just a few points in the ECG, it is extremely robust to noise, clipping and movement artifacts. In fact, postprocessing with the slope algorithm was able to correct the original QRS locations of three different detectors under almost all noise conditions, yielding an average localization error below 2 ms, and a trigger jitter below 8 ms, even for recordings where the signal was severely degraded. Furthermore the increased localization precision improved template matching. After rejecting locations based on their (lower) correlation coefficient, it allowed the correct rejection of nearly all mock false positives added to a base list of detected QRS locations, with only a marginal decrease in sensitivity (0.5% for f_{ i }=100% and 0.8% for f_{ i }=200%).
These results have important consequences for applications which require realtime ECG analysis. Given its low complexity, low localization error and robustness to signal clipping, which is common in sleep recordings, it can enable realtime detection of arousals during sleep. On the other hand, given its robustness to noise and artifacts, it can also enable realtime ECG morphology analysis even under challenging conditions such as during physical exercise. Finally, and as a byproduct of the detection process, the slopes and tangents actually have clinical value, for example in detecting and characterizing myocardial ischemia (Pueyo et al. 2008; Romero et al. 2013).
Endnotes
^{a}Signal averaging is a technique used in QRS morphological analysis whereby a number of QRS complexes in an ECG recording are first aligned in the time domain and then averaged to improve the signaltonoise ratio of the resulting signal.
^{b}A lowpass filter with a cutoff frequency of 0.8*(fs/2), with fs as the desired frequency, was used before downsampling to prevent aliasing.
^{c}This is the same margin as that indicated in the guidelines for analysis of ventricular late potentials using signalaveraging technique (Breithardt et al. 1991) and corresponds to half of the average length of QRS complexes (Rangayyan 2001).
^{d}Using the slope estimates given by the localization algorithm, the minimum and maximum slope ratios found in the PTBD dataset were 0.68 and 1.84 respectively, confirming the expected asymmetry of QRS complexes described in literature (Pueyo et al. 2008; Romero et al. 2013).
Appendix A – Theoretical localization error
This appendix derives the theoretical localization error obtained using the slope algorithm on an ECG signal contaminated with white Gaussian noise.
Consider the ascending and descending slopes of y_{ A } and y_{ D } as defined by (6) and (9) and assume that the ratio β between them is given by
Now consider that the ECG signal has been perturbed by a noise signal with amplitude E. This means that in case both the QRS complex and the noise component have a zero mean, the amplitude of each sample in the QRS complex may change by a maximum of ± e = E/2. The worst possible localization error in this situation is illustrated in Figure 8.
The resulting tangents, y'_{ A } and y’_{ D }, are defined by
with
and intersect at a new location n’_{ I },
Using (13) and (26), the maximum localization error, e’_{ I } is given by
Noting that
we have that
Similarly,
Using the relation n_{ 4 } = n_{ 1 } + L we have
Using (31) and (29) in (27), we finally have
As it can be seen, the localization error depends on the maximum amplitude of the noise component of the signal, the slopes of the QRS complex, the distance between the first and the last sample and the distance between each pair of samples (differentiation step) used to compute the tangents. For simplicity consider that the ascending slope S of the QRS complex is constant and defined by the ratio between the amplitude of the ECG signal A and half of the length of the QRS complex, Q/2. The localization error is then given by
Assuming that the noise component is mainly caused by electromyographic (EMG) noise, it can be considered to follow a zeromean Gaussian distribution with a standard deviation of 10% of the amplitude of the ECG signal (Friesen et al. 1990). Taking as slope ratio β the median value experimentally found in the recordings of the PTBD dataset (1.13 ^{d}), an average QRS duration of 0.08 sec (Rangayyan 2001), using a differentiation step Δ of 0.02 sec and choosing as L the length of the QRS complex Q (the largest possible value such that n_{ 1 } and n_{ 4 } are still part of the QRS), we can estimate the bounds of the standard deviation of the localization error (or trigger jitter),
Appendix B – Computational Complexity
This appendix derives the computational complexity of the xcorr and slope algorithms and compares their performance using a computer simulation. Since for both algorithms peak localization takes place for every QRS complex, let n represent the average number of samples analyzed per complex. The xcorr algorithm performs the following steps:

1.
Search for the local maximum, complexity O(n).

2.
Add the contribution of each sample to the template (consider that the template has the same number of samples n), O(n) .

3.
Perform crosscorrelation with the template for 2n + 1 positions around the center of the peak, O (n⋅(2n + 1)) = O(n ^{2}) .

4.
Find the position that yields the maximum crosscorrelation, O(n) .

5.
Repeat steps 2 to 4.
The overall complexity of the xcorr algorithm is O(n^{2}). Note that the complexity of the upsampling step, necessary to guarantee a high localization performance with this algorithm for recordings with lower sampling rates was not included. Although that does not influence the overall complexity, it is an important factor to take into account when comparing the performance of both algorithms since it introduces an additional factor in the number of samples that need to be analyzed.
The slope algorithm performs the following steps:

1.
Find the local maximum, O(n).

2.
Differentiate the signal, O(n).

3.
Find the maximum of the derivative before the local maximum, O(n/2) = O(n).

4.
Find the minimum of the derivative after the local maximum, O(n/2) = O(n).
The overall complexity of the slope algorithm is O(n).
Both algorithms were also compared in terms of running time, using a nonoptimized implementation in Matlab R2012b (The MathWorks Inc., Massachusetts) running on a computer with an Intel Core i52540 M at a clock speed of 2.60 GHz. Each algorithm was used to localize peaks detected with the HamiltonTompkins detector on the 18 recordings of the MITBIH data set. In the case of the xcorr algorithm, the signal was first upsampled to 1000 Hz to guarantee a comparable localization performance, but the running time for this operation was not included. The average running time (per recording) of the xcorr algorithm was 210.63 ± 55.31 sec and of the slope algorithm, 23.08 ± 6.26 sec, nearly ten times faster.
References
Afonso VX, Tompkins WJ, Nguyen TQ, Luo S: ECG beat detection using filter banks. IEEE Trans Biomed Eng 1999, 46: 192202. 10.1109/10.740882
Bangash MF, Xie A, Skatrud JB, Reichmuth KJ, Barczi SR, Morgan BJ: Cerebrovascular response to arousal from NREM and REM sleep. Sleep 2008, 31: 321327.
Bousseljot R, Kreiseler D, Schnabel A: Nutzung der EKGSignaldatenbank CARDIODAT der PTB über das Internet. Biomed Tech Eng 1995, 40: 317318.
Bragge T, Tarvainen MP, Rantaaho PO, Karjalainen PA: Highresolution QRS fiducial point corrections in sparsely sampled ECG recordings. Physiol Meas 2005, 26: 743751. 10.1088/09673334/26/5/013
Breithardt G, Cain ME, ElSherif N, Flowers NC, Hombach V, Janse M, Simson MB, Steinbeck G: Standards for analysis of ventricular late potentials using highresolution or signalaveraged electrocardiography. J Am Coll Cardiol 1991, 17: 9991006. 10.1016/07351097(91)90822Q
Catcheside PG, Chiong SC, Orr RS, Mercer J, Saunders NA, McEvoy RD: Acute cardiovascular responses to arousal from nonREM sleep during normoxia and hypoxia. Sleep 2001, 24: 895902.
EC57:1998/(R)2008 AS: Testing and Reporting Performance Results of Cardiac Rhythm and ST Segment Measurement Algorithms. ANSI/AASM/ISO, Arlington, Virginia, USA; 1998.
Ferreira JL, Cluitmans PJM, Aarts RM: Detection of sharp wave activity in biological signals using differentiation between consecutive samples. In 6th International Conference on Bioinspired Systems and Signal Processing (BIOSIGNALS 2013). SciTe Press: Barcelona, Spain; 2013:327332.
Friesen GM, Jannett TC, Jadallah MA, Yates SL, Quint SR, Nagle HT: A comparison of the noise sensitivity of nine QRS detection algorithms. IEEE Trans Biomed Eng 1990, 37: 8598. 10.1109/10.43620
Goldberger AL, Amaral LAN, Glass L, Hausdorff JM, Ivanov PC, Mark RG, Mietus JE, Moody GB, Peng CK, Stanley HE: PhysioBank, PhysioToolkit, and PhysioNet: Components of a new research resource for complex physiologic signals. Circulation 2000, 101: e215e220. 10.1161/01.CIR.101.23.e215
Hamilton P: Open source ECG analysis. In Computers in Cardiology 2002. Krakow, Poland: IEEE Conference Publications; 2002:pp 101104.
Hamilton PS, Tompkins WJ: Quantitative investigation of QRS detection rules using the MIT/BIH arrhythmia database. IEEE Trans Biomed Eng 1986, BME33: 11571165.
Jané R, Rix H, Caminal P, Laguna P, Jane R: Alignment methods for averaging of highresolution cardiac signals: A comparative study of performance. IEEE Trans Biomed Eng 1991, 38: 571579. 10.1109/10.81582
Köhler BU, Hennig C, Orglmeister R: The principles of software QRS detection. IEEE Eng Med Biol Mag 2002, 21: 4257. 10.1109/51.993193
Moody GB, Mark RG: The impact of the MITBIH arrhythmia database. IEEE Eng Med Biol Mag 2001, 20: 4550. 10.1109/51.932724
Nygårds ME, Sörnmo L: Delineation of the QRS complex using the envelope of the ECG. Med Biol Eng Comput 1983, 21: 538547. 10.1007/BF02442378
Pan J, Tompkins WJ: A realtime QRS detection algorithm. IEEE Trans Biomed Eng 1985, 32: 230236.
Pueyo E, Sornmo L, Laguna P: QRS slopes for detection and characterization of myocardial ischemia. IEEE Trans Biomed Eng 2008, 55: 468477.
Rangayyan RM: Biomedical Signal Analysis: A CaseStudy Approach. Press, WileyIEEE; 2001.
Redmond SJ, Heneghan C: Cardiorespiratorybased sleep staging in subjects with obstructive sleep apnea. IEEE Trans Biomed Eng 2006, 53: 485496. 10.1109/TBME.2005.869773
Romero D, Ringborn M, Laguna P, Pueyo E: Detection and quantification of acute myocardial ischemia by morphologic evaluation of QRS changes by an anglebased method. J Electrocardiol 2013, 46: 204214. 10.1016/j.jelectrocard.2013.02.014
Shaw GR, Savard P: On the detection of QRS variations in the ECG. IEEE Trans Biomed Eng 1995, 42: 736741. 10.1109/10.391174
Sörnmo L: Vectorcardiographic loop alignment and morphologic beattobeat variability. IEEE Trans Biomed Eng 1998, 45: 14011413. 10.1109/10.730434
Stein PK, Pu Y: Heart rate variability, sleep and sleep disorders. Sleep Med Rev 2012, 16: 4766. 10.1016/j.smrv.2011.02.005
Task Force of the European Society of Cardiology and the North American Society of Pacing and Electrophysiology: Heart rate variability. Standards of measurement, physiologic interpretation, and clinical use. Eur Heart J 1996, 17: 354381. 10.1093/oxfordjournals.eurheartj.a014868
Thakor NV, Webster JG, Tompkins WJ: Estimation of QRS complex power spectra for design of a QRS filter. IEEE Trans Biomed Eng 1984, 31: 702706.
Thayer JF, Yamamoto SS, Brosschot JF: The relationship of autonomic imbalance, heart rate variability and cardiovascular disease risk factors. Int J Cardiol 2010, 141: 12231. 10.1016/j.ijcard.2009.09.543
Van Alsté JA, van Eck W, Herrmann OE: ECG Baseline wander reduction using linear phase. Comput Biomed Res 1986, 19: 417427. 10.1016/00104809(86)900376
Venkatachalam KL, Herbrandson JE, Asirvatham SJ: Signals and signal processing for the electrophysiologist: part II: signal processing and artifact. Circ Arrhythm Electrophysiol 2011, 4: 97481. 10.1161/CIRCEP.111.964973
Volterrani M: Decreased heart rate variability in patients with chronic obstructive pulmonary disease. Chest J 1994, 106: 1432. 10.1378/chest.106.5.1432
Author information
Affiliations
Corresponding author
Additional information
Competing interests
The authors declare that they have no competing interests.
Authors’ contributions
PF implemented and tested the algorithm, and drafted the manuscript, RMA participated in the design of the algorithm and the evaluation study, and helped drafting the manuscript, JF and XL tested and improved the algorithm, and helped drafting the manuscript. All authors read and approved the final manuscript.
Authors’ original submitted files for images
Below are the links to the authors’ original submitted files for images.
Rights and permissions
Open Access This article is distributed under the terms of the Creative Commons Attribution 4.0 International License (https://creativecommons.org/licenses/by/4.0), which permits use, duplication, adaptation, distribution, and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.
About this article
Cite this article
Fonseca, P., Aarts, R.M., Foussier, J. et al. A novel lowcomplexity postprocessing algorithm for precise QRS localization. SpringerPlus 3, 376 (2014). https://doi.org/10.1186/219318013376
Received:
Accepted:
Published:
Keywords
 Electrocardiography
 QRS localization
 Trigger jitter
 Motion artifacts