Biomedical Signal Processing and Control
j ou rn a l h o m e pa g e :w w w . e l s e v i e r . c o m / l o c a t e / b s p c
P- and T-wave delineation in ECG signals using parametric mixture Gaussian and dynamic programming
Achuth Rao MV
a,∗, Prakhar Gupta
b, Prasanta Kumar Ghosh
aaIndianInstituteofScience,Bangalore,560012,India
bNationalInstituteofTechnology,Tiruchirappalli,620015,India
a r t i c l e i n f o
Articlehistory:
Received20September2018
Receivedinrevisedform25February2019 Accepted3March2019
Availableonline15March2019
Keywords:
ECG PTwave
Dynamicprogramming
a b s t r a c t
DetectionandtrackingoftheP-andT-wavesareimportantissuesintheanalysisandinterpretationofthe ECGsignals.ThispaperaddressestheproblembyusingtwomixtureGaussianfunctionandtheDynamic programming.Akeyfeatureoftheproposedalgorithmisthatitallowstoincorporatethepriorknowledge abouttheP/TwavelocationvariationsandrobustnesstoerrorsinQRSdetection.Theproposedalgorithm isevaluatedontheannotatedQT-databaseandcomparedagainstthealgorithmsbasedondifferential evolutionoptimizationstrategy(DEOS)andgeneratingblocksofinterest(GBI).Theexperimentsshow thattheproposedmethoddeterminestheP-andT-peaklocationswitharootmeansquareerrorof0.085s and0.091srespectively.BoththesevaluesarebetterthanthecorrespondingvaluesfromDEOSandGBI.
Similarly,theproposedalgorithmachievesasensitivityof96.13%andpredictivityof97.70%.Whilethe predictivityishigherthanbothDEOSandGBI,thesensitivityisonparwithGBOIandhigherthanthatof DEOS.
©2019ElsevierLtd.Allrightsreserved.
1. Introduction
Theanalysisofelectrocardiograms(ECGs)isusedfordiagnosing cardiacdiseases.MostoftheclinicallyusefulinformationinECGs canbeobtainedfromtheintervals,amplitudesandtheshapeof theECGwaveforms[1].Thedevelopmentofaccurateandrobust methodsforautomaticallyextractingsuchwaveformcharacteris- ticsfromECGisasubjectofmajorimportance,especiallyforthe analysisoflongrecordings[2].
TheECGcapturestheelectricalactivityontheskinasaresult ofthepolarizationanddepolarizationoftheheart[3].Normally thiselectricalactivityisquasiperiodic.Eachperiodcanbedivided intofourkindsofregions:P-wave,QRS-wave,T-waveandU-wave, whereP-waverepresentstheatriadepolarization,QRS-waverep- resentsventriclesdepolarizationandT-waverepresentsventricles repolarization[3].U-wavetypicallyhasverylowamplitude.The processofdetectingtheQRSwaveiscalledQRSdetectionandthe processoflocatingtheP/T-wavestart,endandpeakpointsiscalled P/T-wavedelineation.
EachcycleofECGsignaliscomposedoftwoparts.namely,QRS complexesandnon-QRSregionsasshowninFig.1.AQRScomplex consistsofQ,R,Swaves.Anon-QRSregionsappearsbetweentwo consecutiveQRScomplexes.Fig.1showsthesetwopartsforthree
∗Correspondingauthor.
consecutivecyclesofanillustrativeECGwaveform.Qi,iR,iSdenote thetimelocationsoftheQ,R,Swavesin theithQRScomplex.
TypicallythefirststepinanECGsignalanalysisistheQRSdetection followedbytheP/T-wavedelineationusingthedetectedQRSwave.
AQRSpeakhashighamplitudeandisrelativelyeasytodetecteven inthenoisyECGsignalscomparedtotheP/T-waves.Inthispaper, weaddresstheproblemoflocatingtheP/T-wavesgiventheQRS- locations.
ThereareseveralP/T-wavedelineationapproachesintheliter- ature[4].ThealgorithmsforP/T-wavedelineationcanbegrouped intofivecategories.Thefirstclassofalgorithmsisbasedonadaptive filteringtechniquesproposedbyLagunaetal.[5]andTakoretal.
[4].ThesealgorithmsperformbandpassfilteringoftheECGsig- nalandusethresholdstodetecttheP/T-waveslocations.Strumillo etal.[6]proposedtousemedianfilteringwithdifferentwindow sizesandthedominantpeaksinthesignalarepreservedatallwin- dowsizes.Finally,basedontheamplitudesofthepeaks,theP/T wavesaredetected.Murthyetal.[7]proposedtofilterthesignal intodifferentsubbandsanduseonlyfewsubbandsignalstoget thelocationsoftheP/T-waves.Butthesealgorithmsareverysensi- tivetothethresholdsusedandthereisnomethodtodifferentiate betweentheP/T/U-waves[8].However,Elgendietal.[9]havepro- posedanapproachwhichperformsbandpassfilteringoftheECG signalfollowedbytheusageoftwomovingaveragefilterstodelin- eatethePandTwaveswhich,islesssensitivetothresholdsand candistinguishbetweenP/T/U-waves.
https://doi.org/10.1016/j.bspc.2019.03.001 1746-8094/©2019ElsevierLtd.Allrightsreserved.
Fig.1. ThreeconsecutivecyclesofasampleECG.Ri,iQ,iSindicatethetimelocationsofthepeaksoftheR-wave,onsetoftheQ-waveandendoftheS-waverespectivelyin theithECGcycle.TheP,TandU-waveswithineachnon-QRSregionarecolorcoded.
ThesecondclassofmethodsdecomposestheECGsignalinto differentbasisfunctionsandusesthebasisweightstodetermine thelocationsoftheP-andT-waves.Murthyetal.[10]observed thata twopoleand twozeromodel canrepresentthediscrete cosinetransform(DCT)ofabellshapedbi-phasicfunction.TheQRS, P/T-wavescanbeasinglebellcurveorbiphasicandeachwaveis representedbyatwopoleandtwozeromodel.Thelocationofa P/T-waveisestimatedbythepoleandzerolocations.Lietal.[8]
andMartínezetal.[11,12]decomposedtheECGsignalintodiffer- entscalesusingthewavelettransform(WT)andthelocationofthe P/T-waveisestimatedbyapplyingathresholdonthetransformed signalatdifferentscales.Thesealgorithmsareverysensitivetothe modelorderselectionwheneitherP-orT-waveisabsent[13].The thirdclassofapproachesdirectlyclassifiesthewaveshapesorthe featuresfromtheECGsignalusingclassificationandpatternrecog- nitionmethods,suchasfuzzytheory[14],artificialneuralnetworks [15],patterngrammars[16],andhiddenMarkovmodels[17].There areseveralotherdelineationstrategiesincludinglengthtransfor- mation[18], uniformthresholding [19],approximatingfunction theory[20],andcharacterizationofTUcomplexes[13].
Thefourthclassofalgorithmsisbasedontheconceptoffit- tingamodeltotheECGwaveformandextractingparametersfrom themodeltodeterminewaveformonsetsandoffsets.Cliffordetal.
[21]proposedamethodtofitfivemixtureGaussianfunction(GF)to theECGsignalwhoseparameterswereestimatedusingnonlinear gradientdescent.Themeanparametersofthemixtureswereused toidentifytheP/T-wavelocations.Sayadietal.[22,23]proposed toestimatetheseparametersusingKalmanfilterstoexploitthe dependencyofparametersintheneighboringcycles.Thisresults inanon-convexoptimizationproblem,whichissensitivetotheini- tialcondition.Panigrahyetal.[24]proposedanapproachinvolving templateextractionfollowedbydifferentialevolutionforgetting optimized parameters.This however,is a very computationally expensiveapproach.Itshouldbenotedthattheseapproachesdo notexploitanypriorknowledgeabouttheECGsignalwhichcould potentiallyimprovetheP/T-wavelocalization.
Thefifthclassofalgorithmsincludesnon-parametricBayesian methodsproposedbyLinetal.[25,26].Thismethodassumesthat theECGwaveisgeneratedbyfilteringtheimpulsesusinganFIR filter.TheimpulselocationsindicatethepeaksoftheP/T-waves.
TheyalsoimposepriordistributionsonthelocationsofP/T-waves, forexampleonthedistancebetweentheconsecutiveP/T-waves.
Priorinformation alsoincludesassumptionsthat theP/T-waves arepresent in thefirst and secondhalvesof an ECGcycle and theimpulseresponseofthefilterremainsconstantforfewcon- secutivecycles.Thesepriordistributionsarecombinedwiththe
likelihoodoftheobserveddatatoobtaintheposteriordistribution oftheunknownparameters.Asthereisnoclosedformsolutionfor theparametervalueswhichmaximizetheposteriordistribution, authorsusedifferentvariantsoftheGibbssamplingmethodtoget thesamplesofparametersgiventheECGsignalandtheaverageof thesamplesiscomputedtogetthelocationsofP/T-waves.Itshould benotedthatthereisnoruletodetecttheendandbeginningofa P/T-wave.Alloftheabovemethodsusesomefeaturesofthewave suchaslowslopeandlowmagnitudetodetecttheendandbegin- ningoftheP/T-wave[25].Inadditiontotheestimationofthewave peaksandlimits(beginandend),anaccuratewaveformestimation isrelevantforsomemedicaldiagnoses(suchasT-wavealternans (TWA)detection[28])orpathologyanalysis(suchasarrhythmia detection[27]).
Inthis paperweproposea newalgorithmthat usesmixture GaussiananddynamicprogrammingfortheP/T-wavedelineation.
Ourformulationalsoallowseasyinclusionofthepriorinforma- tionresultinginatractableoptimizationproblem.Weassumethat theshapesofbothP-andT-wavesfollowGaussianfunction.Thus, thenon-QRSregionisassumedtofollowatwomixtureGaussian function(GF).WeuseagoodnessoffitoftheGFasalikelihoodof occurrenceoftheP/T-wavesandwealsoimposepriorknowledge aboutthecharacteristicsofECGsignaltoachieveaccuratedelin- eation.Severalmodelbasedapproaches[21,23]fordelineationuse GFtomodelECGwaveformresultinginanon-convexoptimiza- tionproblemwithmany unknownparametersproportionateto thenumberofmixtures.Incorporatingpriorinformationinsuch casesmakestheoptimizationevenmorechallenging.Althoughwe proposetouseGaussianmixture,wedonotdirectlyfitittothe ECGwaveform.Inparticular,weuseatwomixtureGFreducing thenumberofunknownparametersintheoptimization.Wepro- posetwokindsofprioronthelocationsofP/T-waves:Thefirst prior is related tothesmoothness ofP/T-waves locations from cycletocycle.WeassumethattheperiodicityoftheECGsignal doesnot change drasticallyfromcycle tocycle and hence, the locationsofP/T-waves intheneighboring cyclesarecorrelated.
Further,insteadofassumingtheoccurrenceofP/T-wavesintwo halvesofanECGcycle,weimposeasoftprior ontheP/T-wave locations,suchthattheyaremore likelytoappear closetothe R-peak. Thismakes theproposedalgorithm robust toerrors in R-peaklocationwhich,in turn,makesthetrackingofP-andT- wavesaccurateeveninthepresenceofdominantU-wave.Using thelikelihood and the prior, a score functionis constructed to findtheoptimallocationsoftheP/T-waves.Weoptimizethescore functionusingdynamicprogramming.Thismethodisreferredas MGDP.
Fig.2.BlockdiagramoftheproposedP/T-wavedelineation.
2. Proposedapproach
TheproposedP/T-wavedelineationisperformedintwomain stages–(1)thefirststageisapre-processingstepwhichremoves thehighfrequencynoiseandmotionartifactsandperformsQRS detection,(2) thesecond stagelocatestheP/T wavesusingthe mixtureGFanddynamicprogramming.Theblockdiagramsum- marizingthesetwostagesisshowninFig.2.Thedetailsofeach stageareexplainedbelow.
2.1. Preprocessing
AsshowninFig.2,inthepreprocessingstepoftheproposed P/T-wavedelineation,wefirstdetectQRScomplexesandremove thebaselinedriftthatoccursduetomotionofelectrodesorother lowfrequencynoise.Thelinearfiltering,removalofbaselinedrift andQRSdetectionarecommonpreprocessingblocksinaP/T-wave delineationalgorithm. There-sampling ofthenon-QRS regions, normalizationandsmoothingarerequiredfortheproposedalgo- rithm.Eachblockisbrieflydescribedbelow.
•Linearfiltering:TheECGsignalisfilteredthroughalinearphase lowpassfilter.Thisiscommonlyusedtoremovethehighfre- quencynoisethatcanaffecttheQRSdetection[29,30].
•Removalofbaselinedrift:Baselinedriftcausesinaccuratewave- formestimationintheproposedalgorithm.Forthisreason,we employthemethodproposedbyChouhanetal.[30]toremove thebaselinedriftineachnon-QRSregion.Thismethodfirstsub- tractsthemedianvalueofthesignalfromeachsamplefollowed byfittingafourthdegreepolynomialtothewholesignalusing leastsquareandsubtractingitfromthewholesignal.Themedian valuewithineachnon-QRSregioniscorrectedtogetthebase- lineremovedECGsignal.TheresultingECGsignalisdenotedby ECG[n],wherendenotesthesampleindex.
•QRSdetection:QRScomplexesaredetectedusingthealgorithm proposedbyPan etal. [29].The ECG signalis passedthough abandpassfiltertoattenuatethenoise.Theresultingsignalis passedthoughadifferentiatorfollowedbysquaringandamov- ingwindowintegration.Themovingwindowintegratorproduces asignalwithhighvalueatR-peakbecauseofitshighslopeand thevaluedecaysdownfromR-peaktoQ-peakandS-peakthat givesthelocationsofS-peakandQ-peak.1
•Re-samplingandnormalization:TheP-andT-wavesappearin thenon-QRS region.So we consideronly the samplesin the ith non-QRS region given by ECG[n], Si−1≤n≤Qi (as shown inFig. 1).The number of samplesin each non-QRS region is
1 WeexperimentedwithotherQRSdetectionalgorithms[31,32]withnosignifi- cantimprovementovertheoneused.
differentandthenumberofsamplesinithnon-QRSregionis denotedbyNRR(i).Buttheproposedalgorithmrequiresallnon- QRSsegmentstohavethesamelengthL.Hencewere-sample ithnon-QRSregiontoaconstantnumber(L)ofsamplesusing thelinearinterpolation[33],whichresultsinzi[n]forithnon- QRSregion.Wenormalizesamplesineachnon-QRSregionbythe amplitudeoftheR-peakthatoccursbeforethenon-QRSregionto getZi[n]=ECG[zi[n]i−1
R ].Followingthis,Zisequencesforallnon-QRS regionsarestackedtogethertoformaL×Ndimensionalmatrix ZN=[Z1,Z2,...,ZN],where Ndenotes thenumber ofnon-QRS regionsinagivenECGsignal.
•Smoothing and peak/valley picking: The proposed method requiresasetofcandidatelocationsfortheP/T-waves.AsP/T- wavesoccuronlyinnon-QRSregion,allsamplesinanon-QRS regioncanbegiven asthecandidatelocationsfor P/T-waves.
Butthisincreasesthecomputationalcomplexityoftheproposed algorithm.WehypothesizethattheactualP/T-wavesarelocated atoneofthelocalpeaksorvalleysinanon-QRSregion.Hence, toreducethecomputationalcomplexity,thepeaksandvalleys insmootherversionofECGisprovidedasthepossiblecandidate locationsfortheP/T-waves.Theproposedapproachneedsthe peaksoftheoriginalsignaltobeperseveredaftersmoothingand hence,weuseSGolayfilter[34]oforder2withaframelengthof 101.Theithsmoothednon-QRSregionisdenotedbyZiS[n].Fol- lowingthis,thelocalminimaandmaximaoftheresampledand smoothedECGsignalarefound.Thesetoflocationsofvalleysand peaksatithnon-QRSregionisgiventotheproposedalgorithm asthesetofpossiblecandidatelocationsforP/T-waves.Thisset isdenotedbyKi.
2.2. ProposedPandTpeaktracking
Following pre-processing, the task of P/T-wave delineation becomesselectingthelocationsofP/T-wavesintheithnon-QRS regionfromthesetKi.WehypothesizethattheP-andT-waves together in a non-QRS region follow a two mixtures GF with unknownmeans,variances andmixtureproportions,Such aGF basedapproximationshowntobegoodintheworkbyCliffordetal.
[21].WeusetheinverseofthecostoffittingatwomixtureGFasthe likelihoodofP/T-wavespresentatagivenpairoflocationswhen theselocationsareusedasthemeansof twomixtures.We use twotypesofthepriorinformationaboutthelocationsoftheP/T- peaks.Thefirstpriorusesthefactthatthelocationofthepeakof P-waveinithcycleisclosetoRi andthatofT-waveisclosetoi−1R . Thesecondpriorassumesthatthewaveformshapeofanon-QRS regiondoesn’tchangedrasticallyfromonecycletothenext,which, inturn,providesasmoothnessconstraintonthechangeinrelative positionoftheP/T-peaksfromonecycletothenext.Fromthelikeli- hoodandthepriorprobabilities,weconstructascorefunctiontobe
maximizedtofindtheoptimallocationsoftheP/T-peaks.Thismax- imizationisperformedefficientlyusingthedynamicprogramming technique.
2.2.1. Modelfittingcost
SupposeitisgiventhattheP/T-peaksarelocatedatpthandqth samplesoftheithnon-QRSregion(p,q∈Ki).Wefitatwomixture GFasshownbelow.
G(n,p,q)=˛1N(n;p,1)+˛2N(n;q,2), 1≤n≤L, (1) where
N(x;,)= 1
√22e−
(x−)2 22 ,
1 and2 arethevariancesoftwomixtures. ˛1 and˛2 arethe respectiveweightsofthemixtures.Theparameters={1,2,˛1,
˛2}areobtainedusinggradientdescentgiventhesamplesofZi[n], 1≤n≤L.GiventhemixtureGFmeanlocationspandq,theupdate equations2fori,˛i,i=1,2aregiveninAppendixA.
ToquantifythelikelihoodoflocationsoftheP/T-waveatpand qintheithnon-QRSregion,weusetheinverseofgoodnessoffitof themixtureGFasfollows:
Li[p,q]=
Ln=1
Zi[n]−G(n,p,q)2 −1, p,q∈Ki. (2)
We normalize this pseudolikelihood for all combinations of locations(Ki)togetthepseudoprobabilitymassfunctionovervari- ablespandqasfollows:
LNi[p,q]=
Li[p,q]p,q∈KiLi[p,q]. (3)
Thisallows ustocombinethis pseudoprobabilitymassfunction withthepriordistributiononthelocationsofP/T-peaksasdis- cussedinthefollowingsubsections.
2.2.2. Priors
Thelikelihoodfunctionobtainedabove(Eq.(3))maynotbesuf- ficienttolocatetheP/T-peaksaccuratelybecauseofthenoisein thedataandnon-convexityoftheMGFfitting.Henceweusetwo kindsofpriorsabouttheP/T-peaksintheECGsignals.Eachofthese priorsisexplainedbelow.
a.ThelocationofP-waveistypicallyclosetothebeginningofthe Qwaveand,similarly,T-waveisclosetotheendofS-wave.Due tosuchcommonpatternsinthelocationsofP/T-waves,Linetal.
[25],forexample,constrainedthesearchregionofPandTwaves tobethefirstandlast halvesofa non-QRSregion.Thiscon- straintmaynotbevalidinallnon-QRSsegmentsasshownina fewillustrativeECGcyclesinFig.3.Hence,inplaceofusinga hardconstraint,weuseasoftprioronthelocationsofP/T-peaks byexploitingthestatisticalnatureoftheiroccurrenceswithina non-QRSregion.WeassumethatthelocationoftheTpeakfol- lowsaˇ-probabilitydensityfunction(PDF),MT[n].Similarly,the PDFforthePpeaklocationisdenotedbyMP[n]asfollows:
MT[n]=
Ln(1−Ln)ˇ1−1
B(2,ˇ1) (4)
2NotethatthisoptimizationisdifferentfromthecasewheremeansoftheGaus- sianareincludedintheoptimizationvariablesalongwithvariancesandmixture weightswhichmakestheobjectivefunctionnonconvexandsensitivetotheinitial conditionassuggestedbyCliffordetal.[21].
Fig.3. ExemplaryECGcycles(sel48)highlightingthefactthatthepeakofaT-wave maynotalwaysbeinthefirsthalfofanon-QRSregion.Theblackdashedvertical linesindicatethemidpointofthenon-QRSregions.
Fig.4. BetapriorforpeaklocationofP-andT-wavesforˇ1=150andˇ2=50.
MP[n]=
nL ˇ2−1
(1−Ln)
B(ˇ2,2) (5)
where0≤n≤L,B(a,b)isthebetafunction[35].ˇ1,ˇ2are theparametersofthepriordistributions.ExemplaryMT[n]and MP[n]representing(ˇ1=150andˇ2=50)thepriordistribution ofthelocationsofP/T-peaksinanormalizednon-QRSregionare showninFig.4.
Theˇ prioralsomakestheproposedmethodfor P/T-wave delineationrobusttotheoccurrenceoftheU-waveandtheerror intheestimateofthelocationofRpeak.U-waveprimarilyoccurs inthemiddleofanon-QRSsegmentbetweenP-andT-waves.It couldbedominantcomparedtoeachofP-andT-waves.While thegoodnessoffitofthetwomixtureGFcouldbeerroneously highatthelocationoftheU-wave,thelocationoftheU-wave wouldhavealowweightˇ-prior,becauseitisinthemiddleof thenon-QRSregion.Thiswillreducethechanceoferroneously pickingtheU-wavesinP/T-wavedelineation.Similarly,ifthe locationoftheRpeakisestimatedwrongly,theactualRpeak couldappearintheverybeginningorendpartofanon-QRS regionandthegoodnessofthefitcouldbehighbecauseofits highamplitude.However,theˇpriorhelpsinavoidingsucherro- neousRpeakssincetheˇPDFhasverysmallvaluewhennis closetozeroorL.
b.ItisknownthattheheartrateandalsothelocationsofP/T-peaks do notchangedrasticallyfromonecycle tothenext[2].We assumethatbetterestimatesoftheP/T-peakscouldbeobtained byincorporatingthissmoothnessinthepeaklocationsacross cycles.Wequantifythissmoothnessconstraintbydefiningacost correspondingtothechangeintherelativepositionsoftheP/T- peaksintheconsecutivenon-QRSregions.Supposethelocations
Msmooth(p,q,p,q)= 1
122e− 212 − 222 , (6) wherethe1and2arethehyperparameterswhichcontrol thesmoothnessoftheP/T-peaks.ItisclearthatthecostMsmooth ishighwhenthereissmallchangeintheP/T-peaklocationsin neighboringcyclesmaximizingwhich,inturn,encouragesslow changeoftheP/T-peakslocationsacrossECGcycles.
2.2.3. Objectivefunction
Intheabovesubsectionswediscussedaboutthelikelihoodof P/T-peaklocations,thepriorsonthelocationsof theP/T-peaks and thesmoothnesscost of P/T-peaklocations inthe consecu- tivenon-QRSregions.LetNcbethenumberofnon-QRSregionsin ECG[n].ForagivenP/T-peaklocationatxj,yj∈Kjinthejthnon- QRSregionandxj−1,yj−1 ∈Kj−1inthe(j−1)thnon-QRSregion,we definetwokindsofcostsforjthnon-QRSregionnamely–within non-QRSregioncost Cw(xj,yj)and acrossnon-QRS regions cost Ca(xj,yj,xj−1,yj−1)asfollows
Cw(xj,yj)=LNj(xj,yj)MT(xj)MP(yj), 1≤j≤Nc (7) Ca(xj,yj,xj−1,yj−1)=
1 j=1 Msmooth(xj,yj,xj−1,yj−1) 1<j≤Nc(8) Thetotalcostgiventhesetoflocationsineachnon-QRSregion
(xm,ym):1≤m≤Nc isdefinedasthesumofthecostatNcnon- QRSregionsasfollows:Ctot(
(xm,ym):1≤m≤Nc
)=
Nc
m=1
Cw(xm,ym)Ca(xm,ym,xm−1,ym−1) (9)
The objective is to find the optimal set of indices’s
(x∗m,y∗m):1≤m≤Nc at each non-QRS region to maximize thetotalcost.ThenumberofpossiblecandidatesfortheP/T-peak locations can be further reduced by imposing the minimum distance constraint on the P/T-peaks (ym−xm≥dP,T) similar to [26].WheredP,Tdenotestheminimumdistancethresholdfound usingthevalidationdata.{(x∗m,y∗m):1≤i≤Nc}= argmax {xm,ym∈Km
(ym−xm)≥dP,T: 1≤m≤Nc}
Ctot(
(xm,ym):1≤m≤Nc
). (10)2.2.4. Dynamicprogramming
ThesolutiontotheobjectivefunctioninEq.(10)canbefound bysearchingoverallcombinationsof(xm,ym)∈Kmthatresults in
Nci=1|Ki|2numberofevaluationoftheobjectivefunction.How- ever,theoverallcostintheobjectivefunctioninEq.(10)isthesum oflocalcostswhichdependontheP/T-peaklocationsintwosuc- cessivenon-QRSregions.Weexploitthisnatureofthecostinthe objectivefunctionandsolvetheoptimizationusingdynamicpro- gramming,whosestepsareshowninAlgorithm1.Theoutputof thealgorithm(x∗m,y∗m)containsthelocationsofbothPandTpeaks inthemthnon-QRSregionwhichmaximizethecostshowninEq.
(10).
2.2.5. PandTwavedetection
Theproposedalgorithmestimatesthebestpossiblelocationof P-wave,irrespectiveofwhetherP-waveispresentorabsentina givennon-QRSregion.Itisobservedthat,intheabsenceofP-wave,
Pispresent |˛|˛2|
1|+|˛2|≥WP
Tispresent |˛|˛1|
1|+|˛2|≥WT
Fig.5.AsmoothP-orT-wave(bluecurve)anditsderivative(greencurve)are shown.Thezerocrossingsofthederivativeareconsideredastheonsetandend locationsofthewave.
thelocationestimatedbythealgorithmisclosertotheQ-wavedue tohighˇ-prior,butthecorrespondingvalueofthe˛2issmall.Inthe caseoftheT-wave,weobservesimilartrend.Hence,wedevelop criteriabasedontheseobservationstodeterminewhethertheP- andT-wavearepresentornot.Wedevelopthesecriteriabasedon the(xm∗,y∗m),˛1 and˛2 valuesofthemixtureGFat(x∗m,y∗m)sep- aratelyforP-andT-waves.ThecriteriaaregiveninTable1.The criteriaconsidersthepresenceofP-andT-waveswhenthenormal- izedvaluesof˛2and˛1aregreaterthanapre-definedthresholds WPandWTrespectively.
2.2.6. PandTwavedelineation
OnceweobtaintheP/T-peaks,weproposea delineationcri- terion based on the preprocessed waveform, since there is no universalruletolocatetheonsetsandendsofP/T-waves.Wecom- puteanapproximatederivativeofthesmoothsignalZiS[n]using centraldifference(Z
S
i[m+1]−ZiS[m−1]
2∗Ts ,Tsisthesamplingperiod)and findthelocationswhere thederivativecrosseszeroaroundthe locationsofP/T-peaks.ThelocationthatisbeforetheT-peakand thatisclosesttotheR-peakisconsideredastheT-onset.Theloca- tionthatisaftertheT-peakisconsideredasT-end.Similarly,the P-onsetandP-endarealsoobtained.ThisisillustratedinFig.5for asyntheticwave.
2.2.7. Relativepositiontoabsoluteposition
ThelocationsofP/T-peaksobtainedbythedynamicprogram- ming (x∗m,y∗m) correspond to the locations on the re-sampled versionofthenon-QRSregion.Thelocationsareconvertedtotheir absolutevalues usingthecorrespondinglengthof thenon-QRS region(NRR(m))asgivenbelow.
Tm=mS−1+x∗m×NRR(m) L Pm=mS−1+y∗m×NRR(m)
L ,
where. indicatesthenearestintegeroperation.mT andPmare usedastheestimatedP/T-peaklocations.Similarly,theonsetsand offsetsoftheP-andT-wavesarealsoconvertedtotheirabsolute locations.
Fig.6. IllustrationoftheP/T-delineationusingMGDP.(a)ECGsignalforsele0136.(b)Zoomedversionof(a)toshowthenon-stationarityofECGandtheblackverticallines indicatethecardiologistannotation.(c)Resampledandnormalizednon-QRSregionsZNwiththeestimatedlocationofthepeaksshownbytheblacklines.
Algorithm1. StepsforsolvingEq.(10)usingdynamicprogram- ming
Initialization:
Nc=Numberofnon−QRSregions
O1(x,y)=Cw(x,y)∀(x,y)∈K1(usingEq.(7)) foreachnon-QRSregionofECGlfrom2toNcdo
∀x,y∈Kl and (y−x)≥dP,T,do Ol(x,y)=min(a,b)∈Kl−1
Ol−1(a,b)+Cw(x,y)Ca(x,y,a,b)kl(x,y)=argmin
(a,b)∈Kl−1
Ol−1(a,b)+Cw(x,y)Ca(x,y,a,b)endfor
Backtracking:(x∗Nc,y∗Nc)=argmin
(a,b)∈KNc
ONc(a,b)foreachnon-QRSregionlfromNc−1to1do (x∗l,y∗l)=kl+1(x∗l+1,y∗l+1)
endfor
3. Experimentsandresults 3.1. Databaseandbaselinescheme
We evaluate the ECG delineation algorithm using QTDB database[36].ThisdatabaseincludestheECGsfromtwowidely useddatabases–MIT-BIHarrhythmiadatabase,theEuropeanST- TdatabaseandseveralotherECGdatabasescollectedatBoston’s BethIsraelDeaconessMedicalCenter.Theadditionalrecordings
includeextremesofcardiac(patho)physiology.Itcontainsatotal of105fifteen-minutesexcerptsoftwochannelECGsignalssam- pledat250Hz andatotalof3170beats(∼30–100beats within eachsubject)wasmanuallyannotatedbycardiologists,whoiden- tifiedthebeginning,peakandendoftheP-wave,beginningand end oftheQRS-complex, thebeginning,peak andend oftheT- wave(ifpresent),andthebeginning,peakandendoftheU-wave (ifpresent).ItshouldbenotedthattheQTDBhasnoannotatedECG cyclewithoutaT-wave.WeuseonlythefirstchannelofECGinall experimentsinthiswork.
We compare the proposed algorithm with recent P/T-wave delineation methods, namely GBI [9] and DEOS [24]. They are showntoperformbetterthanseveralECGdelineationtechniques includingthoseproposedbySunetal.[37]andSayadietal.[23]
respectively.
3.2. Evaluation
WeevaluatethetwomaintasksinECGdelineation–P/T-wave detectionandP/T-wavespeakandboundaryestimationusingthe followingmeasures.
•We evaluate the P/T-wave detection accuracy by calculat- ing the sensitivity Se=TP/(TP+FN) and positive predictivity
FPstandsforthenumberoffalsepositivedetection(waveisnot presentbutdetected).
•WeevaluatetheP/T-wavespeakandboundaryestimationaccu- racyusingrootmeansquarederror(RMSE)betweentheground truthlocationofpeakortheboundary(fk)andtheestimatedpeak ortheboundarylocation(ˆfk).FollowingtheworkbyLinetal.
[26],wealsocomputethemean(m)andstandarddeviation(s) asfollows:
RMSE= 1 K
K k=1e2k
m= 1 K
K k=1(ek), s= 1 K
K k=1(ek−m)2
where ek=(fk−ˆfk)and Kis thetotal number of annotated groundtruthlocationsinthedatabase.
•Weevaluatethespeed ofP/T-wavedelineationusing relative computationtime(RCT).Itprovidesanindicationofthespeed ofanalgorithmandiscomputedasfollows
RCT(%)=100 CPUtime(s) durationECG(s)
whereCPUtime(s)isthetimeinsecondstakenbyanalgorithm andDurationECG(s)isthedurationoftheECGsignalinseconds.
3.3. Experimentalsetup
1Preprocessing:The ECGsignalis filteredusinga linearphase FIRfiltertoremovehighfrequencynoise.Thebaselinedriftis removedusing[30]andtheQRS-wavesaredetectedusingthe methodoutlinedin[29].Theheartratecangoaslowas40BPM.
Thus,lengthofanon-QRS regioncangoashighas375sam- ples.Hence,wedecidetochooseL>375.Eachnon-QRSregion isresampledtothelengthL=1000.Eachresamplednon-QRS regionissmoothedusingSGolayfilteroflength101andorder2.A totaloftenvalleysandtenpeaks(correspondingtothetenhigh- estabsoluteamplitudes)are computedfrom everysmoothed non-QRSregion.
2MGDP:ThehistogramsofthegroundtruthlocationsoftheP/T- peaksandU-waveinanormalizednon-QRSregionsareshown inFig.7.ThisshowsthatthebetapriorfortheP/T-peaklocation inanormalizednon-QRSregioncouldbeagoodfit.Italsoshows thatthelocationvariabilityfortheT-peakismorethanthatof theP-peak.TheU-waveappearstoclosertotheT-peakthanthe P-peak.Thehyperparametersofthemodelsaretunedusingaval- idationset,10%randomsubsetoftheannotateddata,whichisnot usedintheevaluation.ThehyperparametersdP,T=150,ˇ1=220, ˇ2=110,1=80and2=80arefoundbyminimizingtheaverage RMSEerrorinthedetectedP/T-peaklocation.WP=0.1isusedto maximizetheP-wavedetectionaccuracy.3
3.3.1. Onetypicalexample
Forillustration,theP/T-wavedelineationisperformedbyapply- ingtheproposedMGDPmethodonthedataset“sele0136”ofQTDB,
3 QTDBhasnoannotatedECGcyclewithoutaT-wave,and,hence,theWTthresh- oldisnotcomputed.
Fig.7. HistogramofP-,T-andU-wavelocationinthenormalizednon-QRSregion.
aportionofwhichisshowninFig.6(a)and(b).Thisexamplehas beenchosen becausesignalsfrom this datasetcontainsudden rhythmchangeswithobviousamplitudevariationsasshownin Fig.6(b).Fromthefigureitisclearthatthewavepeaksaredetected accuratelyusingMGDPinspiteofsuddenbeatchange.Fig.6(c) showsthere-sampledandnormalizedmatrix(ZN)corresponding totheECGsignal.FromFig.6(b),itisinterestingtonotethatthe P-wavesarecorrectlydetectedeventhoughtheirstrengthreduces significantlyafterfifthnon-QRSregion.Thisismainlyduetothe maximizationoftheproposedscorefunctionthatensuressmooth trajectoriesfortheP-aswellasT-wavethatbestfiteverynon-QRS region.
3.3.2. P-andT-wavedelineationfordifferentwavemorphologies Weconsiderotherillustrativeexamples,where,weevaluatethe proposedalgorithmondifferentwavemorphologiesthatoccurdue todifferentclinicalconditionsfourofwhichareshowninFig.8.It isclearfromthefigurethattheMGDPisabletodetecttheP/T- peaksaccuratelyinallfourcases.Forexample,aninvertedT-wave ispresentintheFig.8(a),abi-phasicT-peakispresentinFig.8(b) and(c);inspiteofthesemorphologicaldifferences,theP/T-peaks aredetectedaccurately.TheP/T-peaksaredetectedaccuratelyeven inthepresenceofU-waveinFig.8(d)–(f),inspiteofitbeingmore dominantthantheP/T-wave.ItsuggeststhatthetwomixtureGF assumptiononthewaveshapesis genericand alsoeffectivein detectingtheP/T-peaksincaseofdifferentwaveshapes.
3.3.3. RobustnesstoRR-peakerror–anillustration
Mostof theP/T-wavedelineationmethods [9]includingthe MGDPmethodrequires aprior QRSdetection.Error intheQRS detectioncan causeerrors in P/T-wave delineation.To testthe robustnessofalgorithm toQRSdetectionerrors,wehaveadded arandom±20samplenoisetotheannotatedQRS-peaklocations andthendetecttheP/T-peaksusingMGDP.ThenoisyR-peaksand thedetectionresultsareshowninFig.9(a).Itisclearfromthefig- urethatthedetectedP/T-peaksarestillaccuratewiththeRR-peak error.Thisisbecauseoftheˇpriorwhichislowforthedominant peaksthatappearneartheboundariesofthenon-QRSregion.Most oftheP/TpeaksaredetectedcorrectlyusingMGDP,butthesome ofthemarebiasedtowardtheR-peaksasshowninFig.9.Thenor- malizedmatrixZNisalsoshownin9(b),wherethisbiasnessis clearnear30th–35ths.ItisclearthatduetotheR-peakdetection errors,theZNisaffectedonlyinthetopandbottomrows.However, theMGDPdoesnotselectthosehighvaluedpartsintheoptimal trajectoriesforP/T-peaks.
3.4. Resultsanddiscussion
TheP/T-wavedetectionSeandP+areshowninTable2.Itshould benotedthattheQTDBhasnoannotatedECGcyclewithoutaT-
Fig.8. IllustrativeexamplesofP/T-delineationonECGusingMGDPfordifferentwavemorphologies.Blackverticallinesindicatethelocationsfromthecardiologistannotation ofP/T-peaks.(a)sel306:InvertedT-wavethatoccursduetomyocardialischaemia(b)sele409:biphasicT-wavewheretheT-waveappearsinthemiddleofthenon-QRS region(c)sel42:biphasicT-wavefromasuddendeathpatient(d–f)sele0126,sel103,sel4172:ECGwithU-waveduetohypokalaemia.
Fig.9. IllustrationoftherobustnessoftheMGDPtoerrorinR-peakdetection.(a)DetectedP/T-peaklocationsbyMGDPwhenthedetectedR-peaksareerroneous.(b)The matrixZNwiththedetectedP/T-peaklocationsshownbythedottedredlines.
wave.HencewecomputeSeandP+onlyfortheP-wave.TheMGDP outperformsDEOSandGBIinSeby0.15%and0.37%respectively.
TheMGDPoutperformsDEOSandGBIinP+by0.66%and0.77%
respectively.WeobservethatMGDPisabletoclassifythepresence orabsenceofP/T-peaksinthenoisyconditionsmoreaccurately comparedtothebaselineschemes.Thehistogramsofthe|˛|˛2|
1|+|˛2|
P+ Se RMSE m±s P+ Se RMSE m±s
MGDP 67.18 95.39 96.04 0.085 3.55(13.7) 100 96.21 0.091 3.65(10.25)
DEOS 424.6 94.73 95.89 0.229 7.87(15.35) 100 94.82 0.127 7.20(14.65)
GBI 24.63 94.60 95.67 0.088 4.235(14.7) 100 96.92 0.231 13.09(25.0)
Fig.10.Histogramcomparisonof|˛|˛2|
1|+|˛2|foranon-QRSregionwithandwithoutP-wave.
Fig.11.ComparisonofhistogramoftheerrorinestimatingP/T-peaksforMGDP,DEOSandGBI.ForT-peaktheGBIexcludedbecauseofitslargebias.
Table3
ComparisonofevaluationmetricsfordifferentmethodsindetectingP/T-boundaries.
Method Pon Pend Ton Tend
RMSE m±s RMSE m±s RMSE m±s RMSE m±s
MGDP 0.0861 63.7(30) 0.0645 58.4(13.5) 0.0928 64.2(29.8) 0.0560 48.8(38.4)
DEOS 0.2126 158(52.9) 0.2200 124.1(83.1) 0.1937 135.95(69.6) 0.1083 92(39.6)
GBI 0.0976 78.9(26.3) 0.0970 68.2(33) 0.5949 259.00(119.3) 0.4249 179.9(83.3)
valueforanon-QRSregionwithP-waveandwithoutP-waveare showninFig.10.Itisclearfromthefigurethatthevaluesof|˛|˛2|
1|+|˛2|
arewellseparatedforthesetwoclasses.
TheRMSEofestimatingtheP/T-peaksisalsoshowninTable2.
ForP-peak,itisclearfromthetablethatMGDPdoesbetterthan bothGBIandDEOSintermsofRMSEby0.003sand0.1440srespec- tively.Fig.11(a)comparesthehistogram oferrorek for P-peak usingdifferentmethods.Itcanbeobservedfromthefigurethat forMGDP,theerrorisconcentratedmorearoundzerocompared toDEOS.ForDEOS,thereissignificanterroraround-150ms,we observethatthishappensduetodetectingthedominantU-wave asP-wave.ForT-peak,itisclearfromthetablethatMGDPper- formsbetterthanbothGBIandDEOSintermsofRMSEby0.14s and0.036srespectively.FromFig.11(b)itcanbeobservedthat
thereisasignificanterroraround100msforDEOS,thisisbecause oferror indetectingthedominantbi-phasicT-wave. Theaccu- racyofdetectingtheP/T-waveboundariesisshowninTable3.It isclearfromthetablethattheMGDPperformsbetterthanboth GBIandDEOSbothintermsofRMSEandmeanerror.Itisclear fromthetablethatthere isa largebiasin thedetectionofthe boundaries.We observethattheboundariesaremostlyaffected in case of bi-phasicT-wave, Q and S-wavesand createa large bias.
Table2showsRCT(%)fordifferentmethods.Itisclearfromthe tablethattheproposedmethodis36%(absolute)morecomputa- tionallycomplexthantheGBIandlesscomputationallycomplex thantheDEOS.TheRCT(%)oftheproposedmethodisstilllessthan 100%and,hence,itcanbeusedforrealtimeapplication.