Robust artefact detection in long-term ECG recordings based on
autocorrelation function similarity and percentile analysis*
Carolina Varon, Member, IEEE, Dries Testelmans, Bertien Buyse,
Johan A.K. Suykens Senior Member, IEEE, and Sabine Van Huffel, Fellow, IEEE
Abstract— Artefacts can pose a big problem in the analysis of
This means that, even though the quality of the signal is
electrocardiogram (ECG) signals. Even though methods exists
enhanced, some artefacts are still present, and can have
to reduce the influence of these artefacts, they are not always
a negative influence on the analysis. An approach to find
robust. We propose a new algorithm that is based on easy-to-
locations of artefacts has been proposed in [6], where the
implement tools such as autocorrelation functions, graph theory
and percentile analysis. We show that our algorithm successfully

signal is evaluated with a moving window. One shortcoming
detects artefacts, and that it can be applied to real-life problems
of this method is the use of rules to identify an artefact.
as for example to sleep apnea classification.
Furthermore, the method assumes that no abrupt alterations
occur.
In this paper, we address these problems, and propose a
new algorithm to identify the location of artefacts in long-
I. INTRODUCTION
term ECG recordings. Our method is based on graph theory
The diagnostic capabilities of the electrocardiogram
[15], and detects ECG segments that are highly corrupted by
(ECG) can be reduced by the presence of artefacts in
noise or artefacts. The idea behind it is characterization of
the signal. Artefacts can be caused by electrode motion,
ECG segments by the autocorrelation function (ACF), and
contact noise and electromyography among others [1], which
to use graph theory to distinguish between them. This works
corrupt the ECG. The presence of these artefacts can produce
because the ACF shows repetitive patterns, and hence also
misleading outcomes in research such as diagnosis based
disturbances, i.e. artefacts, in the ECG. The ACF has been
on long-term monitoring, classification of ECG segments,
used in previous studies using ECG signals [8],[9], [10], and
or ECG-derived respiration. In order to obtain accurate
[11], but never to locate artefacts.
conclusions from any ECG analysis, it is very important
The rest of this document is organized as follows. Section
to filter or eliminate noise and artefacts [2]. In principle
II describes the data and elaborates more on the proposed
this can easily be done when short signals are analysed,
algorithm. Section III shows the results and discussions on
because the size of the dataset allows for manual inspection
the findings. Finally, section IV contains the conclusions of
of the artefacts. However, in practice, long-term recordings
this work.
of several patients are studied at the same time. This means
a large dataset, and hence an automated way of detecting
and removing artefacts is required. Different algorithms have
II. METHODOLOGY
been proposed to enhance the quality of the ECG, e.g. [3],
[4] [5]. A disadvantage of those methods is that they do
A. Data
not provide information on the location of the artefacts.
The dataset used in this study consists of 16 single lead
ECG recordings extracted from polysomnographic measures
*Research supported by Research Council KUL: GOA MaNet, CoE
of 16 different patients of the sleep laboratory at the Uni-
EF/05/006 Optimization in Engineering (OPTEC), PFV/10/002 (OPTEC),
versity Hospital Leuven (UZ Leuven), Belgium. The signals
IDO 08/013 Autism, several PhD/postdoc & fellow grants; Flemish Gov-
ernment: FWO: PhD/postdoc grants, projects: FWO G.0302.07 (SVM),
were sampled at 200Hz and the recording time ranged from
G.0341.07 (Data fusion), G.0427.10N (Integrated EEG-fMRI), G.0108.11
4 up to 11 hours. In total 152 hours and 12 minutes were
(Compressed Sensing) G.0869.12N (Tumor imaging) research communi-
extracted. Each recording was manually annotated by a
ties (ICCoS, ANMMM); IWT: TBM070713-Accelero, TBM070706-IOTA3,
TBM080658-MRI (EEG-fMRI), PhD Grants; IBBT; Belgian Federal Sci-
clinician, who indicated the position of different types of
ence Policy Office: IUAP P6/04 (DYSCO, ‘Dynamical systems, control and
sleep apnea events. These annotations are used in Section
optimization’, 2007-2011); ESA AO-PGPF-01, PRODEX (CardioControl)
III to verify the algorithm when applied to the problem of
C4000103224; EU: RECAP 209G within INTERREG IVB NWE pro-
gramme, EU HIP Trial FP7-HEALTH/ 2007-2013 (n 260777) ( Neuromath
detecting sleep apnea.
(COST-BM0601); BIR&D Smart Care
C. Varon is with the KU Leuven, Department of Electrical Engineering
B. Segmentation and characterization of the ECG
ESAT, SCD-SISTA, and IBBT Future Health Department, Leuven, Belgium
e-mail: carolina.varon@esat.kuleuven.be
Our algorithm was originally inspired by sleep apnea clas-
D. Testelmans and B. Buyse are with the UZ Leuven, Department of
sification, where each signal is segmented and analysed on
Pneumology , Leuven, Belgium
a minute-by-minute basis [12],[13]. With this in mind, each
S. Van Huffel and J.A.K. Suykens are with the KU Leuven, Department
of Electrical Engineering ESAT, SCD-SISTA, and IBBT Future Health
ECG recording is first divided into segments of length N .
Department, Belgium.
Then, the low and high frequency components are attenuated,

by means of a band pass Butterworth filter with cut-off
III. RESULTS AND DISCUSSION
frequencies of 1Hz and 40Hz. The frequency bands are
This section is divided in two, first the ability of the
selected based on the low- and high-frequency limits of a
proposed method to identify artefacts in the signals is stud-
diagnostic ECG [1] and on the fact that variations due to
ied. Second, we apply our algorithm to a typical practical
baseline drifts should not be considered.
problem, namely a sleep apnea classifier.
After this preprocessing, the ACF of each ECG segment
is obtained by computing the inverse Fourier transform of its
A. Detection of artefacts
corresponding power spectral density (PSD).
The total number of minutes in the dataset is 9132 and
Note that we are using the Fourier transform of a non-
stationary signal, which normally should be avoided be-
only 294 of them contain artefacts, which we manually
labelled. This labelling allows us to validate our method, and
cause of low frequency resolution. In other words, Fourier
compare the performance with that of k-means and KSC.
transforms can normally not be used to study e.g. beat
abnormalities or rhythm changes [1]. Remember, however,
As mentioned in Table I, we first compute the ACF for
that we are trying to detect artefacts of the signal, rather
each segment. After that, we calculate its weight and we
than deviations from healthy ECGs. That means that for the
apply the 95 percentile threshold. This gives two groups: the
artefact detection, the resolution of the Fourier transform is
normal segments and the contaminated ones. Fig. 2 shows
sufficient, and we indeed verified this to be true.
the weights of the segments of one ECG signal, and the 95th
percentile. Note that the segments with the lowest weights
C. Weights Computation
are clearly separated from the rest. Finally, the other two
Now that we have calculated the ACFs, we need to find
partition algorithms are also applied to the same set of ACFs,
which segments contain artefacts. As we mentioned in the
with the purpose of separating the segments into two clusters.
introduction, when an ECG is interrupted by an artefact, a
Due to inter-subject variabilities in the ECG and ACF,
clear change in the ACF is observed. This means that the
the algorithms are applied to each ECG signal separately.
ACFs that contain artefacts are “dissimilar” from the noise-
To compare the performance of the algorithms, we compute
free segments, and we need to detect this difference. To do
statistical measures often used in classification known as sen-
this, we link our problem to graph theory [15], where we
sitivity, specificity, and accuracy. These values are computed
represent the set of ACFs on a mathematical structure known
for each algorithm and for each patient separately, and they
as a graph. Such a graph consists of vertices, in our case the
are shown in the box plots of Fig. 3 From there we can see
ACFs, that are pairwise connected by edges, which indicate
that our algorithm (95th) outperforms the other two, because
how similar two vertices are. The length of these edges is
accuracy, specificity and sensitivity are higher for all patients.
determined by the inverse of the pairwise similarity between
For completeness, all the one-minute segments are put
the ACFs, namely the cosine similarity. In this way, segments
together and the algorithms are applied to all the signals
that are significantly different from the rest, i.e. artefacts, will
at the same time. The best results for the whole dataset
be represented by isolated vertices.
are again produced by the 95th percentile threshold and
These isolated vertices are characterized by a lower value
correspond to a sensitivity of 93.2% and specificity of 90.4%.
of what is known as the degree of the vertices. A low degree
To determine if the duration of the segments affects the
typically indicates that a vertex is dissimilar from the rest of
results, we repeat the experiments with N ranging from 5
the graph, i.e. it gives the relative importance of a vertex
to 60 seconds. The best results are obtained after analysing
in the graph. The degree of each vertex is computed by
segments of 5 seconds, the lower bound of our epochs. This
adding the pairwise similarities between that specific vertex,
is no surprise, since as shorter segments are analysed, less
and the rest of the graph. When ECG segments are clean
information from normal ECG is included. In other words,
of artefacts, their ACFs are similar, and the corresponding
when the selected epochs contains, proportionally to the
vertices will get high degree values, i.e. they are strongly
connected in the graph. This can be seen in Fig. 1, where we
TABLE I
plot two normal ECG segments (left) and two contaminated
ARTEFACT DETECTION ALGORITHM
ones (right). Their degree values are indicated, as well as
their ACFs.
Input: ECG signal and length N . In this study we use N = 60s.
Our proposal is to use these degrees as a “weight” to
Output: Weight for each ECG segment and 95th percentile of the
indicate how clean an ECG segment is. We include this
weights.
1: Segment the ECG into epochs of length N .
idea in the analysis by only considering the 95 percent most
2: Compute the ACF of each segment using the inverse Fourier
similar segments. In percentile analysis, the 95 percentile
transform of its corresponding PSD.
is an often used value to detect outliers. The algorithm we
3: Calculate the cosine similarity between each pair of ACFs.
This results in the similarity matrix between all ACFs.
propose here is summarized in Table I.
4: Compute the degree values by summing all the columns of the
In the next section, we will show that our algorithm
similarity matrix. These degrees correspond to the weights.
outperforms methods such as k-means [16] and kernel
5: Calculate the 95th percentile of the weights.
6: Label the segments with weights outside the 95th percentile, as
spectral clustering (KSC) [17] in separating normal from
contaminated.
contaminated segments.

ECG
0
5000
10000
0
5000
10000
0
5000
10000
0
5000
10000
samples
samples
samples
samples
d = 1
d = 0.98
d = 0.26
d = 0.23
0.8
0.8
0.8
0.8
0.6
0.6
0.6
0.6
0.4
0.4
0.4
0.4
ACF
0.2
0.2
0.2
0.2
0
0
0
0
−0.2
−0.2
−0.2
−0.2
0
20
40
60
0
20
40
60
0
20
40
60
0
20
40
60
Time lags (τ )
Time lags (τ )
Time lags (τ )
Time lags (τ )
Fig. 1.
Autocorrelation functions (ACFs) of four different ECG segments of one minute. The first two (from left to right) correspond to normal minutes,
while the other two to minutes with artefacts. The normalized degree values d, for the ACFs or vertices, are indicated. Note that the similarity between
the contaminated segments and the rest is significantly low compared to the ones of normal minutes.
1
1
0.9
0.8
0.8
Accuracy 0.6
0.7
KSC
k−means
95th
0.6
Weight
1
0.5
0.8
0.4
Sensitivity
0.3
0.6
KSC
k−means
95th
0.20
50
100
150
200
250
1
Segment number
Fig. 2.
Weights of one minute ECG segments of one patient. The dashed
line indicates the 95th percentile. Note that the points below the threshold
Specificity
are clearly separated from the rest.
0.5
KSC
k−means
95th
Fig. 3.
Box plots for accuracies, sensitivities and specificities of the three
window length, more artefact than normal ECG (see Fig.
different algorithms tested in this study. Note that the discrimination of
4), its ACF differs more from that of a normal segment.
artefacts based on the 95th percentile, is significantly better than for the
clustering algorithms after characterizing the clusters.
There are reasons to explain why the clustering algorithms
do not perform as good as the 95th percentile threshold. On
one hand, it is important to keep in mind that we are dealing
geometrical structures in the data. When such structures are
with a highly unbalanced partition problem, since in most
not present or are not clearly separable, this algorithm tends
of the cases, the artefacts constitute a lower percentage of
to perform poorly.
the signal. In other words, the number of segments in the
“normal” group must be significantly higher than the amount
B. Sleep apnea classification
of segments in the “contaminated” group. KSC uses a model
selection criterion that takes into account these unbalanced
We just showed that our algorithm successfully detects
problems [17]. However, special attention must be paid to
segments containing artefacts. We will now use this in a
the definition of the parameter that determines how balanced
real-life problem, namely sleep apnea classification. In [18],
the clusters must be. A bad selection of this parameter can
a method to classify sleep apnea is proposed that makes use
lead to misleading results. The performance of KSC can
of a training and a validation set. However when artefacts
be improved by using a semi-supervised extension, where
are present in the ECG, they will also influence the training
labelled data are included as constraints in the algorithm.
and validation sets. This has a negative effect on the overall
On the other hand, the k-means clustering algorithm finds
performance of the classifier. We will now show that if we

REFERENCES
[1] G. D. Clifford, F. Azuaje and P. E. McSharry, Advanced Methods and
Tools for ECG Data Analysis. Boston: Artech House, 2006, pp. 57.
[2] G. M. Friesen, T. C. Jannett, M. A. Jadallah, S. L. Yates, S. R. Quint
and H. T. Nagle, A Comparison of the Noise Sensitivity of Nine QRS
ECG
Detection Algorithms. IEEE Trans Biomedical Engineering, vol. 37,
pp. 85-98, 1990.
[3] D. Benitez, P. A. Gaydecki, A. Zaidi and A. P. Fitzpatrick, The use of
the Hilbert transform in ECG signal analysis. Computers in Biology
and Medicine, vol. 31, pp. 399-406, 2001.
[4] K. Sharmila, E. H. Krishna, K. N. Reddy, and K. A. Reddy, Applica-
tion of multiscale principal component analysis (MSPCA) for enhance-
0
2000
4000
6000
8000
10000
12000
ment of ECG signals. Instrumentation and Measurement Technology
Samples
Conference IEEE, 2011.
[5] R. Sameni, M. B. Shamsollahi, C. Jutten, and G. D. Clifford, A
Fig. 4.
One minute ECG segment. Note that only the last 2 parts are
Nonlinear Bayesian Filtering Framework for ECG Denoising. IEEE
contaminated. This indicates that when the window is reduced to 1200
Transactions on Biomedical Engineering, vol. 54, pp. 2172 - 2185,
samples (10 seconds) the resolution of the algorithm is improved.
2007.
[6] S. Bras, N. Ferreira and J. P. Silva, ECG Artefact Detection Algorithm:
An Algorithm to Improve Long-Term ECG Analysis. Proceedings
of the International Conference on Bio-Inspired systems and Signal
use the weighting of the artefacts together with the technique
Processing BIOSIGNALS, pp. 329-333, 2012.
in [18], the classification results will improve.
[7] C. W. Zywietz, V. von Einem, B. Widiger, G. Joseph, ECG Analysis
for Sleep Apnea Detection. Methods Inf. Med., vol. 43, pp. 56-59,
We evaluate the performances of the sleep apnea classifier
2004.
on a validation set, before and after detecting the segments
[8] B. Kulessa, T. Srokowski, S. Drozdz, Long-Time Autocorrelation
with artefacts. The sensitivity and specificity of the classifier
Function of ECG Signal for Healthy versus Diseased Human Heart.
Acta Physica Polonica B, vol. 34, pp. 3, 2003.
before applying our algorithm are 85.9% and 86.7%
[9] T. Syeda-Mahmood, D. Beymer, and W. Fei, Shape-based Matching
respectively. After removing the contaminated segments
of ECG Recordings. IEEE EMBS, pp. 2012-2018, 2007.
from the training and validation sets, the sensitivity and
[10] Z. Piotrowskia and K. R´ozanowski, Robust Algorithm for Heart Rate
(HR) Detection and Heart Rate Variability (HRV) Estimation. Acta
specificity are then 93.2% and 92.1% respectively. Hereby
Physica Polonica A, vol. 118, pp. 131-135, 2010.
we use the ground truth provided by the clinician. Again,
[11] R. D. Throne, Detecting ventricular fibrillation using efficient tech-
one can see that the performance is improved when the
niques for computing a normalized autocorrelation. Computers in
Biology and Medicine, vol. 23, pp. 317-325, 1993.
training set is selected from the minutes with degrees within
[12] T. Penzel, J. McNames, P. de Chazal, B. Raymond, A. Murray
the 95th percentile.
and G. Moody, Systematic comparison of different algorithms for
apnoea detection based on electrocardiogram recordings. Medical &
Biological Engineering & Computing, vol. 40, pp. 402-407, 2002.
[13] C. Maier, H. Wenz and H. Dickhaus, Steps toward subject-specific
IV. CONCLUSION
classification in ECG-based detection of sleep apnea. Physiological
A new algorithm to detect artefacts by means of the auto-
Measurement, vol. 32, pp. 1807-1819, 2011.
[14] G. E. P. Box, G. M. Jenkins, and G. C. Reinsel, Time Series Analysis:
correlation function, in the ECG was presented. In addition,
Forecasting and Control. 3rd ed. Upper Saddle River, NJ: Prentice-
we also included a weighting methodology to distinguish
Hall, 1994, pp. 30-34.
normal from contaminated ECG signals, which outperforms
[15] F.R.K. Chung, Spectral Graph Theory. Am. Math. Soc., 1997, ch. 1.
[16] J. B. MacQueen, Some Methods for classification and Analysis of
other methods such as k-means and kernel spectral cluster-
Multivariate Observations. Proceedings of 5th Berkeley Symposium
ing.
on Mathematical Statistics and Probability, pp. 281-297, 1967.
[17] C. Alzate and J. A. K. Suykens, Multiway Spectral Clustering with
The most important contribution of our proposal is that it
Out-of-Sample Extensions through Weighted Kernel PCA. IEEE Trans
is easy to implement and interpret. This is due to the fact that
Pattern Analysis and Machine Intelligence, vol. 32, pp. 335-347, 2010.
it uses well-known tools such as the autocorrelation function
[18] M. Bsoul, H. Minn, and L. Tamil, Apnea MedAssist: Real-time Sleep
Apnea Monitor Using Single-Lead ECG. IEEE Trans Inf Technol
and percentile analysis. Furthermore, the algorithm does not
Biomed, vol. 15, pp. 416-427, 2011.
require computationally expensive operations, e.g. eigenvalue
decompositions.
Another advantage of our algorithm is that it allows to lo-
cate the contaminated segments in the ECG. This information
is not provided by algorithms that enhance the overall quality
of the signal. In addition, other artefact detection algorithms
require more ECG channels or additional information, to
identify and remove artefacts. This is not the case for our
algorithm, since it only requires a long term ECG signal.
A disadvantage is that our method can only be applied
off-line. It is necessary to have the complete ECG recording
before the artefacts can be detected.