You are on page 1of 60

BioMedSigProcAna

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

Events and Epochs

• biomedical signals carry signatures of physiological events


• epoch =
ˆ part of a biomedical signal related to a specific
event
• biomedical signal analysis
– for monitoring and diagnosis
– requires identification of epochs
– requires investigation of related events
• once an event has been identified, the corresponding wave-
form may be segmented & analyzed in terms of

– 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

Examples of Events: Waves in Ecg’s

noisy ECG signal (random noise)


2
R

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

P wave: Duration less than 120 msec with frequencies below


10–15 Hz.

Pq segment: Lasts about 80 msec; is a “non-event”


Qrs wave: Lasts about 70–110 msec, frequencies mostly con-
centrated in the interval 10–50 Hz
T wave: Has frequency content similar to that of the P wave.
St segment: Duration is usually about 100–120 msec and is
normally flat; is a “non-event”

For the various waves in the Ecg signal we have a summary


of the main attributes in [Goe17c, Section 2]. You find a more in-
depth treatment in [SL05, Section 6.2.3] and in [Ran02], where
you find, besides more general information, in Section 4.2.1 a
discussion targeted to event detection.

6 EventDet 2 2017
BioMedSigProcAna

2 Qrs Detection
2.1 General Structure of Qrs Detector

General Requirements on a Qrs Detector

• must be able to detect a large number of different Qrs


morphologies to be clinical useful
• must be able to follow
– sudden changes
– gradual changes
in prevailing Qrs morphology
• must not lock onto certain types of rhythm, but treat next
possible event as if anything could happen next

6 EventDet 3 2017
BioMedSigProcAna

Detector-Critical Types of Noise and Artifacts

• noise might be in nature


– highly transient
– or persistent (e.g. power-line interference)
• problem of conditioning Ecg signals w.r.t. noise has been
treated
• however, term “noise” has a somewhat different meaning
when considered form the Qrs-detection viewpoint
– P- and T-wave must here be treated as noise
– noise might have physiological as well as technical
origins

We refer to our accompanying document [Goe17a] for the


problem of conditioning Ecg signals with respect to noise.

6 EventDet 4 2017
BioMedSigProcAna

Classification of Noise Problems

signal and noise problems in Qrs detection can be classified into


two main categories with further sub-classification
• changes in morphology (including amplitude changes)
– of physiological origin
– due to technical problems
• occurrence of noise
– Ecg signals with large P- and T-waves
– noise of myoelectric origin
– noise due to transient artifacts (mainly due to elec-
trode problems)

6 EventDet 5 2017
BioMedSigProcAna

General Block-Diagram of Qrs Detectors

• most Qrs detectors described in the literature: developed


from ad hoc reasoning and experimental insight
• general detector forms
– pre-processor: enhance Qrs complex while suppress-
ing noise and artifacts
– usually: linear filtering followed by a non-linear trans-
formation
– decision rule for detection

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

The goal of the linear filter in the above block diagram is


to reduce artifacts while keeping the essential spectral contents
of the Qrs complex. It has a bandpass characteristics and re-
duces the influence of muscle noise, P- and T-waves, power-line
interferences and baseline wander. The center frequency of the
filter varies from 15 Hz to 25 Hz with a bandwidth varying from

6 EventDet 6 2017
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 en-
hance 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 examples—or a more com-
plex transformation involving memory. Note, however, that not
all Qrs detectors use a nonlinear transformation in their pre-
processing 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 thresh-
old 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 com-
plexes with high resolution in time. If time resolution is nev-
ertheless 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 dis-
cussed in [Goe17a]).

6 EventDet 7 2017
BioMedSigProcAna

Qrs Detection as an Estimation Problem

• theoretical justification of Qrs-detector structure on page 6


– investigate statistical models of Ecg signals
– use maximum-likelihood estimation techniques to de-
rive detector structures corresponding to the signal
model of interest
• example model: unknown occurrence-time and amplitude


 v[n] , 0≤n≤θ−1,

x[n] = as[n − θ] + v[n] , θ ≤n≤θ+D−1,


 v[n] , θ+D ≤n≤N −1,

where 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örnmo and Laguna [SL05] discuss in Section 7.4 Qrs detec-


tion in a more theoretically oriented manner. With the proposed
signal model shown above, it is then feasible to estimate the un-
known 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 esti-
mation problem. It is indeed true that the problem considered
in [SL05] can likewise be formulated as a detection problem;

6 EventDet 8 2017
BioMedSigProcAna

Sörnmo and Laguna discuss these different viewpoints and state


that both of them essentially lead to same detector structures,
for details see [SL05, p. 488].

Qrs Detection as an Estimation Problem (2)

• for considered model, theory shows that the Qrs detector


must use as nonlinear transformation a squaring operation
• if example model has more a priori knowledge
– unknown amplitude is constrained to known interval:
– 0 < a 1 < a < a2 , with known a1 and a1
then theory shows that the Qrs detector must use as non-
linear transformation a rectifier

By generalizing the above Ecg-signal model to a model with


unknown occurrence-time, unknown amplitude, and unknown
duration of the Qrs complex, Sörnmo and Laguna [SL05] derive
the optimum Qrs-complex detector structure.

6 EventDet 9 2017
BioMedSigProcAna

2.2 Simplest: Derivative-Based Ideas

Using First- and Second Derivatives

• differentiation forms basis of many Qrs detection algo-


rithms
• differentiation =
ˆ basically a highpass filter
– amplifies higher frequencies that are characteristic for
the Qrs complex
– attenuates lower frequencies that are characteristic
for P- and T-waves
– attenuates low frequencies of baseline wander
• however: differentiation also amplifies higher frequencies
due to noise ; additional significant smoothing is required
• an algorithm based on first and second derivatives, with
smoothing included
– by Balda et. al. in 1977
– modified by Ahlstom and Tompkins for high-speed
applications in 1983
– additionally modified by Friesen et. al. 1990

The references cited in the above slide are [BDD+ 77], [AT83],
and [FJJ+ 90].

6 EventDet 10 2017
BioMedSigProcAna

The Algorithm: Pre-Processing

• 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] .

• second derivative: approximated as absolute value of three-


point first difference of three-point first differences


y1 [n] = x[n] − 2x[n − 2] + x[n − 4] .

• output y[n] of pre-processing stage as linear combination

y[n] = 1.3 · y0 [n] + 1.1 · y1 [n]

To understand the rationals behind the given approximation


of the first derivative, we start with a first-difference operator:
 
δ1 [n] =
ˆ x[n] − x[n − 1] •—• ∆1 (z) = 1 − z −1 X(z) .

6 EventDet 11 2017
BioMedSigProcAna

This filter has a zero at z = 1—at Dc frequency—and has a


magnitude response of 2 sin (ω̂/2). For sufficiently low frequen-
cies ω̂, it approximates the derivative operation as we see from
2 sin (ω̂/2) ≈ 2ω̂/2 = ω̂. To obtain a smoothing such that high-
frequency noise is not too much amplified, we post-process the
sequence δ1 [n] by a two-point moving-average filter having trans-
fer function (1 + z −1 ):1

ỹ0 [n] =
ˆ δ1 [n] + δ1 [n − 1]
 
= x[n] − x[n − 1] + x[n − 1] − x[n − 2]

= x[n] − x[n − 2] .

In the z-transformation domain we equivalently have


 
Ye0 (z) = 1 + z −1 ∆1 (z)
  
= 1 + z −1 1 − z −1 X(z)
 
= 1 − z −2 X(z) .

Clearly, the complete filter (1 − z −2 ) has one zero at z = 1—at


frequency ω̂ = 0—, which approximates the derivative, and a
second zero at z = −1—at frequency ω̂ = ±π—, which sup-
presses high frequency noise. The magnitude response of the fil-
ter is 2 sin (ω̂); for low frequencies we again have 2 sin (ω̂) ≈ 2ω̂,
which approximates a derivative with a gain 2.
For the approximation of the second derivative consider the
sequence ỹ0 [n] being the output of a three-point first difference
filter: ỹ0 [n] = x[n] − x[n − 2]. Processing this sequence by
1 We denote the output of this processing step by ỹ0 [n] to distinguish it
from y0 [n], which we use in the slide on page 11, and which is the absolute
value of ỹ0 [n].

6 EventDet 12 2017
BioMedSigProcAna

another three-point first difference filter, we obtain2

ỹ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 .

The Algorithm: Decision Rule

• 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

2 Again, we denote the output of this processing step by ỹ [n] to distin-


1
guish it from y1 [n], which we use in the slide on page 11, and which is the
absolute value of ỹ1 [n].

6 EventDet 13 2017
BioMedSigProcAna

2.3 Aside: “Integer” Filters

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 opera-
tions
• integer filters are a special class of filters having only in-
teger coefficients
• here more special: coefficients ∈ {0, ±1, ±2}
• here even more special: a preparation to the Pan-Tompkins
algorithm

We admit that we are not sure about the generality of the


notion “integer filters.” We feel that the notion “integer filters”
used in the signal processing community is more general than
the same notion often used in the literature on biomedical signal
processing. Our present discussion treats filters in the more
restricted meaning as given, for example, in [Tom93]—see there
Chapter 7 entitled “Integer Filters,” but also see its Chapter 12
on Qrs detection.
For Qrs detection, for example, it is crucial that the Qrs
complex as well as P- and T-waves remain unchanged. This

6 EventDet 14 2017
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
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

zeros: 6-th roots of unity

Note that the transfer function of the above example defines


a filter that has only coefficients ±1.

6 EventDet 15 2017
BioMedSigProcAna

Simple Example (cont’d)

• poles zp1 = ρejϕ , zp2 = ρe−jϕ = zp1



, zpk = 0, k = 3, . . . , 6
• non-trivial poles
e p) =
D(z ˆ zp2 − zp + 1 ≡ 0
 
zp − ρejϕ zp − ρe−jϕ ≡ 0

zp2 − ρ ejϕ + e−jϕ zp + ρ2 ≡ 0
|{z} | {z } | {z }
≡ 1 = 2 cos ϕ ≡ 1 ≡1
| {z }

; ϕ = 60

j jϕ
e
....................................
.......
..........
......
.......
...× .......
......
.....
....
.....
.. . ....

... ...
. ...
.. ...
... ...

......... ......
. ...
.... ...
.
....
.. ....
...
...
.....
....
..
.. .. 60 ◦ ....
...
..
...
... ...
...
... .
...
.
1
... ...
... ..
... ...
.... ...
..... ....
...... .........
.......
...........
...............................
....... ×
.
.

poles zp1,2 = e±jϕ , ϕ = 60◦

6 EventDet 16 2017
BioMedSigProcAna

Simple Example (cont’d)

• pole-zero map of complete filter (poles “eat” zeros)


j .............................
............ ........
........ ......
......
c .....
..... ....
...... ....
.... ...
...
.... ...
.
. .. ...
. ...
.... ..
... ..
... ..
c.... × 4-fold
c
...
.
...
... ....
... ....
.
1
...
... ...
.
... ...
.... ...
.... ...
..... ....
...... .....
c ........ .
...........
.............. .
.........................

complete pole-zero map

• transfer function (filter is Fir, linear phase)

1 − z −6
H(z) = = 1 + z −1 − z −3 − z −4
1 − z −1 + z −2

To see how we obtain the second form—the non-recursive


form—of the above Fir-filter transfer function, just multiply
the terms that correspond to the remaining zeros and poles:
   
1 − z −1 1 + z −1 1 − ej2π/3 z −1 1 − e−j2π/3 z −1 .


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

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 re-
mainder by the denominator (1 − z −1 + z −2 ) gives z −1 and
a new remainder (−z −3 − z −6 ); again dividing this new re-
mainder 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 different transfer-function expressions for H(z) in
the slide of page 17 suggest that we could implement the filter
as a usual Fir filter by taking the second expression, but also
in a recursive form by taking the first expression. 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

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

geometric series to the first form.

6 EventDet 18 2017
BioMedSigProcAna

whereas the form (1b) could be implemented in direct form as

1 
y[n] = y[n − 1] + x[n] − x[n − N ] , (3)
N
or, in what is called the canonical form, as

w[n] = w[n − 1] + x[n]


1  (4)
y[n] = w[n] − w[n − N ] ;
N
here in (4) w[n] is a newly introduced interval variable—an in-
ternal signal—of the filter.
Comparing the feed-forward implementation (2) to the re-
cursive implementations either (3) or (4), we see that the num-
ber 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 instability—the
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 equa-
tion w[n] = w[n − 1] + x[n] is an accumulator, and accumu-
lating 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 2017
BioMedSigProcAna

However, an additional note is in order: The transfer func-


tion form (1b) shows perfect pole/zero canceling and an imple-
mentation 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, two’s comple-
ment number systems and, more general, any of the residue
number systems5 have the ability to support error-free arith-
metic; in the case of the two’s complement number system, the
arithmetic must be performed modulo 2b , that is, with natural
overflow as we explain in [Goe17b], and in the case of residue
number systems, the arithmetic is performed in modulo M .

5 The two’s complement number system is a member of the family of

residue number systems, if overflow is correctly treated; see the main text.

6 EventDet 20 2017
BioMedSigProcAna

Simple Example (cont’d)

• frequency response of filter



H(ej ω̂ )
................. .................
...... ...3.0 ..... ...
...
. ... .
.. . ... .. ...
.. ... .
. ...
...
.. . ... ..
... .. ...
............. ..
. . . . ... ..............
..
. ..
. .... .. . .
..... ... .... .......
.
.... .. . .... ...
ω̂
−π 0 π

j ω̂
6 H(e )
..........
. ..
.. ..........
....... ....... π/2 ........
....... . .. ......
....... ... .......
. .. ........
....... . ...... .. ....... ............
...... ....... . ...... .. ......... ω̂
−π
...
....... . . ......... .. ....... π
......... ....... .......
−π/2 . ....... ...
....... ..
....

6 EventDet 21 2017
BioMedSigProcAna

General: Poles

• complex-conjugate pole-pair on unit circle

zp1 = ejϕ , zp2 = e−jϕ = zp1


• then  
denominator = z − ejϕ z − e−jϕ

= z 2 − ejϕ + e−jϕ z + 1
= z 2 − 2 cos ϕz + 1

• has (integer) coefficients ∈ {0, ±1, ±2} only for

ϕ cos ϕ 2 cos ϕ
±0◦ 1 2
±60◦ 1/2 1
±90◦ 0 0
±120◦ −1/2 −1
±180◦ −1 −2

Note that the constraints on possible pole locations, which


are given in the above slide, lead to corresponding constraints
on the choice of sampling rates if we need to process continuous-
time (analog) signals by discrete-time filters,6 and if, therefore,
natural (physical) frequencies dictate the useful pole locations;
6 Although there are other occasions, we have in biomedical signal pro-

cessing always, to our knowledge, the situation where the signals to be


processed are in the first instance analog signals.

6 EventDet 22 2017
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 cor-
responding discussion on “general zeros,” the transfer functions
that can be realized with “integer filters.”

General: Poles (cont’d)

• possible pole locations for integer polynomial-coefficients

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

The notation k ∈ {0, m − 1} means that k is in the set


of integers with given lower and upper limits, that is, k =
0, 1, . . . , m − 1.

6 EventDet 24 2017
BioMedSigProcAna

Example: Zeros for z m − 1 = z 12 − 1

• zeros start at z = 1 for a numerator of type z m − 1

jc
..............................
........... ........
.
....
c....... ......
c
..
... .....
. ....
...... ....
.
.. ...
c .
.. ... c
.
. ...
..
. ...
.
.. ...
... ..
..
..
...
c ..
..
.. c
... .....
... .
...
... .
..
...
.
1
... .
c ... ... c
...
... .....
..
.... ...
.....
....... .
.... .....
c ......... .. c
.........................................
c

6 EventDet 25 2017
BioMedSigProcAna

Example: Zeros for z m + 1 = z 12 + 1

• zeros start at z = ejπ/m for a numerator of type z m + 1

.........
.....................................
.......
cj c
...
......... ......
..
... .....
.
.. c .... c
.
. ... ...
...
.
.. ...
.. ...
.
.. ...
..
...
c ...
..
c
..
... ...
.... .
..
... ....
.
...
c ... ... c1
... ...
.
... .
..
...
... .....
... ..
.... ...
.....
.....
c ...
c
....... ..
......... ......
......................................... c c

Note that when the power m is an odd number, the numer-


ator z m + 1 always places a zero at ±180◦—at ±π—and the
complete zero pattern appears “left-right flipped” from the zero
pattern of the corresponding numerator z m − 1. Take the exam-
ple 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 j
................................... ...................................
......... ....... ......... .......
....... ...... ....... ......
......
c ..... ......
c .....
..... .... ..... ....
.... ... .... ...
... ... ... ...
.. ... .. ...
...
. ... ...
. ...
. ... . ...
....
. ... ....
. ...
... ..
.. ... ..
..
... .. ... ..
... c ...
c
.. . .. .
... ... ... ...
... ... ... ...
...
... ..
..
... 1 ...
... .
..
...
.
1
... . ... .
... ....
. ... ....
.
... . ... .
.... ... .... ...
..... .... ..... ....
...... ..... ...... .....
....... ...... ....... ......
c .......... ....... .......... .......
c
................................... ...................................

numerator = z 3 − 1 numerator = z 3 + 1

6 EventDet 26 2017
BioMedSigProcAna

General: Transfer Functions

• two types of general transfer functions


p
(1 − z −m )
H1 (z) = q
(1 − 2 cos ϕz −1 + z −2 )
p
(1 + z −m )
H2 (z) = 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 cas-
cading of identical filters

As an example for cascading, we start with p = q = 1 and


obtain from the above H1 (z)

1 − z −m
H11 (z) = .
1 − 2 cos ϕz −1 + z −2

Taking next p = q = 2, we obtain


2
(1 − z −m )
H12 (z) = 2 = H11 (z) · H11 (z) ,
(1 − 2 cos ϕz −1 + z −2 )

which is just the cascade of two identical filters with transfer


function H11 (z).

6 EventDet 27 2017
BioMedSigProcAna

2.4 The Pan-Tompkins Algorithm

Block Diagram of Pan-Tompkins Algorithm

bandpass derivative squaring mov-win


filter operator operator integrator

• algorithm for Qrs detection in real-time


• referring to general structure on page 6
– linear filtering:
bandpass filter & derivative operator
– nonlinear transformation:
squaring operator & moving-window (mov-win) inte-
grator
– decision rule: not shown
• algorithm is intended for Ecg signals that are sampled at
200 samples/sec

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

We present the algorithm as it is described in [Tom93, Sec-


tion 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 implemen-
tation 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 sig-
nals that have been obtained by sampling the true, continuous-
time Ecg signal at a rate of 200 samples/sec. This is true be-
cause 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 30–49;
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 2017
BioMedSigProcAna

Bandpass Filter

• isolates the predominant Qrs energy, which is centered in


the 5–15 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

.... . ω̂
−π 0 π
.....................................................................Hp.....................................................................
...... ω̂
−π 0 π

........... Bp ...........
..... ........ .... ω̂
−π 0 π

6 EventDet 30 2017
BioMedSigProcAna

Bandpass Filter: The Lowpass Part

• consider the transfer function

1 − z −6
HLp1 (z) = = 1 + z −1 + z −2 + · · · + z −5
1 − z −1

• the Dc gain is (ω̂ = 0 =⇒ z = ej·0 = 1)



HLp1 (z = 1) = 1 + z −1 + z −2 + · · · + z −5 z=1 = 6

• the pole-zero map and the magnitude response are


j H(ej ω̂ )
................................
........... .......
6.0...........
....... ......
......
c c .....
.....
.. ...
..
. ....
.
.... ....
...

... .....
...
. ...
..
. ...
.... ...
...
...
.... ..
..
.. ...
..
c
... × ×c ..
..
... ... ...
...
...
5-fold
1
...
. ...
...
...
...
..
.
.
...
... ..
...
....... .. ... ............ ........
...
. .. . ..... .......... .....
..... ......... .....
... ...
... ...
....
.....
......
....... ......
....
.....
. . ω̂
c .......... .......
c
...................................
−π 0 π

We call HLp1 (z) a running sum filter to distinguish it from


a moving average filter, because it does not take the average; in
the case of HLp1 (z) it does not divide by 6.

6 EventDet 31 2017
BioMedSigProcAna

Bandpass Filter: The Lowpass Part (cont’d)

• the complete Lp filter is the scaled cascade of two HLp1 (z)


2
• the cascade HLp1 (z) · HLp1 (z) = HLp1 (z) has Dc-gain
6 · 6 = 36
• for unity Dc-gain it needs a scaling factor 1/36
• the used scaling factor is 1/32:
– approximates 1/36 to avoid saturation
– can be implemented by a right shift of 5 bit-positions
• the transfer function of the used lowpass filter then is

 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

Bandpass Filter: The Lowpass Part (cont’d)

• the magnitude response is



H(ej ω̂ )
............
1.0...
.. ...
...
... ...
.. ...
.. ...
.. ...
... ....
..
...
...
............. .....................
...
...
...
...
...
...........
. ....................................................................
ω̂
−π 0 π

• the difference equation for a recursive implementation is

1  
y[n] = 2y[n−1] − y[n−2] + x[n] − 2x[n−6] + x[n−12]
32

6 EventDet 33 2017
BioMedSigProcAna

Bandpass Filter: The Highpass Part

• implemented by a delay-complementary transfer function

highpass = delay allpass − lowpass

x[n] delay y[n]


+
allpass −

32-point y1 [n]
moving average

• delay of M -point moving averager is (M − 1)/2


• for M = 32: half-sample delay 31/2 ; 16 is used

You might want to read more about complementary transfer


functions; [Mit98, pp. 245–249] discusses not only delay-com-
plementary transfer functions, but also more general allpass-
complementary filters, power-complementary filters and magni-
tude-complementary filters. Alternatively, you might use the
newer edition of that book; [Mit06, pp. 391–396] additionally
discusses doubly-complementary transfer functions, which are at
the same time allpass-complementary and power-complementary.
Concerning the delay of a moving-average Fir filter we have
the following: First consider a pure delay system

y[n] = x[n − n0 ] ,

6 EventDet 34 2017
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
frequency response becomes H(ω̂) = e−j ω̂n0 .
Next consider an M -point moving-average filter. Its transfer
function is

1   1 1 − z −M
H(z) = 1 + z −1 + . . . + z −(M−1) = .
M M 1 − z −1

Its frequency response can be expressed as

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

where we have used Euler’s formula, and where the indicated


Dirichlet function is purely real. We see then that H(ω̂) is the
product of two functions, the Dirichlet function and e−j ω̂(M−1)/2 ,
with the latter indicating a shift of (M − 1)/2 samples. Clearly,
if the filter length M is an odd integer, (M − 1)/2 becomes an
integer, and the meaning of delaying by an integer number of
samples is clear. In M is, however, an even integer, (M − 1)/2
is not an integer, and the delay needs a special interpretation;
[MSY98, pp. 192–194] gives such an interpretation by applying
a discrete-time moving average filter to process continuous-time
signals.

6 EventDet 35 2017
BioMedSigProcAna

Bandpass Filter: The Highpass Part (cont’d)

• the 32-point moving average filter has transfer function

1  1 1 − z −32
HMA (z) = 1 + z −1 + . . . + z −31 = .
32 32 1 − z −1

• the pole-zero map and the magnitude response are


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 π

We note that the phase response of the moving-average trans-


fer function HMA (z) is linear—it is just a symmetric Fir filter,
and its recursive realization does, of course, neither change the
magnitude- nor the phase response.

6 EventDet 36 2017
BioMedSigProcAna

Bandpass Filter: The Highpass Part (cont’d)

• the highpass transfer function becomes

HHp (z) = z −16 − HMA (z)


1 1 − z −32
= z −16 − .
32 1 − z −1

• the pole-zero map and the magnitude response are

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 π

Note that the phase response of the considered highpass filter


is not exactly linear but merely “almost linear.” This is because
the involved moving-average filter is a 32-point moving average
filter—the length is selected as a power-of-two such that needed
multiplication by 1/32 can be realized by just bit shifting—and
32 being an even integer gives a half-point delay of (32 − 1)/2 =
15.5 The delay allpass must, however, of course have an integer
delay, which has been selected to be 16.

6 EventDet 37 2017
BioMedSigProcAna

If we would use instead of the 32-point a 33-point moving-


average filter, we would obtain a highpass filter with exactly
linear phase response, but we would loose the possibility to re-
alize 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 can-


not 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 2017
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 2017
BioMedSigProcAna

Bandpass Filter: The Highpass Part (cont’d)

• denote by (see the diagram on page 34)

x[n] : the input signal to the highpass filter


y[n] : the output signal of the highpass filter
y1 [n] : the output signal of the moving-average filter part

• then: the difference equation for the moving-average filter


is
1 
y1 [n] = y1 [n − 1] + x[n] − x[n − 32]
32

• then: the difference equation for the highpass filter is

y[n] = x[n − 16] − y1 [n]

The difference equations given above are nearly the difference


equations given in [Tom93, p. 250] and [Ran02, pp. 187–188]
with a slight difference: These two references compute according
to (note that the following two equations stem unaltered from
the articles)

ye1 [n] = ye1 [n − 1] + x[n] − x[n − 32]) , (5)


1  
y[n] = x[n − 16] − ye1 [n − 1] + x[n] − x[n − 32] , (6)
32
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 2017
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 (7)
− x[n] + x[n − 16] − x[n − 17] + x[n − 32] .
32 32

We obtain that difference equation by reformulating the transfer


function from page 37 as

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

Finally, the original paper [PT85] uses a completely differ-


ent highpass filter. We suspect, however, that the formula given
there might be in error; indeed, [HT86] state in their introduc-
tory section that they use “the processor developed by Pan and
Tompkins” with slight modifications.

6 EventDet 41 2017
BioMedSigProcAna

Bandpass Filter: The Complete Filter

the magnitude response is


• linear

H(ej ω̂ )
... ...
........................ .......
.
. . .
.... . . .
.... . . . .
... . . . . .
.
...
...
..... .
.. .... .. .....
.
1.0 . .. . ..
. .. ........ .....
..... ..... ................. ..................
................................................. ... .... .. ω̂
−π 0 π

• in [dB]

H(ej ω̂ )
................... .......
dB
...... ................ .......
. ....... ..... ... .....
.
...
.. .
........... ... 0dB .... ... .... .... .......
. . ... .. ... ... ....
.... ...... ... .... ...−60dB........ ... . ... . ..
.. ... .. ..... ........ .... ..... ... .. ...
.. ..... .... ................ .
... ..... ...
.. .....
ω̂
−π 0 π

If we analyze the complete bandpass filter in detail, we find


that the filter has a middle frequency7 of ω̂mid = 0.2520 rad, a
left −3 dB frequency of ω̂left = 0.1539 rad, and a right −3 dB
7 With a slight abuse of the notion, we call that frequency where the

magnitude is maximum the “middle” frequency.

6 EventDet 42 2017
BioMedSigProcAna

frequency of ω̂right = 0.3707 rad. If the signal to be processed


stems from a continuous-time Ecg signal which has been sam-
pled 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 30—the dominant Qrs energy is contained in the 5–15 Hz
frequency range—, the realized filter characteristics are reason-
able. Note, however, that if the input signal to the Qrs de-
tector 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.

8 Recall that the discrete- and continuous-time frequencies are related

by ω̂ =ˆ ω · Ts = 2πf /fs , where ω is the continuous-time frequency in


rad/sec, Ts =ˆ 1/fs is the sampling time-interval in sec with fs being the
corresponding sampling frequency in Hz, and f is the natural (continuous-
time) frequency in Hz.

6 EventDet 43 2017
BioMedSigProcAna

The Derivative Operator

• a five-point derivative operator


 
Hdif (z) = 0.1 2 + z −1 − z −3 − 2z −4 .

• the true gain 0.1 is approximated by 1/8


• let x[n] =
ˆ input, y[n] =
ˆ output
• the difference equation then becomes

1 
y[n] = 2x[n] + x[n − 1] − x[n − 3] − 2x[n − 4] .
8

Note that the defined derivative operator is an Fir filter with


an impulse response of length 5; this is the reason that we call it
a “five-point derivative operator” although it uses only 4 terms
for the computations—imagine that the fifth term x[n − 2] is
multiplied with a coefficient being zero.

6 EventDet 44 2017
BioMedSigProcAna

The Derivative Operator (cont’d)

the magnitude response is


• linear

H(ej ω̂ )
.... ....
.... ......0.7 ..... .......
.. . .... .. ...
...
.
. ... ..
....... ... . ... ..............
...... ....... ... ... . . ... .. ...
.. ... .. . .
.... ... .. ...
. .. .. . ω̂
−π 0 π

• in [dB] versus log-frequency


0 ...........
...
...
...
.............
jω̂ .......
...........
−20
H(e ) ..
.
.
...
..
.......
[dB] −40
.
...
...
.............
...
−60 ...........
10−3 10−2 10−1 100
log10 (ω̂)

We note from the magnitude plots of the bandpass filter on


page 42 that essentially only signal component-frequencies ω̂
below 1 rad/sample arrive at the derivative operator. For these
frequencies the proposed operator well acts as a differentiator,
as the second of the above plots—magnitude in [dB] versus log-
frequency—clearly reveals: We have in this double logarithmic
plot a slope of +20 dB/decade in the relevant frequency interval.

6 EventDet 45 2017
BioMedSigProcAna

The Squaring Operator

• non-linear operation (as opposed to all other processing


steps)
• but static operation (no memory)
• let x[n] =
ˆ input, y[n] =
ˆ output
 2
then: squaring operation is y[n] = x[n] .

• makes output-signal samples positive


• amplifies output of derivative operator non-linearly
– emphasizes higher frequencies in Ecg signal
– higher frequencies are mainly due to Qrs complex
– smaller differences arising from P- and T-waves are
suppressed

We note that in microprocessor implementations of the Pan-


Tompkins 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 2017
BioMedSigProcAna

The Moving-Window Integrator

• slope of the R-wave in a Qrs complex is not a guaranteed


measure to detect a Qrs event
• many abnormal Qrs complexes that have
– large amplitude
– large duration
– but not very steep slopes
are not detected using only information about slope of R-
wave
• ; need to extract more information from an Ecg signal
to detect a Qrs complex
• moving-window integration extracts additional features

6 EventDet 47 2017
BioMedSigProcAna

The Moving-Window Integrator (cont’d)

• 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

• is an N -point moving average filter


• parameter N =
ˆ window-length must be chosen carefully
– window-length N approximately the same as widest
possible Qrs complex
– usually N is chosen experimentally
– for Ecg signals sampled at a rate of 200 samples/sec,
a value of N ≈ 30 is reasonable

The given difference equation of the moving-average filter


can, of course, also be written in recursive form: The transfer
function is

Y (z) 1  1 1 − z −N
= 1 + z −1 + · · · + z −(N −1) = ,
X(z) N N 1 − z −1

and the difference equation in recursive form then reads

1 
y[n] = y[n − 1] + x[n] − x[n − N ] .
N

6 EventDet 48 2017
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 sim-
plify 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 normalization—the division by
the number N of samples—it 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 argumen-
tation is as follows: If the window size of the moving-average
filter is too large—we have a too wide window—, then the inte-
gration waveform y[n] tends to merge Qrs complexes and sub-
sequent 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 sam-
pled at a rate of 200 samples/sec, a choice of N = 30 has 29
intervals between first and last sample in the window and corre-
sponds to an real-world time interval length of 145 msec. Corre-
spondingly, 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 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

The original original literature is [PT85] and [HT86]; we


supply these papers as pdf-copies along with the laboratory
exercises. Alternatively, you might want to use the textbooks
[Tom93] or [Ran02].

6 EventDet 50 2017
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 of-
ten performed with Cic filters

The acronym Cic stands for cascaded integrator-comb filters,


being a special form of multirate decimation and interpolation
filters. We have the original paper [Hog81], but you might also
want to consult [Don00], [MB07, Section 5.3], [Xil08], or the
corresponding items in the Matlab manuals.9
We note that although the Cic decimation-structures have
as first stages integrators—see our simple example on page 52
which has just one integrator—there is no problem with over-
flows, if the used data type is two’s complement with natural
overflow computations, because then the computations are mod-
ulo 2b , and final overall results staying in the representable range
are correctly computed even if intermediate results have over-
flowed; see our discussion in [Goe17b].

9 In the Matlab help window just search for Cic.

6 EventDet 51 2017
BioMedSigProcAna

Sampling-Rate Conversion: Cic-Filter Example

• to do: realize down-sampling by a factor 5


• needed: lowpass filter for limiting to ω̂p = π/5
• as example use: 10-point moving-sum filter
  1 − z −10
H(z) = 1 + z −1 + · · · + z −9 =
1 − z −1

• with subsequent down-sampling

1 − z −10
↓5
1 − z −1

1
1 − z −10 ↓5
1 − z −1

• with Cic-filter structure

1
↓5 1 − z −2
1 − z −1

We here call a moving-average filter that comes “without


averaging” a moving-sum filter. The moving-average filter cor-
responding to the moving-sum filter introduced above is

1  1 1 − z −10
H(z) = 1 + z −1 + · · · + z −9 = ,
10 10 1 − z −1

6 EventDet 52 2017
BioMedSigProcAna

that is, the moving-average filter has, as compared to the moving-


sum filter, an additional scaling factor 1/10—the computation
of the average.
Reconsider the Cic-filter decimator structure in the graph-
ics on page 52. We see that the first processing block is an
accumulator—we may likewise term it an integrator if we prefer
continuous-time (Ct) system parlance. Obviously, that accu-
mulator contributes a not strictly-stable pole at z = 1 to the
system, and the result might be register overflow in the inte-
grator 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 two’s 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 sam-
ples 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 re-
versed: 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 interpola-
tor, the input signal to the overall filter is preconditioned by
the comb section—the comb section suppresses a potential Dc
term—so that overflow will not occur in the integrator stages.

10 If the input signal to the integrator contains a non-zero Dc component,

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

The summary of economical advantages of Cic-filters is,


1. Cic-filters need no multipliers;
2. consequently, Cic-filters need no storage for filter coeffi-
cients;
3. Cic-filters reduce internal signal-sample storage, as com-
pared to equivalent implementations with uniform Fir fil-
ters, 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 2017
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 Cic-
filter referenced to the high sampling rate would become

N RM−1
!N
1 − z −RM X
−k
H(z) = N
= z .
(1 − z −1 ) k=0

From the above transfer-function formula we now understand


that the frequency response of the Cic-filter depends only on the
three integer parameters {R, M, N }, that is, on the sampling-
rate change factor R, the differential delay M , and the number
of cascaded stages N .

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.

[AT85] M. L. Ahlstrom and W. J. Tompkins. Digital filters


for real-time Ecg signal processing using micropro-
cessors. IEEE Trans. Biomed. Eng., 32(9):708–713,
September 1985.
[BDD+ 77] R. A. Balda, G. Diller, E. Deardorff, J. Doue, and
P. Hsieh. The Hp Ecg analysis program. In J. H.
van Bemmel and J. L. Willems, editors, Trends in
Computer-Processed Electrocardiograms, pages 197–
205. North Holland, Amsterdam, 1977.
[Don00] 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] G. M. Friesen, T. C. Jannett, M. A. Jadallah, S. L.
Yates, S. R. Quint, and H. T. Nagel. A compari-
son of the noise sensitivity of nine Qrs detection al-
gorithms. IEEE Trans. Biomed. Eng., 37(1):85–97,
January 1990.
[Goe17a] Josef Goette. Biomedical Signal Processing and
Analysis—Filtering for Removing Artifacts. Bern
University of Applied Sciences, Script at the Bfh-
ti Biel/Bienne, HuCE-microLab, February 2017.

6 EventDet 56 2017
BioMedSigProcAna

[Goe17b] Josef Goette. Biomedical Signal Processing and


Analysis—On Fixed-Point Filter Realizations. Bern
University of Applied Sciences, Script at the Bfh-ti
Biel/Bienne, HuCE-microLab, February 2017.
[Goe17c] Josef Goette. Biomedical Signal Processing and
Analysis—Review of Various Biomedical Signals.
Bern University of Applied Sciences, Script at the
Bfh-ti Biel/Bienne, HuCE-microLab, February
2017.
[Hog81] Eugene B. Hogenauer. An economical class of digital
filters for decimation and interpolation. IEEE Trans.
Acoust., Speech, Signal Processing, 29(2):155–162,
April 1981.
[HT86] P. S. Hamilton and W. J. Tompkins. Quanti-
tative investigation of Qrs detection rules using
the Mit/Bih arrhythmia database. IEEE Trans.
Biomed. Eng., 33(12):1157–1165, December 1986.
[Los08] Ricardo A. Losada. Digital filters with Matlab.
Technical report, The MathWorks, Inc., May 2008.
[MB07] Uwe Meyer-Baese. Digital Signal Processing with
Field Programmable Gate Arrays. Springer Verlag,
Berlin Heidelberg New York, 3rd edition, 2007.
[Mit98] Sanjit K. Mitra. Digital Signal Processing: A Com-
puter Based Approach. Mc Graw Hill, New York,
1998. Bfh-ti Biel/Bienne Library 621.391 MITRA.
[Mit06] Sanjit K. Mitra. Digital Signal Processing: A Com-
puter Based Approach. Mc Graw Hill, New York, 3rd
edition, 2006. Bfh-ti Biel/Bienne Library 621.391
MITRA.

6 EventDet 57 2017
BioMedSigProcAna

[MSY98] James H. McClellan, Ronald W. Schafer, and


Mark A. Yoder. Dsp First: A Multimedia Approach.
Prentice-Hall Inc., 1998.
[Orf96] Sophocles J. Orfanidis. Introduction to Signal Pro-
cessing. Prentice-Hall Inc., Upper Saddle River, New
Jersey, 1996. Bfh-ti Biel/Bienne Library 621.391
ORFAN.
[PT85] J. Pan and W. J. Tompkins. A real-time Qrs
detection algorithm. IEEE Trans. Biomed. Eng.,
32(3):230–236, March 1985.
[Ran02] Rangaraj M. Rangayyan. Biomedical Signal Analy-
sis: A Case-Study Approach. IEEE Press, New York,
2002. Bfh-ti Biel/Bienne Library 57.08 RANGA.
[SL05] Leif Sörnmo 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 Pro-
cessing. Prentice-Hall Inc., Englewood Cliffs, N.J.,
1993. Eth Bib: +521 458.
[Xil08] Xilinx. Cic Compiler v1.1. On the Web, March
2008. http://www.xilinx.com.

6 EventDet 58 2017

You might also like