Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

LabVIEW for ECG Signal Processing

35 ratings | 4.09 out of 5
Print

The electrocardiogram (ECG) is a technique of recording bioelectric currents generated by the heart. Clinicians can evaluate the conditions of a patient's heart from the ECG and perform further diagnosis. ECG records are obtained by sampling the bioelectric currents sensed by several electrodes, known as leads. A typical one-cycle ECG tracing is shown in Figure 1.


[+] Enlarge Image

Figure 1: A typical one-cycle ECG tracing

Generally, the recorded ECG signal is often contaminated by noise and artifacts that can be within the frequency band of interest and manifest with similar characteristics as the ECG signal itself. In order to extract useful information from the noisy ECG signals, you need to process the raw ECG signals.

ECG signal processing can be roughly divided into two stages by functionality: preprocessing and feature extraction (as shown in Figure 2). The preprocessing stage removes or suppresses noise from the raw ECG signal and the feature extraction stage extracts diagnostic information from the ECG signal.


[+] Enlarge Image

Figure 2: Typical ECG signal processing flowchart

With LabVIEW and related toolkits, such as the Advanced Signal Processing Toolkit (ASPT) and the Digital Filter Design Toolkit (DFDT), you can conveniently build signal processing applications for both stages, including baseline wandering removing, noise cancellation, QRS complexes detection, fetal heart rate extraction and etc. This article discusses typical ECG signal processing methods based on LabVIEW.

Preprocessing ECG Signals

Preprocessing ECG signals helps you remove contaminants from the ECG signals. Broadly speaking, ECG contaminants can be classified into the following categories:

  • power line interference
  • electrode pop or contact noise
  • patient–electrode motion artifacts
  • electromyographic (EMG) noise
  • baseline wandering

Among these noises, the power line interference and the baseline wandering are the most significant and can strongly affect ECG signal analysis. Except for these two noises, other noises may be wideband and usually a complex stochastic process which also distort the ECG signal. The power line interference is narrow-band noise centered at 60 Hz (or 50 Hz) with a bandwidth of less than 1 Hz. Usually the ECG signal acquisition hardware can remove the power line interference. However the baseline wandering and other wideband noises are not easy to be suppressed by hardware equipments. Instead, the software scheme is more powerful and feasible for offline ECG signal processing. You can use the following methods to remove baseline wandering and the other wideband noise.

Removing Baseline Wandering

Baseline wandering usually comes from respiration at frequencies wandering between 0.15 and 0.3 Hz, and you can suppress it by a highpass digital filter. You also can use the wavelet transform to remove baseline wandering by eliminating the trend of the ECG signal.

1. Digital Filter Approach

The LabVIEW DFDT provides an intuitive and interactive way to design and implement finite impulse response (FIR) or infinite impulse response (IIR) filters easily and effectively. For example, you can use the Classical Filter Design Express VI to design a Kaiser Window FIR highpass filter to remove the baseline wandering. Figure 3 shows an example of the specifications of the highpass filter and the block diagram of a sample VI that you can use to remove the baseline wandering.


[+] Enlarge Image

Figure 3: Designing and using a highpass filter to remove baseline wandering

2. Wavelet Transform Approach

In addition to digital filters, the wavelet transform is also an effective way to remove signals within specific subbands. The LabVIEW ASPT provides the WA Detrend VI which can remove the low frequency trend of a signal. Figure 4 shows an example of removing baseline wandering by using the WA Detrend VI.

figure1

Figure 4: Using the WA Detrend VI to remove baseline wandering

This example uses the Daubechies6 (db06) wavelet because this wavelet is similar to the real ECG signal. In this example, the ECG signal has a sampling duration of 60 seconds, and 12000 sampling points in total, therefore the trend level is 0.5 according to the following equation:

                                                                figure1
where t is the sampling duration and N is the number of sampling points.

Figure 5 shows the original ECG signal and the resulting ECG signals processed by the digital filter-based and wavelet transform-based approaches. You can see that the resulting ECG signals contain little baseline wandering information but retain the main characteristics of the original ECG signal. You also can see that the wavelet transform-based approach is better because this approach introduces no latency and less distortion than the digital filter-based approach.


[+] Enlarge Image

Figure 5: Comparing the digital filter-based and wavelet transform-based approaches

Removing Wideband Noise

After you remove baseline wandering, the resulting ECG signal is more stationary and explicit than the original signal. However, some other types of noise might still affect feature extraction of the ECG signal. The noise may be complex stochastic processes within a wideband, so you cannot remove them by using traditional digital filters. To remove the wideband noises, you can use the Wavelet Denoise Express VI.

This Express VI first decomposes the ECG signal into several subbands by applying the wavelet transform, and then modifies each wavelet coefficient by applying a threshold or shrinkage function, and finally reconstructs the denoised signal. The following figure shows an example of applying the undecimated wavelet transform (UWT) to the ECG signal.


[+] Enlarge Image

Figure 6: Removing wideband noises from an ECG signal by applying the UWT

The UWT has a better balance between smoothness and accuracy than the discrete wavelet transform (DWT). By comparing the denoised ECG signal with the non-denoised ECG signal, as shown in Figure 7, you can find that the wideband noises are strongly suppressed while almost all the details of the ECG signal are kept invariant.


[+] Enlarge Image

Figure 7: ECG signals before and after UWT denoising

Performing Feature Extraction on ECG Signals

For the purpose of diagnosis, you often need to extract various features from the preprocessed ECG data, including QRS intervals, QRS amplitudes, PR intervals, ST intervals, fetal heart rate, etc. This section mainly discusses QRS complexes detection and fetal ECG extraction.

QRS Complexes Detection

The detection of the R-peaks and consequently of the QRS complexes in an ECG signal provides information about the heart rate, the conduction velocity, the condition of tissues within the heart as well as various abnormalities. It supplies evidence for the diagnoses of cardiac diseases. For this reason, it has drawn considerable attention in the ECG signal processing field. However, the presence of noise and time-varying morphology makes the detection difficult.

Since well-chosen wavelet can extract main features from noisy signals by multi-resolution analysis, a lot of wavelet-based detection methods are introduced recently. In this article, the WA Multiscale Peak Detection VI in the LabVIEW ASPT is used to detect the Q, R and S points. Before the peak/valley detection, use the Multiresolution Analysis Express VI to decompose the ECG signal by 8 level Daubechies6 (db06) wavelets (as shown in Figure 8) and then reconstruct the signal with D4 and D5 subbands. D4 and D5 subbands will be kept for reconstruction because almost all QRS details are within these two subbands, which will make the QRS detection more accurate.


[+] Enlarge Image

Figure 8: ECG multiresolution analysis and implementation of QRS detection

Figure 9 shows the ECG signals processed by wavelet multiresolution analysis (MRA) and peak/valley detection as well as the original ECG signal (from MIT-BIH database). In this figure, you can find that the peaks and valleys (especially Q and S points) become more distinct after wavelet multiresolution analysis.


[+] Enlarge Image

Figure 9: Original ECG, ECG after MRA and ECG after peak/valley detection

After you extract the features by performing QRS complex detection, you can analyze the features with other methods. For example, you can perform heart rate variability (HRV) analysis on the R-R interval signal to demonstrate the state of the heart and nerve system.

Fetal ECG Extraction

The fetal electrocardiogram (FECG) can be derived from the maternal abdominal ECG (AECG) and be used for the extraction of fetal heart rate (FHR), which indicates the cardiac condition of the fetus. The locations of leads for an 8-channel maternal ECG acquisition system are shown in Figure 10. Maternal thorax ECG signals are sampled from thorax leads while maternal abdominal ECG signals are obtained from abdominal leads. This section uses the following two methods to extract fetal heart rate: Independent Component Analysis (ICA) and adaptive filtering.

figure1

Figure 10: locations of lead sensors for 8-channel maternal ECG acquisition system (including 5 abdominal leads and 3 thorax leads)

1. ICA Approach

ICA is a method for retrieving independent hidden signals from a multi-channel observation. Assume that the observation X is a superposition of the source signal S, you can write:
                                                                                X = AS
where A denotes a mixing matrix. The assumption of statistical independence of the signals S allows you to estimate both unknowns, S and A, from the observation X. Here, the maternal ECG and the fetal ECG can be treated as independent components i.e. they are parts of S, while the 8-channel measured ECG records constitute X. By performing ICA, you can obtain the estimation of S, which means you can obtain both maternal ECG and fetal ECG.

The ASPT provides the TSA Independent Component Analysis VI with which you can easily build an FHR extraction application as shown in Figure 11. In Figure 11, 8-channel ECG signals (acquired by the 8-channel system mentioned before) are the inputs of the ICA function, and the fetal ECG signal can be obtained from the output as one of the independent components. Figure 12 shows one maternal abdominal ECG and one fetal ECG extracted from ICA, respectively. From the fetal ECG, you can see that the maternal ECG has been suppressed effectively and the FHR can be obtained accurately and conveniently.

figure1

Figure 11: ICA method for fetal heart rate extraction


[+] Enlarge Image

Figure 12: FHR extraction using ICA

2. Adaptive Filtering Approach

An adaptive filter is a filter that self-adjusts its coefficients to optimize a specified performance index. Adaptive filters have been used in a wide range of applications, one of which is adaptive noise cancellation, as shown in Figure 13.


[+] Enlarge Image

Figure 13: Adaptive noise cancellation structure

In this example, the coefficients of the adaptive filter are adjusted by minimizing errors between the reference signal and the input noisy signal so that the fetal ECG can be obtained by subtracting the maternal thorax signal from the maternal abdominal signal. The LabVIEW implementation of this approach is shown in Figure 14.


[+] Enlarge Image

Figure 14: Adaptive filtering method for FHR extraction

As shown in Figure 15, the adaptive filter with an appropriate order and step size can track and predict the maternal ECG and extract the fetal ECG as the prediction error.


[+] Enlarge Image

Figure 15: FHR extraction using adaptive filter

Summary

LabVIEW and the signal processing-related toolkits can provide you a robust and efficient environment and tools for resolving ECG signal processing problem. This application note has demonstrated how to use these powerful tools in denoising, analyzing, and extracting ECG signals easily and conveniently not only in heart illness diagnosis but also in ECG signal processing research. Moreover, these tools can be also used in other biomedical signal processing applications such as Magnetic Resonance Imaging (MRI) and Electroencephalography (EEG).

Reference

[1] S. Z. Mahmoodabadi, A. Ahmadian, M.D. Abolhasani, M. Eslami, J. H. Bidgoli, “ECG Feature Extraction Based on Multiresolution Wavelet Transform”, IEEE Engineering in Medicine and Biology, 27th Annual Conference.
[2] Bert-Uwe Kohler, Carsten Henning, Reinhold Orglmeister, “The Principles of Software QRS Detection”, IEEE, Engineering in Medicine and Biology, Jan/Feb 2002.
[3] Donghui Zhang, “Wavelet Approach for ECG Baseline Wander Correction and Noise Reduction”, Proceedings of the 2005 IEEE, Engineering in Medicine and Biology 27th Annual Conference.
[4] Gari D. Clifford, Francisco Azuaje and Patrick McSharry, “Advanced Methods and Tools for ECG Data Analysis”, Artech House Publisers.
[5] Behzad Mozaffary, Mohammad A. Tinati, “ECG Baseline Wander Elimination using Wavelet Packets”, Transactions on engineering, computing and technology, V3, Dec, 2004.
[6]  Ping Gao, Ee-Chien Chang, Lonce Wyse, “Blind Separation of Fetal ECG From Single Mixture Using SVD and ICA”.
[7] Kamran Jamshaid, Omar Akram, Farooq Sabir, Dr. Syed Ismail Shah, Dr. Jamil Ahmed, “Application of Adaptive and Non Adaptive Filters in ECG Signal Processing”.


35 ratings | 4.09 out of 5
Print

Reader Comments | Submit a comment »

The "Adaptive Filtering" Start-Up Kit is needed for this application (this is not mentioned in the text). It can be downloaded at http://www.ni.com/labs/ .
- Jan 16, 2008

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).