BE 310 Final Lab

Digital Filter Performance Analysis

Group R3

Kelvin Tsang

Thanh Tran Nguyen Duc

Dora Chiang

Enzong Yap

Abstract

The purpose of this project is to designalgorithms with Matlab to efficiently and accurately detect QRS complex of the ECG signal. Constructed algorithms and analysis of algorithms’ performance are performed based on Friesen’s paper. Three QRS detection algorithms, AF2, FD1, and FS1, were implemented as representatives of 3 classes of QRS detection algorithms: 1) AF2: mixed amplitude and first derivative,2) FD1: first derivative only,3) FS1: first and second derivative. Then the QRS detection algorithms were run under different types and amplitudes of noise to compare their performance and the robustness. With the intention of imitating the real circumstances in which ECG signals are recorded, three different algorithms were created to generate the following noises: 1) powerline noise, 2) respiration noise and 3) EMG noise. Composite noise was simulated as a combination of the three noises. After the administration of the four noises with varying magnitudes, these corrupted ECG signals were analyzed by the three filter algorithms and the scoring method designed in this project. The results were then compared with the results of Freisen’s paper.

The results of this experiment are the following: 1) Powerline noise: our results directly contradicted with Friesen’s findings because FS1 was found to be least robust in the testing. This could be caused by incorrect selection of sampling rate for our base ECG signal. 2) EMG noise: AF2 algorithm's superior performance over FD1 and FS1 in terms of percentage QRS hits parallel Friesen’s findings. This is because AF2’s detects QRS with an amplitude threshold. From Friesen's paper, it is expected that algorithms filtering by the first and second order characteristics would perform worse than those filtering using amplitude thresholds. There was also a contradiction on AF2 performance in detecting less false positives which resulted from our small time ECG time sample. 3) Respiration noise: FS1 algorithm's superior performance over AF2 and FD1 parallel Friesen’s findings. This is because FS1 detects QRS without an amplitude threshold, which Friesen claim more susceptible to QRS detection with increasing respiration noise levels. For composite noise, it was found that FS1 had the superior performance over the other two algorithms while AF2 had the second highest QRS % hit. However, there is a big tradeoff for high QRS percentage hit as these two algorithms exhibit high number of false positives.

Some possible reasons leading to differences between Friesen's and our results are the following: 1) differences in how base ECG was constructed: In Friesen’s experiment, the researchers used one manually digitized ECG wave to remove any sources of noise or errors. In our experiment, regular ECG waves obtained from a subject were used; thus, there noise already existI in our base ECG data.; 2) differences in determination of threshold values: The threshold values of the algorithms were optimized by using the composite noise through a tuning process in the Freisen’s paper. On the other hand, we did not use the tuning process to determine the threshold values.; 3)short time samples: In the experiment, we used a one minute sample, which could contribute to the inconsistency due to its short length.

1. Introduction

Nowadays cardiac failure and cardiac diseases are becoming one of main causes of death. Therefore, it is necessary for physicians and researchers to have a satisfactory way to determine the cardiac condition of the patient. Electrocardiograph, ECG, is one of the most direct ways to study the cardiac condition because it records the electrical current generated over the cardiac cycle. Any cardiac abnormalities will be clearly seen through investigation of ECG signals. This provides doctors with the most updated cardiac condition of the patient so that a proper treatment can be given. An example for this will be the pacemaker; the pacemaker monitors the ECG of the patient. The pacemaker will also try to regulate abnormal heartbeats once it detects abnormal ECG patterns. Figure 1.1 is an example of ECG signal; Figure 1.2 is the physiological correspondence between the cardiac cycle and the ECG signal.

Figure 1.1[1]: Figure 1.2[2]:

Figure 1.3[3]

The relationship between the ventricular volume, pressure and ECG of the entire cardiac cycle, systole and diastole can be seen in Figure 1.3. From these figures, one can draw parallel between the heart’s activity with the electrocardiograph signal recorded. By understanding abnormalities of certain sections of the signal, the physician can assess the patient’s sickness. Below are the descriptions of the physiological significance of each wave or interval recorded in the ECG. In this lab, we will deal with the detection of the QRS complex.

P wave represents depolarization of the atria. It is the spread of electrical negativity over the atria from right to left after the initial depolarization of the S-A node. Normal = 0.1 sec, 0.2 mV.

QRS Complex is the spread of negativity through the septum and ventricular musculature. It occurs during the depolarization and contraction of the ventricles. A small amount of atrial repolarization occurs at the same time, but is overwhelmed by the ventricular depolarization and does not normally show. Normal (lead II) = 0.08 to 0.12 sec, 1.0 mV.

P-R Interval is the time from the beginning of the P wave to the beginning of the QRS complex. It represents the interval between activation of the S-A node and the beginning of ventricular depolarization. Any abnormal lengthening of this interval suggests some interference with conduction of the impulse through the atria, A-V node, A-V bundle of His, and/or Purkinje fibers. Normal = 0.13 to 0.16 sec.

T Wave represents the repolarization of the ventricles at the beginning of diastole. It is of longer duration and lower amplitude than the depolarization wave which indicates that ventricular repolarization is less synchronized and slower than the depolarization process. Normal = 0.16 to .27 sec, 0.2 to 0.3 mV.

Q-T Interval represents the time from the beginning of the QRS complex to the end of the T wave. The Q-T interval varies with the heart rate, becoming shorter as heart rate increases. Normal = 0.3 to 0.34 sec.

P-R Segment is from the end of the P wave to the beginning of the QRS complex. During this time the impulse is traveling through the A-V node, A-V bundle, and Purkinje fibers. These are slow, on small numbers of fibers, and the record remains isoelectric. Normal = 0.03 to 0.06 sec.

S-T Segment is from the end of the S wave to the beginning of the T wave. During this time the ventricle is completely depolarized and therefore the record is again isoelectric. Its positions and shape are important in diagnosis. Dead or injured cells from a myocardial infarction will generally show up as irregularities on the S-T segment. Normal = 0.08 sec.

R-R interval is the time require for 1 complete cycle. This is used to determine the rate of heart beat: time interval between two successive beats is the reciprocal of the heart rate. A normal interval is 0.83 seconds which corresponds to 72 beats per minute.

In order to obtain better and quicker information from the ECG signal, it is important to develop algorithms that can efficiently detect the amount of QRS peaks over a period of time. However, QRS detection can be clouded by noise. From the observations of BE 310 lab experiment seven, which is also an ECG experiment, it is determined that power line interference, muscle contraction (EMG), and respiration are few of the main sources of noise observed in the ECG signals. These noises can corrupt ECG signal significantly. The original ECG data was collected from the online database Physionet[4] for the normal at rest person. Appendix 4 graphically shows the original ECG data obtained from Physionet.

Powerline noise consists of interference in the ECG by nearby AC power supplies/ power lines. This shows up in the ECG as sinusoidal waves which are of the same frequency as the base and harmonic frequencies of 60 Hz of the power supply. For most countries this base frequency is 60Hz. According to the Friesen paper, the typical amplitude of powerline noise is 50% of the maximum ECG voltage. In our program, only 60 Hz was used for powerline interference. Appendix 5 graphically shows the powerline noise algorithm output of the modified ECG data with powerline noise of 60Hz at 30% of maximum amplitude added to it.

Respiration causes a shift in the baseline of the ECG which changes throughout the entire respiration cycle. This could be a sinusoidal wave representation which has the same frequency as the respiration rate. According to the Friesen paper, the typical amplitude variation of the noise is 15% of the peak to peak amplitude of the ECG, and the typical frequency of the noise is 0.333Hz. Appendix 6 shows the modified ECG data added with respiration noise.

EMG noise is caused by the contraction of other muscles besides the heart. When other muscles in the thoracic area contract, they generate depolarization and repolarization waves that can also be picked up by the ECG. From Friesen’s paper, EMG noise can be modeled by random Gaussian noise whose maximum amplitude is 50% of the maximum amplitude of the ECG. Appendix 7 shows the modified ECG data added with EMG noise.

Digital filters can be constructed to eliminate these noises to allow for more accurate QRS complexes detection. Nevertheless, digital filters, the designed algorithms, can also alter the ECG signal while eliminating the noises. In this experiment, we used 3 different kinds of QRS detection algorithms. Each algorithm represents a different category of QRS detection algorithms.

AF2 is an example of an amplitude and first order derivative class of algorithms. An amplitude threshold is calculated based on the maximum amplitude of the ECG signal. Thus,when data points are filtered, where only the data points higher than the threshold remained. Then the first derivative is calculated from the remaining data. The remaining data points whose first derivative pass the detection criteria were judged to be QRS candidates.

FS1 is an example of a first order derivative class of algorithms. The algorithm uses only the first order derivative of the data points to select QRS candidates. The methods to derive the first order derivative and the candidate selection criteria are different for every algorithm in this class. If the first order derivative exceeded a certain threshold based on the maximum amplitude of the data, then that data point was selected as a QRS candidate.

FD2 is an example of a first and second order derivative class of algorithms. The algorithm uses both the first and second order derivatives to select QRS candidates. For FD2, a weighted sum of the first and second order derivatives was used. If this weighted sum exceeded a certain threshold, then that data point was selected as a QRS candidate.

Aims and Objectives

To determine the performance of the algorithms with respect to power line, EMG and respiration noise, performance of algorithm is judged by:

  1. High QRS detection accuracy: this is measured in terms of having high levels of QRS% and low levels of false positives
  2. High performance consistency: this is measured by the ability of the algorithm to sustain the level of performance through varying levels of noise.

Based on the above two criteria, the ideal digital filter should be able to produce high QRS% and low amounts of false positives and to be able to sustain this performance through increasing levels of noise. If such algorithm exists, then the digital filter is considered to be robust.

2. Methods

The main aim of this project is to determine the performance of the different algorithms for digital filtering of ECG data, using Friesen’s paper as a guideline. This suggests four stages of development in our project.

2.1 Flowchart and Description of Stages

The first stage of the project is to implement different QRS detection algorithms by coding them into the Matlab platform. We chose 3 different algorithms from Friesen’s paper, one from each category of algorithm described in that paper. We chose AF2 because that algorithm was supposed to give the best performance. We choose FD1 and FS1 to be representatives of their respective categories of algorithms. These three algorithms were then implemented according to the mathematical formulas written in Freisen’s papers. During the implementation process, we had to change some of the constants provided by Freisen’s results in order to optimize the analysis our set of ECG data. A 5 second sample of ECG data was used for this part of the design, and the algorithm constants were manually tweaked to get the smallest constant that could detect the most QRS complexes. Our method to optimize the constants differed greatly from Friesen’s method of using computers to test a large range of values at regular intervals. Freisen’s approach was not taken because our main priority was to get a working QRS-detection package in the short period of time that we had.

The second stage was to implement the noises algorithms in the Matlab environment. These noise algorithms would add specific kinds of noises to any ECG data we had. Three main noises were chosen, powerline noise, EMG noise and respiration noise, because we felt those were the noises most likely to be encountered by the ECG machine based on the observation of Experiment 7 of BE 310 Lab. The algorithms for the noise were also provided in Freisen’s paper. At first we used Friesen’s constants; however, the shape of the noise generated with our ECG data, was very different from the shape of the noise shown on graphs in Freisen’s paper. Therefore, we manually adjusted the constants for the noise algorithms until the general shape of the noise was similar to the shapes depicted in Freisen’s graphs. In this case, the ECG data used to calibrate the noise algorithms was the same data that was used to calibrate the QRS complexes detection algorithms.

The third stage was to implement the scoring system. The scoring system would take the time when the QRS peaks were predicted by the QRS detection algorithms and then compare the time obtained with the actual onset and ending time of the QRS peaks in the ECG itself. Since there was no detail description of how the researchers wrote the code for the scoring system in the Freisen paper, we had to come up with our own method. The followings were the steps taken to write the algorithm for the scoring system: first, if the time given by the QRS detection algorithm fell within the onset and ending time of a QRS complex of the ECG signal, the algorithm was considered to have predicted the QRS correctly. Thus, scoring algorithm would give a “hit” as a result of a correct prediction of the QRS complex. Sometimes, the algorithm would predict multiple QRS peaks when there was only one actual QRS peak in that period of time. We therefore consider the first prediction to be a “hit”, and the remaining multiples to be “repeats”. The repeats were ignored in Friesen’s paper. On the other hand, we decided to determine the repeats to see if that made a difference in comparing the performances of the algorithms. Lastly, if the algorithm predicted a QRS peak when there was none on the actual ECG signal, it was considered to be a false positive.

The last stage of the project was to run real trials on our developed QRS detection system algorithms and compare our results with Freisen’s. Primary, we wanted to test the performance of the algorithms with the various types of noise. 1 minute ECG signals combining with powerline, respiration, EMG and composite noises respectively were run through the algorithms, and the results obtained from the scoreing system were tabulated. The composite noise was simulated by running the ECG signals through all three noises algorithms as the following order: powerline, respiration and EMG noises. The constants used in the noise algorithms were chosen to match the upper limit of noise that an ECG detecting device would encounter under normal circumstances.

Moreover, QRS detection algorithms are evaluated under varying levels of noise to test their robustness against certain types of noise. Therefore, the magnitudes of the parameters of the noises in the noise generation algorithms were varied for each noise, powerline, respiration, and composite, and then observed how the QRS detection algorithms performed. These results were then compared with the results of Freisen’s paper as well.

2.2Matlab

2.2.1 Base ECG

Firstly, the base ECG data (ECG signal without added noise levels) would be converted into a tab delimited “ascii” text file. The “ascii” text file format was chosen because this was the first time we used Matlab programming. Thus, a data structure that could be verified by using another software (eg Notepad) was needed. By doing so, it would allow us to concentrate on the more important aspects of the system and not worry about data handling. The ECG file contains two columns of data. The first column would be the time; the second column would be the voltage of the ECG signal. The output of the QRS detection algorithm would also be in “ascii” text file format, which contained two columns of tab-delimited data. The first column consists of the time when the algorithm detects a QRS complex. The second column contains the values assigned by the algorithm to the ECG graph at that time, and these values were used to make sure that our algorithm is running properly. Coding of the QRS detection algorithm for AF2, FD1 and FS1 is in Appendix 2.