You are on page 1of 6

ADAPTIVE ECG FILTERING AND QRS DETECTION

USING ORTHOGONAL WAVELET TRANSFORM

Alice de Jesus Kozakevicius* Cesar Ramos Rodrigues*


Gmicro – Mathematics Department Gmicro – DESP – PPGEE
alicek@smail.ufsm.br cesar@smail.ufsm.br

Raul Ceretta Nunes* Roberto Guerra Filho*


Gmicro – DELC – PPGEP Gmicro
ceretta@inf.ufsm.br rgf@mail.ufsm.br

* Universidade Federal de Santa Maria -Camobi, Santa Maria, CEP 97105900 Brazil

ABSTRACT Recently, it was shown that the wavelet approach can


Biomedical signals like heart wave commonly change be improved by nonlinear processing of the wavelet
their statistical properties over time, tending to be coefficients at each scale [2,10], once the scale is related
nonstationary. For analysing this kind of signal wavelet to the amount of data per time. Thus, the denoising
transforms are a powerful tool. In this paper we utilize process presented in this paper for ECG analysis is based
orthogonal wavelets to filter and analyse ECG signals. on the nonlinear wavelet shrinkage method with adaptive
First, we use compactly supported wavelets associated to threshold obtained by a Stein’s Unbiased Risk Estimator
the statistical Stein’s Unbiased Risk Estimator (SURE) in (SURE).
order to obtain an adaptive thresholding strategy to filter After obtaining a filtered signal, one important issue is
ECG signals. Second, we analyse the filtered signals by the recognition of specific patterns. According to [3],
using the Haar wavelet transform in order to detect the current ECG research has no scientific method for
positions of the occurrence of the QRS complex during determining the starting and endpoints of the P wave,
the period of analysis. As results we obtain a more QRS complex, and T wave. However, individual doctors
efficient filter, since the threshold value depends on the determine these points either intuitively or arbitrarily, and
magnitude of wavelet coefficients in each level, and also a the process has not been standardized.
lightweight QRS detection algorithm. The detection of the QRS complex is the most
important task in automatic ECG signal analysis [6]. A
KEY WORDS wide diversity of algorithms has been proposed in the
Wavelet Filtering, Sure Thresholding, QRS Detection literature for QRS detection, for an extensive review, see
[13]. Some of them utilize spline wavelet transform to
construct ECG delineator [12].
1. Introduction In the present paper we propose a very simple
algorithm based on Haar wavelet coefficients to detect
The new generation of medical treatment has been QRS complex positions.
supported by computerized processes. Signals recorded In section 2 we summarize some theoretical results
from the human body provide valuable information about related to wavelet theory; in section 3 is presented the
the activities of its organs. Their characteristic shape, or adaptive thresholding strategy, and the simulated results
temporal and spectral properties, can be correlated with a are in section 4. The last section presents the algorithm to
normal or pathological function. In response to dynamical the QRS detection and the analysed examples.
changes in the behavior of those organs, the signals may
exhibit time-varying as well as non-stationary responses
[1]. In fact, those signals are always contaminated by drift 2. Fast Wavelet Transforms
and interference caused by several bioelectric phenomena,
or by various types of noise, like intrinsic noise from the The orthogonality of scaling functions and wavelets
recorder and noise from electrode-skin contact. together with the dyadic coupling between MRA (multi
Unfortunately there is no universal method to reduce resolution analysis) spaces lead to a relation between
noise, because the probability distributions of noise are scaling function coefficients and wavelet coefficients on
different, however wavelets thresholding has been used as different scales. This yields a fast and accurate algorithm
an alternative to reduce noise [5,11]. due to Mallat [8], referred as pyramid algorithm or fast
wavelet transform (FWT). We consider the projection of a to its scale j. One way to remove non-significant
function f (here the ECG signal) into the space V j , which information from the signal is discarding wavelets
coefficients from the factorization. We utilize a soft
is generated by all dyadic translations of the scaling
thresholding strategy:
function φ j,i at the scale j, given by the following
d j ,i − λ , if d j ,i > λ
expression:
+∞ δ λS (d j ,i ) = 0, if d j ,i ≤ λ . (5)
( Pv j f )( x) = c j ,i φ j , i ( x ) . (1)
d j ,i + λ , if d j ,i < −λ
i = −∞
From [4], Pv j f = Pv j +1 f + Pw j +1 f . Thus the The choice of a thresholding value λ is a fundamental
projection (1) also has a formulation in a scale coarser issue, once the thresholded factorization fˆ must stay
then j in terms of scaling functions φ j +1,i and wavelets “close” to f. The error (risk) between f and its
ψ j +1,i , which generates the space W j +1 with the property thresholded approximation fˆ is given by:
2
that W j +1 ⊕ V j +1 = V j : R ( fˆ , f ) = fˆ − f . (6)
2
+∞ +∞
Since the transform is orthogonal, this quantity (6) can
( Pv j f )( x ) = c j +1,i φ j +1,i ( x) + d j +1,iψ j +1,i ( x ) . (2)
be expressed in terms of the wavelet coefficients by the
i = −∞ i = −∞
wavelet version of Parserval’s identity:
There is a mapping between the sequence of 2
coefficients {c j ,i }i ∈ Z and the sequences {c j +1,i }i ∈ Z R( fˆ , f ) ∝ dˆ − d = (dˆ j ,k − d j ,k ) 2 . (7)
2 j k
and {d j +1,i }i ∈ Z . The key to the derivations of this
For the adaptive threshold choice at any resolution
mapping are the dilation equations φ ( x) = 2
2 N −1
akφ (2 x − k )
level, j = 1,2,..., J , we use the Stein Principle [7] which
k =0 minimizes the risk (7) with respect to the threshold value
and ψ ( x) = 2
2 N −1
λ. The estimator considers the soft thresholding strategy
bk φ ( 2 x − k ) , which completely define the
and according to [9], the minimization problem is
k =0
translated in determining the minimum value for the
scaling function, the wavelet and consequently, the spaces
following function in each level j:
V j and W j through their filters ak and bk , n n
k = 0,1,..., 2 N − 1 . SURE1 (λ j , d ) = σ 2j n − 2 I ( dk ≤ λ j ) + min 2 ( dk , λ j ) , (8)
k =1 k =1
So, considering c j ,i as 2 j discrete values of the n
1, if x = true
function f at the scale j, the fast wavelet transform is given I ( x) = , I ( d k ≤ λ j ) = # discarded coefficients
0, if x = false k =1
by the following relations: let b k = ( −1) k a 2 N −1− k ,
and the minimal value in each level is the optimal
2 N −1 2 N −1
threshold value λSURE:
c j +1,i = a k c j ,2i + k , d j +1,i = b k c j , 2i + k . (3)
arg min
k =0 k =0 λ SURE = SURE (λ j , d ) (9)
In this paper, filter coefficients ak and bk were chosen
j
0 ≤ λ j ≤ λUj
for the Daubechies wavelet with 4 vanishing momentums For the SURE estimator, we propose here a slight, but
(N=4). effective modification, once coefficients still related to
irrelevant information inside the signal can be removed.
We denote this option by SURE2:
3. Adaptive Wavelet Thresholding n n
SURE 2 (λ j , d ) = σ 2 n − 2 I( dk ≤ λ j ) + min 2 ( d k , λ j ) (10)
After computing the fast wavelet transform of the k =1 k =1

initial signal f, we obtain a factorization of f in different


resolution levels: 4. Comparison between SURE1 and SURE2
+∞ 1 +∞
f = c J , i φ J ,i + d j ,iψ j ,i , (4) Now we present some simulations obtained from heart
i = −∞ j = J i = −∞ waves generated by Biotronik’s ECG software at 2 kHz/s
cJ ,i represents the information of the signal on the sampling rate. These waves contain intrinsic noise found
on recording. On analysing the data, we preserve the
coarsest level, and d j ,i the details (wavelet coefficients) same classification adopted by the manufacturer :
in different scales necessary to reconstruct the function in • PR1 – Normal ECG: sinus rhythm
the fine scale 0. Since the wavelet and the scaling function • PR3 – Anomalous ECG: TAA with atrial fibrillation,
have compact support, all sums are finite in (4). HR about 120/min
Due to noise or other fluctuations the wavelet • PR4 – Anomalous ECG: monomorphic VT,
coefficients d j ,i are affected in different levels according HR=160/min
0 0.82 1.64 2.46 3.28 4.1 On figures 2 and 3 are presented the reconstructed data
after the adaptive thresholding and the sequence of
ECG remaining details considered in each level of the inverse
transform. Figure 2 shows the results obtained by the
D1 SURE1 strategy and figure 3 shows the same information,
considering SURE2. Qualitatively both filtered signals are
D2 comparable, although SURE2 strategy presented a slight
better noise removing result.
D3
The adaptivity of both thresholding strategies is
D4
obtained through the choice of the threshold value in each
level, which is the minimal point of equation (9). These
values are presented in table 1 for both strategies.
D5

Table 1: λSURE
D6
level SURE1 SURE2
1 0.175125706 0.196140791
Figure 1: PR1-signal with its sequence of noisy details. 2 0.228918654 0.228918654
3 0.207307705 0.207307705
0 0.82 1.64 2.46 3.28 4.1 4 0.125072163 0.182797776
5 0.195903862 0.167917596
6 0.533142846 0.102091183
ECG
The four finest scales are completely noisy, as can be
D1 observed on figure 1. Both strategies, SURE1 and SURE2,
D2
remove this amount of high frequency noise and preserve
the essential information of the signal contained at
D3 coarsest levels of the wavelet transformation.
In each level of the wavelet transform, we compute the
D4
maximum detail modules and define 8 subintervals for the
possible details magnitude values. For each level we
D5 count the amount of wavelet coefficients contained in
each subinterval, before and after the thresholding
D6 operation. The remaining quantities after thresholding for
levels 5 and 6 are shown on figure 4, illustrating the
Figure 2: PR1-ECG filtered by SURE1 strategy and the difference between both strategies for these levels.
sequence of significant details. After the SURE thresholding, only levels 5 and 6 have
a significant number of coefficients. It enables the signal
The graphic on figure 1 presents in the first row the reconstruction without high frequency noise.
original ECG (PR1) and below it, the sequence of details
(wavelet coefficients) from scale 1 to 6 without filtering.

0 0.82 1.64 2.46 3.28 4.1

ECG

D1
D2

D3
Figure 4: Number of wavelet coefficients after SURE1
thresholding (left column) and SURE2 (right column).
D4
Through the application of the same wavelet transform
D5 to PR3 and PR4 pathological ECGs, we have observed
that SURE2 provides better filtering results than SURE1.
D6 From figures 5 and 6 we observe that SURE1 can not
filter appropriately the noise contained on the first details
Figure 3: PR1-ECG filtered by SURE2 strategy and the level of the PR3 signal, while SURE2 filter it. The same
sequence of significant details. behaviour can be observed for the PR4, whose graphics
are presented on figures 7 and 8. Low frequencies
information is carried into these coarsest coefficients, Table 2: λSURE
once information associated to high frequencies are level SURE1 SURE2
contained in fine scale details. 1 0.103365948 0.188243678
2 0.268627183 0.268627183
0 0.82 1.64 2.46 3.28 4.1 3 0.248895115 0.248895115
4 0.140817613 0.18685414
5 0.218718358 0.160188093
ECG 6 0.609695838 0.138567236

D1
The last pathological ECG presented is PR4 and the
result of the filtering process by using SURE2 estimator
D2 associated with the wavelet transform is much more
effective. Again SURE2 was able to filter noise associated
D3 to high frequencies, which are concentrated in fine scales.

D4 0 0.82 1.64 2.46 3.28 4.1

D5 ECG

D1
D6
D2
Figure 5: PR3 ECG filtered by SURE1 strategy and
sequence of significant wavelet coefficients. D3

0 0.82 1.64 2.46 3.28 4.1 D4

D5
ECG

D6
D1

D2 Figure 7: PR4 ECG filtered by SURE1 and sequence of


significant wavelet coefficients.
D3
The SURE strategy for data filtering proposed in this
D4 section was also tested on signals from the MIT-BIH
database. Once the amount of noise in these signals is
D5 smaller, we prefer to present the results for Biotronik
signals, which contain higher levels of noise.
D6 0 0.82 1.64 2.46 3.28 4.1

Figure 6:PR3 ECG filtered by SURE2 strategy and ECG


sequence of significant wavelet coefficients.
D1
On table 2 are presented the minimal values of SURE
D2
functions. The optimal threshold values are the minimum
point of SURE functions in each level. In some cases, D3
SURE functions are relatively flat near the place, where
they achieve their minimum. This would indicate that D4
there is a wide range of possible thresholds. But, in terms
of relative smoothness of the resulting estimator, this D5
choice may have a significant difference qualitatively [9,
10]. In cases of multiple choices for λSURE, our algorithm D6
chooses the greatest value.
Figure 8: PR4 ECG filtered by SURE2 and sequence of
Comparing tables 1 and 2, it is possible to observe a
significant wavelet coefficients.
variation between different levels of SURE functions,
being evident that the strategy is fully data and level
The rate of data collection of the MIT-BIH database is
dependent. For each different signal analysed, a new set
smaller than the rate of Biotronik signals, thus the only
of threshold values is initially computed.
adjustment necessary is the correct choice of levels in the 2.5 a) ECG
wavelet transform, according to the amount of data in the 2
finest scale.
1.5

1
5. QRS Detection
0.5
As previously mentioned, QRS detection has been
studied in several approaches [13]. In this section we 0
propose a simpler one, based on Haar transform, to obtain -0.5
a lightweight detection algorithm. On our algorithm, P 0.6 b) D1
and T waves are not detected, since it is focused on 0.4
counting and localizing abnormal QRS patterns for long 0.2
time ECG analysis.
0
After we filtered the signal with the db4 wavelet
transform associated to the SURE thresholding strategy, -0.2
we apply Haar wavelet transform in order to capture small -0.4
scale variations, which are intrinsic to the signal. These 0.15 c) D2
variations will localize the QRS complex in each scale. 0.1
Even in abnormal cases, this behaviour is observed.
0.05
The following algorithm summarizes the procedure for
detecting QRS localization through Haar wavelet 0
coefficients: -0.05
1. apply Haar wavelet transform of ECG with 213 points -0.1
( c 0 ) in J levels; -0.15
2. for each level find the maximum wavelet coefficient 0.4 d) D3
( max(d j ) ); 0.2
3. for each level select the details ( d j ,i ) associated to
0
QRS complex using α 1 = 0.5 (a weight of max(d j ) ):
-0.2
then position i ∈ QRS complex
if d j ,i > α 1 max(d j ) -0.4
else position i ∉ QRS complex
0.8 e) D4
4. identify different QRS complexes:
0.4
d j ,i and d j ,i ' are consecutive selective coefficients;
0
α 2 = 0.1 is 0.1*(standard QRS time duration);
1
∆t = f
= 0.0005s ; -0.4

then i, i'∈ same QRS complex -0.8


if (t = 2 j ∆t i − i'< α 2 )
else i, i'∉ same QRS complex 2 f) D5
5. compute the distance between consecutive QRS and 1
the amount of founded complexes.
0
In figure 9-a the bullets represent positions detected by -1
the algorithm related to the QRS complex at each level of
the transformation. The high of the bullet represents its -2
level in the transformation. The following sequence of 6 g) D6
plots (9-b to 9-g) shows the set of details in levels 1 to 6, 4
that are associated to the same QRS complex. 2
At the bottom of figures 9-a, the bullets are plotted all
0
together, indicating the beginning and the end of the QRS
complexes. -2
Figures 10 and 11 illustrate the potential of our -4
algorithm to localize the positions of great variations in -6
the signal and through this information, obtain a 0 1 2 3 4
preliminary classification of the signal. Figure 9: a) Normal ECG. b-g) QRS detection: family of
positions obtained by wavelet coefficients for
factorizations levels 1 to 6.
These two examples are from anomalous PR3 and PR4 7. Acknowledgements
ECG simulations, where no standard QRS pattern is
present. Even though, it is possible to identify the This work was supported by the Foundation of the
anomalous pattern by computing the distance between State of Rio Grande do Sul – FAPERGS – Brazil under
consecutive spikes and also the amount of them. This grant nº 03512710 and by the Research National Council
distance is related to the mean time duration of the cardiac – CNPq – under grant PDPG/TI 552212/02-4 (TecIR
pulse, relevant to the ECG analysis. Project).
The pathological ECGs presented in figure 10 and 11
have no standard QRS complex at all. Even though, our
algorithm captured all relevant variations. References:

3
[1] J. D. Bronzino, The biomedical engineering
handbook (Boca Raton – FL: CRC Press, 2000).
[2] M. Akay, Wavelet applications in medicine,
2 Biomedical Engineering, IEEE Spectrum, may 1997,
50-56.
[3] Y. Ishikawa, F. Mochimaru, Wavelet theory analysis
1
of high – frequency, high – resolution
electrocardiograms: a new concept for clinical uses,
Process in Biomedical Research, 7(3), sep
2002,179-184.
0
[4] O. M. Nielsen, Wavelets in scientific computing
(Ph.D. Thesis, Technical University of Denmark,
-1
mar 1998).
[5] M. Jansen, Noise reduction by wavelet thresholding
0 1 2 3 4
(New York, Springer Verlag, 2000).
Figure 10: anomalous PR3 ECG: QRS detection by level [6] C. Li, C. Zheng, C. Tai, Detection of ECG
characteristic points using wavelet transforms, IEEE
3 Trans. on Biomedical Engineering, 42(1), 1995, 21-
28.
2 [7] C. M. Stein, Estimation of the mean of a
multivariate normal distribution, Annals of Statistics
9, 1981, 1135-1151.
1
[8] S. G. Mallat, A theory for multiresolution signal
decomposition, the wavelet representation, IEEE,
0 Transactions on Pattern Analysis and Machine
Intelligence 11, 1989, 674-693.
[9] W. Härdle, G. Kerkyacharian, D. Picard, A.
-1
Tsybakov, Wavelets, approximation and statistical
applications, Seminaire Paris-Berlin, Paris, sep
-2
1997, 1-284.
0 1 2 4
3 [10] D. Donoho, I. Johnstone, Adapting to unknown
Figure 11: anomalous PR4 ECG: QRS detection smoothness via wavelet shrinkage, Journal of the
American Statistical Association 90, 1995, 1200-
1224.
6. Conclusion [11] F. Mochimaru, Y. Fujimoto, Y. Ishikawa, Detecting
the fetal electrocardiogram by wavelet theory-based
In this work we pointed out the advantage of using
methods, Progress in Biomedical Research, 7(3),
wavelet transform associated with an adaptive
sep 2002, 185-193.
thresholding strategy. Further, the possibility of detecting
[12] J. P. Martínez, R. Almeida, S. Olmos, A. P. Rocha,
positions of great variations in normal and abnormal ECG
P. Laguna, A wavelet-based ECG delineator:
signals is investigated and a lightweight wavelet
evaluation on standard databases, IEEE Trans.
coefficients based algorithm is proposed.
Biom. Eng., 51(4), apr 2004, 570-581.
Through the SURE adaptive wavelet thresholding all
[13] B. U. Köhler, C. Hennig, R. Orglmeister, The
irrelevant noise are removed of the signal, allowing the
principles of software QRS detection, IEEE Eng
utilization of a simple wavelet transform in the QRS
Biol. Mag., 21, jan/feb 2002, 42-57.
detection. The main advantage of this kind of detection is
a less time consuming analysis for long time ECG signal.

You might also like