# Automating the Diagnosis of Heart Conditions

## By

ECG’s can show slight abnormalities when examined, which can indicate major heart conditions. I hypothesize that if these time-based readings are converted into pure frequencies, the range of certain frequencies can more clearly indicate the presence of a heart condition. Although there is a main frequency identifying each heat beat, there may also be other **frequencies that are distinct to each condition, **which are explored using Fast Fourier Transforms.

Furthermore, these distinct patterns** can be stored in a computer, which would be able to examine all future ECG’s and diagnose the abnormality**, without the need for human analysis.

In the medical institutes of Canada there are clearly not enough doctors to assist the numerous patients and most nurses do not possess the necessary medical background to conduct diagnosis. One of the most common causes for need of medical attention and death is heart disease. Heart disease is presently diagnosed using an ECG, which a cardiac test examining the electrical impusles of the heart. However, some abnormalities in an ECG can be difficult to detect, and require a trained professional. To address this issue I decided to stray from the traditional method of ECG diagnosis, and to convert the time based graphs to pure frequencies instead.

The method I used to convert these graphs into their pure frequencies was by the use of the algorithm of Fast Fourier Transform (FFT). Using FFTs was important because they allow you to view a miniscule frequency produced by spikes in the original graph that go by unnoticed to the untrained eye.

Through my research I have found that FFTs are an appropriate method of analyzing ECGs. It was shown that the frequency graphs of arrhythmias consisting of palpitations and skipped beats created minimal to no frequencies beyond 30 Hz. It was also concluded that the frequencies of atrial fibrillation are all concentrated in the higher frequencies of 50 Hz. These both deviated from the FFT of a normal sinus rhythm whose frequencies were tapered down from 0 Hz to 40 Hz. I was also able to develop a method of MATLab which allowed it to diagnose atrial fibrillation graphs successfully. I concluded that the automated diagnosis of heart conditions using Fast Fourier Analysis is possible.

My name is Anam Rizvi and I am a grade 12 student at Westwood High School in Fort Mcmurray, Alberta. My first look into engineering was in the summer of grade 11 when I got a chance to participate in a women's engineering program at the University of Alberta. While I was part of this program, I got to tour the University of Alberta, particularly their mechanical engineering department. As I looked around the buiding, their were blueprints hung about of ideas of machines to combat several medical issues. For example, a wheel chair that could climb stairs. That was what inspired me to come up with a way to apply engineering towards the two greatest problems plagueing our medical industry: Hospital waiting times and heart disease. In the future, I hope to continue my project and advance to bio medical mechanical engineering. I hope to work with innovative engineers all over the world to construct instruments that can better our quality of life, access to health care and our health care system as a whole. Winning this science fair would mean being able to bring my work to light and expand it to a whole new level. It would mean creating a name in the engineering industry and being able to network with other like minded individuals and experienced engineers. It would mean the world to me.

Can the frequencies produced by the electrical impulses of a heart be indicative of a heart condition? Can this be a better method of diagnosing heart conditions than using an ECG which measures the electrical impusles of the heart as a function of time? Can the frequency patterns presented by an ECG be taught to a computer to automize the diagnosis?

ECG’s can show slight abnormalities when examined, which can indicate major heart conditions. I hypothesize that if these time-based readings are converted into pure frequencies, the range of certain frequencies can more clearly indicate the presence of a heart condition. Although there is a main frequency identifying each heat beat, there may also many other frequencies that are distinct to each condition, which we explore using Fast Fourier Transforms.

Furthermore, these distinct amplitudes of frequencies values can be stored in a computer, which would be able to examine all future ECG’s and diagnose the abnormality, without the need for human analysis. This could pave the way for technological diagnostics.

**Similar Studies**

*Study and Analysis of ECG Signal Using MATLAB & LABVIEW as Effective Tools, M.K.Islam*

*International Journal of Computer and Electrical Engineering, Vol. 4, No. 3, June 2012**,*

- Uses wavelet analysis, which is a mathematical means of analyzing a time based signal with changing frequencies. It provides more precise information about the data which benefits over FFTs in finding small abnormalities
- Concluded that MATlab and/or LabVIEW can be used to monitor a heart condition and even in self diagnosis without the use of an ECG machine. They can also be used to stimulate and analyze ECGs.
- Uses MATlab to study and analyze ECGs
- Also expands to feature extractions, comparisons and detection of abnormalities

*Electrocardiogram signal analysis using zoom FFT, Murugan, Kamalapriya*

*Biosignals and Biorobotics Conference (BRC), 2012 ISSNIP Top of Form*

- Analyzes ECG’s using the Zoom FFT method
- Zoom FFT is used when fine spectral resolution is needed within a small portion of a signal's overall frequency range.
- Generated their own FFT waveforms
- Blends complex down conversion, lowpass filtering, and sample rate change through decimation in a spectrum analysis application. It

*Diagnostic performance of a computer-based ECG rhythm algorithm, **Kimble Poon**, MD, **Peter M. Okin**, MD, **Paul Kligfield**, MD*

*Journal of Electrocardiology July 2005, Vol 38, Iss 3*

- Examined the accuracy of rhythm based computer interpretation
- 7.8% of computer interpretations required revision; false negative rate for sinus rhythm was 1.3% for doctors and 9.9% in computer; false negative for atrial fibrillation was 9.9% for doctors and 1.1% in the computer
- Concluded that computer diagnosis of paced rhythms remains problematic due to the need for physicians to overread and correct computer diagnosis

This research has influenced my project because it has led me to the conclusion that the electrical impulses of the heart can be analyzed using a mathematical means. I have also discovered that sometimes, the diagnosis of a computer can turn out to be more accurate. These references led me to research on the method of FFT's and also to access MATLab as a tool in my project.

My project varies from these studies because firstly FFT analysis was useful in finding patterns and visible distinctions, which was more than enough for the extent of my project, while these studies were a deeper analysis. In the future, I would also like to explore the wavelet method and the Zoom FFT. Also, they did not apply this study to the analysis and detection of ECGs using MATlab based software, and therefore their application is the standard human analysis. The journal of electrocardiology presented a computer based method of diagnosis however they used rhythm based interpretations and I used FFT to examine frequencies, which can determine abnormalities more accurately using frequencies.Lastly, my method is more cost-efficient.

An ECG array can be found in a standardized file collection on physionet.org. It is a digitalized table of values for an ECG. The function I produced on MATlab plots the ECG as a function of time, using the time values found in the first column of the ECG array. The function then computes the spectrum of the ECG using the FFT and plots the strength of each mode (frequency) as a function of the frequency. The frequency on the horizontal axis is the reciprocal of the time values. The spectrum is plotted on two scales, the full spectrum and a low frequency spectrum. This last plotted is obtained by basically zooming in on the low frequency end of the FFT spectrum, which is where most of the signal strength of a healthy heart is found.

The basic heart rhythm is the first non-zero peak in the low frequency spectrum. The peak at zero frequency is known as a DC offset and is due to the fact that the ECG trace is not centered in zero volts. This peak is not significant and is removed from the spectrum plots.

The command used in MATlab is:

ecgArray = rdsamp('ltafdb/01','maxt','0:30');

ecgDesc = wfdbdesc('ltafdb/01',1);

figure(1)

plotECGandFFT(ecgArray, 2, ecgDesc); % Basic plot

figure(2)

plotECGandFFT(ecgArray, 2, ecgDesc, 30); % Rescale max frequency

figure(3)

plotECGandFFT(ecgArray, 2, ecgDesc, 30,20); %Rescale max time for ecg

figure(4)

plotECGandFFT(ecgArray, 2, ecgDesc, 30,20,15,30); %Rescale max frequency for each spectrum

This allows us to control the parameters of the graph such as time values, maximum frequencies etc.

I first drew up files from the arrhythmia database on physionet.org and researched through patient histories to find files where premature ventricular contractions (PVC) were present. Premature ventricular contractions are also catagorized as skipped beats, and are indicative of arrhytmias. I graphed them and analyzed the patterns that their frequencies had in common. I also recorded how the frequencies of the PVCs differed from the frequencies produced by a normal sinus rhythm.

The next condition i analyzed was long term atrial fibrillation. I, again, drew up files from the long term atrial fibrillation database and used my MATlab function to produce their FFTs, so that all the frequencies present in the ECG could be displayed.

Upon analysis, I found that atrial fibrillation produced distinctive frequencies of 40 Hz - 50 Hz which were not present in a normal sinus rhythm, nor in any other heart condition. I used this pattern to create a function on MATLab which would analyze the amplitudes of these frequencie. If it was found that the amplitudes of these frequencies were greater than the maximum amplitude at 10 Hz, then they were concluded to be atrial fibrillation.

To create my FFT’s I used the software program MATlab by mathworks, in collaboration which an online ECG database known as physionet.org. Using MATlab, I was able to draw up digitalized ECGs and graph their readings. I was also able to input a formula which would then graph the FFT’s showing a high frequency range (0 Hz to 50 Hz) and then zooming into a low frequency (0 Hz to 10 Hz).I found that the basic heart rhythm was the first non-zero peak in the low frequency spectrum.

The first condition I observed was using an Arrhythmia database and focussed on patients which experienced premature ventricular contractions (PVCs). A PVC is similar to common heart palpitations or skipped beats and are often indicative of an arrhythmia. I tested the FFT’s of several PVC’s and compared them to a normal heart’s frequencies. What I found was that during a normal sinus rhythm the frequency peaks range from 0 Hz to 30 Hz, and most of the maximum amplitudes are concentrated in the lower frequencies between 0 Hz and 10 Hz. Comparing this to a graph of a PVC, I saw that frequencies were again mainly concentrated in the 0 Hz to 10 Hz range, yet there were miniscule to no frequencies by 30 Hz. This indicated that an arrhythmia causes lower than normal frequencies, and little to no frequencies above 30 Hz. Upon further analysis, I also saw that each graph produced a similar pattern of spikes and found that the amplitudes of the 1 Hz (normal heart rate frequency) and the 2 Hz frequency were closer together. Sometimes the 2 Hz frequency would even be greater than the normal heart rate.

The second heart condition I explored was long term atrial fibrillation. Some symptoms of this condition include a fast and erratic heart rate, heart palpitations and shortness of breath. Due to the erratic heart rates produced by the condition, the FFT showed frequencies largely concentrated in 40 Hz to 50 Hz. This was exactly the opposite of a normal sinus rhythm which barely contained spikes at a 50 Hz frequency.

Since the pattern for this condition was so easily notable, I began to design a MATlab function to diagnose it. Basically, the function consisted of commands which first told it to analyze the maximum value of an ECG for the frequencies ranging from 2 Hz to 10 Hz (these are considered low frequencies). It then finds the maximum amplitude in the frequencies ranging around 40 Hz to 50 Hz (these are considered high frequencies). When it compares the two maximum values, if the high frequencies had a greater maximum amplitude than the low frequencies, then it can be concluded that the ECG is displaying atrial fibrillation.

To test this method, I used a database which was known to consist of all ECG’s displaying atrial fibrillation. Out of 73 trials, it was found that 67 of them were successfully diagnosed, giving a 91.78% accuracy.

In conclusion through my research I have found that FFTs are an appropriate method of analyzing ECGs. It was found that the frequency graphs of arrhythmias consisting of palpitations created minimal to no frequencies beyond 30 Hz, and often display similar patterns in spikes. These patterns consisted of 2 Hz which contained spikes at the same amplitude as the 1 Hz (normal sinus rhythm frequency). It was also concluded that the frequencies of atrial fibrillation are all concentrated in the higher frequencies of 50 Hz. These both deviated from the FFT of a normal sinus rhythm whose frequencies were tapered down from 0 Hz to 40 Hz. Furthermore, I was able to develop a method of MATLab which allowed it to diagnose atrial fibrillation graphs successfully, by comparing the maximum amplitude value at 40 hz to the maximum amplitude value at 10 Hz. If the 40 Hz maximum was greater then the 10 Hz then it was confirmed that atrial fibrillation was present. Overall, this method gave a 91.78% accurate result in diagnosing atrial fibrillation. I have concluded that my initial hypothesis was correct and frequencies are a legitimate method of determining heart conditions from the elctrical impulses of the heart. Frequencies are easier to view when there are minscule changes in a graph, and therefore their patterns can be taught to a software program which can analyze all further ECGs to diagnose heart conditions automatically.

Some improvements I would like to make on this project would be, firstly, to be able to access certain abnormal portions of an ECG, in order to pinpoint their corresponding frequencies. This is because an ECG can run for several hours, yet only show an abnormality for about 30 seconds. This was one of my limitations, as MATlab would only allow me to analyze the first 30 seconds of a graph. I would also have liked to overlay the graphs of a common heart condition, to be able to analyze the patterns of their frequencies more accurately. Furthermore, physionet.org contains a tool which allows a person to create an artificial ECG. Using this, I would like to see how an FFT responds by the manipulation of the different components of an ECG. Lastly, I would like to explore more accurate ways of displaying the frequencies present in a graph. For example, I have researched on a wavelet analysis which is another mathematical means of analyzing a time based signal with changing frequencies. It provides more precise information about the data which benefits over FFTs in finding small abnormalities.

In the future, this method can be developed to discover more heart conditions which create distinct patterns in their frequencies. In a country like Canada, our health care institues are constantly backed up by long waiting times. These can deter busy individuals from seeking medical attention and health check ups. My method is cost and time efficient, and if developed, it can have a profound affect on the waiting times of cardiac institutes and hospitals.

I would like to acknowledge my mentor Dr. Jean-Pierre De Villiers, Keyano College, who has assisted me in the technical areas of this project, especially regarding MATlab. He has supplied me with MATlab software made by MathWorks. He has also helped me learn how to create functions and commands on Matlab, how to utilize MATlab to produce FFTs and has answered any questions I may have.

**References**

*Study and Analysis of ECG Signal Using MATLAB & LABVIEW as Effective Tools, M.K.Islam*

*International Journal of Computer and Electrical Engineering, Vol. 4, No. 3, June 2012, *

*Electrocardiogram signal analysis using zoom FFT, Murugan, Kamalapriya*

*Biosignals and Biorobotics Conference (BRC), 2012 ISSNIP Top of Form*

*Diagnostic performance of a computer-based ECG rhythm algorithm, **Kimble Poon**, MD, **Peter M. Okin**, MD, **Paul Kligfield**, MD*

*Journal of Electrocardiology July 2005, Vol 38, Iss 3*

**Bibliography**

- http://www.youtube.com/watch?v=zKKGA30bHG0
- http://en.wikipedia.org/wiki/Premature_ventricular_contraction
- http://physionet.org/
- http://www.heartandstroke.com/site/c.ikIQLcMWJtE/b.5052135/k.15A/Atrial_fibrillation.htm?utm_campaign=offline&utm_source=bepulseaware&utm_medium=vanity
- http://www.heartandstroke.com/site/c.ikIQLcMWJtE/b.3483991/
- http://hyperphysics.phy-astr.gsu.edu/hbase/math/fft.html
- Matlab: A Practical Introduction to Programming and Problem Solving [Second Edition] by Stormy Attaway