Event Detection:
Qrs-Complexes in Ecg Signals
Josef Goette
Bern University of Applied Sciences, Biel/Bienne
Institute of Human Centered Engineering - microLab
Josef.Goette@bfh.ch
Contents
1 Introduction
2 Qrs
2.1
2.2
2.3
2.4
Detection
General Structure of Qrs Detector
Simplest: Derivative-Based Ideas .
Aside: Integer Filters . . . . . .
The Pan-Tompkins Algorithm . . .
References
6 EventDet
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
3
10
14
28
56
2013
BioMedSigProcAna
c
Josef
Goette, 20072013
All rights reserved. This work may not be translated or copied in
whole or in part without the written permission by the author, except
for brief excerpts in connection with reviews or scholarly analysis.
Use in connection with any form of information storage and retrieval,
electronic adaptation, computer software is forbidden.
6 EventDet
ii
2013
BioMedSigProcAna
Introduction
6 EventDet
2013
BioMedSigProcAna
R
T
ECG
P
0
1
Q
S
2
0.2
0.4
0.6
0.8
1
1.2
time in seconds
1.4
1.6
1.8
6 EventDet
2013
BioMedSigProcAna
Qrs Detection
2
2.1
6 EventDet
2013
BioMedSigProcAna
6 EventDet
2013
BioMedSigProcAna
6 EventDet
2013
BioMedSigProcAna
linear
filtering
nonlinear
transformation
decision
rule
x[n] =
Ecg-signal input to detector
i , i = 1, 2, . . . =
series of occurrence-times of detected
Qrs complexes
2013
BioMedSigProcAna
5 Hz to 10 Hz. Note that waveform distortion is, in contrast to
other types of Ecg-signal filtering, not a critical issue in Qrs
detection; instead, the goal is to improve signal-to-noise ratio to
achieve good detector performance.
The goal of the nonlinear transformation is to further enhance the Qrs complex relative to the remaining background
noise. Additionally, it must transform each Qrs complex into a
single positive peak that is better suited to threshold detection.
In general, the nonlinear transformation might be memory-less
(static)rectification or squaring are examplesor a more complex transformation involving memory. Note, however, that not
all Qrs detectors use a nonlinear transformation in their preprocessing stage.
The goal of the block named decision rule is to perform,
based on the output of the pre-processor, a test on whether at
a certain time a Qrs complex is present or not. The decision
rule might be implemented as simple as an amplitude threshold procedure, but it may perform additional tests, for example
on reasonable durations of certain waveforms, to obtain better
immunity against various types of noise.
Qrs detectors are usually designed to detect heartbeats.
They rarely need to produce occurrence times of the Qrs complexes with high resolution in time. If time resolution is nevertheless important, it may be necessary to improve the initial
resolution with algorithms that perform time alignment of the
detected beats and thus reduce the problem of smearing which
might occur when computing the ensemble average of several
beats (recall the synchronized averaging, which we have discussed in [Goe13a]).
6 EventDet
2013
BioMedSigProcAna
v[n] ,
v[n] ,
where
0n1,
n+D1,
+D nN 1,
N=
length of observation interval
v[n] =
noise
s[n] =
Qrs-complex, known morphology, duration
=
unknown occurrence time of Qrs-complex
a=
unknown amplitude of Qrs-complex
S
ornmo and Laguna [SL05] discuss in Section 7.4 Qrs detection in a more theoretically oriented manner. With the proposed
signal model shown above, it is then feasible to estimate the unknown occurrence time and the unknown amplitude a of the
Qrs-complex. The notion Qrs detection suggests, however,
that we are faced with a detection problem instead of an estimation problem. It is indeed true that the problem considered
in [SL05] can likewise be formulated as a detection problem;
6 EventDet
2013
BioMedSigProcAna
S
ornmo and Laguna discuss these different viewpoints and state
that both of them essentially lead to same detector structures,
for details see [SL05, p. 488].
then theory shows that the Qrs detector must use as nonlinear transformation a rectifier
6 EventDet
2013
BioMedSigProcAna
2.2
The references cited in the above slide are [BDD+ 77], [AT83],
and [FJJ+ 90].
6 EventDet
10
2013
BioMedSigProcAna
11
1 (z) = 1 z 1 X(z) .
2013
BioMedSigProcAna
This filter has a zero at z = 1at Dc frequencyand has a
magnitude response of 2 sin (
/2). For sufficiently low frequencies
, it approximates the derivative operation as we see from
2 sin (
/2) 2
/2 =
. To obtain a smoothing such that highfrequency noise is not too much amplified, we post-process the
sequence 1 [n] by a two-point moving-average filter having transfer function (1 + z 1 ):1
y0 [n] =
1 [n] + 1 [n 1]
= x[n] x[n 1] + x[n 1] x[n 2]
= x[n] x[n 2] .
6 EventDet
12
2013
BioMedSigProcAna
another three-point first difference filter, we obtain2
y1 [n] =
y0 [n] y0 [n 2]
= x[n] x[n 2] x[n 2] x[n 4]
= x[n] 2x[n 2] + x[n 4 .
6 EventDet
13
2013
BioMedSigProcAna
2.3
Motivation
in real-time operations of digital filters
many filter designs are unsatisfactory
because huge computation-time requirements
surely if implemented in floating-point operations
but often also if implemented in fixed-point operations
integer filters are a special class of filters having only integer coefficients
here more special: coefficients {0, 1, 2}
here even more special: a preparation to the Pan-Tompkins
algorithm
14
2013
BioMedSigProcAna
demand on preservation of signal forms calls for linear-phase
filters, which must be Fir filters. Integer filters as we discuss
them here are Fir filters with recursive implementations.
The slide on the previous page 14 states that our integer
filters have only coefficients being 0, 1, and 2. This is not
the full truth: The basic blocks that we consider have such
coefficients, but cascading these basic blocks leads to additional
coefficient values, see page 27.
Simple Example
transfer function
H(z) =
1 z 6
z6 1
N (z)
=
=
1
2
4
2
1z +z
z (z z + 1)
D(z)
zeros
N (zz ) = zz6 1 0
;
zz = ejk2/6 , k = 0, 1, . . . , 5 =
6-th roots of unity
j
................................
.......
...........
......
.......
.....
......
....
.....
...
....
...
.
...
...
...
.
...
..
.
.
...
..
.
...
.
.
..
....
..
..
..
...
.
...
...
...
...
..
...
.
.
...
..
.
.
...
.
...
...
...
...
...
....
.....
....
......
.....
.
.
.
......
.
.
....
........
............................................
15
2013
BioMedSigProcAna
non-trivial poles
e p) =
D(z
zp2 zp + 1 0
zp ej zp ej 0
ej + ej zp + 2 0
zp2
| {z }
|{z} |
{z
}
1
1 = 2 cos 1
{z
}
|
; = 60
j
e
...
.......
.
.
.
... ...
......... ......
.
.
....
.. ..
....................................
.......
..........
......
.......
.....
......
....
.....
...
....
.
.
...
.
...
...
.
...
..
.
...
.
.
...
....
...
.....
....
60
....
..
..
...
...
...
...
.
...
..
.
.
...
...
...
..
...
...
...
...
....
....
.....
.....
......
.
.
.
.
.
.
.......
.......
...........
...............................
poles zp1,2 =
6 EventDet
ej ,
16
= 60
2013
BioMedSigProcAna
.............................
............
........
........
......
......
.....
.....
....
....
....
.
.
...
...
.
...
...
...
.
...
..
.
.
...
.
..
....
..
...
..
...
.
....
...
4-fold
...
...
.
...
.
...
...
.
...
...
.
...
...
...
....
...
...
....
.....
....
......
.....
........
......
.
.
.
.
.
.
.
..............
.........................
c
1
1 z 6
= 1 + z 1 z 3 z 4
1 z 1 + z 2
1 + z 1
1 ej2/3 z 1
1 ej2/3 z 1
The first pair of terms gives 1 z 2 , the second pair of terms
giveswe use the formula of Euler together with the result
cos (120 ) = 1/2the polynomial 1 + z 1 + z 2 , and we
finally obtain
1 z 2
6 EventDet
1 + z 1 + z 2 = 1 + z 1 z 3 z 4 .
17
2013
BioMedSigProcAna
A second, alternative, way to find the second form of the
transfer function in the slide of page 17 is just to carry-out the
division of the first form: Dividing (1 z 6 ) by (1 z 1 + z 2 )
gives 1 with remainder (z 1 z 2 z 6 ); dividing this remainder by the denominator (1 z 1 + z 2 ) gives z 1 and
a new remainder (z 3 z 6 ); again dividing this new remainder by the denominator gives z 3 and a next remainder
(z 4 + z 5 z 6 ); finally, dividing this last remainder by the
denominator (1 z 1 + z 2 ) ends up with z 4 and a zero
remainder.
The two transfer-function formulae on page 17 suggest that
we could implement the filter as a usual Fir filter by taking the
second formula, but also in a recursive form by taking the first
formula. The question then is which kind of implementation to
select.
To discuss the implementation issue, we take a larger filter
of the considered class of filters where the problem becomes
evident. So consider the N -point moving average-filter having
the transfer function forms3
H(z) =
=
1
1 + z 1 + z 2 + + z (N 1) ,
N
1 1 z N
.
N 1 z 1
(1a)
(1b)
Naming the input sequence to the filter x[n] and the output
sequence from the filter y[n], the form (1a) could be implemented
in direct form as
y[n] =
1
x[n] + x[n 1] + x[n 2] + + +x[n (N 1)] ,
N
(2)
3 We obtain the second form by applying the formula for the sum of a
geometric series to the first form.
6 EventDet
18
2013
BioMedSigProcAna
whereas the form (1b) could be implemented in direct form as
y[n] = y[n 1] +
1
x[n] x[n N ] ,
N
(3)
(4)
here in (4) w[n] is a newly introduced interval variablean internal signalof the filter.
Comparing the feed-forward implementation (2) to the recursive implementations either (3) or (4), we see that the number of operations needed to compute one output sample favors
the recursive implementations. This lower computational effort
is the reason that many books on biomedical signal processing
suggest the recursive implementations.
We note, however, that the recursive implementations might
become problems with error accumulation and instabilitythe
implementations (3) and (4) both have a pole at z = 1, which
is not strictly inside of the unit circle. To get a feeling of what
might happen, consider the canonical implementation (4) and
assume that the input signal is a white-noise signal.4 The equation w[n] = w[n 1] + x[n] is an accumulator, and accumulating a white-noise sequence gives a non-stationary stochastic
process with a linearly increasing variance, meaning that w[n]
must sooner or later become unstable, which is, of course, not
acceptable. Similar considerations for the implementation (3)
lead to the same conclusions. We do not go into more details,
but, instead, refer to [Orf96], where these issues are discussed
on pages 402 ff., and which has an Appendix A, pages 728 ff.,
discussing discrete-time random signals and their filtering.
4 A discrete-time white noise signal is a sequence where any two samples
are uncorrelated.
6 EventDet
19
2013
BioMedSigProcAna
However, an additional note is in order: The transfer function form (1b) shows perfect pole/zero canceling and an implementation based on this form relies on the achievement of this
perfect canceling by the arithmetic used in the implementation.
Exact integer arithmetic can achieve it: Both, twos complement number systems and, more general, any of the residue
number systems5 have the ability to support error-free arithmetic; in the case of the twos complement number system, the
arithmetic must be performed modulo 2b , that is, with natural
overflow as we explain in [Goe13b], and in the case of residue
number systems, the arithmetic is performed in modulo M .
6 EventDet
20
2013
BioMedSigProcAna
.................
.................
...
...3.0
......
.....
...
.
...
.
...
.
.. .
...
.
...
..
.
...
.
...
... ..
.. .
...
... ..
.
... ..............
.......... ..
.
.
.
.
.
.
.
.
.
.
.
... .... .......
.... ..
.....
..
.
.
.
....
...
.
..
.
..
0
j
H(e )
..........
.
.
.
.. ..........
.......
/2 ........
.......
.
.......
.. ......
.......
....... ...
.. ........
.
....... .
......
.......
............
..
.......
......
......
.. .........
.
.
.
.
.
.
.
....... .
.......
.......
..
.........
.......
.......
....... ...
/2 .
....... ..
....
6
6 EventDet
21
2013
BioMedSigProcAna
General: Poles
complex-conjugate pole-pair on unit circle
zp1 = ej ,
then
zp2 = ej = zp1
z ej
= z 2 ej + ej z + 1
denominator = z ej
= z 2 2 cos z + 1
0
60
90
120
180
cos
1
1/2
0
1/2
1
2 cos
2
1
0
1
2
6 EventDet
22
2013
BioMedSigProcAna
see our exemplifying discussion on the the bandpass filter of the
Pan-Tompkins Qrs detection algorithm given on page 42.
Also note that we compile, later on page 27 and after a corresponding discussion on general zeros, the transfer functions
that can be realized with integer filters.
................................
...........
.......
.......
......
.
.
.
.
.
.....
.
.
.
.
.
....
.
....
....
.
.
.
...
.
.
.
...
.
.
.
...
.
...
..
.
.
...
.
.
..
...
..
... 2-fold
2-fold
..
...
..
..
...
.....
...
...
...
...
...
.
.
.
...
...
...
..
....
.
.
....
..
.....
....
......
.....
.
.
.
.
........
.
.......
..............
.........................
6 EventDet
23
2013
BioMedSigProcAna
General: Zeros
first case
numerator = z m 1 ,
zeros:
m=
positive integer
second case
numerator = z m + 1 ,
zeros:
zzm
m=
positive integer
6 EventDet
24
2013
BioMedSigProcAna
jc
..............................
...........
........
.......
......
.
.
.
.
.
.
.....
.
.
.
.
....
.
....
....
.
.
.
...
.
.
.
...
.
.
.
...
.
..
...
.
.
...
.
.
..
...
..
..
..
...
..
..
...
.....
...
.
...
..
...
...
.
.
...
.
...
...
...
...
.
...
.
..
....
...
.....
.....
.......
.
.
.
.
.
..
.........
.........................................
6 EventDet
25
2013
BioMedSigProcAna
cj
.....................................
.........
.......
.......
......
.
.
.
.
.
.....
..
.
.
.
....
.
.
.
...
...
.
.
...
.
.
...
.
.
.
...
.
..
...
.
.
...
...
..
..
...
...
.
....
..
...
....
.
...
...
...
...
...
.
.
...
..
...
...
...
.
.
...
..
....
...
.....
.....
.
.
.
.
.......
.
......
.........
.........................................
c1
Note that when the power m is an odd number, the numerator z m + 1 always places a zero at 180at and the
complete zero pattern appears left-right flipped from the zero
pattern of the corresponding numerator z m 1. Take the example m = 3: In the left-hand side of the graphic below we show
the zeros of z 3 1, and in its right-hand side we show the zeros
of z 3 + 1.
j
...................................
.........
.......
.......
......
......
.....
.....
....
...
....
...
...
..
...
...
...
.
.
...
...
...
.
.
..
...
..
...
..
...
.
..
...
...
...
...
..
...
...
...
.
.
.
...
...
...
.
.
.
...
....
...
.....
....
.....
......
......
.......
..........
.......
...................................
...................................
.........
.......
.......
......
......
.....
.....
....
...
....
...
...
..
...
...
...
.
.
...
...
...
.
.
..
...
..
...
..
...
.
..
...
...
...
...
..
...
...
...
.
.
.
...
...
...
.
.
.
...
....
...
.....
....
.....
......
......
.......
..........
.......
...................................
c
1
numerator = z 3 + 1
numerator = z 3 1
6 EventDet
26
2013
BioMedSigProcAna
H1 (z) =
(1 z m )
q
(1 2 cos z 1 + z 2 )
H2 (z) =
(1 + z m )
q
(1 2 cos z 1 + z 2 )
where m, p, q =
integers
and where {0 , 60 , 90, 120 , 180}
note:
raising p & q by equal integer-amounts corresponds to cascading of identical filters
1 z m
.
1 2 cos z 1 + z 2
H12 (z) =
(1 z m )
(1 2 cos z 1 + z 2 )
27
2013
BioMedSigProcAna
2.4
bandpass
filter
squaring
operator
derivative
operator
mov-win
integrator
The algorithm for Qrs detection in real time has been developed by Pan and Tompkins [PT85]; it has further been analyzed
and described by Hamilton and Tompkins [HT86]. The algorithm recognizes Qrs complexes by analyzing slope and amplitude of Ecg signals taking into account the width of appearing
Ecg waves.
6 EventDet
28
2013
BioMedSigProcAna
We present the algorithm as it is described in [Tom93, Section 12.5]; you might also want to consult [Ran02, Section 4.3.2]
and/or study the original literature [PT85] and [HT86]. The
described form of the algorithm is targeted to an implementation on a microprocessor using integer programming. In the
laboratory exercises we explore variants that might be useful for
hardware implementations.
The slide on the previous page 28 states that the described
Pan-Tompkins algorithm is intended for discrete-time Ecg signals that have been obtained by sampling the true, continuoustime Ecg signal at a rate of 200 samples/sec. This is true because the algorithm uses integer filters that realize pole- and
zero locations that are useful for the intended sampling rate,
but become unreasonable for different sampling rates; see our
discussion starting on page 42.
Because this subsection is quit long, we give an overview
on where you find what. The pre-processing according to the
block diagram shown on page 28 is discussed on pages 3049;
we indicate on page 50 how Pan and Tompkins implement the
decision rule.
For the pre-processing stage we treat the first preprocessing
block, the bandpass filter, on pages 30 to 42. Next we discuss
the derivative operator on pages 44 to 45. The squaring operator
follows on page 46, and the final moving-window integrator is
described on pages 47 to 49.
6 EventDet
29
2013
BioMedSigProcAna
Bandpass Filter
isolates the predominant Qrs energy, which is centered in
the 515 Hz range
attenuates the low -frequency characteristics
of the P- and T-waves
of baseline wander
attenuates the high frequencies associated with
electromyographic noise
power-line interferences
measurement noise
implementation as
integer filter in which poles cancel zeros on unit
circle
cascade of lowpass and highpass filter
Lp
....................................
....
.
.....................................................................Hp.....................................................................
......
........... Bp ...........
6 EventDet
30
2013
BioMedSigProcAna
1 z 6
= 1 + z 1 + z 2 + + z 5
1 z 1
the Dc gain is (
= 0 = z = ej0 = 1)
HLp1 (z = 1) = 1 + z 1 + z 2 + + z 5 z=1 = 6
................................
.......
...........
......
.......
.....
......
....
.....
.
.
.
....
...
.
.
...
...
...
.
...
..
.
...
....
...
....
..
..
...
..
..
...
..
...
5-fold
...
...
..
.
...
.
.
.
...
...
...
...
...
...
...
....
...
.
.
.
.....
....
......
......
.......
.......
..........
...................................
6 EventDet
6.0...........
.. ...
... .....
...
..
c
...
...
...
1
.
...... ..
.
.
... ............ ........
.
.
.
.
.
.
.
.
.
.
.
.
. ..
..... .......... .....
..... ......... .....
.
31
2013
BioMedSigProcAna
32
6 EventDet
1 z 6
1 z 1
2
Y (z)
1 1 2z 6 + z 12
=
1
2
32 1 2z + z
X(z)
32
2013
BioMedSigProcAna
............
...
..
...
...
...
..
...
..
...
..
...
...
....
.
.
.
.
.
.
.
.
.
.
.
....................................................................
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.........
............. ...................
1.0...
6 EventDet
1
x[n] 2x[n6] + x[n12]
32
33
2013
BioMedSigProcAna
32-point
moving average
delay of M -point moving averager is (M 1)/2
for M = 32: half-sample delay 31/2 ; 16 is used
34
2013
BioMedSigProcAna
which delays each sample of the input sequences by n0 samples.
The transfer function of this system is H(z) = z n0 , and its
0
.
frequency response becomes H(
) = ej n
Next consider an M -point moving-average filter. Its transfer
function is
H(z) =
1 1 z M
1
1 + z 1 + . . . + z (M1) =
.
M
M 1 z 1
1 1 ej M
j
M 1 e
ej M/2
ej M/2
1 ej M/2
=
M
ej /2
ej /2
ej /2
1 sin(
M/2) j (M1)/2
e
,
=
M sin(
/2)
{z
}
|
Dirichlet function
6 EventDet
35
2013
BioMedSigProcAna
1 1 z 32
1
1 + z 1 + . . . + z 31 =
.
32
32 1 z 1
........................................
.........
.......
......
......
......
.....
.....
....
.
.
..
...
.
.
...
...
.
...
..
...
.
...
....
...
...
..
....
...
...
..
...
31-fold
...
..
.
...
.
.
.
...
.
.
.
...
.
...
...
...
...
...
...
....
...
.
.....
.
.
...
......
.......
......
..........
.......
...................................
c
c
c
c
c
c
c
c
c
c
c
c
c1
c
cc
c
c c c c
H(ej )
.
.....
.......
.. ....
... ....
. ..
... ........
.
.
.
..... ......
................................................... ... .. ......................................................
1.0
We note that the phase response of the moving-average transfer function HMA (z) is linearit is just a symmetric Fir filter,
and its recursive realization does, of course, neither change the
magnitude- nor the phase response.
6 EventDet
36
2013
BioMedSigProcAna
1 1 z 32
.
32 1 z 1
c c c c
c
c
c
c
c
c
c 1
c c c c
H(ej )
......................................
.........
.......
.......
......
......
.....
....
....
.
.
.
...
..
.
.
...
...
...
.
...
..
.
...
....
..
...
.. 2-fold
..
.. zero
..
...
...
...
31-fold
...
..
.
...
..
.
...
...
...
..
...
...
...
...
...
.
.
.
....
...
.....
.....
......
......
.......
.......
..........
...................................
..... ......
.................................................................. .. ...................................................
.......... .. .
.. . .
... .
.
.
... ..
...
...
.
.
.. ..
.
...
... ..
1.0
... .
.....
.....
.
37
2013
BioMedSigProcAna
If we would use instead of the 32-point a 33-point movingaverage filter, we would obtain a highpass filter with exactly
linear phase response, but we would loose the possibility to realize the needed multiplication by mere bit shifting. To illustrate
these arguments, we consider the situation for shorter lengths
of the involved moving average filter.
First consider a 5-point moving-average filter. Its delay is
(M 1)/2 = (5 1)/2 = 2, and we use a delay allpass having a
delay of 2. The transfer function of the realized highpass filter
becomes
HHp5 (z) = z 2 HMA5 (z)
1
= z 2
1 + z 1 + z 2 + z 3 + z 4
5
1
= 1 + z 1 4z 2 + z 3 + z 4 .
5
Clearly, HHp5 (z) realizes a symmetric Fir filter which has a
purely linear phase.
Next consider a 4-point moving-average filter. Its delay is
(M 1)/2 = (4 1)/2 = 1.5, and we must use a delay allpass
having either a delay of 1 or of 2. Consider first the delay 2.
The transfer function of the realized highpass filter becomes
HHp4,2 (z) = z 2 HMA4 (z)
1
= z 2
1 + z 1 + z 2 + z 3
4
1
= 1 + z 1 3z 2 + z 3 .
4
Obviously, HHp4,2 (z) is not a symmetric Fir filter and we cannot expect that it has a linear phase. If we consider to realize
the delay allpass with the delay 1, the transfer function of the
6 EventDet
38
2013
BioMedSigProcAna
realized highpass filter becomes
HHp4,1 (z) = z 1 HMA4 (z)
1
= z 1
1 + z 1 + z 2 + z 3
4
1
= 1 3z 1 + z 2 + z 3 .
4
Again, HHp4,1 (z) is not a symmetric Fir filter and we cannot
expect that it has a linear phase.
6 EventDet
39
2013
BioMedSigProcAna
that is, they have the moving-average filter not scaled and do the
scaling only when subtracting the moving-average filter output
6 EventDet
40
2013
BioMedSigProcAna
from the delayed input; we do not understand why they seem
to recompute ye1 [n] in (6).
The reference [HT86] computes differently according to
y[n] = y[n 1]
1
1
x[n] + x[n 16] x[n 17] + x[n 32] .
32
32
(7)
HHp (z) = z 16
1
32
+ z 16 z 17 +
1 z 1
1 32
32 z
Finally, the original paper [PT85] uses a completely different highpass filter. We suspect, however, that the formula given
there might be in error; indeed, [HT86] state in their introductory section that they use the processor developed by Pan and
Tompkins with slight modifications.
6 EventDet
41
2013
BioMedSigProcAna
... ...
........................ .......
.
. .
.
.... . . .
.... . . . .
.
... . .
.
.
.... .
.
.
.
.
... .. .....
...
.
...
.
1.0
. .. . ..
.. ........ .....
.
..... ..... ................. ..................
...
....
..
.................................................
in [dB]
H(ej )
dB
................... .......
...... ................ .......
. ....... ..... ... .....
......... ... 0dB
... .... .... .......
....
.
.
.
.
.
.
.
.
.
.
.
... .. ... ... ....
.... ...... ... .... ...60dB........
... . ..
... .
..... ........ ....
...
... ..
..
... ..
.....
.... ................
...
.....
.....
..
.
...
..
.....
6 EventDet
42
2013
BioMedSigProcAna
frequency of
right = 0.3707 rad. If the signal to be processed
stems from a continuous-time Ecg signal which has been sampled at a rate of fs = 200 samples/sec, these characteristics
translate8 to left, middle, and right natural frequencies being
{4.9, 8.0, 11.8}Hz. In the light of the frequency characteristics
of the Qrs complex of Ecg signals as we have compiled on
page 30the dominant Qrs energy is contained in the 515 Hz
frequency range, the realized filter characteristics are reasonable. Note, however, that if the input signal to the Qrs detector stems from a continuous-time Ecg signal sampled at a
rate of fs = 1000 samples/sec, for example, the discrete-time
filter characteristics translate to left, middle, and right natural
frequencies being {24.5, 40, 59}Hz. Obviously, in that case the
bandpass filter is not useful.
6 EventDet
43
2013
BioMedSigProcAna
1
2x[n] + x[n 1] x[n 3] 2x[n 4] .
8
6 EventDet
44
2013
BioMedSigProcAna
H(ej )
....
....
.... ......0.7 ..... .......
...
..
.. . ....
...
... ..
.
.
... ..............
.......
... .
.
...... ....... ...
... .. ...
... .
... ..
...
..
.
... ..
.
.
...
.
..
.
..
j
H(e )
[dB]
20
40
60
...........
............
.
.
.
.
.
.
.
.
.
.
.......
...........
.
.
.
.
.
.
.
.
.
.......
...........
.
.
.
.
.
.
.
.
.
...
...........
103
102
101
log10 (
)
100
6 EventDet
45
2013
BioMedSigProcAna
2
y[n] = x[n] .
We note that in microprocessor implementations of the PanTompkins algorithm the output of the squaring-operation stage
should be hard-limited to a certain level corresponding to the
number of bits used to represent the data type of the signals.
In hardware implementations, however, we do not need a single
data type for all signals in the chain of operations, and the
decision whether and how to limit the squaring-operator output
must be taken based on other considerations.
6 EventDet
46
2013
BioMedSigProcAna
6 EventDet
47
2013
BioMedSigProcAna
1
x[n] + x[n 1] + + x[n (N 1)]
N
6 EventDet
1
x[n] x[n N ] .
N
48
2013
BioMedSigProcAna
We also note that it might not be necessary to compute the
true average, that is, we could leave away the factor 1/N to simplify the computation, because the subsequent processing step
realizing the decision rule can take account of the resulting
signal gain in that it works with adjusted threshold values. If
we nevertheless like to have the normalizationthe division by
the number N of samplesit is clearly best to choose N = 32,
which is in the order of the proposed 30, because the division
then becomes a mere bit shift.
Concerning the selection of the window size N , the argumentation is as follows: If the window size of the moving-average
filter is too largewe have a too wide window, then the integration waveform y[n] tends to merge Qrs complexes and subsequent T-waves together. If, however, the window size is too
small, a single Qrs complex might produce several peaks at the
integrator-stage output. For the considered Ecg signals sampled at a rate of 200 samples/sec, a choice of N = 30 has 29
intervals between first and last sample in the window and corresponds to an real-world time interval length of 145 msec. Correspondingly, we obtain for a choice of N = 31 a real-world time
interval length of 150 msec, and for N = 32 one of 155 msec.
6 EventDet
49
2013
BioMedSigProcAna
Decision Rule
adaptive thresholding
algorithm adapts to changes in the Ecg signal
by: computing running estimates of signal and noise
peaks
a peak is said to be detected whenever the final output changes direction within a specified interval
adjusting average heartbeat-rate estimates
R-R interval: R-wave to R-wave interval =
heartbeat
interval
works with two averages
1. average: over 8 most recent beats
2. average: over 8 most recent beats that fall into
certain limits
reason (idea): to be able to adapt to quickly changing
or irregular heartbeat rates
for details: see original literature
6 EventDet
50
2013
BioMedSigProcAna
Sampling-Rate Conversion
note: the Pan-Tompkins algorithm is designed for Ecg
signals sampled with fs = 200 samples/sec
if we have an Ecg signal with a different sampling rate,
say fs = 1000 samples/sec, we need a pre-processing
pre-processing: sample-rate conversion
in fixed-point implementations: sample-rate conversion often performed with Cic filters
9 In
6 EventDet
51
2013
BioMedSigProcAna
1 z 10
1 z 2
6 EventDet
1 1 z 10
1
1 + z 1 + + z 9 =
,
10
10 1 z 1
52
2013
BioMedSigProcAna
that is, the moving-average filter has, as compared to the movingsum filter, an additional scaling factor 1/10the computation
of the average.
Reconsider the Cic-filter decimator structure in the graphics on page 52. We see that the first processing block is an
accumulatorwe may likewise term it an integrator if we prefer
continuous-time (Ct) system parlance. Obviously, that accumulator contributes a not strictly-stable pole at z = 1 to the
system, and the result might be register overflow in the integrator stage.10 However, such a register overflow will have no
consequence if we ensure that the following two conditions hold:
(i) The filter is implemented in twos complement arithmetic;11
(ii) The range of the used number system is equal to or exceeds
the maximum magnitude expected at the output of the complete
Cic filter.
Corresponding to the operation of decimation, there is the
complementary operation of interpolation: Here, an incoming
signal is first upsampled to a higher rate by inserting zero samples and subsequently lowpass filtered for interpolation. In the
interpolation-operation too, Cic-filter structures can be used,
but the sequence of comb sections and integrator sections is reversed: Corresponding to the example on page 52 we would have
the comb block (1 z 2 ), followed by an upsampler, followed
by the integrator. In this situation of the Cic-filter interpolator, the input signal to the overall filter is preconditioned by
the comb sectionthe comb section suppresses a potential Dc
termso that overflow will not occur in the integrator stages.
6 EventDet
53
2013
BioMedSigProcAna
The summary of economical advantages of Cic-filters is,
1. Cic-filters need no multipliers;
2. consequently, Cic-filters need no storage for filter coefficients;
3. Cic-filters reduce internal signal-sample storage, as compared to equivalent implementations with uniform Fir filters, by integrating at the high sampling rate and comb
filtering at the low sampling rate;
4. Cic-filters have a very regular structure consisting of
two basic building blocks;
5. Cic-filters can be implemented with little external control
or complicated internal timing;
6. Cic-filters allow to use the same filter design for a wide
range of rate-change factors, with only the addition of a
scaling circuit and minimum changes to the filter timing.
Problems encountered with Cic-filters include: (i) Register
widths might become large if large sampling-rate factors are
to be implemented; (ii) The frequency response can only be
influenced by three integer parameters.
To understand this second statement, we must generalize
the example on page 52: Instead of using there the 10-point
moving-sum filter for lowpass filtering prior to downsampling
by a factor of 5, we could start with only a 5-point moving
sum filter. Correspondingly, the comb section would become
(1 z 1 ), and in general, the comb section is (1 z M ), where
M is named the differential delay.12 Next, instead of starting
just with the 10-point moving-sum filter as done on page 52, we
could use a cascade of N such moving sum filters, leading then
12 Of course we could also start with a 15-point, or a 20-point, or . . . ,
moving-sum filter, leading to M = 3, M = 4, . . . , but in practice the
differential delay is usually held to M = 1, 2.
6 EventDet
54
2013
BioMedSigProcAna
to a Cic-filter structure corresponding to that on page 52 which
would first have N integrator stages, next the downsampler by
the factor 5, and finally N comb stages each of the form (1
z 2 ). Finally, of course, the downsampling factor could be some
general positive integer R, and the transfer function of the Cicfilter referenced to the high sampling rate would become
H(z) =
1 z RM
N
(1 z 1 )
RM1
X
k=0
!N
6 EventDet
55
2013
BioMedSigProcAna
References
[AT83]
[AT85]
Matthew P. Donadio.
Cic filter introduction.
On the Web: For Free Publication by Iowegian,
July 2000. m.p.donadio@ieee.org, http://www.dspguru.com/info/tutor/cic.htm.
[FJJ+ 90]
[Goe13a]
6 EventDet
56
2013
BioMedSigProcAna
[Goe13b]
[Goe13c]
[Hog81]
[HT86]
[Los08]
[MB07]
[Mit98]
Sanjit K. Mitra. Digital Signal Processing: A Computer Based Approach. Mc Graw Hill, New York,
1998. Bfh-ti Biel/Bienne Library 621.391 MITRA.
[Mit06]
Sanjit K. Mitra. Digital Signal Processing: A Computer Based Approach. Mc Graw Hill, New York, 3rd
edition, 2006. Bfh-ti Biel/Bienne Library 621.391
MITRA.
6 EventDet
57
2013
BioMedSigProcAna
[MSY98]
[Orf96]
Sophocles J. Orfanidis. Introduction to Signal Processing. Prentice-Hall Inc., Upper Saddle River, New
Jersey, 1996. Bfh-ti Biel/Bienne Library 621.391
ORFAN.
[PT85]
[Ran02]
Rangaraj M. Rangayyan. Biomedical Signal Analysis: A Case-Study Approach. IEEE Press, New York,
2002. Bfh-ti Biel/Bienne Library 57.08 RANGA.
[SL05]
Leif S
ornmo and Pablo Laguna. Bioelectrical Signal
Processing in Cardiac and Neurological Applications.
Elsevier Academic Press, Amsterdam, 2005. Bfh-ti
Biel/Bienne Library 616 SOERN.
[Tom93]
Willis J. Tompkins. Biomedical Digital Signal Processing. Prentice-Hall Inc., Englewood Cliffs, N.J.,
1993. Eth Bib: +521 458.
[Xil08]
6 EventDet
58
2013