# Shannon’s Energy Based Algorithm in ECG Signal Processing

Authors: Hamed Beyramienanlou; Nasser Lotfivand
Journal: Computational and Mathematical Methods in Medicine
 (2017)

---

## Abstract

Physikalisch-Technische Bundesanstalt (PTB) database is electrocardiograms (ECGs) set from healthy volunteers and patients with different heart diseases. PTB is provided for research and teaching purposes by National Metrology Institute of Germany. The analysis method of complex QRS in ECG signals for diagnosis of heart disease is extremely important. In this article, a method on Shannon energy (SE) in order to detect QRS complex in 12 leads of ECG signal is provided. At first, this algorithm computes the Shannon energy (SE) and then makes an envelope of Shannon energy (SE) by using the defined threshold. Then, the signal peaks are determined. The efficiency of the algorithm is tested on 70 cases. Of all 12 standard leads, ECG signals include 840 leads of the PTB Diagnostic ECG Database (PTBDB). The algorithm shows that the Shannon energy (SE) sensitivity is equal to 99.924%, the detection error rate (DER) is equal to 0.155%, Positive Predictivity (+P) is equal to 99.922%, and Classification Accuracy (Acc) is equal to 99.846%.


---

## Body

## 1. Introduction

In recent years, cardiovascular disorders have been one of the major diseases threatening human life. Therefore, the detection of heart signal waves such as QRS complex is highly significant [1]. Electrocardiogram is used to detect most of heart disorders and shows the electrical activities of heart as a signal [2]. ECG signals contain a lot of information concerning heart diseases. The detection of special points and different parameters such as QRS complex are one of the basic topics and are of high importance, because they lead to the diagnosis of heart diseases. The QRS are used to diagnose many cardiac diseases and noncardiac pathologies such as autonomic malfunction vascular, respiratory (RR) assessment in cardiomyopathy and the normal ventricular myocardium, estimate the heart rate and heart rate variability analysis, and detect ST segment [3–5]. Heart problems usually involve leaking valves and blocked coronary arteries. This research is motivated by reasons expressed. Heart rate cycle consists of a P-wave, a QRS complex, T-wave, and sometimes U-wave [5]. Figure 1 shows schematic representation of normal ECG.Figure 1
Schematic diagram of normal ECG.Detecting any of heart signal waves may be difficult due to variable physiology, arrhythmia, disease, and noise. Therefore, in methods such as artificial neural networks and supportive vector machines, detection by the wave R is not always successful and true detection cannot be reached in different signals [6, 7].The shape of the waves T, P, and QRS is well known; however, the time and frequency of these waves depend on the physiological and physical conditions. In addition, the signal may face polluted recordings with noises such as transmission lines [3].In recent decades, various methods have been presented to improve the detection of heart signal waves, including Pan-Tompkins algorithm [7], Wavelet Transform, by usage of a constant scale in signal analysis, not considering the characteristics of the signal [8, 9], and artificial neural networks, containing of a series of interconnected simple processing units that each connection has a weight. Input layer, one or multiple hidden layers, and output layer constitute a neural network [10, 11]. Adaptive filter [12], called Hilbert-Huang Transform (HHT), is a new technique for extracting features that are nonlinear and nonstationary signals. This technique has a leakage in practical tasks [13]. Filter bank [14], a Hidden Markov Model (HMM), describes the process where direct observation is not possible, when sequence of symbols can observe HMM. It is used in many fields such as classification of heartbeat and apnea bradycardia detection in preterm infants [15]. Hermite Transform (HT) was recently used instead of Fourier Transform. HT shows better performance, when optimization is done properly [16]. Threshold method [17], Shannon energy envelope (SEE), is the average spectrum of energy and is better able to detect peaks in case of various QRS polarities and sudden changes in QRS amplitude. SEE detects R-peak with a better estimate [18]. S-Transform and Shannon energy (SSE) create a frequency-dependent regulation which is directly related with the Fourier spectrum. S-Transform includes short time Fourier Transform (STFT) and the Wavelet Transform (WT). SSE gives a smooth cover for P-waves and T-waves and completely decreases their influence [19]. Methods such as pattern matching are based on their comparing and contrasting. The calculations are complex and need manual classification [6].In this paper, an algorithm based on Shannon energy has been proposed to improve the QRS complex detection and simplify the detection process. First, a band-pass filter is used for eliminating noise. Second, Shannon energy of ECG signal is calculated. Third, include moving averages and a differential for the envelope of step 2. Finally, with defining a threshold, peaks are detected. The proposed algorithm is tested on 115-second (to end) ECG signal of PTB Diagnostic ECG Database (PTBDB) [20, 21] and detection accuracy of 99.846% is obtained. The proposed technique results in good performance without being mathematically complex.


## 2. Method

The block diagram of detecting QRS complex algorithm is shown in Figure2. It includes four stages. Stage 1 includes band-pass digital filter and amplitude normalization. Stage 2 includes calculating Shannon energy of stage 1. In stage 3, with moving average and differencing, make a pack of Shannon energy, and in stage 4, with defining a threshold, QRS complex is detected.Figure 2
Block diagram to detect QRS complex.


### 2.1. Preparations Signal

Digital-analog conversion process is causing all kinds of noise interference and sometimes strongly affects the information. These interactions include frequency interference, muscle contraction, and wandering signals from the baseline or Gaussian white noise [5].The ECG signal recorded from human beings is a poor signal and is often contaminated by noise. Frequency interference includes a narrow band from 48 to 60 Hz and harmonic interference, and the noise from muscle contraction occurs in 38 to 45 Hz. To eliminate this noise, notch filter is good [22]. Deep breathing, loosely connected electrodes, and sudden changes in voltage lead the baseline signal to be wondered (baseline drift) [5]. Random variable vector (mean) and chromatogram baseline estimation and denoising using sparsity (BEADS) algorithm [23] are good methods to eliminate baseline drift. The band-pass filter decreases efficacy of muscle contraction, frequency interference, baseline drift, and P-wave and T-wave interference [7, 24]. To repress these noises, Butterworth band-pass digital filter with stop-point set at 5 to 16 Hz is used. Butterworth has no ripple in band-pass. [25]. After band-pass filter, the signal is normalized with (1) in stage 1 [26].(1)
a
n
=
f
n
m
a
x
i
=
1
N
f
n
,where a
n is a normalized amplitude; f
n is an after processes band-pass filter (BPF). N denotes the number of samples.


### 2.2. Shannon Energy and Detection of QRS Complex

The proposed method is based on the use of signal energy. The signal square is very close to the signal energy. For discrete time signal energy is defined as follows:(2)
E
x
=
∑
-
∞
∞
x
n
x
∗
n
=
∑
-
∞
∞
x
n
2
.Here,E
x expresses the signal energy, x
n defined ECG data, and n is samples. ∑ represents sum from (
-
∞
∞
) [27]. To explain, we have the following: (3)
E
x
=
x
0
2
+
x
1
2
+
x
2
2
+
x
3
2
+
⋯
.Shannon energy calculates the average spectrum of the signal energy. In other words, discount the high components into the low components. So, input amplitude is not important. Shannon energy and Hilbert Transform (SEHT) provide a good accessory for detecting R-peak but this technique has a problem. SEHT needs high memory and has delays [28]. It is designed for solving our actual requirements. To find smooth Shannon energy, zero-phase filter and Shannon energy approximate are playing a basic role [24, 28].Shannon energy (SE) calculates the energy of the local spectrum for each sample. Below is a calculation of Shannon energy:(4)
S
E
=
-
a
n
log
⁡
a
n
,
s
n
=
-
a
2
n
log
⁡
a
2
n
,where a
n is after process normalization.Energy that better approaches detection ranges in presence of noise or domains with more width results in fewer errors. Capacity to emphasize medium is the advantage of using Shannon energy rather than classic energy [18, 19]. The selected signal is normalized with (5) in stage 3 for decreasing the signal base and placing the signal below the baseline.(5)
s
n
=
s
n
-
μ
σ
,where μ is the random variable vector and σ defined standard deviation of the signal.In stage 3, after computing Shannon energy, small spikes around the main peak of the energy are generated. These spikes make main peaks detection difficult. To eliminate this spike, Shannon energy is converted into energy package (Shannon energy envelope (SEE)). To overcome this problem, the Hilbert Transform is used. SEHT method is a simple and high accessory but the SEHT needs high memory and has delays, so it is unfit for real time detection [24, 28]. To smooth out the spikes, rectangular (h) with L length is used. Filtering operation is shown as follows:(6)
m
n
=
filter
h
,
j
,
S
,
m
′
n
=
filter
h
,
j
,
S
,where m
n defines moving average, j is a constant, and S defines Shannon energy from previous steps. For spikes reducing and enveloping, the nonzero peaks obtained from differential get linked. In other words, diagnosed peaks are linked together.Difference is defined below:(7)
d
n
=
f
n
-
f
n
-
1
,
n
=
2,3
,
…
.The sign is defined as follows:(8)
s
g
n
x
-
1
if
x
<
0
0
if
x
=
0
1
if
x
>
0
,where x is a real number.In stage 4, positive peaks are QRS complex location. To detect QRS complex, a threshold (see (9)) is defined. In fact, samples with greater amplitude than the threshold are selected as output.(9)
threshold
=
κ
μ
1
-
σ
2
if
σ
<
μ
,
threshold
=
κ
σ
1
-
μ
2
if
σ
>
μ
,where κ is a constant.


## 2.1. Preparations Signal

Digital-analog conversion process is causing all kinds of noise interference and sometimes strongly affects the information. These interactions include frequency interference, muscle contraction, and wandering signals from the baseline or Gaussian white noise [5].The ECG signal recorded from human beings is a poor signal and is often contaminated by noise. Frequency interference includes a narrow band from 48 to 60 Hz and harmonic interference, and the noise from muscle contraction occurs in 38 to 45 Hz. To eliminate this noise, notch filter is good [22]. Deep breathing, loosely connected electrodes, and sudden changes in voltage lead the baseline signal to be wondered (baseline drift) [5]. Random variable vector (mean) and chromatogram baseline estimation and denoising using sparsity (BEADS) algorithm [23] are good methods to eliminate baseline drift. The band-pass filter decreases efficacy of muscle contraction, frequency interference, baseline drift, and P-wave and T-wave interference [7, 24]. To repress these noises, Butterworth band-pass digital filter with stop-point set at 5 to 16 Hz is used. Butterworth has no ripple in band-pass. [25]. After band-pass filter, the signal is normalized with (1) in stage 1 [26].(1)
a
n
=
f
n
m
a
x
i
=
1
N
f
n
,where a
n is a normalized amplitude; f
n is an after processes band-pass filter (BPF). N denotes the number of samples.


## 2.2. Shannon Energy and Detection of QRS Complex

The proposed method is based on the use of signal energy. The signal square is very close to the signal energy. For discrete time signal energy is defined as follows:(2)
E
x
=
∑
-
∞
∞
x
n
x
∗
n
=
∑
-
∞
∞
x
n
2
.Here,E
x expresses the signal energy, x
n defined ECG data, and n is samples. ∑ represents sum from (
-
∞
∞
) [27]. To explain, we have the following: (3)
E
x
=
x
0
2
+
x
1
2
+
x
2
2
+
x
3
2
+
⋯
.Shannon energy calculates the average spectrum of the signal energy. In other words, discount the high components into the low components. So, input amplitude is not important. Shannon energy and Hilbert Transform (SEHT) provide a good accessory for detecting R-peak but this technique has a problem. SEHT needs high memory and has delays [28]. It is designed for solving our actual requirements. To find smooth Shannon energy, zero-phase filter and Shannon energy approximate are playing a basic role [24, 28].Shannon energy (SE) calculates the energy of the local spectrum for each sample. Below is a calculation of Shannon energy:(4)
S
E
=
-
a
n
log
⁡
a
n
,
s
n
=
-
a
2
n
log
⁡
a
2
n
,where a
n is after process normalization.Energy that better approaches detection ranges in presence of noise or domains with more width results in fewer errors. Capacity to emphasize medium is the advantage of using Shannon energy rather than classic energy [18, 19]. The selected signal is normalized with (5) in stage 3 for decreasing the signal base and placing the signal below the baseline.(5)
s
n
=
s
n
-
μ
σ
,where μ is the random variable vector and σ defined standard deviation of the signal.In stage 3, after computing Shannon energy, small spikes around the main peak of the energy are generated. These spikes make main peaks detection difficult. To eliminate this spike, Shannon energy is converted into energy package (Shannon energy envelope (SEE)). To overcome this problem, the Hilbert Transform is used. SEHT method is a simple and high accessory but the SEHT needs high memory and has delays, so it is unfit for real time detection [24, 28]. To smooth out the spikes, rectangular (h) with L length is used. Filtering operation is shown as follows:(6)
m
n
=
filter
h
,
j
,
S
,
m
′
n
=
filter
h
,
j
,
S
,where m
n defines moving average, j is a constant, and S defines Shannon energy from previous steps. For spikes reducing and enveloping, the nonzero peaks obtained from differential get linked. In other words, diagnosed peaks are linked together.Difference is defined below:(7)
d
n
=
f
n
-
f
n
-
1
,
n
=
2,3
,
…
.The sign is defined as follows:(8)
s
g
n
x
-
1
if
x
<
0
0
if
x
=
0
1
if
x
>
0
,where x is a real number.In stage 4, positive peaks are QRS complex location. To detect QRS complex, a threshold (see (9)) is defined. In fact, samples with greater amplitude than the threshold are selected as output.(9)
threshold
=
κ
μ
1
-
σ
2
if
σ
<
μ
,
threshold
=
κ
σ
1
-
μ
2
if
σ
>
μ
,where κ is a constant.


## 3. Result

The experimental results are obtained after simulation on 70 healthy patients’ signals for all 12 leads and using PTB Diagnostic ECG Database (PTBDB). The Physikalisch-Technische Bundesanstalt (PTB) is the National Metrology Institute of Germany. PTB database is provided for PhysioNet and has different morphologies. The ECGs in this database obtain 15 input channels including the conventional 12 leads (i, ii, iii, avr, avl, avf, v1, v2, v3, v4, v5, and v6) together with the 3 Frank lead ECGs (vx, vy, and vz). Input voltage is ±16 mV, input resistance is 100 Ω, ADC resolution is equal to 16 bits with 0.5μ/LSB, and sampling frequency is equal to 1 KHz [20, 21]. The proposed algorithm was performed on a 2.4 GHz Intel core i3 CPU using GNU Octave version 4.0.2 [29]. A selected signal from patient 117 has a variety of physiology and baseline drift. Leads (i, ii, avl, avf, v3, v4, v5, and v6) of record s0291lrem and leads (i, ii, iii, avf, v1, v2, v4, v5, and v6) of record s0292lrem have high amplitude. Leads (i, avl, v2, v3, and v4) of record s0291lrem and leads (avr, avl, and avf) of record s0292lrem have a sharp and tall T-wave.Figure3 shows the result of simulation to detect each lead of patient 117 in Octave. Figures 4 and 5 show the process of ECG signal provision and peak detection. The QRS detection of the 12 channels of healthy ECG signal in patient 117 of the PTB database is reported in Table 1 and the Appendix. Detection of the 12 leads is shown in Figure 6. Figure 7 shows 3 leads of 3 cases.Table 1
The QRS detection of ECG signal of the PTB database.
Case
TP
FN
FP
DER%
Se%
+P
Acc
s0010_rem
624
0
0
0.000
100.000
100.000
100.000
s0014lrem
1987
0
0
0.000
100.000
100.000
100.000
s0015lrem
1815
0
2
0.110
100.000
99.890
99.890
s0017lrem
1673
0
5
0.299
100.000
99.702
99.702
s0020arem
1906
4
21
1.312
99.791
98.910
98.705
s0020brem
1867
5
20
1.339
99.733
98.940
98.679
s0021arem
2207
1
0
0.045
99.955
100.000
99.955
s0021brem
2196
0
0
0.000
100.000
100.000
100.000
s0025lrem
2382
6
0
0.252
99.749
100.000
99.749
s0029lrem
1638
0
0
0.000
100.000
100.000
100.000
s0031lrem
2111
1
0
0.047
99.953
100.000
99.953
s0035_rem
552
0
0
0.000
100.000
100.000
100.000
s0036lrem
2066
0
2
0.097
100.000
99.903
99.903
s0037lrem
1479
0
3
0.203
100.000
99.798
99.798
s0038lrem
1572
0
0
0.000
100.000
100.000
100.000
s0039lrem
2088
0
0
0.000
100.000
100.000
100.000
s0042lrem
1815
0
0
0.000
100.000
100.000
100.000
s0043lrem
1212
0
0
0.000
100.000
100.000
100.000
s0044lrem
1812
0
0
0.000
100.000
100.000
100.000
s0045lrem
1968
0
0
0.000
100.000
100.000
100.000
s0046lrem
1944
0
0
0.000
100.000
100.000
100.000
s0047lrem
2651
1
0
0.038
99.962
100.000
99.962
s0049lrem
2040
0
0
0.000
100.000
100.000
100.000
s0050lrem
1461
3
0
0.205
99.795
100.000
99.795
s0051lrem
1912
0
2
0.105
100.000
99.896
99.896
s0052lrem
1356
0
0
0.000
100.000
100.000
100.000
s0053lrem
2148
0
0
0.000
100.000
100.000
100.000
s0054lrem
1979
31
2
1.668
98.458
99.899
98.360
s0055lrem
1381
0
1
0.072
100.000
99.928
99.928
s0056lrem
1732
0
0
0.000
100.000
100.000
100.000
s0057lrem
1896
0
0
0.000
100.000
100.000
100.000
s0058lrem
2017
0
1
0.050
100.000
99.950
99.950
s0059lrem
1800
0
0
0.000
100.000
100.000
100.000
s0060lrem
140
0
0
0.000
100.000
100.000
100.000
s0062lrem
1488
0
0
0.000
100.000
100.000
100.000
s0063lrem
1845
3
0
0.163
99.838
100.000
99.838
s0064lrem
1797
3
0
0.167
99.833
100.000
99.833
s0065lrem
1704
0
0
0.000
100.000
100.000
100.000
s0066lrem
1513
0
1
0.066
100.000
99.934
99.934
s0067lrem
424
0
4
0.943
100.000
99.065
99.065
s0068lrem
1377
5
15
1.452
99.638
98.922
98.568
s0069lrem
1188
0
0
0.000
100.000
100.000
100.000
s0070lrem
1983
0
1
0.050
100.000
99.950
99.950
s0071lrem
1848
0
0
0.000
100.000
100.000
100.000
s0072lrem
2040
0
0
0.000
100.000
100.000
100.000
s0073lrem
2125
5
0
0.235
99.765
100.000
99.765
s0074lrem
1140
0
0
0.000
100.000
100.000
100.000
s0075lrem
1453
0
1
0.069
100.000
99.931
99.931
s0076lrem
1308
0
0
0.000
100.000
100.000
100.000
s0077lrem
1692
0
0
0.000
100.000
100.000
100.000
s0078lrem
1225
0
1
0.082
100.000
99.918
99.918
s0079lrem
1620
0
0
0.000
100.000
100.000
100.000
s0080lrem
1556
0
0
0.000
100.000
100.000
100.000
s0082lrem
1602
0
0
0.000
100.000
100.000
100.000
s0083lrem
1465
1
0
0.068
99.932
100.000
99.932
s0084lrem
1464
0
0
0.000
100.000
100.000
100.000
s0085lrem
1276
0
4
0.313
100.000
99.688
99.688
s0097lrem
2133
0
1
0.047
100.000
99.953
99.953
s0101lrem
1500
0
0
0.000
100.000
100.000
100.000
s0103lrem
1273
0
2
0.157
100.000
99.843
99.843
s0149lrem
1572
0
0
0.000
100.000
100.000
100.000
s0152lrem
1532
4
0
0.261
99.740
100.000
99.740
s0087lrem
1654
12
0
0.726
99.280
100.000
99.280
s0088lrem
1728
0
0
0.000
100.000
100.000
100.000
s0091lrem
1380
1
1
0.145
99.928
99.928
99.855
s0095lrem
1797
3
0
0.167
99.833
100.000
99.833
s0096lrem
2603
1
0
0.038
99.962
100.000
99.962
s0150lrem
1583
1
0
0.063
99.937
100.000
99.937
s0090lrem
1358
0
2
0.147
100.000
99.853
99.853
s0093lrem
1249
0
1
0.080
100.000
99.920
99.920
s0291lrem
1548
0
0
0.000
100.000
100.000
100.000
s0292lrem
1584
0
0
0.000
100.000
100.000
100.000
Total
119054
91
93
0.155
99.924
99.922
99.846Figure 3
Simulation result. Time and number of peaks detection in each lead are shown. ((a) record s0292lrem; (b) record s0291lrem).
(a)
(b)Figure 4
Process of preparations of ECG signal (record s0291lrem, lead v3).
(a)
(b)
(c)
(d)Figure 5
Process of preparation of ECG signal (record s0292lrem, lead avr).
(a)
(b)
(c)
(d)Figure 6
Detected QRS complex of ECG data (record s0292lrem); red line defines QRS complex detection.y-axis represents the amplitude, and x-axis represents the sample.Figure 7
(a) Detected QRS complex of ECG data (record s0020arem, lead avf). Records s0020arem and s0020brem include tall and sharp P-wave and T-wave. In this case, the QRS area has low energy. (b) Detected QRS complex of s0087lrem-lead 3. This case includes Irregular RR interval. (c) Lead v5 of s0089lrem. FN (false negative) is the number of not detected R peaks, and FP (false positive) is the number of noise spikes detected as R peaks.y-axis represents the amplitude, and x-axis represents the sample.
(a)
(b)
(c)In order to define performance and efficiency of the algorithm, the Classification Accuracy (Acc), Positive Predictivity (+P), sensitivity (Se), and detection error rate were calculated by using the following equations:(10)
A
c
c
=
T
P
T
P
+
F
N
+
F
P
×
100
,
+
P
=
T
P
T
P
+
F
P
×
100
,
S
e
=
T
P
T
P
+
F
N
×
100
,
D
E
R
=
F
P
+
F
N
T
P
×
100
.Here, TP defines a true detected peak by the algorithm; FN (false negative) is the number of not detected R peaks, and FP (false positive) is the number of noise spikes detected as R peaks [3, 30].Figures4(a) and 5(a) show the output after the band-pass filter f
n and normalized amplitude a
n. Figures 4(b) and 5(b) show Shannon energy s
n and normalized amplitude, and Figures 4(c) and 5(c) show after envelope e
n signal. QRS complex of ECG signal is shown in Figures 4(d) and 5(d). Red line defines a detected peak. y-axis represents the amplitude, and x-axis represents the sample.In this study, the proposed technique is tested on 840 leads of PTB Diagnostic ECG Database (PTBDB), and values achieved showed that sensitivity (Se) equals 99.924%, detection error rate (DER) equals 0.155%, Positive Predictivity (+P) equals 99.922%, and Classification Accuracy was 99.846%.


## 4. Conclusion

In the present study, the most common methods to remove noise in the ECG signal are evaluated. A Shannon energy-based approach to determine the QRS complex of the 12-lead ECG signal is provided. ECG signal is selected with a variety of physiology from the PTB Database and examined by Octave software. Accuracy and sensitivity achieved from Table1 showed that the presented algorithm is fast and simple, without complex equations. This algorithm does not need a high memory and high hardware. Diagnosis time for each lead is approximately 2.5 seconds based on Octave. The results showed that algorithm detection has very little lag, less than 0.013 seconds, without error. This lag is generated from stage 3.



---

*Source: 8081361-2017-01-18.xml*