A Graph-Constrained Changepoint Learning Approach for Automatic QRS-Complex Detection
AA Graph-Constrained Changepoint Learning Approach forAutomatic QRS-Complex Detection
Atiyeh Fotoohinasab, Toby Hocking, and Fatemeh Afghah,
Abstract — This study presents a new viewpoint on ECGsignal analysis by applying a graph-based changepointdetection model to locate R-peak positions. This modelis based on a new graph learning algorithm to learnthe constraint graph given the labeled ECG data. Theproposed learning algorithm starts with a simple initialgraph and iteratively edits the graph so that the finalgraph has the maximum accuracy in R-peak detection. Weevaluate the performance of the algorithm on the MIT-BIHArrhythmia Database. The evaluation results demonstratethat the proposed method can obtain comparable resultsto other state-of-the-art approaches. The proposed methodachieves the overall sensitivity of
Sen = 99.64%, positivepredictivity of
PPR = 99.71%, and detection error rate of
DER = 0.19.
Index Terms — Changepoint detection, ECG fiducialpoints detection, Constraint learning, Graph learning.
I. INTRODUCTIONThe electrocardiogram (ECG) is a quasi-periodicbiomedical signal, which serves as the most commonlyused non-invasive tool in the diagnosis of cardiovasculardiseases. One cardiac cycle in a typical ECG signal isidentified by arrangements of P, QRS-complex, and Twaveforms as well as PQ and ST segments. In mostautomated ECG analysis tools, correct R-wave detectionis of great importance as it is used for detecting otherECG fiducial points and is served a significant criterionfor the diagnosis of many heart arrhythmias. Neverthe-less, efficient R-peak detection is still a challenging taskdue to the time-variant waveform morphology caused bynoise corruption or a specific cardiac condition.There are various methods in the literature that havebeen proposed to detect R-peak in ECG signal [1]. How-ever, these methods mainly suffer from some criticaldrawbacks that limit their implementations in practicalapplications. First, the non-stationary morphology of theQRS complex can lead to the misdetection of R-peak,especially in some determinant morphological patternsconcerning certain life-threatening heart arrhythmias.Considering this limitation, it is apparent that incorrectidentification of other waves can occur subsequent to theincorrect detection of R-peaks. Second, the performanceof most R-peak detection algorithms highly depends ona preprocessing step to remove the impact of differenttypes of noise contaminating the ECG signal. However,
A. Fotoohinasab, T. Hocking and F. Afghah are with the Schoolof Informatics, Computing and Cyber Systems at Northern ArizonaUniversity. in real-time data processing and ambulatory care set-tings, preprocessing-based algorithms are less effective.Several studies have utilized deep learning techniques todetect the ECG waveforms motivated by the high perfor-mance of deep learning methods in various classificationtasks [9]. However, the problem with deep learning-based algorithms is that they need large scale datasets totrain the algorithm and often suffer from the imbalancedclass problem [8].In [4], we introduced a new class of graph-based sta-tistical models based on optimal changepoint detectionmodels, named graph-constrained changepoint detection(GCCD) model to locate R-peak in the ECG signal.This work was the first study performed to apply achangepoint detection model for extracting ECG fiducialpoints. The GCCD model is constrained to a graphunder which prior biological knowledge of the signal istaken into account in order to accomplish the segmen-tation task. However, the performance of the previousGCCD model depends on the choice of the constraintgraph, which is manually defined by an expert withprior knowledge. To tackle this issue, in this paper, wepropose a new graph-based changepoint detection modelthat learns the structure of the constraint graph in thelabeled ECG data. It is worth mentioning that, like theprevious model, the proposed method does not requireany preprocessing step as it leverages the sparsity ofchangepoints to denoising the signal as well as detectingabrupt changes.The rest of the paper is organized as follows. Inthe next section, we describe the proposed Graph-Constrained Changepoint Detection model and its appli-cation in the localization of R-peak. Section III providesa description of the dataset used in this study and adiscussion of the results as well as a comparison betweenthe performance of the proposed algorithm and otherstate-of-the-art algorithms. Finally, IV summarizes thisresearch work and its contributions.II. M
ETHODOLOGY
In [4], we developed an initial GCCD model based ona manually defined constraint graph using regarding thelabeled ECG data. This GCCD model extracted the R-peaks in an ECG signal by representing the periodic non-stationary ECG signal as a piecewise-stationary timeseries with constant mean values per segment [4]. Toautomate the ECG segmentation task, we propose a new a r X i v : . [ ee ss . SP ] F e b odel, which takes a raw ECG signal and an initialgraph structure as its inputs and yields the onset/offsetand the mean of desired segments regarding the structureof the learned constraint graph. The model architecture iscomposed of two steps, including training and detection.The training phase is utilized for optimizing the structureof the constraint graph. It takes the raw ECG signaland an initial graph structure as the inputs and tries tofind an optimum graph structure that can minimize thelabel errors over the training set. Then, the changepointdetection model extracts the R-peaks in the raw ECGrecord subject to the trained graph from the previousstep. In the following sections, we describe the detailsof various parts of the proposed model. A. Graph-Constrained Changepoint Detection Model
ECG waves can be considered as abrupt up or downchanges over time per cardiac cycle. Thus, we employthe optimal changepoint detection model introduced in[6] to localize R-peak positions in the ECG signal. Inthis framework, the prior biological knowledge about theexpected sequence of changes are specified in a graphas the model constraints. Then, a functional pruningdynamic programming algorithm is used to compute theglobally optimal model (mean, changes, hidden states)in fast log-linear O ( N log N ) time.The constraint graph can be defined with a directedgraph G = ( V, E ) , where a vertex set V ∈ { , . . . , | V |} represents the hidden states/segments (not necessarily awaveform), and the edge set E ∈ { , . . . , | E |} repre-sents the expected changes between the states/segments.Each edge e ∈ E encodes the following associateddata based on the prior knowledge about the expectedsequences of changes: • The source v e ∈ V and target v e ∈ V ver-tices/states for a changepoint e from v e to v e . • A non-negative penalty constant λ e ∈ R + which isthe cost of changepoint e . • A constraint function g e : R × R → R whichdefines the possible mean values before and aftereach changepoint e . If m i is the mean beforethe changepoint and m i +1 is the mean after thechangepoint, then the constraint is g e ( m i , m i +1 ) ≤ . These functions can be used to constrain thedirection (up or down) and/or the magnitude of thechange (greater/less than a certain amount).Given the input signal Y = { y , . . . , y n } and thedirected graph G = ( V, E ) , the problem of findingchangepoints c , segment means m , and hidden states s can be mathematically stated as follows; minimize m ∈ R N , s ∈ V N c ∈{ , ,..., | E |} N − N (cid:88) i =1 (cid:96) ( m i , z i ) + N − (cid:88) i =1 λ c i (1)s. t no change: c i = 0 ⇒ m i = m i +1 & s i = s i +1 (2)change: c i (cid:54) = 0 ⇒ g c i ( m i , m i +1 ) ≤ s i , s i +1 ) = ( v c i , v c i ) . (3)where the segment means m , the hidden states s , andthe changepoints c are the optimization variables. Also,the changepoints c i can be any of the pre-defined edges( c i ∈ { , . . . , | E |} ), or c i = 0 which indicates nochange (and has no cost, λ = 0 ). The above objectivefunction (1) consists of a data-fitting term (cid:96) and a modelcomplexity term λ c i . (cid:96) represents the negative log-likelihood of each data point, and λ c i is a non-negativepenalty on each changepoint. The constraint function g e also encodes the expected up/down change and theleast amplitude gap between the mean of two states. Theconstraint (2) enforces the model to keep its currentstate s i = s i +1 with no change in mean m i = m i +1 when there is no change c i = 0 . On the other hand, theconstraint (3) forces a change in the mean implied by theconstraint function g c i ( m i , m i +1 ) ≤ , and a change inthe state ( s i , s i +1 ) = ( v c i , v c i ) when there is a change c i (cid:54) = 0 . B. Constraint Graph Learning
The constraint graph G = ( V, E ) in the optimizationproblem of (1) can be designed manually or in alearning framework. In [4], we constructed the constraintgraph, including the graph topology and edge informa-tion manually using some pre-specified categories foreach waveform [12]. However, the manual definition ofthe constraint graph can be inefficient for ECG signalanalysis considering the various morphological patternsfor each waveform. Besides, the performance of themodel depends on the expert knowledge while encodingthe prior knowledge into the constraint graph. Therefore,in this work, we propose a graph learning algorithm forlearning the constraint graph using the R-peak labelsprovided by a gold standard.The goal of constraint graph learning is to automati-cally discover the desired graph topology property (i.e.,identifying the desired V and E sets in graph G ) and theinformation of edges from data. In this study, the edgeinformation consists of the expected up/down changein the segment means, the least amplitude gap betweenthe mean of two states, and a non-negative penaltycorresponded to the edge transition. In order to learn theconstraint graph, the proposed graph learning algorithmstarts with an initial graph, including an initial graphtopology and an initial edge information set; and then,iteratively optimizes the graph parameters to find a graph 𝒏 𝑽 𝒊 ൗ𝝀 2 𝑽 𝒋 ൗ𝝀 2↑, ൗ𝑔 2 ↑, ൗ𝑔 2𝑽 𝒋 𝑽 𝒊 𝝀↑,𝑔 𝑽 𝒏 𝑽 𝒊 ൗ𝝀 2 𝑽 𝒋 ൗ𝝀 2↓,𝑔 = 0 ↑,𝑔𝑽 𝒏 𝑽 𝒊 ൗ𝝀 2 𝑽 𝒋 ൗ𝝀 2↑,𝑔 ↓,𝑔 = 0 a) Initial Graph b) Add One Node 𝑽 𝒋 𝑽 𝒊 𝜆 𝑽 𝒔 𝜆 ↑, 𝑔 ↓, 𝑔 𝑽 𝒔 𝑽 𝒊 𝜆 + 𝜆 ↑, 𝑔 𝑽 𝒔 𝑽 𝒊 𝜆 + 𝜆 ↓, 𝑔 d) Delete One Node 𝑽 𝒋 𝑽 𝒊 𝝀↑, 𝑔 𝑽 𝒋 𝑽 𝒊 c) Increase/Decrease Penalty RB 𝝀 = , 𝑔 =100 , 𝑔 =100 𝝀 = (1) a: The initial constraint graph with two nodes labeled as B and R , representing the baseline and the R-peaksegments, respectively, in a cycle. b-d: Some of the applied graph editing candidates related to the edge ( V i , V j ) with an up change.that maximizes the accuracy regarding the given labels.Figure 1a shows the simple initial graph used for theoptimization process. It should be noted that the initialedge information is chosen based on the overall resultsobtained from the manual definition of the constraintgraph.The algorithm considers 10 editing candidates peredge to heuristically determine the graph candidate setin each iteration. Graph editing candidates set in theproposed algorithm consists of three types of addinga node, two types of deleting a node, one type ofadding two nodes, and increasing or decreasing thepenalty and gap corresponding to an edge. We believeall morphological patterns of the ECG waveforms canbe constructed using these editing candidates. Figure 1exemplifies some of the applied graph editing candidatesrelated to the edge ( V i , V j ) with an up change.III. E XPERIMENTAL S TUDIES
A. Dataset
We applied the publicly available MIT-BIH arrhyth-mia (MIT-BIH-AR) database to evaluate the proposedmodel [7], [5]. The MIT-BIH-AR database contains48 ECG recordings taken from 47 subjects, and eachrecording is sampled at 360 Hz for 30 min with 200samples resolution over a 10 mV range. Each recordingconsists of two ECG leads, including leads V1, V2, V4,V5, and the modified lead II (MLII). Only the MLII andV5 are used to evaluate the performance of the algo-rithm. The database is annotated with both RR intervalsand heartbeat class information by two or more expertcardiologists independently. We employ the provided annotations for R-wave positions in order to train themodel and evaluate its performance. The training andtesting sets are also generated by randomly dividing theECG cycles per records with an approximate ratio of3:1.
B. Experimental Results
Figure 2 demonstrates the performance of the pro-posed model in the localization of R-peak for subject107 from the MIT-BIH-AR dataset. This figure illus-trates how the proposed algorithm iteratively edits thesimple initial graph to find a graph with maximumaccuracy in detecting R-peaks regarding the labels inthe training set. The red part of the graph in eachiteration shows the modified part of the graph regardingthe constraint graph in the previous iteration. It is worthnoting that the performance of the proposed algorithmdepends on the initial graph structure. Therefore, themodels for 5 records out of all records are trained basedon a more complex initial graph than the initial graphin 1a. We evaluate the performance of the proposed al-gorithm using the sensitivity (Sen), positive predictivityrate (PPR), and detection error rate (DER), which aredefined as below:
Sen (%) =
T PT P + F N × (4) PPR (%) =
T PT P + F P × (5) DER (%) =
F N + F PT P + F N × (6) 𝝀 = , 𝑔 =100 , 𝑔 =100 𝝀 =
25 ∗ 10 R 1 , 𝑔 =0 𝝀 =
25 ∗ 10 , 𝑔 =100 𝝀 =
25 ∗ 10 R 1 , 𝑔 =100 𝝀 ≅ 16 ∗ 10 B 2 3 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 =
25 ∗ 10 , 𝑔 =200 𝝀 =
25 ∗ 10 R 1 , 𝑔 =100 𝝀 ≅ 16 ∗ 10 B 2 3 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 =
25 ∗ 10 , 𝑔 =400 𝝀 =
25 ∗ 10 R 1 , 𝑔 =100 𝝀 ≅ 16 ∗ 10 B 2 3 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 =
25 ∗ 10 , 𝑔 =400 𝝀 =
25 ∗ 10 R 1 , 𝑔 =100 𝝀 ≅ 16 ∗ 10 B 2 3 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 =
25 ∗ 10 , 𝑔 =400 𝝀 =
25 ∗ 10 R 1 , 𝑔 =100 𝝀 ≅ 16 ∗ 10 B 2 3 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 =
25 ∗ 10 (e) (f)(c) (d)(a) (b) , 𝑔 =400 𝝀 =
25 ∗ 10 R 1 , 𝑔 =100 𝝀 ≅ 16 ∗ 10 B 2 3 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 ≅ 16 ∗ 10 , 𝑔 =0 𝝀 =
25 ∗ 10 (a) (2) The demonstration of constraint graph optimization using the proposed graph learning algorithm for thesubject 107 from the MIT-BIH-AR dataset. a-e top: Extracted R-peak positions given the learned constraint graphin each learning iteration. The red and orange coverage bands show the used labels in the training procedure,including both training and validation sets. a-e bottom:
The learned constraint graph in each learning iteration.Below each edge e , we show the penalty λ e , and above, we show the type of change (i.e., up/down) and the gap,which is the minimum magnitude of change. The red part of the graph in each iteration shows the modified partof the graph regarding the constraint graph in the previous iteration. f: Testing the final learned constraint graph ina new window of data. The orange coverage band shows the labels provided by the MIT-BIH-AR dataset.3) Label errors in detection of R-peak positionsregarding the learned constraint graph per 5 learningiterations for subject 107 in the MIT-BIH-AR dataset.where TP is true positives, FP is false positives, FN isfalse negatives, and TN is true negatives. We used k -foldcross-validation approach to train and test the proposedmodel with a k size of 5. Indeed, we divided the datasetinto k= 5 folds. Then, for each fold of the 5 folds, onefold is used for evaluating the model, and the remaining4 folds are used to train the model. In the end, the finalresult was averaged over all 5 folds. Figure 3 illustratesthe training progress over 5 iterations for record 107from the MIT-BIH-AR dataset, where the Y axis showsthe sum of false negative and false positive error rates.Table I represents the R-peak detection success forthe proposed algorithm against other state-of-the-artmethods. As shown in the table, the proposed algorithmachieves remarkable results, Sen = %99.64,
PPR =%99.71, and
DER = 0.19, in R-peak detection. We notethat here our remarkable results were obtained regardlessof a preprocessing step, as opposed to other methods inthe literature. We noticed that the records with
Sen and
PPR values lower than 99% contain multiple differentmorphological patterns. In these records, more thanone optimum graph path is required in the constraintgraph in order to detect R-peaks. The performance ofthe proposed model for such cases can be improvedby learning a multi-path constraint graph, which isconsidered as future work. Besides, learning a multi-path constraint graph can be applied for detecting allECG waveforms as considering morphological patternsof each waveform leads to having cycles with completelyvarious morphological patterns.(I) Comparison of performance of several R-peakdetection methods using the MIT-BIH-AR database
Method
Sen (%)
PPR (%)
DER (%) P ark et al. [10] 99.93 99.91 0.163 F arashi [3] 99.75 99.85 0.40 S harma and Sunkaria [11] 99.50 99.56 0.93 C astells-Rufas and Carrabina [2] 99.43 99.67 0.88 Proposed Model 99.64 99.71 0.19
IV. C
ONCLUSION
In this paper, the task of R-peak detection in the ECGsignal is carried out based on a new viewpoint using achangepoint detection model. The proposed algorithmuses a changepoint detection algorithm constrained toa graph in which prior biological knowledge of theexpected changepoints per cardiac cycle is encoded. Wepropose an algorithm for learning the constraint graphin labeled data. The proposed learning algorithm startsfrom an initial graph and optimizes the structure of theconstraint graph as well as the edges information tofind a model that can maximize the detection accuracy.The results provided in this paper demonstrates thatchangepoint detection models constrained to a graphare promising approaches for detecting ECG waveforms.The proposed learning algorithm can be advanced tolearn a multi-path constraint graph in order to detectall ECG waveforms and find the overall ECG morpho-logical patterns per cardiac cycle.R
EFERENCES[1] Idoia Beraza and I˜naki Romero. Comparative study of algorithmsfor ecg segmentation.
Biomedical Signal Processing and Control ,34:166–173, 2017.[2] David Castells-Rufas and Jordi Carrabina. Simple real-time qrsdetector with the mamemi filter.
Biomedical Signal Processingand Control , 21:137–145, 2015.[3] Sajjad Farashi. A multiresolution time-dependent entropymethod for qrs complex detection.
Biomedical Signal Processingand Control , 24:63–71, 2016.[4] Atiyeh Fotoohinasab, Toby Hocking, and Fatemeh Afghah. Agraph-constrained changepoint detection approach for ecg seg-mentation. In ,pages 332–336. IEEE, 2020.[5] Ary L Goldberger, Luis AN Amaral, Leon Glass, Jeffrey MHausdorff, Plamen Ch Ivanov, Roger G Mark, Joseph E Mietus,George B Moody, Chung-Kang Peng, and H Eugene Stanley.Physiobank, physiotoolkit, and physionet: components of a newresearch resource for complex physiologic signals. circulation ,101(23):e215–e220, 2000.[6] Toby Dylan Hocking, Guillem Rigaill, Paul Fearnhead, andGuillaume Bourque. A log-linear time algorithm for constrainedchangepoint detection. arXiv preprint arXiv:1703.03352 , 2017.[7] George B Moody and Roger G Mark. The impact of the mit-biharrhythmia database.
IEEE Engineering in Medicine and BiologyMagazine , 20(3):45–50, 2001.[8] S. Mousavi and F. Afghah. Inter- and intra- patient ecg heartbeatclassification for arrhythmia detection: A sequence to sequencedeep learning approach. In
ICASSP 2019 - 2019 IEEE Interna-tional Conference on Acoustics, Speech and Signal Processing(ICASSP) , pages 1308–1312, 2019.[9] Sajad Mousavi, Atiyeh Fotoohinasab, and Fatemeh Afghah.Single-modal and multi-modal false arrhythmia alarm reductionusing attention-based convolutional and recurrent neural net-works.
PloS one , 15(1):e0226990, 2020.[10] Jeong-Seon Park, Sang-Woong Lee, and Unsang Park. R peakdetection method using wavelet transform and modified shannonenergy envelope.
Journal of healthcare engineering , 2017, 2017.[11] Tanushree Sharma and Kamalesh Kumar Sharma. Qrs complexdetection in ecg signals using locally adaptive weighted totalvariation denoising.
Computers in biology and medicine , 87:187–199, 2017.[12] Reza Tafreshi, Abdul Jaleel, Jongil Lim, and Leyla Tafreshi.Automated analysis of ecg waveforms with atypical qrs com-plex morphologies.