An Adaptive Threshold Algorithm Combining Shifting Window ...

3 downloads 0 Views 204KB Size Report
impact of the high P-wave, high T-wave and other high-frequency interference signals ... R-wave detection in ECG is the basic step for any further processing.
An Adaptive Threshold Algorithm Combining Shifting Window Difference and Forward-Backward Difference in Real-time R-wave Detection Lihuang She, Guohua Wang, Shi Zhang, and Jinshuan Zhao School of Information Science and Engineering Northeastern University Shenyang, People’s Republic of China Abstract—Most ECG diagnosis techniques require an accurate detection of the R-wave, so R-wave detection is important in ECG signal analysis. This paper presents a new real-time R-wave detection algorithm combining adaptive Shifting Window Difference Threshold (SWDT) and Forward-Backward Difference Threshold (FBDT). The algorithm can eliminate or weaken the impact of the high P-wave, high T-wave and other high-frequency interference signals onto the detection of R-wave. It can solve the problem of heavily loaded computation caused by the complicated algorithm of the traditional theory, and has been implemented on a Portable Single-lead ECG Monitor (PSEM) developed by authors. Finally, the algorithm was simulated by the American MIT-BIH Arrhythmia Database [1] with an average detection error rate (DER) 0.2%. Some real data was also collected by our PSEM from several patients. Experimental results indicated that the proposed algorithm was simple, effective, robust, accurate and suitable for application in the embedded system.

I. I NTRODUCTION R-wave detection in ECG is the basic step for any further processing. Many algorithms have been proposed recent years, such as the Difference threshold algorithm [2], Template matching algorithm [3], Wavelet transform algorithm [4], and Neural network algorithm [5]. Difference threshold method is simple, fast and easy to use. Template matching method is simple in theory, but sensitive to high-frequency noise and baseline wandering. Wavelet transform method has good timefrequency localization properties and high detection accuracy, but suffering from the heavily loaded computation, so it’s not suitable for real-time processing. Neural network method makes a good performance in determination, but the long training time makes it difficult to Engineering applications. These methods have their own characteristics, both advantages and disadvantages. So the combination of two or more methods used in R-wave detection algorithm may has more advantages. In this paper, a new adaptive threshold real-time algorithm combining SWDT and FBDT is used in R-wave detection. The algorithm is divided into four stages: Difference calculation. Smooth filter. R-wave detection by SWDT and FBDT separately. Determination and threshold adjustment. See Fig. 1. For the simple and high accuracy performance, the algorithm has been implemented in an embedded system.

Fig. 1.

X(n) is considered as discrete-time signals by analogto-digital converter (ADC) performing quantization with a resolution of 12 bits at a sampling frequency of 200 Hz, D(n) is the first-order difference of X(n), S(n) is the signal after filter of D(n), A(n) is acquired by calculating forwardbackward difference of S(n), Y (n) is the output that marking the position where a R-wave peak appears in the signal sequence, the length of the ECG signal to be processed is L. Step 1: The difference of primitive signal is calculated by (1), this is equivalent to a high-pass filter, so the low-frequency components in X(n) will disappear after difference calculation by (1). Characteristics of P-wave and T-wave are removed, leaving the characteristic of R-wave only. An example is shown in Fig. 2. D (n) = X (n) − X (n − 1)

(1)

Step 2: Noise with high-frequencies and low-amplitudes may also exist after difference calculation. A smooth filter is defined to reduce the interference of noise. The equation is described by (2): y (n) =

1 [x (n − 3) + x (n − 2) + x (n − 1) + x (n)] 4

(2)

where n = 1, 2, ......, L − 1, and (3) is the transfer function of the smooth filter.

II. M ETHODOLOGY The block diagram of R-wave detection is shown in Fig. 1.

R-wave detection frame

H (z) =

¢ 1¡ 1 + z −1 + z −2 + z −3 4

(3)

Fig. 2.

(a) is the primitive ECG signal. (b) is the difference of (a).

Amplitude-frequency response is shown in Fig. 3, we can see the power line interference around 50Hz is also removed.

Fig. 3.

Amplitude-frequency response of Smooth Filter

Step 3: In this step, we start to detect R-wave. The primitive signal is converted into S(n) after step 2. Now the forwardbackward difference will be acquired by calculating S(n) with FBDT. Another two sequences named DIF F (n) and A(n) with the same length as S(n) are needed. All the elements are initialized with zero in the two sequences. Scan S(n) and calculate the difference by (4), then the results are stored into sequence DIF F (n). DIF F (n) = S (n) − S (n − 1)

(4)

where n = 1, 2, ......, L − 1. Judge the value in DIF F (n) one-by-one, and determine whether it is positive or negative. If the adjacent elements DIF F (i) to DIF F (j), (i < j) are all positive ones. aj =

j X

DIF F (m)|DIF F (m)>0

(5)

m=i

If the adjacent elements DIF F (i) to DIF F (j), (i < j) are all negative ones. aj =

j X m=i

DIF F (m)|DIF F (m) AT hreshold and DIF F (i) < −AT hreshold (where j = i + 1), the R-wave peaks are marked in primitive signal sequence X(n). Window difference is also calculated the same time as the forward-backward difference with SWDT method. In this stage, a shifting window W (n) is established to detect R-wave in S(n). Suppose K the length of W (n). Scan the sequence W (n) from the beginning to the end, and calculate difference as (7).   T emp(1) = W (2) − W (1)     T emp(2) = W (3) − W (2) (7)  ......     T emp(k − 1) = W (k) − W (k − 1) where k = 1, 2, 3......, K. If any T emp(i) is greater than a threshold ‘ST hreshold’, then an R-wave peak is marked in sequence X(n) then the window shifts backward. The length of the window can be adjusted According to actual needs. Step4: In the last stage, determination rule is made to decide whether a detected R-wave is a real wave or a noise. So when an R-wave point is marked both in FBDT and SWDT, it’s a real R-wave, else interference. Then the position of R-wave in the primitive signal sequence is memorized to sequence Y (n). At the same time, automation threshold [6] adjustment is applied to adaptive the different R-wave amplitude of variety patients. The algorithm uses a threshold calculated as a percent of the maximum value at the output of the squaring stage taken place in the last 30s. This threshold is set to 50% of the previous maximum value for the signals exceeding 0.5 mV in amplitude. Otherwise, it is set to 25%. Additionally, for heart rates beyond 120 bpm this formerly set percent is lowered twice. This is of mayor importance when using a detection algorithm based on an adaptive threshold because R-wave rates may occasionally fluctuate suddenly. III. A LGORITHM I MPLEMENTATION AND RESULTS The algorithm is implemented on STM32F103xx, an ARM micro-processor of Cortex-M3 core produced by ST Company. Cortex-M3 is a micro-chip with Harvard architecture, the instruction and data are separated from each other. Hardware multiplier is also integrated internally. It includes an ADC module with a resolution of 12 bits at a maximum sampling frequency of 1µs. This can quickly achieve a variety of digital signal processing algorithms. The whole algorithm is developed in C language in IAR Embedded Workbench development environment. The flowchart is shown as Fig. 4. The R-wave detection algorithm was tested by two separate ways: (1) ECG records selected from the MIT-BIH Arrhythmia Database at the sampling rate of 200Hz and resolution of 12 bits, the performance is evaluated by DER described by (8). (2) ECG signal getting from several patients by the PSEM.

Fig. 5. X(n) is the noisy ECG Signal with 0.5Hz base line wander and 50Hz power line interference. S(n) is Difference of X(n). A(n) is Forward-Backward difference. TABLE I T EST RESULTS BY MIT-BIH A RRHYTHMIA DATABASE

Fig. 4.

DER =

R-wave detection algorithm flowchart

FP + FN × 100% T otal number of R wave

Records

R-waves in records

FP

FN

DER

100

2273

0

6

0.3%

105

2572

0

0

0

109

2532

3

0

0.1%

111

2124

2

1

0.1%

112

2539

0

0

0

210

2650

5

8

0.5%

212

2748

0

5

0.2%

(8)

The DER was measured in terms of false positives (FP) and false negatives (FN) detection rates for different signal-tonoise ratios and different R-wave rates as indicated in (8). Table I summarizes the most important results of the conducted tests basing the records selected from MIT-BIH Arrhythmia Database. The average DER get from the algorithm was 0.2%. Fig. 5 shows an example of the tests by MIT-BIH arrhythmia database. Here X(n) is the test signal with baseline wander and power line interference. S(n) is the difference of X(n) after smooth filter. A(n) is Forward-backward difference. The R-wave positions in X(n) is marked after the algorithm is finished. The test results by the PSEM on human body are shown in Fig. 6. The heart rate get from the algorithm is compared with standard Electrocardiograph. One or two beats deviation per-second may appear sometimes.

Fig. 6.

Test on human body by the PSEM

IV. C ONCLUSION In this paper, a new algorithm combining Adaptive Shifting Window Difference Threshold and Forward-backward Difference Threshold is proposed. Comparing with traditional methods such as Wavelet Transform and Neural network, the

algorithm in this paper is less at computation, simple, reliable, and good at real-time application. The special filter of baseline wander removal and power line interference are not used in this algorithm, because the algorithm itself could remove the interference very well, so the algorithm efficiency is raised. At the same time, an adaptive algorithm is used to adjust the thresholds because of the different amplitude of R-wave among different people, so the robustness of the algorithm is also strengthened. It proved that this algorithm is very suitable for applications in embedded systems after simulation and practical tests. R EFERENCES [1] MIT-BIH Arrhythmia Database. http://www.physionet.org/physiobank /database/mitdb/. [2] L. Su, G. Z. liang, and D. M. Li, “Study of algorithms of QRS complexes detection in electrocardiogram signal,” Editorial Board of Journal of Harbin Engineering, Harbin Engineering University, China, 2005, pp. 513-517. [3] V. Krasteva and I. Jekova, “QRS template matching for recognition of ventricular ectopic beats,” Annals of Biomedical Engineering, Kluwer Academic/Plenum Publishers, USA, 2007, pp. 2065-2076. [4] A. H. Golbayani and M. Ghasemi, “A new mathematical based QRS detector using continuous wavelet transform,” Computers and Electrical Engineering, Elsevier Science Ltd, UK, 2008, pp. 81-91. [5] H. -G. Choi and E. -B. Shim, “Enhancement of QRS complex using a neural network based ALE,” Proceedings of the 22nd Annual International Conference of the IEEE Engineering in Medicine and Biology Society, IEEE, USA, 2000, pp. 958-961. [6] F. Chiarugi, V. Sakkalis, D. Emmanouilidou, T. Krontiris, M. Varanini, and I. Tollis, “Adaptive Threshold QRS Detector with Best Channel Selection Based on a Noise Rating System,” Computers in Cardiology, IEEE, USA, 2007, pp. 157-160.