**3.2 R-Peak Detection from Single Lead ECG**

**3.2.2 Proposed Fractal Based R-Peak Detection**

A simple, reliable, and intuitive algorithm for real-time R-peak detection is proposed using the geometry of fractals that meets the clinical needs. Fractals are described as an object with a never ending self similar structure that are created by repeating a simple process over and over as in recursion [208]. Fractal geometry provide meth- TH-2764_156201001

3.2. R-PEAK DETECTION FROM SINGLE LEAD ECG

ods for analyzing irregular structures existing in nature. It helps to understand the amount of similarity between two objects. The fact that ECG signal is produced by a nonlinear system, generating small or large variations, motivated the use of fractals for QRS detection. The QRS complex structure repeats periodically in ECG making it suitable for detection using fractals. The fast and low computational complex- ity properties of fractals make an effective real-time QRS detector. The approach consists of a Preprocessing stage, Fractal Analysis, and a Post Processing stage as described in Figure 3.10. During preprocessing, ECG is cleaned from noise followed by calculation of area under the curve using Mathematical Morphology (MM) oper- ators such as erosion and dilation. The operators are implemented using dynamic programming with memoization that helps in achieving accurate results in a shorter duration. During post processing, the final peaks are extracted after resampling and thresholding the area curve to produce the peaks of ECG signal.

ECG Signal

Normalization

BW Removal

PLI Removal Area

Dilation Erosion

Post Processing Preprocessing Fractal Analysis Using Mathematical Morphological Operators

Resampling

Hard Thresholding Maximum

Minimum

Length R-Peaks

Figure 3.10: Different stages of the proposed approach.

The validity of the application of MM principles for signal analysis depends on
the following two properties: 1) Partial ordering and 2) Each subset should have a
maximum and minimum. To check the above mentioned properties in the context of
ECG signal, consider a signal x[n] where x[n] ⊂ R. Any set that is a subset of R
satisfies the property, partial ordering by the relation ≤ for any pair of elements
x_{i}, x_{j} ∀i, j,∈ N. The second property is satisfied in x[n] because of the existence
of peaks and valleys in the signal. They are the local maxima and local minima of
any subset of elements in x[n]. Therefore, MM operators are applicable for R-peak
detection from ECG signals.

Data Description and Preprocessing: MLII lead from recordings of MIT- BIH database described in Section 3.1.3 are used for R-Peak detection. The original ECG signal is shown in Figure 3.11a. PLI is removed using a notch filter and BW is removed using a mean median filter with an initial window of 70 and the final window

54 TH-2764_156201001

3. PREPROCESSING ELECTROCARDIOGRAM SIGNAL

of 250. The clean signal is illustrated in Figure 3.11b.

(a) Normalised Signal

(b) Clean Signal

(c) Area obtained through Fractal Analysis

(d) Resampled Area

(e) Hard Thresholding

(f) Signal overlapped with Obtained Peaks

Figure 3.11: R-Peak Detection for Record 100 from MIT-BIH.

Fractal Analysis Using MM Operators: The MM operators, dilation and erosion are given in Equations 3.9 and 3.10 respectively. The area under a curve is TH-2764_156201001

3.2. R-PEAK DETECTION FROM SINGLE LEAD ECG

calculated as the difference between dilation and erosion and is given in Equation 3.11. The key idea of morphological analysis is the understanding of features of the regions in the signal by filling those regions by different operators. The Steps to calculate area are described in Algorithm 5. The recursive nature of Algorithm 5 was further optimised using the approach of dynamic programming with memoization that reduced the time complexity of the algorithm and made it computationally efficient.

For a discrete-time finite-length ECG signal S[n], n(= 0,1, ..., N), covers are used at
discrete scales = (1,2, ..., signal length/2) then the structuring element G[n] (at
scale = 1) is restricted to three sample support with only two shapes: a triangle,
defined by G_{t}[−1] = 0, G_{t}[1] = 0 and G_{t}[0] = h ≥ 0, or a rectangle, defined by
G_{r}[−1] =G_{r}[1] = G_{r}[0] =h ≥ 0. The height h matches the amplitude range of the
signal S[n] and controls finesse or coarseness of multi-scale area measurements [209].

The final area is calculated using the difference between dilation and erosion. Figure 3.11c depicts the area obtained after applying MM operators.

S⊕G[n] = max

−1≤k≤1{S[n+k] +G[k]}, = 1
S⊕G_{+1} = (S⊕G_{})⊕G, ≥2

(3.9)

S G[n] = min

−1≤k≤1{S[n+k]−G[k]}, = 1
S G_{+1} = (S G_{}) G, ≥2

(3.10)

A=

N

X

n=0

h

(S⊕Gε)[n]−(S Gε)[n]

i

(3.11) Post-Processing: After obtaining the area through fractal analysis in Figure 3.11c, the length of area is reduced with a factor of frame size. So for accurate QRS detection we resampled the signal to original signal length. Figure 3.11d depicts the resampled area curve. The frame size is varied to achieve best results. After resampling, thresholding was performed to reduce false detections. However, it leads to some missing beats. Figure 3.11e depicts the thresholded signal. The thresholding was also varied to obtain best results. Thresholding also led to both false and missed beats. Figure 3.11f depicts the overlapping of obtained peaks and original signal. For the comparison of obtained beats with the annotation provided in the data set by cardiologist, a window of size 60 samples was employed. If the extracted markers are not in this range then the beat is assumed to be missed by our algorithm and if more

56 TH-2764_156201001

3. PREPROCESSING ELECTROCARDIOGRAM SIGNAL

Algorithm 5 Area Calculation using MM operators Input: ECG signal S[n], FS: Frame size

Output: Area

n_{f rames} ←length_{signal}/F S
k←0

Area← ∅

for k ←0 to n_{f rames} do

seg←signal[F S∗k :F S∗(k+ 1)]

h←max(seg)−min(seg) h←h/len(seg)

area_{k}←dilation(seg, h)−erosion(seg, h)
k←k+ 1

Area←Area∪area_{k}
end

than one marker is found out by our algorithm then it is assumed to be an extra beat.