You are on page 1of 5

Document Type: Tutorial NI Supported: Yes Publish Date: Jan 9, 2012

LabVIEW for ECG Signal Processing


Overview LabVIEW with its signal processing capabilities provides you a robust and efficient environment for resolving ECG signal processing problems. This application note demonstrates how to use LabVIEW's powerful tools in denoising, analyzing, and extracting ECG signals easily and conveniently. These tools can be also used in other biomedical signal processing applications such as Magnetic Resonance Imaging (MRI) and Electroencephalography (EEG). Table of Contents 1. 2. 3. 4. 5. 6. Preprocessing ECG Signals Performing Feature Extraction on ECG Signals Summary Resources for Biomedical Signal Processing Related Documentation Testing Your ECG (EKG) Products to ANSI/AAMI EC13

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. NI LabVIEW is an ideal tool for acquiring and processing ECG, EEG, EMG, and other biopotential signals. A typical one-cycle ECG tracing is shown in Figure 1.

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. The preprocessing stage removes or suppresses noise from the raw ECG signal and the feature extraction stage extracts diagnostic information from the ECG signal. As an example, Figure 2 demonstrates this functionality but also demonstrates an example where ECG data may be embedded within another ECG signal, such as a Fetal ECG signal.

1/5

www.ni.com

Figure 2: Typical ECG signal processing flowchart With NI 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 patientelectrode 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.

2/5

www.ni.com

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.

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:

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.

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 LabVIEW based higher-level 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.

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

3/5

www.ni.com

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.

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.

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.

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.

Summary

4/5

www.ni.com

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).

Resources for Biomedical Signal Processing FREE NI Biomedical Starter Kit - Collection of example programs and LabVIEW VI's for biomedical signal processing and file I/O. Biomedical User Group Forum - On-line user community with discussion forum and resources for LabVIEW users in the biosciences.

Related Documentation Refer to the following documents to learn more about ECG measurements and the application of Graphical System Design using the NI sbRIO with the TI MDXMDKEK1258 Electrocardiogram (ECG) Analog Front End (AFE) module: Electrocardiography ECG Reference Design Embedded Starter Kit Electrocardiography ECG Starter Kit Application Software NI sbRIO Adapter to the Texas Instruments Electrocardiogram (ECG) Analog Front End Module LabVIEW FPGA IP for Texas Instruments ADS1258 16-Channel, 24-Bit ADC Bioelectromagnetism and the 12 Lead ECG System Texas Instruments TMDXMDKEK1258 Electrocardiogram (ECG) Analog Front End (AFE) Testing Your ECG (EKG) Products to ANSI/AAMI EC13 Learn how to test and validate any Electrocardiography (ECG) (EKG) based medical device to ANSI/AAMI EC13. In this document, you will learn how to automate and reduce time required to test and validate any ECG based device using NI PXI modular instruments and NI software.

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/).

5/5

www.ni.com

You might also like