Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
February 9, 2017
Contents
1 Introduction 1
2 Qrs Detection 3
2.1 General Structure of Qrs Detector . . . . . . . . 3
2.2 Simplest: Derivative-Based Ideas . . . . . . . . . 10
2.3 Aside: “Integer” Filters . . . . . . . . . . . . . . 14
2.4 The Pan-Tompkins Algorithm . . . . . . . . . . . 28
References 56
6 EventDet i 2017
BioMedSigProcAna
c
Josef Goette, 2007–2017
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 2017
BioMedSigProcAna
1 Introduction
– amplitude
– wave shape (morphology)
– time duration
– time intervals between events
– energy distribution
– frequency content
– . . . and many more
• therefore: event detection is an important step in biomed-
ical signal analysis
6 EventDet 1 2017
BioMedSigProcAna
1 T
P
ECG
0 P
−1
Q
−2 S
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
time in seconds
6 EventDet 2 2017
BioMedSigProcAna
2 Qrs Detection
2.1 General Structure of Qrs Detector
6 EventDet 3 2017
BioMedSigProcAna
6 EventDet 4 2017
BioMedSigProcAna
6 EventDet 5 2017
BioMedSigProcAna
prepocessor
x[n] linear nonlinear decision θ̂i
filtering transformation rule
• x[n] =
ˆ Ecg-signal input to detector
• θ̂i , i = 1, 2, . . . =
ˆ series of occurrence-times of detected
Qrs complexes
6 EventDet 6 2017
BioMedSigProcAna
6 EventDet 7 2017
BioMedSigProcAna
6 EventDet 8 2017
BioMedSigProcAna
6 EventDet 9 2017
BioMedSigProcAna
The references cited in the above slide are [BDD+ 77], [AT83],
and [FJJ+ 90].
6 EventDet 10 2017
BioMedSigProcAna
• let x[n] =
ˆ input to and y[n] =
ˆ output from pre-processing
stage of algorithm
• use for pre-processing a linear combination of first- and
second derivative
• first derivative: approximated as absolute value of three-
point first difference
y0 [n] = x[n] − x[n − 2] .
6 EventDet 11 2017
BioMedSigProcAna
ỹ0 [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 2017
BioMedSigProcAna
ỹ1 [n] =
ˆ ỹ0 [n] − ỹ0 [n − 2]
= x[n] − x[n − 2] − x[n − 2] − x[n − 4]
= x[n] − 2x[n − 2] + x[n − 4 .
• threshold y[n] =
ˆ output of pre-processing with a threshold-
value of 1.0
• if y[n0 ] ≥ 1.0 for a certain n0 , then compare next 8 samples
to threshold
• if 6 or more of these 8 samples pass threshold test, then
take the 8-samples segment as part of a Qrs complex
• advantage: additionally to detecting Qrs complexes, the
algorithm produces a pulse that is proportional in width
to the Qrs complex
• disadvantage: the method is extremely sensitive to high-
frequency noise
6 EventDet 13 2017
BioMedSigProcAna
Motivation
6 EventDet 14 2017
BioMedSigProcAna
Simple Example
• transfer function
1 − z −6 z6 − 1 N (z)
H(z) = −1 −2
= 4 2
=
ˆ
1−z +z z (z − z + 1) D(z)
• zeros
N (zz ) = zz6 − 1 ≡ 0
; zz = ej·k·2π/6 , k = 0, 1, . . . , 5 =
ˆ 6-th roots of unity
j
................................
........... .......
....... ......
......
c c .....
..... ....
... ....
.... ...
...
. ...
...
. ...
...
.... ...
.
.... ..
..
.. ..
...
c c.
... ...
... ...
..
...
...
... ...
.
.. 1
.
... ...
... ...
... ....
..... ....
......
...... ....
......
c ........ ....
............................................
c
6 EventDet 15 2017
BioMedSigProcAna
j jϕ
e
....................................
.......
..........
......
.......
...× .......
......
.....
....
.....
.. . ....
... ...
. ...
.. ...
... ...
......... ......
. ...
.... ...
.
....
.. ....
...
...
.....
....
..
.. .. 60 ◦ ....
...
..
...
... ...
...
... .
...
.
1
... ...
... ..
... ...
.... ...
..... ....
...... .........
.......
...........
...............................
....... ×
.
.
6 EventDet 16 2017
BioMedSigProcAna
1 − z −6
H(z) = = 1 + z −1 − z −3 − z −4
1 − z −1 + z −2
The first pair of terms gives 1 − z −2 , the second pair of terms
gives—we use the formula of Euler together with the result
cos (120◦ ) = −1/2—the polynomial 1 + z −1 + z −2 , and we
finally obtain
1 − z −2 1 + z −1 + z −2 = 1 + z −1 − z −3 − z −4 .
6 EventDet 17 2017
BioMedSigProcAna
1
H(z) = 1 + z −1 + z −2 + · · · + z −(N −1) , (1a)
N
1 1 − z −N
= . (1b)
N 1 − z −1
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
1
y[n] = 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
6 EventDet 18 2017
BioMedSigProcAna
1
y[n] = y[n − 1] + x[n] − x[n − N ] , (3)
N
or, in what is called the canonical form, as
are uncorrelated.
6 EventDet 19 2017
BioMedSigProcAna
residue number systems, if overflow is correctly treated; see the main text.
6 EventDet 20 2017
BioMedSigProcAna
j ω̂
6 H(e )
..........
. ..
.. ..........
....... ....... π/2 ........
....... . .. ......
....... ... .......
. .. ........
....... . ...... .. ....... ............
...... ....... . ...... .. ......... ω̂
−π
...
....... . . ......... .. ....... π
......... ....... .......
−π/2 . ....... ...
....... ..
....
6 EventDet 21 2017
BioMedSigProcAna
General: Poles
• then
denominator = z − ejϕ z − e−jϕ
= z 2 − ejϕ + e−jϕ z + 1
= z 2 − 2 cos ϕz + 1
ϕ cos ϕ 2 cos ϕ
±0◦ 1 2
±60◦ 1/2 1
±90◦ 0 0
±120◦ −1/2 −1
±180◦ −1 −2
6 EventDet 22 2017
BioMedSigProcAna
j
.......
........... ×
................................
.......
....×
..
..... × ......
.....
....
.....
. ....
..
. ...
..
. ...
.
. ...
.... ...
.. ...
... ..
..
... 2-fold 2-fold ..
×...
..
...
× ..
.....
...
... ...1
... ...
.
... ..
... ...
.... ....
.... ..
..... ....
...... .......
× ........
..............
.........................
×
.......
.
..
×
6 EventDet 23 2017
BioMedSigProcAna
General: Zeros
• first case
numerator = z m − 1 , m=
ˆ positive integer
zeros: zzm = 1 , zz = ej·k·2π/m , k ∈ {0, m−1}
; zeros are m-th roots of unity
; evenly spaced zeros around the unit circle
starting at z = 1
• second case
numerator = z m + 1 , m=
ˆ positive integer
zeros: zzm = −1 , zz = ej(π/m+k·2π/m) , k ∈ {0, m−1}
; zeros are m-th roots of (−1)
; evenly spaced zeros around the unit circle
starting at z = ejπ/m
6 EventDet 24 2017
BioMedSigProcAna
jc
..............................
........... ........
.
....
c....... ......
c
..
... .....
. ....
...... ....
.
.. ...
c .
.. ... c
.
. ...
..
. ...
.
.. ...
... ..
..
..
...
c ..
..
.. c
... .....
... .
...
... .
..
...
.
1
... .
c ... ... c
...
... .....
..
.... ...
.....
....... .
.... .....
c ......... .. c
.........................................
c
6 EventDet 25 2017
BioMedSigProcAna
.........
.....................................
.......
cj c
...
......... ......
..
... .....
.
.. c .... c
.
. ... ...
...
.
.. ...
.. ...
.
.. ...
..
...
c ...
..
c
..
... ...
.... .
..
... ....
.
...
c ... ... c1
... ...
.
... .
..
...
... .....
... ..
.... ...
.....
.....
c ...
c
....... ..
......... ......
......................................... c c
numerator = z 3 − 1 numerator = z 3 + 1
6 EventDet 26 2017
BioMedSigProcAna
• where m, p, q =
ˆ integers
• and where ϕ ∈ {0◦ , ±60◦ , ±90◦, ±120◦ , 180◦}
• note:
raising p & q by equal integer-amounts corresponds to cas-
cading of identical filters
1 − z −m
H11 (z) = .
1 − 2 cos ϕz −1 + z −2
6 EventDet 27 2017
BioMedSigProcAna
The algorithm for Qrs detection in real time has been devel-
oped by Pan and Tompkins [PT85]; it has further been analyzed
and described by Hamilton and Tompkins [HT86]. The algo-
rithm recognizes Qrs complexes by analyzing slope and ampli-
tude of Ecg signals taking into account the width of appearing
Ecg waves.
6 EventDet 28 2017
BioMedSigProcAna
6 EventDet 29 2017
BioMedSigProcAna
Bandpass Filter
....................................
Lp
.... . ω̂
−π 0 π
.....................................................................Hp.....................................................................
...... ω̂
−π 0 π
........... Bp ...........
..... ........ .... ω̂
−π 0 π
6 EventDet 30 2017
BioMedSigProcAna
1 − z −6
HLp1 (z) = = 1 + z −1 + z −2 + · · · + z −5
1 − z −1
j H(ej ω̂ )
................................
........... .......
6.0...........
....... ......
......
c c .....
.....
.. ...
..
. ....
.
.... ....
...
... .....
...
. ...
..
. ...
.... ...
...
...
.... ..
..
.. ...
..
c
... × ×c ..
..
... ... ...
...
...
5-fold
1
...
. ...
...
...
...
..
.
.
...
... ..
...
....... .. ... ............ ........
...
. .. . ..... .......... .....
..... ......... .....
... ...
... ...
....
.....
......
....... ......
....
.....
. . ω̂
c .......... .......
c
...................................
−π 0 π
6 EventDet 31 2017
BioMedSigProcAna
2
1 1 − z −6 1 1 − 2z −6 + z −12 Y (z)
HLp (z) =
ˆ = =
ˆ
32 1 − z −1 −1
32 1 − 2z + z −2 X(z)
6 EventDet 32 2017
BioMedSigProcAna
1
y[n] = 2y[n−1] − y[n−2] + x[n] − 2x[n−6] + x[n−12]
32
6 EventDet 33 2017
BioMedSigProcAna
32-point y1 [n]
moving average
y[n] = x[n − n0 ] ,
6 EventDet 34 2017
BioMedSigProcAna
1 1 1 − z −M
H(z) = 1 + z −1 + . . . + z −(M−1) = .
M M 1 − z −1
1 1 − e−j ω̂M
ˆ H(z = ej ω̂ ) =
H(ω̂) =
M 1 − e−j ω̂
1 e−j ω̂M/2 ej ω̂M/2 − e−j ω̂M/2
=
M e−j ω̂/2 ej ω̂/2 − e−j ω̂/2
1 sin(ω̂M/2) −j ω̂(M−1)/2
= e ,
M sin(ω̂/2)
| {z }
Dirichlet function
6 EventDet 35 2017
BioMedSigProcAna
1 1 1 − z −32
HMA (z) = 1 + z −1 + . . . + z −31 = .
32 32 1 − z −1
H(ej ω̂ )
cj c c c .........
........................................
cc .
.....
...... .......
.....
......
c ......
..... 1.0
.......
c .. ....
c
.
... ...
... ...
c .
c
...
.. ....
c ... c...
.... ...
... ....
c ... c ...
.... ..
...
...
× ×c
. ..
c.. ...
... 31-fold ..
... ........
c ... c ..
c1
... ..
c ... .
...
..
.
.. .
...
..... ......
................................................... ... .. ...................................................... ω̂
c ... ...c
... ...
c ....
..... . ....
.c
...... ...
cc .......
c ......
.......... .......
c c c c ...................................
−π 0 π
6 EventDet 36 2017
BioMedSigProcAna
c
c j c
.........
...................................... H(ej ω̂ )
.......
.......
..... ......
c c
......
......
.................................................................. .. ...................................................
.....
....... c c c c ....
.
... ...
... ...
.......... .. .
c ..
. c c ...
...
. c
....
.. . .
...
... .
..
..
... c .. 2-fold
.. zero .
...
. ... ..
c ...
... × ×c ..
... ....
. .. ..
...
...
c 31-fold
..
..
.
.
... ... ..
...
... c 1 ..
...
. 1.0
... .
...
.....
c ...
c ...
...
... .
c
....
.....
c c c c
......
...
.....
......
.
.
.....
c .......
..........
...................................
....... c . ω̂
c c c −π 0 π
6 EventDet 37 2017
BioMedSigProcAna
6 EventDet 38 2017
BioMedSigProcAna
6 EventDet 39 2017
BioMedSigProcAna
6 EventDet 40 2017
BioMedSigProcAna
y[n] = y[n − 1]
1 1 (7)
− x[n] + x[n − 16] − x[n − 17] + x[n − 32] .
32 32
1 1 − z −32
HHp (z) = z −16 −
32 1 − z −1
1
1 − z −1 z −16 − 32 1 − z −32
=
1 − z −1
1 1 −32
− 32 + z −16 − z −17 + 32 z
= .
1 − z −1
6 EventDet 41 2017
BioMedSigProcAna
• in [dB]
H(ej ω̂ )
................... .......
dB
...... ................ .......
. ....... ..... ... .....
.
...
.. .
........... ... 0dB .... ... .... .... .......
. . ... .. ... ... ....
.... ...... ... .... ...−60dB........ ... . ... . ..
.. ... .. ..... ........ .... ..... ... .. ...
.. ..... .... ................ .
... ..... ...
.. .....
ω̂
−π 0 π
6 EventDet 42 2017
BioMedSigProcAna
6 EventDet 43 2017
BioMedSigProcAna
1
y[n] = 2x[n] + x[n − 1] − x[n − 3] − 2x[n − 4] .
8
6 EventDet 44 2017
BioMedSigProcAna
6 EventDet 45 2017
BioMedSigProcAna
6 EventDet 46 2017
BioMedSigProcAna
6 EventDet 47 2017
BioMedSigProcAna
• let x[n] =
ˆ input, y[n] =
ˆ output of moving-window integra-
tor
• then, difference equation is
1
y[n] = x[n] + x[n − 1] + · · · + x[n − (N − 1)]
N
Y (z) 1 1 1 − z −N
= 1 + z −1 + · · · + z −(N −1) = ,
X(z) N N 1 − z −1
1
y[n] = y[n − 1] + x[n] − x[n − N ] .
N
6 EventDet 48 2017
BioMedSigProcAna
6 EventDet 49 2017
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 out-
put 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 2017
BioMedSigProcAna
Sampling-Rate Conversion
6 EventDet 51 2017
BioMedSigProcAna
1 − z −10
↓5
1 − z −1
1
1 − z −10 ↓5
1 − z −1
1
↓5 1 − z −2
1 − z −1
1 1 1 − z −10
H(z) = 1 + z −1 + · · · + z −9 = ,
10 10 1 − z −1
6 EventDet 52 2017
BioMedSigProcAna
the register will overflow sooner or later independently of how small that
Dc component might be.
11 The filter can likewise be implemented by any other number system that
has “wrap-around” between the most positive and most negative numbers—
the number system must have modulo arithmetic.
6 EventDet 53 2017
BioMedSigProcAna
6 EventDet 54 2017
BioMedSigProcAna
N RM−1
!N
1 − z −RM X
−k
H(z) = N
= z .
(1 − z −1 ) k=0
6 EventDet 55 2017
BioMedSigProcAna
References
[AT83] M. L. Ahlstrom and W. J. Tompkins. Automated
high-speed analysis of holter tapes with microcom-
puters. IEEE Trans. Biomed. Eng., 30(10):651–657,
October 1983.
6 EventDet 56 2017
BioMedSigProcAna
6 EventDet 57 2017
BioMedSigProcAna
6 EventDet 58 2017