11.07.2015 Views

Event Detection: Qrs-Complexes in Ecg Signals - microLab

Event Detection: Qrs-Complexes in Ecg Signals - microLab

Event Detection: Qrs-Complexes in Ecg Signals - microLab

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BioMedSigProcAnaExamples of <strong>Event</strong>s: Waves <strong>in</strong> <strong>Ecg</strong>’s2Rnoisy ECG signal (random noise)1TECG0PP−1−2QS0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2time <strong>in</strong> secondsP wave: Duration less than 120 msec with frequencies below10–15 Hz.Pq segment: Lasts about 80 msec; is a “non-event”<strong>Qrs</strong> wave: Lasts about 70–110 msec, frequencies mostly concentrated<strong>in</strong> the <strong>in</strong>terval 10–50 HzT wave: Has frequency content similar to that of the P wave.St segment: Duration is usually about 100–120 msec and isnormally flat; is a “non-event”For the various waves <strong>in</strong> the <strong>Ecg</strong> signal we have a summaryof the ma<strong>in</strong> attributes <strong>in</strong> [Goe14c, Section 2]. You f<strong>in</strong>d a more <strong>in</strong>depthtreatment <strong>in</strong> [SL05, Section 6.2.3] and <strong>in</strong> [Ran02], whereyou f<strong>in</strong>d, besides more general <strong>in</strong>formation, <strong>in</strong> Section 4.2.1 adiscussion targeted to event detection.6 <strong>Event</strong>Det 2 2014


BioMedSigProcAna2 <strong>Qrs</strong> <strong>Detection</strong>2.1 General Structure of <strong>Qrs</strong> DetectorGeneral Requirements on a <strong>Qrs</strong> Detector• must be able to detect a large number of different <strong>Qrs</strong>morphologies to be cl<strong>in</strong>ical useful• must be able to follow– sudden changes– gradual changes<strong>in</strong> prevail<strong>in</strong>g <strong>Qrs</strong> morphology• must not lock onto certa<strong>in</strong> types of rhythm, but treat nextpossible event as if anyth<strong>in</strong>g could happen next6 <strong>Event</strong>Det 3 2014


BioMedSigProcAnaDetector-Critical Types of Noise and Artifacts• noise might be <strong>in</strong> nature– highly transient– or persistent (e.g. power-l<strong>in</strong>e <strong>in</strong>terference)• problem of condition<strong>in</strong>g <strong>Ecg</strong> signals w.r.t. noise has beentreated• however, term “noise” has a somewhat different mean<strong>in</strong>gwhen considered form the <strong>Qrs</strong>-detection viewpo<strong>in</strong>t– P- and T-wave must here be treated as noise– noise might have physiological as well as technicalorig<strong>in</strong>sWe refer to our accompany<strong>in</strong>g document [Goe14a] for theproblem of condition<strong>in</strong>g <strong>Ecg</strong> signals with respect to noise.6 <strong>Event</strong>Det 4 2014


BioMedSigProcAna5 Hz to 10 Hz. Note that waveform distortion is, <strong>in</strong> contrast toother types of <strong>Ecg</strong>-signal filter<strong>in</strong>g, not a critical issue <strong>in</strong> <strong>Qrs</strong>detection; <strong>in</strong>stead, the goal is to improve signal-to-noise ratio toachieve good detector performance.The goal of the nonl<strong>in</strong>ear transformation is to further enhancethe <strong>Qrs</strong> complex relative to the rema<strong>in</strong><strong>in</strong>g backgroundnoise. Additionally, it must transform each <strong>Qrs</strong> complex <strong>in</strong>to as<strong>in</strong>gle positive peak that is better suited to threshold detection.In general, the nonl<strong>in</strong>ear transformation might be memory-less(static)—rectification or squar<strong>in</strong>g are examples—or a more complextransformation <strong>in</strong>volv<strong>in</strong>g memory. Note, however, that notall <strong>Qrs</strong> detectors use a nonl<strong>in</strong>ear transformation <strong>in</strong> their preprocess<strong>in</strong>gstage.The goal of the block named decision rule is to perform,based on the output of the pre-processor, a test on whether ata certa<strong>in</strong> time a <strong>Qrs</strong> complex is present or not. The decisionrule might be implemented as simple as an amplitude thresholdprocedure, but it may perform additional tests, for exampleon reasonable durations of certa<strong>in</strong> waveforms, to obta<strong>in</strong> betterimmunity aga<strong>in</strong>st various types of noise.<strong>Qrs</strong> detectors are usually designed to detect heartbeats.They rarely need to produce occurrence times of the <strong>Qrs</strong> complexeswith high resolution <strong>in</strong> time. If time resolution is neverthelessimportant, it may be necessary to improve the <strong>in</strong>itialresolution with algorithms that perform time alignment of thedetected beats and thus reduce the problem of smear<strong>in</strong>g whichmight occur when comput<strong>in</strong>g the ensemble average of severalbeats (recall the synchronized averag<strong>in</strong>g, which we have discussed<strong>in</strong> [Goe14a]).6 <strong>Event</strong>Det 7 2014


BioMedSigProcAna<strong>Qrs</strong> <strong>Detection</strong> as an Estimation Problem• theoretical justification of <strong>Qrs</strong>-detector structure on page 6– <strong>in</strong>vestigate statistical models of <strong>Ecg</strong> signals– use maximum-likelihood estimation techniques to derivedetector structures correspond<strong>in</strong>g to the signalmodel of <strong>in</strong>terest• 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 ,whereN ˆ= length of observation <strong>in</strong>tervalv[n] ˆ= noises[n] ˆ= <strong>Qrs</strong>-complex, known morphology, durationθ ˆ= unknown occurrence time of <strong>Qrs</strong>-complexa ˆ= unknown amplitude of <strong>Qrs</strong>-complexSörnmo and Laguna [SL05] discuss <strong>in</strong> Section 7.4 <strong>Qrs</strong> detection<strong>in</strong> a more theoretically oriented manner. With the proposedsignal model shown above, it is then feasible to estimate the unknownoccurrence time θ and the unknown amplitude a of the<strong>Qrs</strong>-complex. The notion “<strong>Qrs</strong> detection” suggests, however,that we are faced with a detection problem <strong>in</strong>stead of an estimationproblem. It is <strong>in</strong>deed true that the problem considered<strong>in</strong> [SL05] can likewise be formulated as a detection problem;6 <strong>Event</strong>Det 8 2014


BioMedSigProcAna2.2 Simplest: Derivative-Based IdeasUs<strong>in</strong>g First- and Second Derivatives• differentiation forms basis of many <strong>Qrs</strong> detection algorithms• differentiation ˆ= basically a highpass filter– amplifies higher frequencies that are characteristic forthe <strong>Qrs</strong> complex– attenuates lower frequencies that are characteristicfor P- and T-waves– attenuates low frequencies of basel<strong>in</strong>e wander• however: differentiation also amplifies higher frequenciesdue to noise ❀ additional significant smooth<strong>in</strong>g is required• an algorithm based on first and second derivatives, withsmooth<strong>in</strong>g <strong>in</strong>cluded– by Balda et. al. <strong>in</strong> 1977– modified by Ahlstom and Tompk<strong>in</strong>s for high-speedapplications <strong>in</strong> 1983– additionally modified by Friesen et. al. 1990The references cited <strong>in</strong> the above slide are [BDD + 77], [AT83],and [FJJ + 90].6 <strong>Event</strong>Det 10 2014


BioMedSigProcAnaThe Algorithm: Pre-Process<strong>in</strong>g• let x[n] ˆ= <strong>in</strong>put to and y[n] ˆ= output from pre-process<strong>in</strong>gstage of algorithm• use for pre-process<strong>in</strong>g a l<strong>in</strong>ear comb<strong>in</strong>ation of first- andsecond derivative• first derivative: approximated as absolute value of threepo<strong>in</strong>tfirst difference∣y 0 [n] = ∣x[n] − x[n − 2] ∣ .• second derivative: approximated as absolute value of threepo<strong>in</strong>tfirst difference of three-po<strong>in</strong>t first differences∣y 1 [n] = ∣x[n] − 2x[n − 2] + x[n − 4] ∣ .• output y[n] of pre-process<strong>in</strong>g stage as l<strong>in</strong>ear comb<strong>in</strong>ationy[n] = 1.3 · y 0 [n] + 1.1 · y 1 [n]To understand the rationals beh<strong>in</strong>d the given approximationof 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 <strong>Event</strong>Det 11 2014


BioMedSigProcAnaThis filter has a zero at z = 1—at Dc frequency—and has amagnitude response of 2 s<strong>in</strong>(ˆω/2). For sufficiently low frequenciesˆω, it approximates the derivative operation as we see from2 s<strong>in</strong>(ˆω/2) ≈ 2ˆω/2 = ˆω. To obta<strong>in</strong> a smooth<strong>in</strong>g such that highfrequencynoise is not too much amplified, we post-process thesequence δ 1 [n] by a two-po<strong>in</strong>t mov<strong>in</strong>g-average filter hav<strong>in</strong>g transferfunction (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 doma<strong>in</strong> we equivalently haveỸ 0 (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—atfrequency ˆω = 0—, which approximates the derivative, and asecond zero at z = −1—at frequency ˆω = ±π—, which suppresseshigh frequency noise. The magnitude response of the filteris 2 s<strong>in</strong>(ˆω); for low frequencies we aga<strong>in</strong> have 2 s<strong>in</strong>(ˆω) ≈ 2ˆω,which approximates a derivative with a ga<strong>in</strong> 2.For the approximation of the second derivative consider thesequence ỹ 0 [n] be<strong>in</strong>g the output of a three-po<strong>in</strong>t first differencefilter: ỹ 0 [n] = x[n] − x[n − 2]. Process<strong>in</strong>g this sequence by1 We denote the output of this process<strong>in</strong>g step by ỹ 0 [n] to dist<strong>in</strong>guish itfrom y 0 [n], which we use <strong>in</strong> the slide on page 11, and which is the absolutevalue of ỹ 0 [n].6 <strong>Event</strong>Det 12 2014


BioMedSigProcAnaanother three-po<strong>in</strong>t first difference filter, we obta<strong>in</strong> 2ỹ 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-process<strong>in</strong>g with a thresholdvalueof 1.0• if y[n 0 ] ≥ 1.0 for a certa<strong>in</strong> n 0 , then compare next 8 samplesto threshold• if 6 or more of these 8 samples pass threshold test, thentake the 8-samples segment as part of a <strong>Qrs</strong> complex• advantage: additionally to detect<strong>in</strong>g <strong>Qrs</strong> complexes, thealgorithm produces a pulse that is proportional <strong>in</strong> widthto the <strong>Qrs</strong> complex• disadvantage: the method is extremely sensitive to highfrequencynoise2 Aga<strong>in</strong>, we denote the output of this process<strong>in</strong>g step by ỹ 1 [n] to dist<strong>in</strong>guishit from y 1 [n], which we use <strong>in</strong> the slide on page 11, and which is theabsolute value of ỹ 1 [n].6 <strong>Event</strong>Det 13 2014


BioMedSigProcAna2.3 Aside: “Integer” FiltersMotivation• <strong>in</strong> real-time operations of digital filters– many filter designs are unsatisfactory– because huge computation-time requirements– surely if implemented <strong>in</strong> float<strong>in</strong>g-po<strong>in</strong>t operations– but often also if implemented <strong>in</strong> fixed-po<strong>in</strong>t operations• <strong>in</strong>teger filters are a special class of filters hav<strong>in</strong>g only <strong>in</strong>tegercoefficients• here more special: coefficients ∈ {0, ±1, ±2}• here even more special: a preparation to the Pan-Tompk<strong>in</strong>salgorithmWe admit that we are not sure about the generality of thenotion “<strong>in</strong>teger filters.” We feel that the notion “<strong>in</strong>teger filters”used <strong>in</strong> the signal process<strong>in</strong>g community is more general thanthe same notion often used <strong>in</strong> the literature on biomedical signalprocess<strong>in</strong>g. Our present discussion treats filters <strong>in</strong> the morerestricted mean<strong>in</strong>g as given, for example, <strong>in</strong> [Tom93]—see thereChapter 7 entitled “Integer Filters,” but also see its Chapter 12on <strong>Qrs</strong> detection.For <strong>Qrs</strong> detection, for example, it is crucial that the <strong>Qrs</strong>complex as well as P- and T-waves rema<strong>in</strong> unchanged. This6 <strong>Event</strong>Det 14 2014


BioMedSigProcAnademand on preservation of signal forms calls for l<strong>in</strong>ear-phasefilters, which must be Fir filters. “Integer” filters as we discussthem here are Fir filters with recursive implementations.The slide on the previous page 14 states that our “<strong>in</strong>teger”filters have only coefficients be<strong>in</strong>g 0, ±1, and ±2. This is notthe full truth: The basic blocks that we consider have suchcoefficients, but cascad<strong>in</strong>g these basic blocks leads to additionalcoefficient values, see page 27.Simple Example• transfer function• zerosH(z) =N(z z ) = z 6 z − 1 ≡ 01 − z −61 − z −1 + z −2 = z 6 − 1z 4 (z 2 − z + 1)ˆ=N(z)D(z)❀z z = e j·k·2π/6 , k = 0, 1, . . ., 5 ˆ= 6-th roots of unity❝j❝❝.❝1❝❝zeros: 6-th roots of unityNote that the transfer function of the above example def<strong>in</strong>esa filter that has only coefficients ±1.6 <strong>Event</strong>Det 15 2014


BioMedSigProcAnaSimple Example (cont’d)• poles z p1 = ρe jϕ , z p2 = ρe −jϕ = z ∗ p1 , z pk = 0, k = 3, . . .,6• non-trivial polesz 2 p −ρ}{{}≡ 1˜D(z p ) ˆ= z 2 p − z p + 1 ≡ 0(zp − ρe jϕ) ( z p − ρe −jϕ) ≡ 0(e jϕ + e −jϕ) z p + ρ 2 ≡ 0} {{ } }{{}= 2 cosϕ ≡ 1 ≡ 1} {{ }❀ ϕ = 60 ◦j.60 ◦e jϕ×......1×poles z p1,2 = e ±jϕ , ϕ = 60 ◦6 <strong>Event</strong>Det 16 2014


BioMedSigProcAnaSimple Example (cont’d)• pole-zero map of complete filter (poles “eat” zeros)❝j❝× 4-fold.❝1❝complete pole-zero map• transfer function (filter is Fir, l<strong>in</strong>ear phase)H(z) =1 − z −61 − z −1 + z −2 = 1 + z−1 − z −3 − z −4To see how we obta<strong>in</strong> the second form—the non-recursiveform—of the above Fir-filter transfer function, just multiplythe terms that correspond to the rema<strong>in</strong><strong>in</strong>g zeros and poles:(1 − z−1 ) ( 1 + z −1) ( 1 − e j2π/3 z −1)( 1 − e −j2π/3 z −1) .The first pair of terms gives ( 1 − z −2) , the second pair of termsgives—we use the formula of Euler together with the resultcos(120 ◦ ) = −1/2—the polynomial ( 1 + z −1 + z −2) , and wef<strong>in</strong>ally obta<strong>in</strong>(1 − z−2 ) ( 1 + z −1 + z −2) = 1 + z −1 − z −3 − z −4 .6 <strong>Event</strong>Det 17 2014


BioMedSigProcAnaA second, alternative, way to f<strong>in</strong>d the second form of thetransfer function <strong>in</strong> the slide of page 17 is just to carry-out thedivision of the first form: Divid<strong>in</strong>g (1 − z −6 ) by (1 − z −1 + z −2 )gives 1 with rema<strong>in</strong>der (z −1 − z −2 − z −6 ); divid<strong>in</strong>g this rema<strong>in</strong>derby the denom<strong>in</strong>ator (1 − z −1 + z −2 ) gives z −1 anda new rema<strong>in</strong>der (−z −3 − z −6 ); aga<strong>in</strong> divid<strong>in</strong>g this new rema<strong>in</strong>derby the denom<strong>in</strong>ator gives −z −3 and a next rema<strong>in</strong>der(−z −4 + z −5 − z −6 ); f<strong>in</strong>ally, divid<strong>in</strong>g this last rema<strong>in</strong>der by thedenom<strong>in</strong>ator (1 − z −1 + z −2 ) ends up with −z −4 and a zerorema<strong>in</strong>der.The two transfer-function formulae on page 17 suggest thatwe could implement the filter as a usual Fir filter by tak<strong>in</strong>g thesecond formula, but also <strong>in</strong> a recursive form by tak<strong>in</strong>g the firstformula. The question then is which k<strong>in</strong>d of implementation toselect.To discuss the implementation issue, we take a larger filterof the considered class of filters where the problem becomesevident. So consider the N-po<strong>in</strong>t mov<strong>in</strong>g average-filter hav<strong>in</strong>gthe transfer function forms 3H(z) = 1 N= 1 N(1 + z −1 + z −2 + · · · + z −(N−1)) , (1a)1 − z −N. (1b)1 − z−1 Nam<strong>in</strong>g the <strong>in</strong>put sequence to the filter x[n] and the outputsequence from the filter y[n], the form (1a) could be implemented<strong>in</strong> direct form asy[n] = 1 N()x[n] + x[n − 1] + x[n − 2] + · · · + +x[n − (N − 1)] ,3 We obta<strong>in</strong> the second form by apply<strong>in</strong>g the formula for the sum of ageometric series to the first form.(2)6 <strong>Event</strong>Det 18 2014


BioMedSigProcAnawhereas the form (1b) could be implemented <strong>in</strong> direct form asy[n] = y[n − 1] + 1 Nor, <strong>in</strong> what is called the canonical form, as()x[n] − x[n − N] , (3)w[n] = w[n − 1] + x[n]y[n] = 1 ()w[n] − w[n − N] ;N(4)here <strong>in</strong> (4) w[n] is a newly <strong>in</strong>troduced <strong>in</strong>terval variable—an <strong>in</strong>ternalsignal—of the filter.Compar<strong>in</strong>g the feed-forward implementation (2) to the recursiveimplementations either (3) or (4), we see that the numberof operations needed to compute one output sample favorsthe recursive implementations. This lower computational effortis the reason that many books on biomedical signal process<strong>in</strong>gsuggest the recursive implementations.We note, however, that the recursive implementations mightbecome problems with error accumulation and <strong>in</strong>stability—theimplementations (3) and (4) both have a pole at z = 1, whichis not strictly <strong>in</strong>side of the unit circle. To get a feel<strong>in</strong>g of whatmight happen, consider the canonical implementation (4) andassume that the <strong>in</strong>put signal is a white-noise signal. 4 The equationw[n] = w[n − 1] + x[n] is an accumulator, and accumulat<strong>in</strong>ga white-noise sequence gives a non-stationary stochasticprocess with a l<strong>in</strong>early <strong>in</strong>creas<strong>in</strong>g variance, mean<strong>in</strong>g that w[n]must sooner or later become unstable, which is, of course, notacceptable. Similar considerations for the implementation (3)lead to the same conclusions. We do not go <strong>in</strong>to more details,but, <strong>in</strong>stead, refer to [Orf96], where these issues are discussedon pages 402 ff., and which has an Appendix A, pages 728 ff.,discuss<strong>in</strong>g discrete-time random signals and their filter<strong>in</strong>g.4 A discrete-time white noise signal is a sequence where any two samplesare uncorrelated.6 <strong>Event</strong>Det 19 2014


BioMedSigProcAnaHowever, an additional note is <strong>in</strong> order: The transfer functionform (1b) shows perfect pole/zero cancel<strong>in</strong>g and an implementationbased on this form relies on the achievement of thisperfect cancel<strong>in</strong>g by the arithmetic used <strong>in</strong> the implementation.Exact <strong>in</strong>teger arithmetic can achieve it: Both, two’s complementnumber systems and, more general, any of the residuenumber systems 5 have the ability to support error-free arithmetic;<strong>in</strong> the case of the two’s complement number system, thearithmetic must be performed modulo 2 b , that is, with naturaloverflow as we expla<strong>in</strong> <strong>in</strong> [Goe14b], and <strong>in</strong> the case of residuenumber systems, the arithmetic is performed <strong>in</strong> modulo M.5 The two’s complement number system is a member of the family ofresidue number systems, if overflow is correctly treated; see the ma<strong>in</strong> text.6 <strong>Event</strong>Det 20 2014


BioMedSigProcAnaSimple Example (cont’d)• frequency response of filter∣ H(e jˆω ) ∣ 3.0̸. ˆω−π 0 πH(e jˆω )π/2−π−π/2ˆωπ.6 <strong>Event</strong>Det 21 2014


BioMedSigProcAnaGeneral: Poles• complex-conjugate pole-pair on unit circlez p1 = e jϕ ,z p2 = e −jϕ = z ∗ p1• thendenom<strong>in</strong>ator = ( z − e jϕ) ( z − e −jϕ)= z 2 − ( e jϕ + e −jϕ) z + 1= z 2 − 2 cosϕz + 1• has (<strong>in</strong>teger) 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 −2Note that the constra<strong>in</strong>ts on possible pole locations, whichare given <strong>in</strong> the above slide, lead to correspond<strong>in</strong>g constra<strong>in</strong>tson the choice of sampl<strong>in</strong>g rates if we need to process cont<strong>in</strong>uoustime(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 <strong>in</strong> biomedical signal process<strong>in</strong>galways, to our knowledge, the situation where the signals to beprocessed are <strong>in</strong> the first <strong>in</strong>stance analog signals.6 <strong>Event</strong>Det 22 2014


BioMedSigProcAnasee our exemplify<strong>in</strong>g discussion on the the bandpass filter of thePan-Tompk<strong>in</strong>s <strong>Qrs</strong> detection algorithm given on page 42.Also note that we compile, later on page 27 and after a correspond<strong>in</strong>gdiscussion on “general zeros,” the transfer functionsthat can be realized with “<strong>in</strong>teger filters.”General: Poles (cont’d)• possible pole locations for <strong>in</strong>teger polynomial-coefficientsj×× ××2-fold2-fold.×1×××6 <strong>Event</strong>Det 23 2014


BioMedSigProcAnaGeneral: Zeros• first casenumerator = z m − 1 ,m ˆ= positive <strong>in</strong>tegerzeros:❀❀zz m = 1 , z z = e j·k·2π/m , k ∈ {0, m−1}zeros are m-th roots of unityevenly spaced zeros around the unit circlestart<strong>in</strong>g at z = 1• second casenumerator = z m + 1 ,m ˆ= positive <strong>in</strong>tegerzeros:❀❀z m z = −1 , z z = e j(π/m+k·2π/m) , k ∈ {0, m−1}zeros are m-th roots of (−1)evenly spaced zeros around the unit circlestart<strong>in</strong>g at z = e jπ/mThe notation k ∈ {0, m − 1} means that k is <strong>in</strong> the setof <strong>in</strong>tegers with given lower and upper limits, that is, k =0, 1, . . .,m − 1.6 <strong>Event</strong>Det 24 2014


BioMedSigProcAnaExample: Zeros for z m − 1 = z 12 − 1• zeros start at z = 1 for a numerator of type z m − 1❝❝❝❝❝j ❝❝❝❝❝. ❝1❝6 <strong>Event</strong>Det 25 2014


BioMedSigProcAnaExample: Zeros for z m + 1 = z 12 + 1• zeros start at z = e jπ/m for a numerator of type z m + 1j❝ ❝❝ ❝❝❝❝.❝ 1❝❝❝❝Note that when the power m is an odd number, the numeratorz m + 1 always places a zero at ±180 ◦ —at ±π—and thecomplete zero pattern appears “left-right flipped” from the zeropattern of the correspond<strong>in</strong>g numerator z m −1. Take the examplem = 3: In the left-hand side of the graphic below we showthe zeros of z 3 − 1, and <strong>in</strong> its right-hand side we show the zerosof z 3 + 1.❝jj❝. ❝1❝.1❝numerator = z 3 − 1❝numerator = z 3 + 16 <strong>Event</strong>Det 26 2014


BioMedSigProcAnaGeneral: Transfer Functions• two types of general transfer functionsH 1 (z) =H 2 (z) =• where m, p, q ˆ= <strong>in</strong>tegers(1 − z −m ) p(1 − 2 cosϕz −1 + z −2 ) q(1 + z −m ) p(1 − 2 cosϕz −1 + z −2 ) q• and where ϕ ∈ {0 ◦ , ±60 ◦ , ±90 ◦ , ±120 ◦ , 180 ◦ }• note:rais<strong>in</strong>g p & q by equal <strong>in</strong>teger-amounts corresponds to cascad<strong>in</strong>gof identical filtersAs an example for cascad<strong>in</strong>g, we start with p = q = 1 andobta<strong>in</strong> from the above H 1 (z)H 11 (z) =Tak<strong>in</strong>g next p = q = 2, we obta<strong>in</strong>H 12 (z) =1 − z −m1 − 2 cosϕz −1 + z −2 .(1 − z −m ) 2(1 − 2 cosϕz −1 + z −2 ) 2 = H 11(z) · H 11 (z) ,which is just the cascade of two identical filters with transferfunction H 11 (z).6 <strong>Event</strong>Det 27 2014


BioMedSigProcAna2.4 The Pan-Tompk<strong>in</strong>s AlgorithmBlock Diagram of Pan-Tompk<strong>in</strong>s Algorithmbandpassfilterderivativeoperatorsquar<strong>in</strong>goperatormov-w<strong>in</strong><strong>in</strong>tegrator• algorithm for <strong>Qrs</strong> detection <strong>in</strong> real-time• referr<strong>in</strong>g to general structure on page 6– l<strong>in</strong>ear filter<strong>in</strong>g:bandpass filter & derivative operator– nonl<strong>in</strong>ear transformation:squar<strong>in</strong>g operator & mov<strong>in</strong>g-w<strong>in</strong>dow (mov-w<strong>in</strong>) <strong>in</strong>tegrator– decision rule: not shown• algorithm is <strong>in</strong>tended for <strong>Ecg</strong> signals that are sampled at200 samples/secThe algorithm for <strong>Qrs</strong> detection <strong>in</strong> real time has been developedby Pan and Tompk<strong>in</strong>s [PT85]; it has further been analyzedand described by Hamilton and Tompk<strong>in</strong>s [HT86]. The algorithmrecognizes <strong>Qrs</strong> complexes by analyz<strong>in</strong>g slope and amplitudeof <strong>Ecg</strong> signals tak<strong>in</strong>g <strong>in</strong>to account the width of appear<strong>in</strong>g<strong>Ecg</strong> waves.6 <strong>Event</strong>Det 28 2014


BioMedSigProcAnaWe present the algorithm as it is described <strong>in</strong> [Tom93, Section12.5]; you might also want to consult [Ran02, Section 4.3.2]and/or study the orig<strong>in</strong>al literature [PT85] and [HT86]. Thedescribed form of the algorithm is targeted to an implementationon a microprocessor us<strong>in</strong>g <strong>in</strong>teger programm<strong>in</strong>g. In thelaboratory exercises we explore variants that might be useful forhardware implementations.The slide on the previous page 28 states that the describedPan-Tompk<strong>in</strong>s algorithm is <strong>in</strong>tended for discrete-time <strong>Ecg</strong> signalsthat have been obta<strong>in</strong>ed by sampl<strong>in</strong>g the true, cont<strong>in</strong>uoustime<strong>Ecg</strong> signal at a rate of 200 samples/sec. This is true becausethe algorithm uses “<strong>in</strong>teger” filters that realize pole- andzero locations that are useful for the <strong>in</strong>tended sampl<strong>in</strong>g rate,but become unreasonable for different sampl<strong>in</strong>g rates; see ourdiscussion start<strong>in</strong>g on page 42.Because this subsection is quit long, we give an overviewon where you f<strong>in</strong>d what. The pre-process<strong>in</strong>g accord<strong>in</strong>g to theblock diagram shown on page 28 is discussed on pages 30–49;we <strong>in</strong>dicate on page 50 how Pan and Tompk<strong>in</strong>s implement thedecision rule.For the pre-process<strong>in</strong>g stage we treat the first preprocess<strong>in</strong>gblock, the bandpass filter, on pages 30 to 42. Next we discussthe derivative operator on pages 44 to 45. The squar<strong>in</strong>g operatorfollows on page 46, and the f<strong>in</strong>al mov<strong>in</strong>g-w<strong>in</strong>dow <strong>in</strong>tegrator isdescribed on pages 47 to 49.6 <strong>Event</strong>Det 29 2014


BioMedSigProcAnaBandpass Filter• isolates the predom<strong>in</strong>ant <strong>Qrs</strong> energy, which is centered <strong>in</strong>the 5–15 Hz range• attenuates the low-frequency characteristics– of the P- and T-waves– of basel<strong>in</strong>e wander• attenuates the high frequencies associated with– electromyographic noise– power-l<strong>in</strong>e <strong>in</strong>terferences– measurement noise• implementation as– “<strong>in</strong>teger” filter <strong>in</strong> which poles cancel zeros on unitcircle– cascade of lowpass and highpass filterLp.ˆω−π 0 πHp.. .ˆω−π 0 πBpˆω−π 0 π.6 <strong>Event</strong>Det 30 2014


BioMedSigProcAnaBandpass Filter: The Lowpass Part• consider the transfer functionH Lp1 (z) = 1 − z−61 − z −1 = 1 + z−1 + z −2 + · · · + z −5• the Dc ga<strong>in</strong> is (ˆω = 0 =⇒ z = e j·0 = 1)H Lp1 (z = 1) = 1 + z −1 + z −2 + · · · + z −5∣ ∣z=1= 6• the pole-zero map and the magnitude response are❝j❝6.0∣ H(e jˆω ) ∣ ∣❝× × .❝5-fold1❝❝. ˆω−π 0 π6 <strong>Event</strong>Det 31 2014


BioMedSigProcAnaBandpass Filter: The Lowpass Part (cont’d)• the complete Lp filter is the scaled cascade of two H Lp1 (z)• the cascade H Lp1 (z) · H Lp1 (z) = ( H Lp1 (z) ) 2has Dc-ga<strong>in</strong>6 · 6 = 36• for unity Dc-ga<strong>in</strong> it needs a scal<strong>in</strong>g factor 1/36• the used scal<strong>in</strong>g 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 isH Lp (z) ˆ= 1 ( ) 1 − z−6 232 1 − z −1 = 1321 − 2z −6 + z −12 Y (z)1 − 2z −1 ˆ=+ z−2 X(z)6 <strong>Event</strong>Det 32 2014


BioMedSigProcAnaBandpass Filter: The Lowpass Part (cont’d)• the magnitude response is∣ H(e jˆω ) ∣ 1.0. ˆω−π 0 π• the difference equation for a recursive implementation isy[n] = 2y[n−1] − y[n−2] + 1 ()x[n] − 2x[n−6] + x[n−12]326 <strong>Event</strong>Det 33 2014


BioMedSigProcAnaBandpass Filter: The Highpass Part• implemented by a delay-complementary transfer functionhighpass = delay allpass − lowpassdelayallpass+−32-po<strong>in</strong>tmov<strong>in</strong>g average• delay of M-po<strong>in</strong>t mov<strong>in</strong>g averager is (M − 1)/2• for M = 32: half-sample delay 31/2 ❀ 16 is usedYou might want to read more about complementary transferfunctions; [Mit98, pp. 245–249] discusses not only delay-complementarytransfer functions, but also more general allpasscomplementaryfilters, power-complementary filters and magnitude-complementaryfilters. Alternatively, you might use thenewer edition of that book; [Mit06, pp. 391–396] additionallydiscusses doubly-complementary transfer functions, which are atthe same time allpass-complementary and power-complementary.Concern<strong>in</strong>g the delay of a mov<strong>in</strong>g-average Fir filter we havethe follow<strong>in</strong>g: First consider a pure delay systemy[n] = x[n − n 0 ] ,6 <strong>Event</strong>Det 34 2014


BioMedSigProcAnawhich delays each sample of the <strong>in</strong>put sequences by n 0 samples.The transfer function of this system is H(z) = z −n0 , and itsfrequency response becomes H(ˆω) = e −jˆωn0 .Next consider an M-po<strong>in</strong>t mov<strong>in</strong>g-average filter. Its transferfunction isH(z) = 1 M(1 + z −1 + . . . + z −(M−1)) = 1 1 − z −MM 1 − z −1 .Its frequency response can be expressed asH(ˆω) ˆ= H(z = e jˆω ) = 1 M1 − e −jˆωM1 − e −jˆω= 1 e ( −jˆωM/2 e jˆωM/2 − e −jˆωM/2)M e ( −jˆω/2 e jˆω/2 − e −jˆω/2)( ) 1 s<strong>in</strong>(ˆωM/2)=e −jˆω(M−1)/2 ,M s<strong>in</strong>(ˆω/2)} {{ }Dirichlet functionwhere we have used Euler’s formula, and where the <strong>in</strong>dicatedDirichlet function is purely real. We see then that H(ˆω) is theproduct of two functions, the Dirichlet function and e −jˆω(M−1)/2 ,with the latter <strong>in</strong>dicat<strong>in</strong>g a shift of (M −1)/2 samples. Clearly,if the filter length M is an odd <strong>in</strong>teger, (M − 1)/2 becomes an<strong>in</strong>teger, and the mean<strong>in</strong>g of delay<strong>in</strong>g by an <strong>in</strong>teger number ofsamples is clear. In M is, however, an even <strong>in</strong>teger, (M − 1)/2is not an <strong>in</strong>teger, and the delay needs a special <strong>in</strong>terpretation;[MSY98, pp. 192–194] gives such an <strong>in</strong>terpretation by apply<strong>in</strong>ga discrete-time mov<strong>in</strong>g average filter to process cont<strong>in</strong>uous-timesignals.6 <strong>Event</strong>Det 35 2014


BioMedSigProcAnaBandpass Filter: The Highpass Part (cont’d)• the 32-po<strong>in</strong>t mov<strong>in</strong>g average filter has transfer functionH MA (z) = 1 (1 + z −1 + . . . + z −31) = 1 1 − z −323232 1 − z −1 .• the pole-zero map and the magnitude response are❝ ❝❝❝❝❝ ❝ ❝❝❝❝❝ ❝❝j ❝∣❝H(e❝jˆω ) ∣ ❝❝1.0❝❝❝× × . ❝31-fold❝❝ 1❝❝❝ ❝ ❝ ❝ ❝. ˆω−π 0 πWe note that the phase response of the mov<strong>in</strong>g-average transferfunction H MA (z) is l<strong>in</strong>ear—it is just a symmetric Fir filter,and its recursive realization does, of course, neither change themagnitude- nor the phase response.6 <strong>Event</strong>Det 36 2014


BioMedSigProcAnaBandpass Filter: The Highpass Part (cont’d)• the highpass transfer function becomesH Hp (z) = z −16 − H MA (z)= z −16 − 1 1 − z −3232 1 − z −1 .• the pole-zero map and the magnitude response are❝❝❝❝❝❝❝❝❝❝❝❝❝❝j❝❝❝❝❝❝❝× × . ❝31-fold❝ 1❝❝❝ ❝❝❝ ❝2-foldzero1.0∣∣H(e jˆω ) ∣ ∣..ˆω−π 0 π.Note that the phase response of the considered highpass filteris not exactly l<strong>in</strong>ear but merely “almost l<strong>in</strong>ear.” This is becausethe <strong>in</strong>volved mov<strong>in</strong>g-average filter is a 32-po<strong>in</strong>t mov<strong>in</strong>g averagefilter—the length is selected as a power-of-two such that neededmultiplication by 1/32 can be realized by just bit shift<strong>in</strong>g—and32 be<strong>in</strong>g an even <strong>in</strong>teger gives a half-po<strong>in</strong>t delay of (32 −1)/2 =15.5 The delay allpass must, however, of course have an <strong>in</strong>tegerdelay, which has been selected to be 16.6 <strong>Event</strong>Det 37 2014


BioMedSigProcAnaIf we would use <strong>in</strong>stead of the 32-po<strong>in</strong>t a 33-po<strong>in</strong>t mov<strong>in</strong>gaveragefilter, we would obta<strong>in</strong> a highpass filter with exactlyl<strong>in</strong>ear phase response, but we would loose the possibility to realizethe needed multiplication by mere bit shift<strong>in</strong>g. To illustratethese arguments, we consider the situation for shorter lengthsof the <strong>in</strong>volved mov<strong>in</strong>g average filter.First consider a 5-po<strong>in</strong>t mov<strong>in</strong>g-average filter. Its delay is(M − 1)/2 = (5 − 1)/2 = 2, and we use a delay allpass hav<strong>in</strong>g adelay of 2. The transfer function of the realized highpass filterbecomesH Hp5 (z) = z −2 − H MA5 (z)= z −2 − 1 (1 + z −1 + z −2 + z −3 + z −4)5= − 1 (1 + z −1 − 4z −2 + z −3 + z −4) .5Clearly, H Hp5 (z) realizes a symmetric Fir filter which has apurely l<strong>in</strong>ear phase.Next consider a 4-po<strong>in</strong>t mov<strong>in</strong>g-average filter. Its delay is(M − 1)/2 = (4 − 1)/2 = 1.5, and we must use a delay allpasshav<strong>in</strong>g either a delay of 1 or of 2. Consider first the delay 2.The transfer function of the realized highpass filter becomesH Hp4,2 (z) = z −2 − H MA4 (z)= z −2 − 1 (1 + z −1 + z −2 + z −3)4= − 1 (1 + z −1 − 3z −2 + z −3) .4Obviously, H Hp4,2 (z) is not a symmetric Fir filter and we cannotexpect that it has a l<strong>in</strong>ear phase. If we consider to realizethe delay allpass with the delay 1, the transfer function of the6 <strong>Event</strong>Det 38 2014


BioMedSigProcAnarealized highpass filter becomesH Hp4,1 (z) = z −1 − H MA4 (z)= z −1 − 1 (1 + z −1 + z −2 + z −3)4= − 1 (1 − 3z −1 + z −2 + z −3) .4Aga<strong>in</strong>, H Hp4,1 (z) is not a symmetric Fir filter and we cannotexpect that it has a l<strong>in</strong>ear phase.6 <strong>Event</strong>Det 39 2014


BioMedSigProcAnaBandpass Filter: The Highpass Part (cont’d)• denote byx[n] : the <strong>in</strong>put signal to the highpass filtery[n] : the output signal of the highpass filtery 1 [n] : the output signal of the mov<strong>in</strong>g-average filter part• then: the difference equation for the mov<strong>in</strong>g-average filterisy 1 [n] = 1 ()y 1 [n − 1] + x[n] − x[n − 32]32• then: the difference equation for the highpass filter isy[n] = x[n − 16] − y 1 [n]The difference equations given above are nearly the differenceequations given <strong>in</strong> [Tom93, p. 250] and [Ran02, pp. 187–188]with a slight difference: These two references compute accord<strong>in</strong>gto (note that the follow<strong>in</strong>g two equations stem unaltered fromthe articles)ỹ 1 [n] = ỹ 1 [n − 1] + x[n] − x[n − 32]) , (5)y[n] = x[n − 16] − 1 ()ỹ 1 [n − 1] + x[n] − x[n − 32] , (6)32that is, they have the mov<strong>in</strong>g-average filter not scaled and do thescal<strong>in</strong>g only when subtract<strong>in</strong>g the mov<strong>in</strong>g-average filter output6 <strong>Event</strong>Det 40 2014


BioMedSigProcAnafrom the delayed <strong>in</strong>put; we do not understand why they seemto recompute ỹ 1 [n] <strong>in</strong> (6).The reference [HT86] computes differently accord<strong>in</strong>g toy[n] = y[n − 1]− 1 1x[n] + x[n − 16] − x[n − 17] +32 32 x[n − 32] . (7)We obta<strong>in</strong> that difference equation by reformulat<strong>in</strong>g the transferfunction from page 37 asH Hp (z) = z −16 − 1 1 − z −3232 1 − z −1( ) 1 − z−1z −16 − 1 32=1 − z −1(1 − z−32 )= − 132 + z−16 − z −17 + 1 32 z−321 − z −1 .F<strong>in</strong>ally, the orig<strong>in</strong>al paper [PT85] uses a completely differenthighpass filter. We suspect, however, that the formula giventhere might be <strong>in</strong> error; <strong>in</strong>deed, [HT86] state <strong>in</strong> their <strong>in</strong>troductorysection that they use “the processor developed by Pan andTompk<strong>in</strong>s” with slight modifications.6 <strong>Event</strong>Det 41 2014


..BioMedSigProcAnaBandpass Filter: The Complete Filterthe magnitude response is• l<strong>in</strong>ear∣ H(e jˆω ) ∣ ∣1.0. ˆω−π 0 π• <strong>in</strong> [dB]∣ H(e jˆω ) ∣ ∣dB. .0dB−60dB.. . .. . . ˆω−π 0 πIf we analyze the complete bandpass filter <strong>in</strong> detail, we f<strong>in</strong>dthat the filter has a middle frequency 7 of ˆω mid = 0.2520 rad, aleft −3 dB frequency of ˆω left = 0.1539 rad, and a right −3 dB7 With a slight abuse of the notion, we call that frequency where themagnitude is maximum the “middle” frequency.6 <strong>Event</strong>Det 42 2014


BioMedSigProcAnafrequency of ˆω right = 0.3707 rad. If the signal to be processedstems from a cont<strong>in</strong>uous-time <strong>Ecg</strong> signal which has been sampledat a rate of f s = 200 samples/sec, these characteristicstranslate 8 to left, middle, and right natural frequencies be<strong>in</strong>g{4.9, 8.0, 11.8}Hz. In the light of the frequency characteristicsof the <strong>Qrs</strong> complex of <strong>Ecg</strong> signals as we have compiled onpage 30—the dom<strong>in</strong>ant <strong>Qrs</strong> energy is conta<strong>in</strong>ed <strong>in</strong> the 5–15 Hzfrequency range—, the realized filter characteristics are reasonable.Note, however, that if the <strong>in</strong>put signal to the <strong>Qrs</strong> detectorstems from a cont<strong>in</strong>uous-time <strong>Ecg</strong> signal sampled at arate of f s = 1000 samples/sec, for example, the discrete-timefilter characteristics translate to left, middle, and right naturalfrequencies be<strong>in</strong>g {24.5, 40, 59}Hz. Obviously, <strong>in</strong> that case thebandpass filter is not useful.8 Recall that the discrete- and cont<strong>in</strong>uous-time frequencies are relatedby ˆω ˆ= ω · T s = 2πf/f s, where ω is the cont<strong>in</strong>uous-time frequency <strong>in</strong>rad/sec, T s ˆ= 1/f s is the sampl<strong>in</strong>g time-<strong>in</strong>terval <strong>in</strong> sec with f s be<strong>in</strong>g thecorrespond<strong>in</strong>g sampl<strong>in</strong>g frequency <strong>in</strong> Hz, and f is the natural (cont<strong>in</strong>uoustime)frequency <strong>in</strong> Hz.6 <strong>Event</strong>Det 43 2014


BioMedSigProcAnaThe Derivative Operator• a five-po<strong>in</strong>t derivative operator(H dif (z) = 0.1 2 + z −1 − z −3 − 2z −4) .• the true ga<strong>in</strong> 0.1 is approximated by 1/8• let x[n] ˆ= <strong>in</strong>put, y[n] ˆ= output• the difference equation then becomesy[n] = 1 8()2x[n] + x[n − 1] − x[n − 3] − 2x[n − 4] .Note that the def<strong>in</strong>ed derivative operator is an Fir filter withan impulse response of length 5; this is the reason that we call ita “five-po<strong>in</strong>t derivative operator” although it uses only 4 termsfor the computations—imag<strong>in</strong>e that the fifth term x[n − 2] ismultiplied with a coefficient be<strong>in</strong>g zero.6 <strong>Event</strong>Det 44 2014


BioMedSigProcAnaThe Derivative Operator (cont’d)the magnitude response is• l<strong>in</strong>ear∣ H(e jˆω ) ∣ ∣0.7. ˆω−π 0 π• <strong>in</strong> [dB] versus log-frequency∣∣ H(e jˆω )[dB]∣0−20−40.−6010 −3 10 −2 10 −1 10 0log 10 (ˆω)We note from the magnitude plots of the bandpass filter onpage 42 that essentially only signal component-frequencies ˆωbelow 1 rad/sample arrive at the derivative operator. For thesefrequencies the proposed operator well acts as a differentiator,as the second of the above plots—magnitude <strong>in</strong> [dB] versus logfrequency—clearlyreveals: We have <strong>in</strong> this double logarithmicplot a slope of +20 dB/decade <strong>in</strong> the relevant frequency <strong>in</strong>terval.6 <strong>Event</strong>Det 45 2014


BioMedSigProcAnaThe Squar<strong>in</strong>g Operator• non-l<strong>in</strong>ear operation (as opposed to all other process<strong>in</strong>gsteps)• but static operation (no memory)• let x[n] ˆ= <strong>in</strong>put, y[n] ˆ= outputthen: squar<strong>in</strong>g operation is y[n] =(x[n]) 2.• makes output-signal samples positive• amplifies output of derivative operator non-l<strong>in</strong>early– emphasizes higher frequencies <strong>in</strong> <strong>Ecg</strong> signal– higher frequencies are ma<strong>in</strong>ly due to <strong>Qrs</strong> complex– smaller differences aris<strong>in</strong>g from P- and T-waves aresuppressedWe note that <strong>in</strong> microprocessor implementations of the Pan-Tompk<strong>in</strong>s algorithm the output of the squar<strong>in</strong>g-operation stageshould be hard-limited to a certa<strong>in</strong> level correspond<strong>in</strong>g to thenumber of bits used to represent the data type of the signals.In hardware implementations, however, we do not need a s<strong>in</strong>gledata type for all signals <strong>in</strong> the cha<strong>in</strong> of operations, and thedecision whether and how to limit the squar<strong>in</strong>g-operator outputmust be taken based on other considerations.6 <strong>Event</strong>Det 46 2014


BioMedSigProcAnaThe Mov<strong>in</strong>g-W<strong>in</strong>dow Integrator• slope of the R-wave <strong>in</strong> a <strong>Qrs</strong> complex is not a guaranteedmeasure to detect a <strong>Qrs</strong> event• many abnormal <strong>Qrs</strong> complexes that have– large amplitude– large duration– but not very steep slopesare not detected us<strong>in</strong>g only <strong>in</strong>formation about slope of R-wave• ❀ need to extract more <strong>in</strong>formation from an <strong>Ecg</strong> signalto detect a <strong>Qrs</strong> complex• mov<strong>in</strong>g-w<strong>in</strong>dow <strong>in</strong>tegration extracts additional features6 <strong>Event</strong>Det 47 2014


BioMedSigProcAnaThe Mov<strong>in</strong>g-W<strong>in</strong>dow Integrator (cont’d)• let x[n] ˆ= <strong>in</strong>put, y[n] ˆ= output of mov<strong>in</strong>g-w<strong>in</strong>dow <strong>in</strong>tegrator• then, difference equation isy[n] = 1 N()x[n] + x[n − 1] + · · · + x[n − (N − 1)]• is an N-po<strong>in</strong>t mov<strong>in</strong>g average filter• parameter N ˆ= w<strong>in</strong>dow-length must be chosen carefully– w<strong>in</strong>dow-length N approximately the same as widestpossible <strong>Qrs</strong> complex– usually N is chosen experimentally– for <strong>Ecg</strong> signals sampled at a rate of 200 samples/sec,a value of N ≈ 30 is reasonableThe given difference equation of the mov<strong>in</strong>g-average filtercan, of course, also be written <strong>in</strong> recursive form: The transferfunction isY (z)X(z) = 1 (1 + z −1 + · · · + z −(N−1)) = 1 1 − z −NNN 1 − z −1 ,and the difference equation <strong>in</strong> recursive form then readsy[n] = y[n − 1] + 1 N()x[n] − x[n − N] .6 <strong>Event</strong>Det 48 2014


BioMedSigProcAnaWe also note that it might not be necessary to compute thetrue average, that is, we could leave away the factor 1/N to simplifythe computation, because the subsequent process<strong>in</strong>g steprealiz<strong>in</strong>g the “decision rule” can take account of the result<strong>in</strong>gsignal ga<strong>in</strong> <strong>in</strong> that it works with adjusted threshold values. Ifwe nevertheless like to have the normalization—the division bythe number N of samples—it is clearly best to choose N = 32,which is <strong>in</strong> the order of the proposed 30, because the divisionthen becomes a mere bit shift.Concern<strong>in</strong>g the selection of the w<strong>in</strong>dow size N, the argumentationis as follows: If the w<strong>in</strong>dow size of the mov<strong>in</strong>g-averagefilter is too large—we have a too wide w<strong>in</strong>dow—, then the <strong>in</strong>tegrationwaveform y[n] tends to merge <strong>Qrs</strong> complexes and subsequentT-waves together. If, however, the w<strong>in</strong>dow size is toosmall, a s<strong>in</strong>gle <strong>Qrs</strong> complex might produce several peaks at the<strong>in</strong>tegrator-stage output. For the considered <strong>Ecg</strong> signals sampledat a rate of 200 samples/sec, a choice of N = 30 has 29<strong>in</strong>tervals between first and last sample <strong>in</strong> the w<strong>in</strong>dow and correspondsto an real-world time <strong>in</strong>terval length of 145 msec. Correspond<strong>in</strong>gly,we obta<strong>in</strong> for a choice of N = 31 a real-world time<strong>in</strong>terval length of 150 msec, and for N = 32 one of 155 msec.6 <strong>Event</strong>Det 49 2014


BioMedSigProcAnaDecision Rule• adaptive threshold<strong>in</strong>g– algorithm adapts to changes <strong>in</strong> the <strong>Ecg</strong> signal– by: comput<strong>in</strong>g runn<strong>in</strong>g estimates of signal and noisepeaks– a peak is said to be detected whenever the f<strong>in</strong>al outputchanges direction with<strong>in</strong> a specified <strong>in</strong>terval• adjust<strong>in</strong>g average heartbeat-rate estimates– R-R <strong>in</strong>terval: R-wave to R-wave <strong>in</strong>terval ˆ= heartbeat<strong>in</strong>terval– works with two averages– 1. average: over 8 most recent beats– 2. average: over 8 most recent beats that fall <strong>in</strong>tocerta<strong>in</strong> limits– reason (idea): to be able to adapt to quickly chang<strong>in</strong>gor irregular heartbeat rates• for details: see orig<strong>in</strong>al literatureThe orig<strong>in</strong>al orig<strong>in</strong>al literature is [PT85] and [HT86]; wesupply these papers as pdf-copies along with the laboratoryexercises. Alternatively, you might want to use the textbooks[Tom93] or [Ran02].6 <strong>Event</strong>Det 50 2014


BioMedSigProcAnaSampl<strong>in</strong>g-Rate Conversion• note: the Pan-Tompk<strong>in</strong>s algorithm is designed for <strong>Ecg</strong>signals sampled with f s = 200 samples/sec• if we have an <strong>Ecg</strong> signal with a different sampl<strong>in</strong>g rate,say f s = 1000 samples/sec, we need a pre-process<strong>in</strong>g• pre-process<strong>in</strong>g: sample-rate conversion• <strong>in</strong> fixed-po<strong>in</strong>t implementations: sample-rate conversion oftenperformed with Cic filtersThe acronym Cic stands for cascaded <strong>in</strong>tegrator-comb filters,be<strong>in</strong>g a special form of multirate decimation and <strong>in</strong>terpolationfilters. We have the orig<strong>in</strong>al paper [Hog81], but you might alsowant to consult [Don00], [MB07, Section 5.3], [Xil08], or thecorrespond<strong>in</strong>g items <strong>in</strong> the Matlab manuals. 9We note that although the Cic decimation-structures haveas first stages <strong>in</strong>tegrators—see our simple example on page 52which has just one <strong>in</strong>tegrator—there is no problem with overflows,if the used data type is two’s complement with naturaloverflow computations, because then the computations are modulo2 b , and f<strong>in</strong>al overall results stay<strong>in</strong>g <strong>in</strong> the representable rangeare correctly computed even if <strong>in</strong>termediate results have overflowed;see our discussion <strong>in</strong> [Goe14b].9 In the Matlab help w<strong>in</strong>dow just search for Cic.6 <strong>Event</strong>Det 51 2014


BioMedSigProcAnaSampl<strong>in</strong>g-Rate Conversion: Cic-Filter Example• to do: realize down-sampl<strong>in</strong>g by a factor 5• needed: lowpass filter for limit<strong>in</strong>g to ˆω p = π/5• as example use: 10-po<strong>in</strong>t mov<strong>in</strong>g-sum filterH(z) =(1 + z −1 + · · · + z −9) = 1 − z−101 − z −1• with subsequent down-sampl<strong>in</strong>g1 − z −101 − z −1 ↓ 511 − z −1 1 − z −10 ↓ 5• with Cic-filter structure11 − z −1 ↓ 5 1 − z −2We here call a mov<strong>in</strong>g-average filter that comes “withoutaverag<strong>in</strong>g” a mov<strong>in</strong>g-sum filter. The mov<strong>in</strong>g-average filter correspond<strong>in</strong>gto the mov<strong>in</strong>g-sum filter <strong>in</strong>troduced above isH(z) = 1 (1 + z −1 + · · · + z −9) = 1 1 − z −101010 1 − z −1 ,6 <strong>Event</strong>Det 52 2014


BioMedSigProcAnathat is, the mov<strong>in</strong>g-average filter has, as compared to the mov<strong>in</strong>gsumfilter, an additional scal<strong>in</strong>g factor 1/10—the computationof the average.Reconsider the Cic-filter decimator structure <strong>in</strong> the graphicson page 52. We see that the first process<strong>in</strong>g block is anaccumulator—we may likewise term it an <strong>in</strong>tegrator if we prefercont<strong>in</strong>uous-time (Ct) system parlance. Obviously, that accumulatorcontributes a not strictly-stable pole at z = 1 to thesystem, and the result might be register overflow <strong>in</strong> the <strong>in</strong>tegratorstage. 10 However, such a register overflow will have noconsequence if we ensure that the follow<strong>in</strong>g two conditions hold:(i) The filter is implemented <strong>in</strong> two’s complement arithmetic; 11(ii) The range of the used number system is equal to or exceedsthe maximum magnitude expected at the output of the completeCic filter.Correspond<strong>in</strong>g to the operation of decimation, there is thecomplementary operation of <strong>in</strong>terpolation: Here, an <strong>in</strong>com<strong>in</strong>gsignal is first upsampled to a higher rate by <strong>in</strong>sert<strong>in</strong>g zero samplesand subsequently lowpass filtered for <strong>in</strong>terpolation. In the<strong>in</strong>terpolation-operation too, Cic-filter structures can be used,but the sequence of comb sections and <strong>in</strong>tegrator sections is reversed:Correspond<strong>in</strong>g to the example on page 52 we would havethe comb block (1 − z −2 ), followed by an upsampler, followedby the <strong>in</strong>tegrator. In this situation of the Cic-filter <strong>in</strong>terpolator,the <strong>in</strong>put signal to the overall filter is preconditioned bythe comb section—the comb section suppresses a potential Dcterm—so that overflow will not occur <strong>in</strong> the <strong>in</strong>tegrator stages.10 If the <strong>in</strong>put signal to the <strong>in</strong>tegrator conta<strong>in</strong>s a non-zero Dc component,the register will overflow sooner or later <strong>in</strong>dependently of how small thatDc component might be.11 The filter can likewise be implemented by any other number system thathas “wrap-around” between the most positive and most negative numbers—the number system must have modulo arithmetic.6 <strong>Event</strong>Det 53 2014


BioMedSigProcAnaThe 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 <strong>in</strong>ternal signal-sample storage, as comparedto equivalent implementations with uniform Fir filters,by <strong>in</strong>tegrat<strong>in</strong>g at the high sampl<strong>in</strong>g rate and combfilter<strong>in</strong>g at the low sampl<strong>in</strong>g rate;4. Cic-filters have a very “regular” structure consist<strong>in</strong>g oftwo basic build<strong>in</strong>g blocks;5. Cic-filters can be implemented with little external controlor complicated <strong>in</strong>ternal tim<strong>in</strong>g;6. Cic-filters allow to use the same filter design for a widerange of rate-change factors, with only the addition of ascal<strong>in</strong>g circuit and m<strong>in</strong>imum changes to the filter tim<strong>in</strong>g.Problems encountered with Cic-filters <strong>in</strong>clude: (i) Registerwidths might become large if large sampl<strong>in</strong>g-rate factors areto be implemented; (ii) The frequency response can only be<strong>in</strong>fluenced by three <strong>in</strong>teger parameters.To understand this second statement, we must generalizethe example on page 52: Instead of us<strong>in</strong>g there the 10-po<strong>in</strong>tmov<strong>in</strong>g-sum filter for lowpass filter<strong>in</strong>g prior to downsampl<strong>in</strong>gby a factor of 5, we could start with only a 5-po<strong>in</strong>t mov<strong>in</strong>gsum filter. Correspond<strong>in</strong>gly, the comb section would become(1 − z −1 ), and <strong>in</strong> general, the comb section is (1 − z −M ), whereM is named the differential delay. 12 Next, <strong>in</strong>stead of start<strong>in</strong>gjust with the 10-po<strong>in</strong>t mov<strong>in</strong>g-sum filter as done on page 52, wecould use a cascade of N such mov<strong>in</strong>g sum filters, lead<strong>in</strong>g then12 Of course we could also start with a 15-po<strong>in</strong>t, or a 20-po<strong>in</strong>t, or . ..,mov<strong>in</strong>g-sum filter, lead<strong>in</strong>g to M = 3, M = 4, ..., but <strong>in</strong> practice thedifferential delay is usually held to M = 1,2.6 <strong>Event</strong>Det 54 2014


BioMedSigProcAnato a Cic-filter structure correspond<strong>in</strong>g to that on page 52 whichwould first have N <strong>in</strong>tegrator stages, next the downsampler bythe factor 5, and f<strong>in</strong>ally N comb stages each of the form (1 −z −2 ). F<strong>in</strong>ally, of course, the downsampl<strong>in</strong>g factor could be somegeneral positive <strong>in</strong>teger R, and the transfer function of the Cicfilterreferenced to the high sampl<strong>in</strong>g rate would become( ) (1 − z−RM N RM−1) NH(z) =(1 − z −1 ) N = z −k .∑k=0From the above transfer-function formula we now understandthat the frequency response of the Cic-filter depends only on thethree <strong>in</strong>teger parameters {R, M, N}, that is, on the sampl<strong>in</strong>gratechange factor R, the differential delay M, and the numberof cascaded stages N.6 <strong>Event</strong>Det 55 2014


BioMedSigProcAnaReferences[AT83][AT85]M. L. Ahlstrom and W. J. Tompk<strong>in</strong>s. Automatedhigh-speed analysis of holter tapes with microcomputers.IEEE Trans. Biomed. Eng., 30(10):651–657,October 1983.M. L. Ahlstrom and W. J. Tompk<strong>in</strong>s. Digital filtersfor real-time <strong>Ecg</strong> signal process<strong>in</strong>g us<strong>in</strong>g microprocessors.IEEE Trans. Biomed. Eng., 32(9):708–713,September 1985.[BDD + 77] R. A. Balda, G. Diller, E. Deardorff, J. Doue, andP. Hsieh. The Hp <strong>Ecg</strong> analysis program. In J. H.van Bemmel and J. L. Willems, editors, Trends <strong>in</strong>Computer-Processed Electrocardiograms, pages 197–205. North Holland, Amsterdam, 1977.[Don00] Matthew P. Donadio. Cic filter <strong>in</strong>troduction.On the Web: For Free Publication by Iowegian,July 2000. m.p.donadio@ieee.org, http://www.-dspguru.com/<strong>in</strong>fo/tutor/cic.htm.[FJJ + 90] G. M. Friesen, T. C. Jannett, M. A. Jadallah, S. L.Yates, S. R. Qu<strong>in</strong>t, and H. T. Nagel. A comparisonof the noise sensitivity of n<strong>in</strong>e <strong>Qrs</strong> detection algorithms.IEEE Trans. Biomed. Eng., 37(1):85–97,January 1990.[Goe14a] Josef Goette. Biomedical Signal Process<strong>in</strong>g andAnalysis—Filter<strong>in</strong>g for Remov<strong>in</strong>g Artifacts. BernUniversity of Applied Sciences, Script at the BfhtiBiel/Bienne, HuCE-<strong>microLab</strong>, February 2014.6 <strong>Event</strong>Det 56 2014


BioMedSigProcAna[Goe14b] Josef Goette. Biomedical Signal Process<strong>in</strong>g andAnalysis—On Fixed-Po<strong>in</strong>t Filter Realizations. BernUniversity of Applied Sciences, Script at the Bfh-tiBiel/Bienne, HuCE-<strong>microLab</strong>, February 2014.[Goe14c] Josef Goette. Biomedical Signal Process<strong>in</strong>g andAnalysis—Review of Various Biomedical <strong>Signals</strong>.Bern University of Applied Sciences, Script at theBfh-ti Biel/Bienne, HuCE-<strong>microLab</strong>, February2014.[Hog81]Eugene B. Hogenauer. An economical class of digitalfilters for decimation and <strong>in</strong>terpolation. IEEE Trans.Acoust., Speech, Signal Process<strong>in</strong>g, 29(2):155–162,April 1981.[HT86] P. S. Hamilton and W. J. Tompk<strong>in</strong>s. Quantitative<strong>in</strong>vestigation of <strong>Qrs</strong> detection rules us<strong>in</strong>gthe Mit/Bih arrhythmia database. IEEE Trans.Biomed. Eng., 33(12):1157–1165, December 1986.[Los08][MB07][Mit98][Mit06]Ricardo A. Losada. Digital filters with Matlab.Technical report, The MathWorks, Inc., May 2008.Uwe Meyer-Baese. Digital Signal Process<strong>in</strong>g withField Programmable Gate Arrays. Spr<strong>in</strong>ger Verlag,Berl<strong>in</strong> Heidelberg New York, 3rd edition, 2007.Sanjit K. Mitra. Digital Signal Process<strong>in</strong>g: A ComputerBased Approach. Mc Graw Hill, New York,1998. Bfh-ti Biel/Bienne Library 621.391 MITRA.Sanjit K. Mitra. Digital Signal Process<strong>in</strong>g: A ComputerBased Approach. Mc Graw Hill, New York, 3rdedition, 2006. Bfh-ti Biel/Bienne Library 621.391MITRA.6 <strong>Event</strong>Det 57 2014


BioMedSigProcAna[MSY98][Orf96]James H. McClellan, Ronald W. Schafer, andMark A. Yoder. Dsp First: A Multimedia Approach.Prentice-Hall Inc., 1998.Sophocles J. Orfanidis. Introduction to Signal Process<strong>in</strong>g.Prentice-Hall Inc., Upper Saddle River, NewJersey, 1996. Bfh-ti Biel/Bienne Library 621.391ORFAN.[PT85] J. Pan and W. J. Tompk<strong>in</strong>s. A real-time <strong>Qrs</strong>detection algorithm. IEEE Trans. Biomed. Eng.,32(3):230–236, March 1985.[Ran02][SL05][Tom93][Xil08]Rangaraj M. Rangayyan. Biomedical Signal Analysis:A Case-Study Approach. IEEE Press, New York,2002. Bfh-ti Biel/Bienne Library 57.08 RANGA.Leif Sörnmo and Pablo Laguna. Bioelectrical SignalProcess<strong>in</strong>g <strong>in</strong> Cardiac and Neurological Applications.Elsevier Academic Press, Amsterdam, 2005. Bfh-tiBiel/Bienne Library 616 SOERN.Willis J. Tompk<strong>in</strong>s. Biomedical Digital Signal Process<strong>in</strong>g.Prentice-Hall Inc., Englewood Cliffs, N.J.,1993. Eth Bib: +521 458.Xil<strong>in</strong>x. Cic Compiler v1.1. On the Web, March2008. http://www.xil<strong>in</strong>x.com.6 <strong>Event</strong>Det 58 2014

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!