# An Improved Sliding Window Area Method forT Wave Detection

Authors: Haixia Shang; Shoushui Wei; Feifei Liu; Dingwen Wei; Lei Chen; Chengyu Liu
Journal: Computational and Mathematical Methods in Medicine
 (2019)

---

## Abstract

Background. The T wave represents ECG repolarization, whose detection is required during myocardial ischemia, and the first significant change in the ECG signal is being observed in the ST segment followed by changes in other waves like P wave and QRS complex. To offer guidance in clinical diagnosis, decision-making, and daily mobile ECG monitoring, the T wave needs to be detected firstly. Recently, the sliding area-based method has received an increasing amount of attention due to its robustness and low computational burden. However, the parameter setting of the search window’s boundaries in this method is not adaptive. Therefore, in this study, we proposed an improved sliding window area method with more adaptive parameter setting for T wave detection. Methods. Firstly, k-means clustering was used in the annotated MIT QT database to generate three piecewise functions for delineating the relationship between the RR interval and the interval from the R peak to the T wave onset and that between the RR interval and the interval from the R peak to the T wave offset. Then, the grid search technique combined with 5-fold cross validation was used to select the suitable parameters’ combination for the sliding window area method. Results. With respect to onset detection in the QT database, F1 improved from 54.70% to 70.46% and 54.05% to 72.94% for the first and second electrocardiogram (ECG) channels, respectively. For offset detection, F1 also improved in both channels as it did in the European ST-T database. Conclusions. F1 results from the improved algorithm version were higher than those from the traditional method, indicating a potentially useful application for the proposed method in ECG monitoring.


---

## Body

## 1. Introduction

Nowadays, an increase in the number of people suffering from heart diseases has been seen. Characterized by several waveforms such as theP wave, QRS complex, and T wave, electrocardiogram (ECG) becomes the most intuitive and basic tool to diagnose heart diseases in clinical applications which can provide essential physiological/pathological information for clinical diagnoses and decision-making [1], including important time interval information between the onset and offset of different waves [2]. Besides, many wearable monitoring devices have appeared in recent years, which makes it possible to monitor ECG signals throughout an individual’s daily life. Meanwhile, a large amount of ECG data are generated daily, which is impossible for physicians to view/diagnose each ECG signal manually [3]. Therefore, developing accurate automatic analysis algorithms for ECG signals is critical, especially with respect to mobile ECG monitoring [4]. Furthermore, QRS complex have been widely investigated because of its highest amplitude over the past decades. Up to now, there are many classical methods for detecting QRS complex and most of the methods have been listed in [5], and the classical widely-used methods are parabolic fitting [6], neural-network-based method [7], and convolutional neural network [8]. In addition, those methods for detecting the QRS complex have shown high sensitivity with positive predictivity (>99%) on the MIT-BIH arrhythmia database [9], which can provide powerful support for other waves’ detections.As one of three main waves of ECG, theT wave represents ECG repolarization, and its absence or unusual shapes may signify disruption in repolarization or another segment of the heartbeat [10]. Additionally, T wave abnormalities are associated with some heart diseases such as inverted T waves found in other leads (other than the V1 to V4 leads), which is related to an increase in cardiac deaths, and a tall or wide QRS complex with an upright T wave is further suggestive of a posterior infarction. Furthermore, during myocardial ischemia, the first significant change in ECG signal is being observed in ST-segment followed by changes in other waves like P wave and QRS complex of ECG signal. Hence, detection of the T wave is significant in clinical applications [11].However, accurate/robustT wave detection still presents challenges due to its low amplitude (usually 0.1 to 0.3 mV) as well as great variations in T waves’ morphologies [12], like positive T wave, negative T wave, and biphasic T wave. Besides, most of the ischemic cases suffering from earlier STEMI (ST-elevation myocardial infarction) have a prominent ST elimination or depression, which significantly affects the detection of the T onsets. Nowadays, various approaches based on different techniques have been proposed for T wave detection, and those typical techniques are wavelet [13, 14], mathematical model [15], support vector machine (SVM) [16], artificial neural network (ANN) [17–19], low-pass differentiation (LPD) [20], hidden Markov model (HMM) [21, 22], partially collapsed Gibbs sample and Bayesian (PCGS) [23], “wings” function [24], derivative curve [25], adaptive technique [26], computing the Trapezium’s area [27], TU complex analyses [28], correlation analysis [29], k-nearest neighbor [30], and sliding window area (SWA) [31]. In these aforementioned methods, the wavelet-based method is robust to waveform morphological variations but is sensitive to noise [13, 14]. The mathematical model method needs to build robust ECG templates, but when the waveform variations are large, building universal templates becomes difficult [15]. The SVM-based method is efficient but constructing efficient features is tough [16], and the ANN-based method faces the drawback of high computational complexity [17]. As a comparison, the SWA method has low computational complexity which is also robust to noise and waveform morphological variations [31].In 2006, Zhang et al. first proposed the SWA method for detectingT wave offsets and confirmed its efficiency in the QT database [31]. Subsequently, Song et al. improved this method for detecting T wave onsets [32]. Afterwards, our team combined onsets and offsets detection for classifying the morphology of the ST segment [33]. In 2017, our team analyzed its efficiency in the QT database with a different evaluation index (F1 measure), and we found that there is still some space for further improvement since the parameter settings in the transitional SWA method are not adaptive [34], and the parameters given by Zhang et al. [31]and Song et al. [32] are empiric values and there is no optimization step included.Hence, in this study, an improved SWA method for both onset and offset detections ofT wave with more adaptive parameter settings is proposed. The performance of the improved method was compared with the traditional method, and both methods were validated in two common ECG databases: (1) the QT database (training and testing) and (2) another independent European ST-T database (only testing).


## 2. Methods

### 2.1. Data

Records from two datasets are used. The first is the QT database, which contains 105 15-minute two-channel ECG recordings with the sample rate of 250 Hz, and we chose it as the training and testing sets because multiple-type records from different databases are contained in this database. Besides, totally 43 recordings have manually annotatedT wave onsets and 103 recordings have manually annotated T wave offsets. All records with annotations are selected, and for each record, a 0.05–45 Hz low-pass zero-phase filter was applied for denoising before importing to our algorithm. Furthermore, there are usually 30 to 100 representatively manually annotated discrete beats in each annotated recording. Thus, an RR interval adjustment is also needed before using these records because we used the manually annotated R peak locations. Table 1 shows the summarized annotated information of the QT database. More detailed information about the annotations of this database can be found in the study by Laguna et al. [35].Table 1
Summary of the annotative information of the QT and the European ST-T databases.
Variable
QT database
European ST-T database
Onset
Offset
Onset
Offset
No. of recordings
43
105
23
23
No. of annotated beats
1371
3542
14337
14337
Min. Dis_qrs (ms)
52
228
60
220
Max. Dis_qrs (ms)
412
784
264
612
Mean of Dis_qrs (ms)
164
360
160
380
SD of Dis_qrs (ms)
60
71
29
47
Dis_qrs: the time interval between theT wave onset/offset and the R wave position within the current beat; SD: standard deviation. The annotations of the QT database are taken from the database website https://www.physionet.org/physiobank/database/qtdb/doc/index.shtml.The second database is the European ST-T database, which consists 90 2-hour two-channel ECG recordings sampled at 250 Hz, and records of this database are only used to test the robustness of our improved method. The European ST-T database is chosen because of its widely usages in evaluation of algorithms for analysis of ST andT wave changes [36, 37]. In this study, 23 recordings (only the first 5 minutes in each recording) were selected and were manually annotated for T wave onsets and offsets by a trained staff member because of loss of T wave international annotations. Table 1 also shows the detailed annotation information of this database. Besides, when choosing records, if there were serious signal quality problems within the first 5-minute episode, the following 5-minute episode was used and a 0.05–45 Hz bandpass filter was applied for denoising for each record we chose before importing into the algorithm. We do not implement RR interval adjustment because R peaks were detected by jqrs method [21].To verify the consistency of the annotations between the two databases, we analyzed the time interval information between theT wave onset/offset and the corresponding R peak position for the two databases. Figure 1 shows the probability density distributions of the time interval information from the two databases. As shown in Figure 1, we found that our manual annotations of the onset/offset of T wave in the European ST-T database had similar probability density distributions with the annotations in the QT database, which indicated the effectiveness of our annotations.Figure 1
Probability density distribution of the time interval information betweenT wave onset/offset and R wave peak by analyzing the annotations from the two databases: (a) QT database and (b) European ST-T database.
(a)
(b)


### 2.2. Sliding Window Area (SWA) Method

#### 2.2.1. SWA Method

SWA is an algorithm for detectingT wave onset and offset (Ton and Tend, respectively) by analyzing the waveform area of ECG within a sliding window [31]. Onset/offset is detected when the area of the sliding window reaches its maximum in a prefixed searching range. Then, we show an example for explaining the method in Figures 2 and 3.Figure 2
Demonstration of the SWA method forT wave onset detection.
(a)
(b)Figure 3
Demonstration of the SWA method for detecting offsets of theT wave.
(a)
(b)Figure2 illustrates the detection for Ton. Firstly, with the location of R peak, the left and right boundaries (t1 and t2, respectively) of search window are determined based on the current RR interval as suggested in the study by Song et al. [32]:(1)t1=0.5×RRi+Ri+0.08s,t2=0.15×RRi+Ri+0.12s,ifRRi<0.88s,t1=0.5×RRi+Ri+0.1s,t2=Ri+0.32s,ifRRi≥0.88s,where RRi is the ith RR interval and Ri is the ith position of R peak.The waveform area (area of onset denoted as:Ao) within the fixed sliding window tt+w was calculated using the following formula:(2)Ao=∑j=tt+wsj−s¯k,where w=0.12s (by default), which is the window width, t stretches from t1 to t2, sj is the waveform amplitude at the jth sample point, and s¯k is the local average amplitude (using a smoothing window of p=0.016s by default), which is defined according to the following equation:(3)S¯k=12p+1∑j=t−pt+pSj.As shown in Figure2, when t = Ton, Ao reaches its maximum value.Figure3 illustrates the Tend detection. At first, with the location of the R peak, the left and right boundaries (t3 and t4, respectively) of the search window are determined based on the current RR interval as suggested in a study by Zhang et al. [31]:(4)t3=0.15×RRi+Ri+0.148s,t4=0.7×RRi+Ri−0.036s,ifRRi<0.88s,t3=Ri+0.28s,t4=0.2×RRi+Ri+0.404s,ifRRi≥0.88s.The waveform area (area of ends denoted as:Ae) within the fixed sliding window t−wt was then calculated according to the following formula:(5)Ae=∑j=t−wtsj−s¯k,where w=0.128s (by default), t is from t3 to t4, and sj and s¯k have been defined in equation (2). As shown in Figure 3, when t = Tend, Ae reaches its maximum value. As for the difference between Figures 2 and 3 is the direction to calculate the sliding area.In addition, Algorithm1 shows the description of the traditional SWA algorithm and more details to which the algorithm proof can refer [31].Algorithm 1:Traditional SWA algorithm (T wave onset detection).
Input: ECG signal St, R peak locations, R peak numbers N, sliding window width w, smoothing factor p, and morphology predefined factor r
Output: T wave onset locations
Calculation:
(1)
Calculatet1 and t2 and construct sliding window
window =St1:t2
(2)
Smooth signal and calculate sliding area for each pointi inside [t1, t2]
Areai=sumSi:i+w−sumSi−p:i+p/p∗2+1
(3)
T wave morphology classification
ifr=“p”r=“pn”r=“bm”r=“”
calculatek1,l1=maxArea
end if
ifr=“n”r=“np”r=“”
calculatek2,l2=max−Area
end if
(4)
Getk
k=mink1,k2
Output: T wave onset = R peak + k.


#### 2.2.2. Improved SWA Method

One key issue with respect to the SWA method is to accurately determine the search boundaries, but the search boundaries are closely related to the RR interval. As shown in Figures2 and 3, if the interval of the searching window’s boundaries was set too small which means that two boundary points are near the current R peak, the maximum of sliding area could not be found or the detected onset/offset of T wave are nearer to the R peak. These issues affect detection accuracy, which results in detection error and vice versa.In the traditional SWA method, there are two piecewise functions with predefined parameter settings. In order to more accurately model the relationships between RR interval and the searching boundaries in this study, we performed ak-means clustering analysis between RR intervals and RTon (RTon denotes the time interval between the R peak and T wave onset) as well as the relationship between the RR intervals and RToff (RToff the time interval between the R peak and T wave offset), which is implemented by means of the k-means function in Matlab. The scatter plots with the optimal k-means clustering (k = 3) are shown in Figure 4 [38], and k is determined by combining the results of clustering and the computational complexity of parameters’ settings as well as the adaptiveness of the algorithm. Then, the two relationships (between RR intervals and RTon, and between RR intervals and RToff) are obtained using the following equations:(6)case1:RR<0.76s,0.05s<RTon<0.25s,case2:0.76s≤RR<1.13s,0.05s<RTon<0.35s,case3:RR≥1.13s,0.05s<RTon<0.45s,case1:RR<0.72s,0.2s<RToff<0.45s,case2:0.72s≤RR<1.1s,0.2s<RToff<0.6s,case3:RR≥1.1s,0.2s<RToff<0.8s.Figure 4
Clustering results forT wave feature points: (a) clustering information of T wave onsets; (b) clustering information of T wave offsets.
(a)
(b)Thus, the three piecewise functions for determining the search boundaries forT wave onset and offset detections were obtained with the parameters presented in Table 2:(7)t1=Ri+ald×RRi+0.02s,t2=Ri+alu×RRi+0.16s,ifRRi<0.76s,t1=Ri+ard×RRi+0.04s,t2=Ri+aru×RRi+0.24s,if0.76s≤RRi<1.13s,t1=Ri+amd×RRi+0.04s,t2=Ri+amu×RRi+0.4s,ifRRi≥1.13s,(8)t3=Ri+ald×RRi+0.18s,t4=Ri+alu×RRi+0.3s,ifRRi<0.72s,t3=Ri+ard×RRi+0.18s,t4=Ri+aru×RRi+0.4s,if0.72s≤RRi<1.1s,t3=Ri+amd×RRi+0.18s,t4=Ri+amu×RRi+0.48,sifRRi≥1.1s.Table 2
Information of parameters when detecting theT wave.
Parameters
T onset
T offset
IV
CS
CR
IV
CS
CR
ald/alu/ard
0.1
0.1
0.1∼0.4
0.1
0.1
0.1∼0.4
aru/amd
0.0
0.0∼0.4
amu
0.0
0.0∼0.4
IV: initialized value; CS: change step; CR: change range.Then, thegrid search was used to determine the best combination of parameters in equations (7) and (8), which was implemented by for loop. In a loop, we changed the value of one parameter at a time, kept the other parameters unchanged, and applied the algorithm in the QT database as well as using a 5-fold cross-validation. Then, we stored the F1 measure of one loop and started another loop. Through all loops, we traversed all of the combinations of parameters referred to in Table 2. After comparing the results, the combinations of parameters with the highest F1 measure were chosen. The best parameters’ combinations for T wave onsets are listed: ald = 0.4, alu = 0.2, ard = 0.4, aru = 0.4, amd = 0.3, and amu = 0.0 and for T wave ends are listed: ald = 0.2, alu = 0.1, ard = 0.2, ard = 0.1, aru = 0.0, amd = 0.0, and amu = 0.1. The improved SWA method can be summarized as a block diagram in Figure 5.Figure 5
The block diagram of the proposed method for delineating theT wave onset/offset.


### 2.3. Evaluation Method

Detections for true and false positives (TP and FP, respectively) and false negative (FN) were determined with a threshold of 100 ms. In this study, indices like sensitivity (Se), positive precision (P+), and F1 measurement were selected as evaluation indices [39, 40] with the following definitions: Se=TP/TP+FN, P+=TP/TP+FN, and F1=TP×2/TP×2+FN+FP. F1 measure is selected other than accuracy since F1 measure is the weighted average of precision and recall which satisfies our asymmetric datasets where values of false positive and false negatives are not the same.


## 2.1. Data

Records from two datasets are used. The first is the QT database, which contains 105 15-minute two-channel ECG recordings with the sample rate of 250 Hz, and we chose it as the training and testing sets because multiple-type records from different databases are contained in this database. Besides, totally 43 recordings have manually annotatedT wave onsets and 103 recordings have manually annotated T wave offsets. All records with annotations are selected, and for each record, a 0.05–45 Hz low-pass zero-phase filter was applied for denoising before importing to our algorithm. Furthermore, there are usually 30 to 100 representatively manually annotated discrete beats in each annotated recording. Thus, an RR interval adjustment is also needed before using these records because we used the manually annotated R peak locations. Table 1 shows the summarized annotated information of the QT database. More detailed information about the annotations of this database can be found in the study by Laguna et al. [35].Table 1
Summary of the annotative information of the QT and the European ST-T databases.
Variable
QT database
European ST-T database
Onset
Offset
Onset
Offset
No. of recordings
43
105
23
23
No. of annotated beats
1371
3542
14337
14337
Min. Dis_qrs (ms)
52
228
60
220
Max. Dis_qrs (ms)
412
784
264
612
Mean of Dis_qrs (ms)
164
360
160
380
SD of Dis_qrs (ms)
60
71
29
47
Dis_qrs: the time interval between theT wave onset/offset and the R wave position within the current beat; SD: standard deviation. The annotations of the QT database are taken from the database website https://www.physionet.org/physiobank/database/qtdb/doc/index.shtml.The second database is the European ST-T database, which consists 90 2-hour two-channel ECG recordings sampled at 250 Hz, and records of this database are only used to test the robustness of our improved method. The European ST-T database is chosen because of its widely usages in evaluation of algorithms for analysis of ST andT wave changes [36, 37]. In this study, 23 recordings (only the first 5 minutes in each recording) were selected and were manually annotated for T wave onsets and offsets by a trained staff member because of loss of T wave international annotations. Table 1 also shows the detailed annotation information of this database. Besides, when choosing records, if there were serious signal quality problems within the first 5-minute episode, the following 5-minute episode was used and a 0.05–45 Hz bandpass filter was applied for denoising for each record we chose before importing into the algorithm. We do not implement RR interval adjustment because R peaks were detected by jqrs method [21].To verify the consistency of the annotations between the two databases, we analyzed the time interval information between theT wave onset/offset and the corresponding R peak position for the two databases. Figure 1 shows the probability density distributions of the time interval information from the two databases. As shown in Figure 1, we found that our manual annotations of the onset/offset of T wave in the European ST-T database had similar probability density distributions with the annotations in the QT database, which indicated the effectiveness of our annotations.Figure 1
Probability density distribution of the time interval information betweenT wave onset/offset and R wave peak by analyzing the annotations from the two databases: (a) QT database and (b) European ST-T database.
(a)
(b)


## 2.2. Sliding Window Area (SWA) Method

### 2.2.1. SWA Method

SWA is an algorithm for detectingT wave onset and offset (Ton and Tend, respectively) by analyzing the waveform area of ECG within a sliding window [31]. Onset/offset is detected when the area of the sliding window reaches its maximum in a prefixed searching range. Then, we show an example for explaining the method in Figures 2 and 3.Figure 2
Demonstration of the SWA method forT wave onset detection.
(a)
(b)Figure 3
Demonstration of the SWA method for detecting offsets of theT wave.
(a)
(b)Figure2 illustrates the detection for Ton. Firstly, with the location of R peak, the left and right boundaries (t1 and t2, respectively) of search window are determined based on the current RR interval as suggested in the study by Song et al. [32]:(1)t1=0.5×RRi+Ri+0.08s,t2=0.15×RRi+Ri+0.12s,ifRRi<0.88s,t1=0.5×RRi+Ri+0.1s,t2=Ri+0.32s,ifRRi≥0.88s,where RRi is the ith RR interval and Ri is the ith position of R peak.The waveform area (area of onset denoted as:Ao) within the fixed sliding window tt+w was calculated using the following formula:(2)Ao=∑j=tt+wsj−s¯k,where w=0.12s (by default), which is the window width, t stretches from t1 to t2, sj is the waveform amplitude at the jth sample point, and s¯k is the local average amplitude (using a smoothing window of p=0.016s by default), which is defined according to the following equation:(3)S¯k=12p+1∑j=t−pt+pSj.As shown in Figure2, when t = Ton, Ao reaches its maximum value.Figure3 illustrates the Tend detection. At first, with the location of the R peak, the left and right boundaries (t3 and t4, respectively) of the search window are determined based on the current RR interval as suggested in a study by Zhang et al. [31]:(4)t3=0.15×RRi+Ri+0.148s,t4=0.7×RRi+Ri−0.036s,ifRRi<0.88s,t3=Ri+0.28s,t4=0.2×RRi+Ri+0.404s,ifRRi≥0.88s.The waveform area (area of ends denoted as:Ae) within the fixed sliding window t−wt was then calculated according to the following formula:(5)Ae=∑j=t−wtsj−s¯k,where w=0.128s (by default), t is from t3 to t4, and sj and s¯k have been defined in equation (2). As shown in Figure 3, when t = Tend, Ae reaches its maximum value. As for the difference between Figures 2 and 3 is the direction to calculate the sliding area.In addition, Algorithm1 shows the description of the traditional SWA algorithm and more details to which the algorithm proof can refer [31].Algorithm 1:Traditional SWA algorithm (T wave onset detection).
Input: ECG signal St, R peak locations, R peak numbers N, sliding window width w, smoothing factor p, and morphology predefined factor r
Output: T wave onset locations
Calculation:
(1)
Calculatet1 and t2 and construct sliding window
window =St1:t2
(2)
Smooth signal and calculate sliding area for each pointi inside [t1, t2]
Areai=sumSi:i+w−sumSi−p:i+p/p∗2+1
(3)
T wave morphology classification
ifr=“p”r=“pn”r=“bm”r=“”
calculatek1,l1=maxArea
end if
ifr=“n”r=“np”r=“”
calculatek2,l2=max−Area
end if
(4)
Getk
k=mink1,k2
Output: T wave onset = R peak + k.


### 2.2.2. Improved SWA Method

One key issue with respect to the SWA method is to accurately determine the search boundaries, but the search boundaries are closely related to the RR interval. As shown in Figures2 and 3, if the interval of the searching window’s boundaries was set too small which means that two boundary points are near the current R peak, the maximum of sliding area could not be found or the detected onset/offset of T wave are nearer to the R peak. These issues affect detection accuracy, which results in detection error and vice versa.In the traditional SWA method, there are two piecewise functions with predefined parameter settings. In order to more accurately model the relationships between RR interval and the searching boundaries in this study, we performed ak-means clustering analysis between RR intervals and RTon (RTon denotes the time interval between the R peak and T wave onset) as well as the relationship between the RR intervals and RToff (RToff the time interval between the R peak and T wave offset), which is implemented by means of the k-means function in Matlab. The scatter plots with the optimal k-means clustering (k = 3) are shown in Figure 4 [38], and k is determined by combining the results of clustering and the computational complexity of parameters’ settings as well as the adaptiveness of the algorithm. Then, the two relationships (between RR intervals and RTon, and between RR intervals and RToff) are obtained using the following equations:(6)case1:RR<0.76s,0.05s<RTon<0.25s,case2:0.76s≤RR<1.13s,0.05s<RTon<0.35s,case3:RR≥1.13s,0.05s<RTon<0.45s,case1:RR<0.72s,0.2s<RToff<0.45s,case2:0.72s≤RR<1.1s,0.2s<RToff<0.6s,case3:RR≥1.1s,0.2s<RToff<0.8s.Figure 4
Clustering results forT wave feature points: (a) clustering information of T wave onsets; (b) clustering information of T wave offsets.
(a)
(b)Thus, the three piecewise functions for determining the search boundaries forT wave onset and offset detections were obtained with the parameters presented in Table 2:(7)t1=Ri+ald×RRi+0.02s,t2=Ri+alu×RRi+0.16s,ifRRi<0.76s,t1=Ri+ard×RRi+0.04s,t2=Ri+aru×RRi+0.24s,if0.76s≤RRi<1.13s,t1=Ri+amd×RRi+0.04s,t2=Ri+amu×RRi+0.4s,ifRRi≥1.13s,(8)t3=Ri+ald×RRi+0.18s,t4=Ri+alu×RRi+0.3s,ifRRi<0.72s,t3=Ri+ard×RRi+0.18s,t4=Ri+aru×RRi+0.4s,if0.72s≤RRi<1.1s,t3=Ri+amd×RRi+0.18s,t4=Ri+amu×RRi+0.48,sifRRi≥1.1s.Table 2
Information of parameters when detecting theT wave.
Parameters
T onset
T offset
IV
CS
CR
IV
CS
CR
ald/alu/ard
0.1
0.1
0.1∼0.4
0.1
0.1
0.1∼0.4
aru/amd
0.0
0.0∼0.4
amu
0.0
0.0∼0.4
IV: initialized value; CS: change step; CR: change range.Then, thegrid search was used to determine the best combination of parameters in equations (7) and (8), which was implemented by for loop. In a loop, we changed the value of one parameter at a time, kept the other parameters unchanged, and applied the algorithm in the QT database as well as using a 5-fold cross-validation. Then, we stored the F1 measure of one loop and started another loop. Through all loops, we traversed all of the combinations of parameters referred to in Table 2. After comparing the results, the combinations of parameters with the highest F1 measure were chosen. The best parameters’ combinations for T wave onsets are listed: ald = 0.4, alu = 0.2, ard = 0.4, aru = 0.4, amd = 0.3, and amu = 0.0 and for T wave ends are listed: ald = 0.2, alu = 0.1, ard = 0.2, ard = 0.1, aru = 0.0, amd = 0.0, and amu = 0.1. The improved SWA method can be summarized as a block diagram in Figure 5.Figure 5
The block diagram of the proposed method for delineating theT wave onset/offset.


## 2.2.1. SWA Method

SWA is an algorithm for detectingT wave onset and offset (Ton and Tend, respectively) by analyzing the waveform area of ECG within a sliding window [31]. Onset/offset is detected when the area of the sliding window reaches its maximum in a prefixed searching range. Then, we show an example for explaining the method in Figures 2 and 3.Figure 2
Demonstration of the SWA method forT wave onset detection.
(a)
(b)Figure 3
Demonstration of the SWA method for detecting offsets of theT wave.
(a)
(b)Figure2 illustrates the detection for Ton. Firstly, with the location of R peak, the left and right boundaries (t1 and t2, respectively) of search window are determined based on the current RR interval as suggested in the study by Song et al. [32]:(1)t1=0.5×RRi+Ri+0.08s,t2=0.15×RRi+Ri+0.12s,ifRRi<0.88s,t1=0.5×RRi+Ri+0.1s,t2=Ri+0.32s,ifRRi≥0.88s,where RRi is the ith RR interval and Ri is the ith position of R peak.The waveform area (area of onset denoted as:Ao) within the fixed sliding window tt+w was calculated using the following formula:(2)Ao=∑j=tt+wsj−s¯k,where w=0.12s (by default), which is the window width, t stretches from t1 to t2, sj is the waveform amplitude at the jth sample point, and s¯k is the local average amplitude (using a smoothing window of p=0.016s by default), which is defined according to the following equation:(3)S¯k=12p+1∑j=t−pt+pSj.As shown in Figure2, when t = Ton, Ao reaches its maximum value.Figure3 illustrates the Tend detection. At first, with the location of the R peak, the left and right boundaries (t3 and t4, respectively) of the search window are determined based on the current RR interval as suggested in a study by Zhang et al. [31]:(4)t3=0.15×RRi+Ri+0.148s,t4=0.7×RRi+Ri−0.036s,ifRRi<0.88s,t3=Ri+0.28s,t4=0.2×RRi+Ri+0.404s,ifRRi≥0.88s.The waveform area (area of ends denoted as:Ae) within the fixed sliding window t−wt was then calculated according to the following formula:(5)Ae=∑j=t−wtsj−s¯k,where w=0.128s (by default), t is from t3 to t4, and sj and s¯k have been defined in equation (2). As shown in Figure 3, when t = Tend, Ae reaches its maximum value. As for the difference between Figures 2 and 3 is the direction to calculate the sliding area.In addition, Algorithm1 shows the description of the traditional SWA algorithm and more details to which the algorithm proof can refer [31].Algorithm 1:Traditional SWA algorithm (T wave onset detection).
Input: ECG signal St, R peak locations, R peak numbers N, sliding window width w, smoothing factor p, and morphology predefined factor r
Output: T wave onset locations
Calculation:
(1)
Calculatet1 and t2 and construct sliding window
window =St1:t2
(2)
Smooth signal and calculate sliding area for each pointi inside [t1, t2]
Areai=sumSi:i+w−sumSi−p:i+p/p∗2+1
(3)
T wave morphology classification
ifr=“p”r=“pn”r=“bm”r=“”
calculatek1,l1=maxArea
end if
ifr=“n”r=“np”r=“”
calculatek2,l2=max−Area
end if
(4)
Getk
k=mink1,k2
Output: T wave onset = R peak + k.


## 2.2.2. Improved SWA Method

One key issue with respect to the SWA method is to accurately determine the search boundaries, but the search boundaries are closely related to the RR interval. As shown in Figures2 and 3, if the interval of the searching window’s boundaries was set too small which means that two boundary points are near the current R peak, the maximum of sliding area could not be found or the detected onset/offset of T wave are nearer to the R peak. These issues affect detection accuracy, which results in detection error and vice versa.In the traditional SWA method, there are two piecewise functions with predefined parameter settings. In order to more accurately model the relationships between RR interval and the searching boundaries in this study, we performed ak-means clustering analysis between RR intervals and RTon (RTon denotes the time interval between the R peak and T wave onset) as well as the relationship between the RR intervals and RToff (RToff the time interval between the R peak and T wave offset), which is implemented by means of the k-means function in Matlab. The scatter plots with the optimal k-means clustering (k = 3) are shown in Figure 4 [38], and k is determined by combining the results of clustering and the computational complexity of parameters’ settings as well as the adaptiveness of the algorithm. Then, the two relationships (between RR intervals and RTon, and between RR intervals and RToff) are obtained using the following equations:(6)case1:RR<0.76s,0.05s<RTon<0.25s,case2:0.76s≤RR<1.13s,0.05s<RTon<0.35s,case3:RR≥1.13s,0.05s<RTon<0.45s,case1:RR<0.72s,0.2s<RToff<0.45s,case2:0.72s≤RR<1.1s,0.2s<RToff<0.6s,case3:RR≥1.1s,0.2s<RToff<0.8s.Figure 4
Clustering results forT wave feature points: (a) clustering information of T wave onsets; (b) clustering information of T wave offsets.
(a)
(b)Thus, the three piecewise functions for determining the search boundaries forT wave onset and offset detections were obtained with the parameters presented in Table 2:(7)t1=Ri+ald×RRi+0.02s,t2=Ri+alu×RRi+0.16s,ifRRi<0.76s,t1=Ri+ard×RRi+0.04s,t2=Ri+aru×RRi+0.24s,if0.76s≤RRi<1.13s,t1=Ri+amd×RRi+0.04s,t2=Ri+amu×RRi+0.4s,ifRRi≥1.13s,(8)t3=Ri+ald×RRi+0.18s,t4=Ri+alu×RRi+0.3s,ifRRi<0.72s,t3=Ri+ard×RRi+0.18s,t4=Ri+aru×RRi+0.4s,if0.72s≤RRi<1.1s,t3=Ri+amd×RRi+0.18s,t4=Ri+amu×RRi+0.48,sifRRi≥1.1s.Table 2
Information of parameters when detecting theT wave.
Parameters
T onset
T offset
IV
CS
CR
IV
CS
CR
ald/alu/ard
0.1
0.1
0.1∼0.4
0.1
0.1
0.1∼0.4
aru/amd
0.0
0.0∼0.4
amu
0.0
0.0∼0.4
IV: initialized value; CS: change step; CR: change range.Then, thegrid search was used to determine the best combination of parameters in equations (7) and (8), which was implemented by for loop. In a loop, we changed the value of one parameter at a time, kept the other parameters unchanged, and applied the algorithm in the QT database as well as using a 5-fold cross-validation. Then, we stored the F1 measure of one loop and started another loop. Through all loops, we traversed all of the combinations of parameters referred to in Table 2. After comparing the results, the combinations of parameters with the highest F1 measure were chosen. The best parameters’ combinations for T wave onsets are listed: ald = 0.4, alu = 0.2, ard = 0.4, aru = 0.4, amd = 0.3, and amu = 0.0 and for T wave ends are listed: ald = 0.2, alu = 0.1, ard = 0.2, ard = 0.1, aru = 0.0, amd = 0.0, and amu = 0.1. The improved SWA method can be summarized as a block diagram in Figure 5.Figure 5
The block diagram of the proposed method for delineating theT wave onset/offset.


## 2.3. Evaluation Method

Detections for true and false positives (TP and FP, respectively) and false negative (FN) were determined with a threshold of 100 ms. In this study, indices like sensitivity (Se), positive precision (P+), and F1 measurement were selected as evaluation indices [39, 40] with the following definitions: Se=TP/TP+FN, P+=TP/TP+FN, and F1=TP×2/TP×2+FN+FP. F1 measure is selected other than accuracy since F1 measure is the weighted average of precision and recall which satisfies our asymmetric datasets where values of false positive and false negatives are not the same.


## 3. Results

Figure6 shows the detection examples of the proposed method, compared with the traditional methods, Zhang’s method for T wave offset detection [31] and Song’s method for T wave onset detection [32]. Figure 6(a) shows the inverted T wave detections, Figure 6(b) shows the biphasic T wave detections, and Figure 6(c) shows the normal T wave detections. From Figure 6, T wave offset detections get better results than T wave onset detections. And, our method got obviously better results when it is applied in T wave onsets detections.Figure 6
T wave detection examples. The solid points marked () are R peaks; the solid points marked ( and ) are results of our method; the hollow circles marked ( and ) are results of the traditional method; the shadow areas are accepted as TP cases. (a) e0107; (b) e0111; (c) e0118.
(a)
(b)
(c)


### 3.1. Results from the QT Database

We firstly tested the performance of the improved SWA method on the QT database. The traditional SWA methods (Song’s method [32] and Zhang’s method [31]) were used as comparators.Table3 shows the results of onset and offset detections in the QT database. Both of the two channels signals (first and second channels) were tested. From Table 3, we found the improved SWA method significantly enhanced detection accuracies for both onset and offset detections. For onset detection, F1 improved from 54.70% to 70.46% and 54.05% to 72.94% for two ECG channels, respectively. For offset detection, F1 improved from 87.83% to 93.73% and 86.73% to 94.75% for two ECG channels, respectively. In addition, detection errors were also analyzed. As expected, the improved SWA method indicated smaller detection errors than the traditional method except for a slight increase in the offset detection from the second channel (traditional 0.027 ± 31.85 ms versus improved 2.45 ± 33.98 ms). However, it is worthwhile to note that all Se, P+, and F1 indices increased from ∼86% to ∼94%.Table 3
Results ofT wave detection in the QT database.
Detection
Channel
Method
Se (%)
P+ (%)
F1 (%)
Error mean ± SD (ms)
Onset
First
Traditional SWA [32]
54.70
54.70
54.70
−30.2 ± 40.75
Improved SWA
70.46
70.46
70.46
7.3 ± 53.12
Second
Traditional SWA [32]
54.05
54.05
54.05
−36.27 ± 43.29
Improved SWA
72.94
72.94
72.94
6.35 ± 53.78
Offset
First
Traditional SWA [31]
87.83
87.83
87.83
−2.57 ± 30.08
Improved SWA
93.93
93.93
93.93
1.19 ± 33.59
Second
Traditional SWA [31]
86.73
86.73
86.73
0.027 ± 31.85
Improved SWA
94.75
94.75
94.75
2.45 ± 33.98


### 3.2. Results from the European ST-T Database

Table4 shows the results of onset and offset detections in the European ST-T database. The improvements after using the improved method were more significant when performing T wave onset detection. F1 improved from 41.02% to 84.13% and 44.33% to 87.62% for two ECG channels, respectively. The mean detection errors significantly decreased from 19.52 ms to 7.04 ms and 36.27 ms to 6.35 ms for two ECG channels, respectively. Performance improvements in offset detection were small but convincing F1 improved from 98.83% to 99.57% and 91.76% to 98.29% for two ECG channels, respectively. However, the mean detection errors for T wave offset detection slightly increased (not significant) when performing the improved method.Table 4
Results ofT wave detection in the European ST-T database.
Detection
Channel
Method
Se (%)
P+ (%)
F1 (%)
Error mean ± SD (ms)
Onset
First
Traditional SWA [32]
41.02
41.02
41.02
19.52 ± 31.89
Improved SWA
84.13
84.13
84.13
−7.87 ± 44.22
Second
Traditional SWA [32]
44.33
44.32
44.33
−36.27 ± 43.29
Improved SWA
87.62
87.61
87.62
−15.20 ± 33.54
Offset
First
Traditional SWA [31]
98.80
98.86
98.83
22.2 ± 22.70
Improved SWA
99.50
99.65
99.57
26.94 ± 20.98
Second
Traditional SWA [31]
91.80
91.71
91.76
21.07 ± 26.31
Improved SWA
98.29
98.28
98.29
24.54 ± 25.52


## 3.1. Results from the QT Database

We firstly tested the performance of the improved SWA method on the QT database. The traditional SWA methods (Song’s method [32] and Zhang’s method [31]) were used as comparators.Table3 shows the results of onset and offset detections in the QT database. Both of the two channels signals (first and second channels) were tested. From Table 3, we found the improved SWA method significantly enhanced detection accuracies for both onset and offset detections. For onset detection, F1 improved from 54.70% to 70.46% and 54.05% to 72.94% for two ECG channels, respectively. For offset detection, F1 improved from 87.83% to 93.73% and 86.73% to 94.75% for two ECG channels, respectively. In addition, detection errors were also analyzed. As expected, the improved SWA method indicated smaller detection errors than the traditional method except for a slight increase in the offset detection from the second channel (traditional 0.027 ± 31.85 ms versus improved 2.45 ± 33.98 ms). However, it is worthwhile to note that all Se, P+, and F1 indices increased from ∼86% to ∼94%.Table 3
Results ofT wave detection in the QT database.
Detection
Channel
Method
Se (%)
P+ (%)
F1 (%)
Error mean ± SD (ms)
Onset
First
Traditional SWA [32]
54.70
54.70
54.70
−30.2 ± 40.75
Improved SWA
70.46
70.46
70.46
7.3 ± 53.12
Second
Traditional SWA [32]
54.05
54.05
54.05
−36.27 ± 43.29
Improved SWA
72.94
72.94
72.94
6.35 ± 53.78
Offset
First
Traditional SWA [31]
87.83
87.83
87.83
−2.57 ± 30.08
Improved SWA
93.93
93.93
93.93
1.19 ± 33.59
Second
Traditional SWA [31]
86.73
86.73
86.73
0.027 ± 31.85
Improved SWA
94.75
94.75
94.75
2.45 ± 33.98


## 3.2. Results from the European ST-T Database

Table4 shows the results of onset and offset detections in the European ST-T database. The improvements after using the improved method were more significant when performing T wave onset detection. F1 improved from 41.02% to 84.13% and 44.33% to 87.62% for two ECG channels, respectively. The mean detection errors significantly decreased from 19.52 ms to 7.04 ms and 36.27 ms to 6.35 ms for two ECG channels, respectively. Performance improvements in offset detection were small but convincing F1 improved from 98.83% to 99.57% and 91.76% to 98.29% for two ECG channels, respectively. However, the mean detection errors for T wave offset detection slightly increased (not significant) when performing the improved method.Table 4
Results ofT wave detection in the European ST-T database.
Detection
Channel
Method
Se (%)
P+ (%)
F1 (%)
Error mean ± SD (ms)
Onset
First
Traditional SWA [32]
41.02
41.02
41.02
19.52 ± 31.89
Improved SWA
84.13
84.13
84.13
−7.87 ± 44.22
Second
Traditional SWA [32]
44.33
44.32
44.33
−36.27 ± 43.29
Improved SWA
87.62
87.61
87.62
−15.20 ± 33.54
Offset
First
Traditional SWA [31]
98.80
98.86
98.83
22.2 ± 22.70
Improved SWA
99.50
99.65
99.57
26.94 ± 20.98
Second
Traditional SWA [31]
91.80
91.71
91.76
21.07 ± 26.31
Improved SWA
98.29
98.28
98.29
24.54 ± 25.52


## 4. Discussion

As seen from Tables3 and 4, both T wave onset and offset detection of the new proposed method reported better performances (F1 measure) than the traditional method, suggesting that applying the clustering technique in the SWA method for deciding searching boundaries is helpful to enhance detection accuracy. In addition, clustering is a statistical-based technique, which can be used to determine whether the independent part of a population belongs to different groups by comparing quantitative multiple features [38]. Besides, we noted that, for the T wave offset detections, neither the traditional SWA nor the improved version reported the better performance than the detection of T wave onsets. One possible explanation is that Zhang proposed this method originally to detect T wave offsets not T wave onsets and proved its mathematical rationality for T wave offsets. Another possible explanation is that the clustering method for determining the search boundaries is a statistical-based technique. Therefore, the accuracy of the clustering results is related to the data amount. However, the annotated T wave onsets in the QT database are far less than the annotated T wave offsets (1371 versus 3452). Thus, the relationship found by clustering analysis between the RR interval and RTon is not that strong (Figure 4(a)) compared to the relationship between the RR interval and RToff (Figure 4(b)). Moreover, the significant difference between the improved and traditional SWAs indicates that the improved version can more extensively and adaptively determine the search window’s boundaries by using the k-means clustering based on the QT database and grid search strategy. However, the traditional SWA only used predefined parameters and did not give out any detailed explanations.Another difference between Zhang’s [31] and our results was observed when using the QT database for validation, Zhang’s study chose the better result from the outputs of the two ECG channels [31]. In order to compare our results with those from Zhang, we also calculated smaller errors from the results of two ECG channels. The comparable results are summarized in Table 5. The mean detection errors are similar between Zhang’s and our results. We also noted that the standard deviation of detection errors was 25.82 ms for our method and 21.19 ms for the traditional SWA. Both of them were smaller than the acceptable threshold (30.6 ms) proposed by the common standards in Electrocardiography Working Party [41].Table 5
Comparable detection results ofT wave offset in the QT database.
Methods
Annotations
Se (%)
P+ (%)
Mean
±
SD (ms)
Improved SWA
3542
98.5
98.5
1.21 ± 25.82
Traditional SWA [31]
3542
95.5
95.5
−1.12 ± 21.19
Wavelet-based [13, 14]
3542
99.77
97.79
−1.6 ± 18.1
Low-pass differentiation-based [20]
3542
99.00
97.74
13.5 ± 27.0
Hidden Markov model-based [21, 22]
3542
NA
NA
−5 ± 14
Partially collapsed Gibbs sample [23]
3403
99.81
98.97
4.3 ± 20.8
k-nearest neighbor-based [30]
30 records
NA
NA
2.8 ± 18.6
TU complex analysis [28]
3528
92.60
NA
0.8 ± 30.3
Neural network and fixed-size least-squares SVM [19]
3542
NA
NA
−3.0 ± 16.9
L.EKF25 [42]
10 records
NA
NA
11 ± 39
N.L.EKF25 [42]
4 ± 23
L.EKF25 [42]
15 records
NA
NA
−17 ± 30
N.L.EKF25 [42]
−21 ± 19
NA: not available; L.EKF25: linear Kalman filter; N.L.EKF25: nonlinear Kalman filter.Table5 also summarizes comparable results from other studies. The wavelet-based method reported a mean error of 1.6 ms [13, 14]; the low-pass differentiation-based method gave a relative large mean error of 13.5 ms [20], while the hidden Markov model-based method reported a mean error of 5 ms [21, 22]. Furthermore, the partially collapsed Gibbs sample reported 4.3 ms [23], and the k-nearest neighbor-based method reported 2.8 ms [20]. The TU complex analysis gave a minimum detection mean error of 0.8 ms but did not include the corresponding Se and P+ results [28]. In addition, methods proposed by Mahsa with linear and nonlinear phase observation to detect fiducial points are also listed as comparative method [42], and two parts of QT database including normal sinus rhythm and arrhythmia database are used when evaluating extraction of fiducial points and the nonlinear observation has more smaller deviations 23 ms for the first database and 19 ms for the second database.The potential issues existing in the above studies consist of two main points: (1) the time tolerance for determining true positive detection was not clear and (2) training and testing were both performed in the QT database, but we used the European ST-T database as the independent testing dataset.Besides, as deep-learning technology improves, more and more methods based on this technique have been proposed to detect ECG feature points; for instance, a recently proposed method using neural network and fixed-size least-squares SVM to detectT wave end reported it is a minimum detection mean error of −3 ms in the QT database; a QRS complex detection by using two-level convolutional neural network [8] reported its sensitivity of 99.77% in the MIT-BIH AR database. When using deep-learning technique, a great amount of data is needed, and in T wave detection, the annotated T wave ends are limited but a meaningful strategy was proposed in [19], which is to use different strategies for selecting different training sets such as random selection and k-means. But, we just proposed an idea that is to use one independent database (QT dataset) as the training set and testing set and another independent database (records from the European ST-T database annotated by a trained staff) as the testing set.In order to illustrate difference between error andF1 measure, we did statistical analysis of error. And, Figure 7 gives the cumulative line chart of error (denoted as CLCE) of T wave offsets in the QT database which explains our method got more true positive beats than the traditional method inside our time tolerance. The CLCE of T wave onsets in the QT database and CLCE of T wave in the European ST-T database also have the same regularities of distribution as it did in the T wave offsets in the QT database.Figure 7
The cumulative line chart of error (T offsets in the QT database). TR result represents the traditional SWA method result, and IM result represents the improved SWA method result.Moreover, the limitation of our study is that the annotations of the European ST-T database are only done by a trained staff member which may result in nonauthoritative annotations. Besides, we only combine the data statistic and data mining technique to changing the parameters of traditional SWA method. In our following work, more records with authoritative annotations will be used to test the robustness of the combination of parameters we obtained in this study.


## 5. Conclusion

In this paper, an improved sliding window area method for detectingT wave onset and offset was proposed. The main contribution/novelty was for application of the data statistic and data mining technique: (1) k-means clustering for the setting of search boundaries and (2) grid search strategy to optimize the parameters. Experiments performed in the QT database and the European ST-T database demonstrated the improved method’s better performance.



---

*Source: 3130527-2019-04-01.xml*