**3. Description of the algorithm**

The algorithm for automatic measurement of QTd in the quasi-orthogonal leads DI, aVF and V2 is based on the multilead generalization of a previous algorithm for single-lead detection of characteristic points of the QRS complex and T wave using the CWT with splines [18]. This new algorithm for multilead detection includes the identification of more types of morphologies of QRS complex and T waves [30], which are integrated with the previous algorithm for single-lead detection. **Figure 5** shows the algorithm proposed which is organized in four modules. In the first module, different kinds of QRS complexes and T-waves are detected and identified. In the second module, the algorithm detects the Q wave onset, R wave peak and T wave end, which is based on an algorithm for single-lead detection previously mentioned [18]. Next, the algorithm measures the QT and RR intervals from detections of significant points in each quasi-orthogonal lead. Finally, the algorithm calculates QTd as the difference in duration between the longest and shortest QT intervals measured on the three quasi-orthogonal leads and HR.

QRS. If Wnq position is after the Wpq position, then the type complex is rS, which is defined as negative QRS (**Figure 6**). Flowchart of polarity detection of the QRS complex is shown in

An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic…

http://dx.doi.org/10.5772/intechopen.74864

31

**Figure 5.** Flowchart of the algorithm for automatic measurement of QTd in the leads DI, aVF and V2.

To determine the type of QRS complex once its polarity is defined, two algorithms are applied depending if QRS complex is positive or negative. The algorithm to determine the type of QRS complex with positive polarity when R is higher, it defines if Q or S wave is present as follows. From the onset of the Pmm corresponding to the R wave at scale w2, Q wave is present if the nearest positive peak backwards is larger than a defined positive threshold. From the end of this Pmm, S wave is present if the nearest negative peak forward is lower than a defined negative threshold. These peaks are detected by looking inside a search window defined by the maximal duration of both waves. This algorithm detects and identifies the morphologies qR, qRs, R and Rs (**Figure 7**). Flowchart of the QRS complex type detection when R is higher

Figure 2 of [30].

is shown in Figure 5 of [30].

#### **3.1. Detection of different kinds of QRS complex and T wave**

As a first step in this stage, polarity of QRS complex and T wave is identified. QRS complex corresponds to a Pmm of the CTW and the scale used is w2, where it has its major component. Then, the highest positive peak (Wpq) and its nearest negative peak backwards (Wnq) are searched within the first 2 s of the record in order to define the position of these peaks. If Wnq position is before the Wpq position, then the type complex is qRs, which is defined as positive An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic… http://dx.doi.org/10.5772/intechopen.74864 31

**Figure 5.** Flowchart of the algorithm for automatic measurement of QTd in the leads DI, aVF and V2.

by baseline wandering. If the ECG is contaminated with high-frequency noise, scales 2 and 3

The algorithm for automatic measurement of QTd in the quasi-orthogonal leads DI, aVF and V2 is based on the multilead generalization of a previous algorithm for single-lead detection of characteristic points of the QRS complex and T wave using the CWT with splines [18]. This new algorithm for multilead detection includes the identification of more types of morphologies of QRS complex and T waves [30], which are integrated with the previous algorithm for single-lead detection. **Figure 5** shows the algorithm proposed which is organized in four modules. In the first module, different kinds of QRS complexes and T-waves are detected and identified. In the second module, the algorithm detects the Q wave onset, R wave peak and T wave end, which is based on an algorithm for single-lead detection previously mentioned [18]. Next, the algorithm measures the QT and RR intervals from detections of significant points in each quasi-orthogonal lead. Finally, the algorithm calculates QTd as the difference in duration between the longest and shortest QT intervals measured on the three quasi-orthog-

As a first step in this stage, polarity of QRS complex and T wave is identified. QRS complex corresponds to a Pmm of the CTW and the scale used is w2, where it has its major component. Then, the highest positive peak (Wpq) and its nearest negative peak backwards (Wnq) are searched within the first 2 s of the record in order to define the position of these peaks. If Wnq position is before the Wpq position, then the type complex is qRs, which is defined as positive

are the most affected.

30 Topics in Splines and Applications

onal leads and HR.

**3. Description of the algorithm**

**Figure 4.** ECG and its CWT at scales 2, 3, 8 and 10.

**3.1. Detection of different kinds of QRS complex and T wave**

QRS. If Wnq position is after the Wpq position, then the type complex is rS, which is defined as negative QRS (**Figure 6**). Flowchart of polarity detection of the QRS complex is shown in Figure 2 of [30].

To determine the type of QRS complex once its polarity is defined, two algorithms are applied depending if QRS complex is positive or negative. The algorithm to determine the type of QRS complex with positive polarity when R is higher, it defines if Q or S wave is present as follows. From the onset of the Pmm corresponding to the R wave at scale w2, Q wave is present if the nearest positive peak backwards is larger than a defined positive threshold. From the end of this Pmm, S wave is present if the nearest negative peak forward is lower than a defined negative threshold. These peaks are detected by looking inside a search window defined by the maximal duration of both waves. This algorithm detects and identifies the morphologies qR, qRs, R and Rs (**Figure 7**). Flowchart of the QRS complex type detection when R is higher is shown in Figure 5 of [30].

**Figure 6.** Polarity of QRS complexes and their CWT at scale w2. (a) Positive and (b) negative.

The algorithm to determine the QRS complex with negative polarity when S is higher, it defines if Q or R wave is present as follows. From the onset of the Pmm corresponding to the S wave at scale w2, R wave is present if the nearest negative peak backwards is lower than a defined negative threshold. From this point, Q wave is present if the nearest positive peak backwards is larger than a defined positive threshold. These peaks are detected by looking inside a search window defined by the maximal duration of both waves. This algorithm detects and identifies the morphologies qrS, rS and QS. **Figure 8** shows rS complex type and its CWT at scale w2. Flowchart of the QRS complex type detection when S is higher is shown in Figure 6 of [30].

described later [18], and before the T wave detection. To identify T waves, the same procedure used for detecting of Wpt and Wnt of Pmm of T wave described earlier is used. According to the comparison of the absolute values of these peaks with defined thresholds and its position, the algorithm classifies five types of T waves: positive, negative, ascending, descending and biphasic (**Figure 9b**). Flowchart of the T wave type detection is shown

An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic…

http://dx.doi.org/10.5772/intechopen.74864

33

**Figure 7.** Complex types and their CWT at scale w2. (a). qRs and (b) R.

in Figure 4 of [30].

**Figure 8.** rS complex type and its CWT at scale w2.

Identification of polarity and type of T wave is performed with two algorithms. The first one classifies T wave into only two types: positive and negative (although it is biphasic, ascending or descending) as follows. As T wave corresponds to a Pmm of the CWT and only in this procedure, the scale used is w4 to enhance its characteristics. The highest positive peak (Wpt) and its nearest negative peak backwards (Wnt) larger than a defined threshold are searched from the end of the Pmm corresponding to R or S wave in a window whose limits depend on HR [31]. If Wnt position is before the Wpt position, then the T wave is positive or normal (**Figure 9a**). If Wnt position is after the Wpt position, then the T wave is inverted or negative. Flowchart of polarity detection of the T wave is shown in Figure 3 of [30].

The second algorithm to determine the type of T wave is applied after, once the R or S wave position is defined by the algorithm for single detection of characteristic points An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic… http://dx.doi.org/10.5772/intechopen.74864 33

**Figure 7.** Complex types and their CWT at scale w2. (a). qRs and (b) R.

The algorithm to determine the QRS complex with negative polarity when S is higher, it defines if Q or R wave is present as follows. From the onset of the Pmm corresponding to the S wave at scale w2, R wave is present if the nearest negative peak backwards is lower than a defined negative threshold. From this point, Q wave is present if the nearest positive peak backwards is larger than a defined positive threshold. These peaks are detected by looking inside a search window defined by the maximal duration of both waves. This algorithm detects and identifies the morphologies qrS, rS and QS. **Figure 8** shows rS complex type and its CWT at scale w2. Flowchart of the QRS complex type detection when S is higher is shown in Figure 6 of [30]. Identification of polarity and type of T wave is performed with two algorithms. The first one classifies T wave into only two types: positive and negative (although it is biphasic, ascending or descending) as follows. As T wave corresponds to a Pmm of the CWT and only in this procedure, the scale used is w4 to enhance its characteristics. The highest positive peak (Wpt) and its nearest negative peak backwards (Wnt) larger than a defined threshold are searched from the end of the Pmm corresponding to R or S wave in a window whose limits depend on HR [31]. If Wnt position is before the Wpt position, then the T wave is positive or normal (**Figure 9a**). If Wnt position is after the Wpt position, then the T wave is inverted or negative.

**Figure 6.** Polarity of QRS complexes and their CWT at scale w2. (a) Positive and (b) negative.

32 Topics in Splines and Applications

Flowchart of polarity detection of the T wave is shown in Figure 3 of [30].

The second algorithm to determine the type of T wave is applied after, once the R or S wave position is defined by the algorithm for single detection of characteristic points described later [18], and before the T wave detection. To identify T waves, the same procedure used for detecting of Wpt and Wnt of Pmm of T wave described earlier is used. According to the comparison of the absolute values of these peaks with defined thresholds and its position, the algorithm classifies five types of T waves: positive, negative, ascending, descending and biphasic (**Figure 9b**). Flowchart of the T wave type detection is shown in Figure 4 of [30].

**Figure 8.** rS complex type and its CWT at scale w2.

**Figure 9.** T wave types and their CWT at scale w4. (a). Positive and (b) biphasic.

**3.2. Detection of characteristic points of QRS complex and T wave**

QRS complex is the most characteristic waveform in the ECG due to its shape with high amplitude, which makes its detection easier than other ECG waves. Its accurate detection in the presence of noise and interferences is the most important task in the ECG automatic analysis because it is used as a reference in the cardiac cycle to perform a more detailed analysis of other ECG waves, segments and intervals, as automated measurement of HR and

An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic…

http://dx.doi.org/10.5772/intechopen.74864

35

*3.2.1. QRS detection*

**Figure 11.** Flowchart of the Rp detection algorithm.

QT interval.

**Figure 10.** Onset, peak and end of the QRS complex and its CWT at scale w2.

An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic… http://dx.doi.org/10.5772/intechopen.74864 35

**Figure 11.** Flowchart of the Rp detection algorithm.

### **3.2. Detection of characteristic points of QRS complex and T wave**

#### *3.2.1. QRS detection*

**Figure 9.** T wave types and their CWT at scale w4. (a). Positive and (b) biphasic.

34 Topics in Splines and Applications

**Figure 10.** Onset, peak and end of the QRS complex and its CWT at scale w2.

QRS complex is the most characteristic waveform in the ECG due to its shape with high amplitude, which makes its detection easier than other ECG waves. Its accurate detection in the presence of noise and interferences is the most important task in the ECG automatic analysis because it is used as a reference in the cardiac cycle to perform a more detailed analysis of other ECG waves, segments and intervals, as automated measurement of HR and QT interval.

According to the wavelet function selected, QRS complex corresponds to a Pmm of the CWT at selected scale, where the R wave peak (Rp) corresponds to the zero crossing observed between the Pmm (**Figure 6**). The developed algorithm [18] detects the QRS by using the scale w2 and the Pmm corresponding to the R wave by defined threshold comparing inside a search window defined by the average RR interval and the last RR interval calculated [31]. From that Pmm, the start of the Q wave defined as Qi (or the start of R wave (Ri) in the absence of Q wave) corresponds to the zero crossing preceding the Pmm; the end of the S wave defined as Se (or the end of the R wave in the absence of the S wave) corresponds to the zero crossing after the Pmm (**Figure 10**). Those zero crossings are detected by looking inside a search window defined by the maximal duration of both waves. Flowcharts of the Rp and Qi

An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic…

http://dx.doi.org/10.5772/intechopen.74864

37

Because of the low-frequency components of T wave [29], scale w3 of the CWT was used for its detection. The process for detection of positive and negative T waves is as follows: from the end of the Pmm of the Rp, we define a search window whose length decreases when RR diminishes [31]; inside that window, we look for the Pmm corresponding to the T wave that exceeds a defined threshold. The end of this Pmm and the zero crossing between them, corresponds to, respectively, the end (Te) and the peak (Tp) of the T wave. Detection and identification of ascending, descending and biphasic types depend on the number, polarity

(Ri) detection algorithms are shown in **Figures 11** and **12**, respectively.

**Figure 14.** Flowchart of the Tp and Te detection algorithm of T wave monophasic or biphasic.

*3.2.2. T wave detection*

**Figure 12.** Flowchart of the Qi (Ri) detection algorithm.

**Figure 13.** Peak and end of T waves and their CWT at scale w3. (a) Positive and (b) biphasic.

According to the wavelet function selected, QRS complex corresponds to a Pmm of the CWT at selected scale, where the R wave peak (Rp) corresponds to the zero crossing observed between the Pmm (**Figure 6**). The developed algorithm [18] detects the QRS by using the scale w2 and the Pmm corresponding to the R wave by defined threshold comparing inside a search window defined by the average RR interval and the last RR interval calculated [31]. From that Pmm, the start of the Q wave defined as Qi (or the start of R wave (Ri) in the absence of Q wave) corresponds to the zero crossing preceding the Pmm; the end of the S wave defined as Se (or the end of the R wave in the absence of the S wave) corresponds to the zero crossing after the Pmm (**Figure 10**). Those zero crossings are detected by looking inside a search window defined by the maximal duration of both waves. Flowcharts of the Rp and Qi (Ri) detection algorithms are shown in **Figures 11** and **12**, respectively.

#### *3.2.2. T wave detection*

**Figure 12.** Flowchart of the Qi (Ri) detection algorithm.

36 Topics in Splines and Applications

**Figure 13.** Peak and end of T waves and their CWT at scale w3. (a) Positive and (b) biphasic.

Because of the low-frequency components of T wave [29], scale w3 of the CWT was used for its detection. The process for detection of positive and negative T waves is as follows: from the end of the Pmm of the Rp, we define a search window whose length decreases when RR diminishes [31]; inside that window, we look for the Pmm corresponding to the T wave that exceeds a defined threshold. The end of this Pmm and the zero crossing between them, corresponds to, respectively, the end (Te) and the peak (Tp) of the T wave. Detection and identification of ascending, descending and biphasic types depend on the number, polarity

**Figure 14.** Flowchart of the Tp and Te detection algorithm of T wave monophasic or biphasic.

and absolute values of the found local maxima (Wpt) or minimum (Wnt). **Figure 13** shows peak and end of the positive and biphasic T wave and their characteristic points of CWT at scale w3. Flowchart of the Tp and Te detection algorithm of T wave monophasic or biphasic is shown in **Figure 14**.

**4.2. Delineation of characteristic points of the QRS complex and T wave**

**25 Recordings CSE Mo1\_001:121 (5:5)**

the CSEDB.

**QT database**

Tolerance limits for deviations according to experts [31]

Tolerance limits for deviations according to experts [31]

Values are in ms; m, mean; sd, standard deviation.

QTDB in ms.

Values are in ms; m, mean; sd, standard deviation.

The developed algorithm for delineation of Qi and Se of the QRS complex and Te of the T wave has been tested on 25 recordings from the CSE database [25], which includes 15 ECG leads and manual annotations on them. **Table 4** shows the average (m) and standard deviation (sd)

An Algorithm Based on the Continuous Wavelet Transform with Splines for the Automatic…

m ± sd – 4.5 ± 1.5 7.6 ± 1.8 8.2 ± 3.6

sd (CSE) 6.5 11.6 30.6

sel100 15.4 −2.4 sel102 −5.3 22.8 sel103 11.9 20.5 sel104 4.1 −5.6 sel114 14.7 29.3 sel116 2.2 17.6 sel117 1.6 −13.8 sel123 2.9 −20.8 sel213 20.4 16.8 sel221 11.2 −16.3 sel223 −11.2 14.6 sel230 9.3 3.7 sel231 13.1 4.5 sel232 3.2 20.8 sel233 −5.8 13.2 **m ± sd 5.8(8) 7(15)**

sd (CSE) 6.5 30.6

**Table 5.** Validation results of the delineation algorithm of characteristic points Qi and Te for 15 recordings from the

**Table 4.** Validation results for delineation algorithm of characteristic points Qi, Se and Te on 25 annotated recordings of

**Qi Se Te**

**WT – CSE WT – CSE WT – CSE**

http://dx.doi.org/10.5772/intechopen.74864

39

**Qi Te WT – C1 WT – C1**

#### **3.3. Measurement of QT and RR intervals and calculus of QTd and HR**

Once Qi and Te have been detected, the algorithm measures the QT and RR interval points in each quasi-orthogonal lead. Finally, the algorithm calculates QTd as the difference in duration between the longest and the shortest QT intervals measured in the three quasi-orthogonal leads, in which each QT interval is the average of three consecutive QT intervals. HR is calculated from the average of RR intervals measured in the same leads, in which each RR interval is the average of two consecutive RR intervals.
