detection of diseases using ecg

39
T.C. DOKUZ EYLUL UNIVERSITY ENGINEERING FACULTY ELECTRICAL & ELECTRONICS ENGINEERING DEPARTMENT DETECTION OF DISEASES USING ECG SIGNAL Final Year Project Report by Serhat DAĞ February, 2017 İZMİR

Upload: serhat-dag

Post on 15-Feb-2017

33 views

Category:

Engineering


3 download

TRANSCRIPT

Page 1: DETECTION OF DISEASES USING ECG

T.C.

DOKUZ EYLUL UNIVERSITY

ENGINEERING FACULTY

ELECTRICAL & ELECTRONICS ENGINEERING

DEPARTMENT

DETECTION OF DISEASES USING ECG SIGNAL

Final Year Project Report

by

Serhat DAĞ

February, 2017

İZMİR

Page 2: DETECTION OF DISEASES USING ECG

DETECTION OF DISEASES USING ECG SIGNAL

SERHAT DAĞ

([email protected])

Page 3: DETECTION OF DISEASES USING ECG

I

Page 4: DETECTION OF DISEASES USING ECG

I

ABSTRACT

In recent years, electrocardiogram (ECG) has been used as main method for the diagnosis of heart

disease. The purpose of this study is to design a decision algorithm which automatically detect heart

diseases. With this project, arrhythmia diseases will be detected more easily. This program can also be

used in education for physicians.

In this project , peak classification approach is used in ECG signal for determining various diseases .

As known the amplitudes and duration values of P-Q-R-S-T peaks determine the functioning of heart of

human. Therefore duration and amplitude of all peaks are found. R-R and P-R intervals are calculated.

Finally, we have obtained the necessary information for disease detection

This project is implemented by using MATLAB software. An interface was created to easily select

and process the signal. “.dat” format is used the for ECG signal data. We have detected bradycardia

and tachycardia.

Page 5: DETECTION OF DISEASES USING ECG

II

ÖZET

Son yıllarda, kalp hastalığının tanısında ana yöntem olarak elektrokardiyogram (EKG)

kullanılmaktadır. Bu çalışmanın amacı, kalp hastalıklarını otomatik olarak tespit eden bir karar

algoritması tasarlamaktır. Bu proje sayesinde aritmi hastalıkları daha kolay tespit edilecektir. Bu

program aynı zamanda doktorlar için eğitimde de kullanılabilir.

Bu projede, çeşitli hastalıkların belirlenmesinde EKG sinyalinde pik sınıflandırma yaklaşımı

kullanılmaktadır. Bilindiği gibi P-Q-R-S-T piklerinin genlik ve süre değerleri insan kalbinin işleyişini

belirler. Bunun için tüm piklerin genliği ve süresi bulunur. R-R ve P-R aralıkları hesaplanır. Son olarak

hastalık tespiti için gerekli bilgileri elde etmiş oluruz

Bu proje MATLAB yazılımı kullanılarak gerçekleştirilmiştir. Sinyali kolayca seçme ve işleme için

bir arayüz oluşturuldu. EKG sinyal verileri için ".dat" biçimi kullanıldı. Bradikardi ve taşikardi

hastalıklarının tespiti yapıldı.

Page 6: DETECTION OF DISEASES USING ECG

III

TABLE OF CONTENTS

ABSTRACT ............................................................................................................................................ I

ÖZET ..................................................................................................................................................... II

TABLE OF CONTENTS .................................................................................................................... III

LIST OF FIGURES............................................................................................................................. IV

1.INTRODUCTION .............................................................................................................................. 1

1.1 GENERAL OVERVIEW ..................................................................................................................... 1

1.2. THE ELECTROCARDIOGRAM ......................................................................................................... 1

1.3. DATA ............................................................................................................................................ 3

2.ARRHYTMIA .................................................................................................................................... 3

2.1. NORMAL SINUS RHYTHM ............................................................................................................. 4

2.2. SINUS TACHYCARDIA .................................................................................................................... 4

2.3. SINUS BRADYCARDIA ................................................................................................................... 4

2.4.HEART BLOCK ............................................................................................................................... 4

3. ALGORITHM OF PROGRAM ...................................................................................................... 5

3.1. WAVELET TRANSFORM ................................................................................................................ 6

3.2 PEAKS DETECTION ....................................................................................................................... 11

4. DEMONSTRATION OF PROGRAM .......................................................................................... 11

5. COST ANALYSİS ........................................................................................................................... 15

6. WORK PLAN .................................................................................................................................. 15

7. CONCLUSION ................................................................................................................................ 16

8. REFERENCES ................................................................................................................................ 17

9.APPENDIX-I .................................................................................................................................... 18

10.APPENDIX-II ................................................................................................................................. 28

11.APPENDIX-III ............................................................................................................................... 29

12.APPENDIX-IV................................................................................................................................ 30

13.APPENDIX-V ................................................................................................................................. 32

Page 7: DETECTION OF DISEASES USING ECG

IV

LIST OF FIGURES

FIGURE 1-REPRESENTS A TYPICAL ECG WAVES ..................................................................................... 1

FIGURE 2-. SHAPES OF THE ELECTROCARDIOGRAM ................................................................................ 2

FIGURE 3-THE HEART’S ANATOMY ......................................................................................................... 3

FIGURE 4-DESCRIPTION OF THE ALGORITHMS ........................................................................................ 5

FIGURE 5-SCALING FUNCTION FOR WAVELET DAUBECHIES 8 ................................................................ 7

FIGURE 6-SCALING FUNCTION COEFFICIENT FOR DB8 ............................................................................. 8

FIGURE 7-WAVELET FUNCTION FOR WAVELET DAUBECHIES 8 (DB8) .................................................... 8

FIGURE 8-WAVELET FUNCTION COEFFICIENT FOR DB8 .......................................................................... 9

FIGURE 9-RELATIONSHIP BETWEEN DIGITAL WAVELET COEFFICIENTS ................................................ 10

FIGURE 10-THREE LEVEL WAVELET DECOMPOSITION TREE ................................................................. 10

FIGURE 11-APPROXIMATION COEFFICIENT OF SIGNAL AT LEVEL 4 ...................................................... 11

FIGURE 12-DEMONSTRATION OF PROGRAM .......................................................................................... 12

FIGURE 13-ORIGINAL SIGNAL (PROPERTIES OF SIGNAL IS DESCRIBED IN 1.3 DATA) .......................... 12

FIGURE 14- COEFFICIENTS OF SIGNAL AT 1 LEVEL DECOMPOSITION .................................................. 13

FIGURE 15-COEFFICIENTS OF SIGNAL AT 2 LEVEL DECOMPOSITION .................................................... 13

FIGURE 16-COEFFICIENTS OF SIGNAL AT 3 LEVEL DECOMPOSITION ................................................... 14

FIGURE 17-COEFFICIENTS OF SIGNAL AT 4 LEVEL DECOMPOSITION ................................................... 14

FIGURE 18-WORK PLAN ........................................................................................................................ 15

FIGURE 19-WAVELET FAMILIES ............................................................................................................ 28

FIGURE 20-ANALYSIS RESULTS OF THE SIGNALS IN THE DATA FOLDER ............................................... 29

FIGURE 21-APPROXIMATION COEFFICIENTS OF SIGNAL LEVELS FOR DB8 ........................................... 30

FIGURE 22-DETAIL COEFFICIENTS OF SIGNAL LEVELS FOR DB8 .......................................................... 31

FIGURE 23- ATR. FILE FOR 101.DAT FILE ............................................................................................... 32

FIGURE 24-HEADER FILE FOR 101.DAT FILE .......................................................................................... 32

Page 8: DETECTION OF DISEASES USING ECG

1

1.INTRODUCTION

1.1 General Overview

The population increases day by day. Therefore people don't get enough benefit from health services.

It is impossible for patients to be kept under the supervision of a physician at all times. Speed and time

are very important for physicians. This project is intended to help doctors to analyze the ECG signal.

Doctors will save time thanks to program. This program can also be used for education for.

1.2. The Electrocardiogram

Open and see method were used for diseases of internal organs by physician. It meant that people

were always suffering. This was also a very difficult situation for both physicians and patients.

Technology has improved. Now doctors use non-invasive methods. For example urine and blood tests.

Various signals are taken from the organs in the human body. The information generated by these signals

is in this group. For examples EEG (electrical activity of the brain, electroencephalogram), EMG

(electrical activity of the muscles, electromyogram). and ECG. ECG signal analysis was performed in

this project. Detailed information about this signal is given below.

The electrical current is spread through the body when the heart undergoes depolarization (The

electrical activation of the tissues is positive) repolarization (The discharge of electrical charge of the

tissues ) [1]. This electrical activity generated by heart. It can be measured by an array of electrodes

placed on the body surface. These records are called electrocardiograms (ECG or EKG).

Over the past few years, there has been an increased trend toward processing of the electrocardiogram

(ECG) using microcomputers. A survey of literature in this reach area indicates that system based on

microcomputers can perform needed medical services in extremely efficient manner [2].

Figure 1: Represents a typical ECG waves. [2]

Page 9: DETECTION OF DISEASES USING ECG

2

The heart beat period of time curve (typical ECG waveforms) is examined in figure 1. There is a

sharpness in the figure. Periodic sharpness can be seen in figure 2. These sharpness associated with the

contraction of the ventricular. These are called “depolarization” [3]. Muscle fibers lost resting potential

during depolarization [2]. Signal prepared to go slightly negative deviation as a rule, it continues with a

big positive taper [2]. Followed by a second negative deviation income. The cons traction of the

ventricles is called “QRS complex”. A oscillation is seen after QRS complex. This oscillation also is

called ST range or ST wave. Now the potential difference is immeasurable. A zero line is drawn at this

time is called the isoelectric line. This is followed by T-wave ( representing the depolarization). The P

wave indicates that they are in the excited state to the atrium. Finally U waves is not always seen [1]. It

is typically small . U waves are thought to represent repolarization of the papillary muscles. A ECG

signal can be examine in figure 2 (This is a theoretical signal. The actual ECG signal is not as smooth

as this signal) .

Figure 2 . Shapes of the electrocardiogram : signal heart might produce assuming a 4000 Hz

sampling rate. The heart rate for this signal is approximately 89 beats per minute, and the peak

voltage of the signal is 3.5 millivolts [4]

An electrocardiogram is a measurement of the electrical activity of the heart muscle which can be

obtained from the surface of the skin and from different angles like Figure 3. When the heart muscle

contracted and pumping the blood for all parts of body, action potentials will be released through the

mechanical process within the heart muscle which leads to electrical activity.

Page 10: DETECTION OF DISEASES USING ECG

3

Figure 3: The heart’s anatomy with waveforms from different specific part of the heart . [3]

1.3. Data

ECG signals are collected from Physionet MIT-BIH arrhythmia database. ECG signals are

described by a text header file (.hea), a binary file (.dat) and a binary annotation file (.atr). Header file

consists of detailed information such as number of samples, sampling frequency, format of ECG signal,

type of ECG leads and number of ECG leads, patient’s history and the detailed clinical information.[5]

In binary data signal file, raw ECG recordings were sampled at 360 Hz with an 12-bit resolution over

the 10 mV range. Binary data file store raw data signals (12 bits used for each sample). Binary data

files are created with reference to header files [5]. The signal is stored in 212 format. Other files are .atr

files (annotation file). “.atr ” files contain some comments for the record files. So which storages some

experts note about the analysis of signal quality results [6].

2.ARRHYTMIA

For a normal healthy person the ECG comes off as a nearly periodic signal with depolarization

followed by repolarization at equal intervals(as figure 2). However, sometimes this rhythm becomes

irregular.

Cardiac arrhythmia (also dysrhythmia) is a term for any of a large and heterogeneous group of

conditions in which there is abnormal electrical activity in the heart. The heart beat may be too fast or

too slow, and may be regular or irregular. Arrthymia comes in varieties. It may be described as a flutter

in chest or sometimes “racing heart” [7]. The diagnosis of Arrthymia requires Electrocardiogram. By

studying ECG, Doctors can diagnose the disease and prescribe the required medications. Most of time

arrythmia’s are harmless and happen in healthy people free of heart disease. However, some abnormal

heart rhythms can be serious or even deadly [8]. Having other types of heart disease an also increase the

risk of arrhytmia’s.

Page 11: DETECTION OF DISEASES USING ECG

4

2.1. Normal Sinus Rhythm

The first measurement is known as the "P-R interval" and is measured from the beginning of the

upslope of the P wave to the beginning of the QRS wave. This measurement should be between 0.12

and 0.20 seconds(120-200 ms)[7]. Duration of PR is represented “res” in MATLAB code.

When measuring the PR interval, the lead with the longest PR interval should be chosen. (In some

leads, the initial part of the PR interval may be isoelectric. This may be misinterpreted as a short PR

interval) [9] . The R-R intervals are constant; the rhythm is regular for normal sinus rhythm. Duration

of RR interval should be between 480 and 600 ms [7] ( Duration of RR interval is represented res_2

in MATLAB codes)

2.2. Sinus tachycardia

Generally, occurs normally in exercises and stress. Other causes may be under lying medical

problems (Anemia, Fever ,Blood loss…[10]) Electrical signal is faster than usual. The heart rate is

fast. But heart beats is properly. Therefore RR interval is constant and regular. Due to the above

reasons, duration of RR peak should be shorter than normal sinus (it is between 0.45 and 0.48

second). PR interval is between 0.12–0.20 seconds.

2.3. Sinus Bradycardia

Electrical signal is slower than usual. The heart rate is slower. But heart beats is properly. Therefore

RR interval is constant and regular. PR interval is between 0.12–0.20 seconds. Causes of bradycardia

are Sleep, hypothermia, some drugs etc. [10] Duration of RR peak should be bigger than tachycardia

and sinus rhythm.

2.4.Heart Block

Heart block is an abnormal heart rhythm where the heart beats too slowly. It's slower than

bradycardia. PR interval is bigger than 0.20 second [9].

Page 12: DETECTION OF DISEASES USING ECG

5

3. ALGORITHM OF PROGRAM

Figure 4: Description of the Algorithms

In this project we will implement a algorithm in MATLAB. The program will firstly extract the

characteristics of ECG. After that we will find the location and amplitude of ECG signal. That's why

we can find the problem that cause to patient.

Apply Wavelet Transform for Decomposed Signal

R peak detection (Find the maximum value of ECG signal and

locate Rloc )

P peak detection (Using window Rloc-90 to Rloc-10, find the

maximum)

Q peak detection (The minima in the window of Rloc-40 to

Rloc-10 )

50)

S Peak Detection (The minima in the window of Rloc+5 to

Rloc+40)

T Peak Detection (Using window of Rloc+25 to Rloc+90, find

the maximum)

Calculate PR and PR Intervals

Decision for Patient Healthy

or not Healthy

Take a RAW ECG Signal

From Data Set

Page 13: DETECTION OF DISEASES USING ECG

6

3.1. Wavelet Transform

Recently, wavelets transform is applied to electro cardiology for several problems . Wavelet

transform is used for including data compression, analysis of ventricular late potentials, and the

detection of ECG characteristic points [11]. The wavelet transform can separate high frequency

component an low frequency component in time domain. In addition wavelet transform is able to

decompose signals at various resolutions. It allows accurate feature extraction from non-stationary

signals like ECG [11] .

The Continuous Wavelet Transform of a signal is defined as f (t), and it is represented as (the sum

of over all time of the signal multiplied by scaled [11] ):

W(a, b) = ∫ f(t)ᴪa,b (t)+∞

−∞dt ………… ( 3.1)

where

ᴪa,b(t) = 1

√aᴪ∗(

t−b

a) ……….( 3.2)

Where * denotes complex conjugation and , ᴪ∗(𝑡−𝑏

𝑎) is a window function called the mother

wavelet, a’ is a scale factor ,b’ is also a translation factor [12].

Wavelets are defined by the wavelet function ψ(t) (i.e. the mother wavelet) and scaling function φ(t)

(also called father wavelet) in the time domain.

Let a=𝑎0−𝑟 , b=ka0

−rb0 and a0 = 2 , and b0 = 1 from dyadic transformation (dyadic

transformation are samples of wavelet transforms following a geometric sequence of ratio 2). Value of

j and k is integer and t is a variable in the continuous space (j is number of level and k is shifting value

).

We can define scaling and wavelet function as below

Φj,k(t) = 2j

2ΦN(2jt − k) ……(3.3) , ᴪj,k(t) = 2j

2ᴪ(2kt − k) ……….(3.4)

We define wavelet and scaling function Φj,k(t), ᴪa,b(t) ∈ L2(R), which is limited in time domain.

The continuous wavelet transform is the sum of the signal multiplied by the shifted and scaled versions

of the main wavelet in the time domain. As a result of these operations, wavelet coefficients are obtained

depending on the scale and position.

In this project we use discrete wavelet transform with ‘wavedec’ function. Because , discrete wavelet

transform is most practical . It provides enough information for signal. It offers a significant reduction

in computation time, it mean it is faster .

Page 14: DETECTION OF DISEASES USING ECG

7

𝑊ᴪ(j, k)= 1

√M ∑ f(n)ᴪj,k(n)𝑛 …..(3.5) and 𝑊𝛷(𝑗0, k)=

1

√𝑀∑ f(n)Φj0,k(n)n …(3.6)

j≥ 𝑗0 and n∈ 𝑍

1

√𝑀 is normalization constant.

Φ𝑁(t) = ∑ hΦ(n)√2 Φ(2t − n)𝑛 …….. (3.7) and

ᴪ(t)= ∑ hᴪ(n)√2 Φ(2t − n)𝑛 ………(3.8)

where

𝛷(𝑡) = { 1 when 0 ≤ t ≤ 1

0 otherwise …..(3.9) and ᴪ(𝑡) = {

1 when 0 ≤ t ≤ 1/2

−1 when 1

2≤ t ≤ 1

0 otherwise

..(3.10)

ℎᴪ(𝑛) and ℎ𝛷(𝑛) is wavelet and scaling function coefficient. These coefficients indicate

characteristic characteristics of wavelet and scaling function. There are several wavelet families like

Harr , Daubechies , Coeiflets, Symlets, Morlet, Mexican Hat, Meyer ect [12] ( wavelet form can be

examined in appendix 2). Selecting a wavelet function which closely matches the signal to be processed

is of most importance in wavelet applications Daubechies is chosen (d8 scaling function is used) .

Daubechies wavelet family are similar in shape to QRS complex and their energy spectrum are

concentrated around low frequencies [13] .

Figure 5: Scaling function for wavelet Daubechies 8 (db8) [14]

Page 15: DETECTION OF DISEASES USING ECG

8

Figure 6: Scaling function coefficient for db8 [14]

Figure 7: Wavelet function for wavelet Daubechies 8 (db8) [14]

Page 16: DETECTION OF DISEASES USING ECG

9

Figure 8: Wavelet function coefficient for db8 [14]

If we use (3.4) and (3.8) for (3.7)

𝑊ᴪ(j, k)= 1

√M ∑ f(n)ᴪj,k(n)𝑛 where , ᴪj,k(n) = 2

j

2ᴪ(2jn − k)

𝑊ᴪ(j, k)= 1

√M ∑ f(n)𝑛 2

j

2ᴪ(2jn − k)….(*) after we can write by 3.8

ᴪ(2jn − k)= ∑ ℎᴪ(𝑛′)√2 𝛷(2j+1𝑛 − 2𝑘 − 𝑛′)𝑛′ …(**) After that we can write into * equation

𝑊ᴪ(j, k)= 1

√M ∑ f(n)𝑛 2

j

2 ∑ ℎᴪ(𝑛′)√2 𝛷(2j+1𝑛 − 2𝑘 − 𝑛′)𝑛′

Let n’=m-2k

𝑊ᴪ(j, k)= 1

√M ∑ f(n)𝑛 2

j

2 ∑ ℎᴪ(𝑚 − 2𝑘)√2 𝛷(2j+1𝑛 − 𝑚)𝑚

𝑊ᴪ(j, k)= 1

√M ∑ ℎᴪ(𝑚 − 2𝑘)𝑚 ∑ f(n)2

j+1

2 𝛷(2j+1𝑛 − 𝑚)𝑛

𝑊𝛷(j+1, m) = 1

√M ∑ f(n)2

j+1

2 𝛷(2j+1𝑛 − 𝑚)𝑛 (From equation * )

So we can write 𝑊ᴪ(j, k)= ∑ ℎᴪ(𝑚 − 2𝑘)𝑚 𝑊𝛷(j+1, m) This means,

𝑊ᴪ(j, k)= ℎᴪ(−𝑛)* 𝑊ᴪ(j+1, m) and we can apply same operation for approximation coefficient

Therefore 𝑊𝛷(j, k)= ℎ𝛷(−𝑛)* 𝑊𝛷(j+1, m) for n=2k and k≥ 0

Page 17: DETECTION OF DISEASES USING ECG

10

The last equations determine relationship between digital wavelet coefficients of adjacent scales.

Wavelet coefficient is scaling and scaling time-reversed for each step. Block diagram can be examined

in figure 9.

Figure 9: Relationship between digital wavelet coefficients [11]

After wavelet transform is applied two component emerge (with wavedec function in MATLAB).

First component is approximation components (it has lower frequency function) and high scale

information other component is detail components have higher frequency and less information.

Approximation components (coefficient) occurs after low band pass filter (associated with scaling

function). Detail coefficients can be obtained after high band pass filter (associated with wavelet

transform).

The original signal is filtered by half band low pass and high pass filter. This is done for each

coefficient. The width of the filter will be reduced by half for each level. These operations consist of

decomposition tree. Operations can be repeated many times. In this project the signal decompose at level

8. We can see three level wavelet decomposition tree in figure 10.

Figure 10: Three level wavelet decomposition tree [13]

𝒂𝒋+𝟏(𝒏) = ∑ 𝒉(𝟐𝒏 − 𝒌)𝒂𝒋(𝒏)𝟐𝒏𝒌=𝟏 And 𝒅𝒋+𝟏(𝒏) = ∑ 𝒈(𝟐𝒏 − 𝒌)𝒂𝒋(𝒏)𝟐𝒏

𝒌=𝟏

Page 18: DETECTION OF DISEASES USING ECG

11

3.2 Peaks detection

Peaks of the R waves have a largest amplitude (we can see in figure 1). After the decompose the signal

high frequency component is removed. R peaks is noticeable even if R peak are deformed.

Approximation coefficient signal of signal at 4 level can be examined on figure 11.

Figure 11: Approximation coefficient of signal At Level 4 (101.dat signal is used)

The locations of the maximum points of the signal were determined. Then these locations of R peaks

were found in the original signal. Finally, amplitude of R peaks were found for original signal.

Detection of R peaks is very important. Because other peaks are found according to R peaks. After R

peak detection we need to select a window of Rloc‐90 to Rloc‐10 and find the maximum, than that

maxima is P peak [15]. For location of Q peak we must select a window of Rloc‐40 to Rloc‐10 and find

the maximum [16]. To find S peak select a window of Rloc+5 to Rloc+40 and find the maximum [16].

Lastly we select a window of Rloc‐100 to Rloc‐50 and find the maximum for T peak [16]. Generally

window is used to search signal because of down sampling. Down sampling deviate location of wave

.

4. DEMONSTRATION OF PROGRAM

When we run the program, we encounter a interface which has multiple section. Firstly we select a

raw ECG signal from data file. Second step we need enter two value. First value represent number of

sample and other value is window size. Window size also represent part of sample to use. After that we

click on Apply Wavelet button. Wavelet transform apply to signal. That’s why we can see

approximation coefficient. Next step we click on Processing Button and we calculate P,Q,R ,S,T

Page 19: DETECTION OF DISEASES USING ECG

12

(durations and amplitude) peaks. Finally , to read result on the interface we need to click on Result

Button.

Figure 12:Demonstration of Program ( 101.dat signal is used)

Approximation coefficient of 101.dat signal is drawn below. We can see R peak noticeable (4. level is

enough to consider R peaks )

Figure 13: Original signal (properties of signal is described in 1.3 DATA)

Page 20: DETECTION OF DISEASES USING ECG

13

Figure 14: Coefficients of Signal At 1 Level Decomposition Very similar to the original

signal.

Figure 15: Coefficients of signal At 2 Level Decomposition , Better than the original

signal. But not smooth enough

Page 21: DETECTION OF DISEASES USING ECG

14

Figure 16: Coefficients of Signal At 3 Level Decomposition , It still is not smooth

Figure 17: Coefficients of Signal At 4 Level Decomposition

High-frequency compounds are removed when the graphics are examined. As a result we can see R

peaks. Other important point is y axis of signal increased and x axis is reduced by scaling function (if

we examine axis we can notice that).

Page 22: DETECTION OF DISEASES USING ECG

15

5. COST ANALYSİS

ECG Signal Compression is a software project that is created and developed via MATLAB. For this

project, MATLAB is provided by free license from the university to the students. For this project,

personal computer HP k53sv series with 2.4 Ghz processor, 6GB RAM, 500 GB Hard disc space, 5400

rpm hard disc driver NVIDIA GeForce GT 540M + Intel GMA HD graph card is used.

6. WORK PLAN

Figure 18 :Work Plan

Each step of the plant is interconnected . We have to pay attention to this every step of the way. The

table was created entirely according to the effort I spent.

Page 23: DETECTION OF DISEASES USING ECG

16

7. CONCLUSION

Over the past few years, importance for human life has been known heart disease. ECG is the

main method is used in the diagnosis of heart disease. Purpose of project that the analysis of heart

disease with ECG signal. This project is implemented by using MATLAB software and on the basis of

the wave form obtain the peaks are classified and are used for the detection of the disease.

Wavelet decomposition applied for decomposed ECG signal. All R peaks are noticeable.

Daubechies wavelet family are similar in shape to QRS complex. Therefore Daubechies wavelet is

chosen for prototype wavelet used.

After wavelet transform is applied the ECG, we detect R peaks. The location of the other peaks

was determined with location of R peaks. Lastly , we calculated RR and PR intervals. These interval

is very important for detecting diseases. These intervals are important for determining the type of illness.

For example , electrical signal is faster than usual for tachycardia. Therefore duration of RR peak

should be shorter than normal sinus. PR interval is also important for us. It was a fixed interval in the

detection of tachycardia and bradycardia. This value was high in some patients' data. Thus Heart block

disease is added

It consist of effective, simple, non-invasive, low cost procedures for the diagnosis of various

disorders physicians for their for their decision and education. This project will reduce the workload

of the doctors. It would be easier for a doctor to verify later.

Page 24: DETECTION OF DISEASES USING ECG

17

8. REFERENCES

[1] H. Al-jobouri, “Designation of interface and software program as a base for ECG monitoring and

signal analysis,” M.S. thesis, Dept. of Medical Eng., AlNahrain Univ., Baghdad, Iraq, 2004

[2] Advances in Cardiac Signal Processing Rajendra Acharya U, Jasjit S. Suri, Jos A.E. Spaan an d S

.M. Krishnan, pp.3-13

[3] P. Gustafsso and J. Hagblad, “Miniaturised multi-channel wireless ECG connected to graphical

computer interface using bluetooth,” M.S. thesis, Dept. of Comp. Sci. and Electronics, Mälardalen

University, Sweden, 2007.

[4] http://www.mathworks.com/matlabcentral/fileexchange/35328, 01/02/2017

[5] THE MIT-BIH Arrhythmia Database On CD_ROM AND Software For Use With it, George B.

Moody and Roger G. Mark

[6] https://www.physionet.org/physiobank/database/mitdb/ ,01/02/2017

[7] A Research Work on Identification of Cardiac Disorders using LabVIEW Mohan Kumar

[8] F.A.Davis, “ECG_NOTES,” 2005

[9] The value of the electrocardiogram in the differential diagnosis of a tachycardia with a widened QRS

complex ,Hein J.J. Wellens. Author

[10] Diagnosis and Treatment of Sick Sinus Syndrome VICTOR ADÁN, M.D., Angel Medical Center,

Franklin, North Carolina LOREN A. CROWN, M.D., University of Tennessee Health Sciences Center,

Covington, Tennessee

[11] A Tutorial of the Wavelet Transform Chun-Lin, Liu February 23, 2010

[12] Digital Image Processing (3rd Edition) 3rd Edition by Rafael C. Gonzalez, pp.477-493

[13] ECG Feature Extraction Using Daubechies Wavelets S. Z. Mahmoodabadi, A. Ahmadian, M. D.

Abolhasani, Tehran University of Medical Sciences (TUMS), Tehran, Iran

[14] A Wavelet Transform Method to Detect P and S-Phases in Three Component Seismic Data Salam

Al-Hashmi, Adrian Rawlins, Frank Vernon

[15] Automatic Delineation of ECG Characteristics Points using Window Search & Multi-resolution

Wavelet Transform approach Amit Kumar Manocha, Mandeep Singh

[16] EKG Sinyallerinde Gürültü Gidermede Ayrık Dalgacık Dönüşümünde Farklı Ana Dalgacıkların

Ve Ayrıştırma Seviyelerinin Karşılaştırılması Cengiz Tepe, Hatice Sezgin

[17] Empirical Wavelet Transform-based Detection of Anomalies in ULF Geomagnetic Signals

Associated to Seismic Events with a Fuzzy Logic-based System for Automatic Diagnosis ,Omar Chavez

Alegria, Martin Valtierra-Rodriguez,

Page 25: DETECTION OF DISEASES USING ECG

18

9.APPENDIX-I

%--------------Final Project------------------------------------------------

% DETECTION OF DISEASES USING ECG SIGNAL

%

% SERHAT DAĞ 2011502024

% February, 2016

%------------------------------------------------------------------------------

function varargout = ecg_wavelet(varargin)

% ECG_WAVELET MATLAB code for ecg_wavelet.fig

% ECG_WAVELET, by itself, creates a new ECG_WAVELET or raises the existing

% singleton*.

%

% H = ECG_WAVELET returns the handle to a new ECG_WAVELET or the handle to

% the existing singleton*.

%

% ECG_WAVELET('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in ECG_WAVELET.M with the given input arguments.

%

% ECG_WAVELET('Property','Value',...) creates a new ECG_WAVELET or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before ecg_wavelet_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to ecg_wavelet_OpeningFcn via varargin.

%

% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one

% instance to run (singleton)".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ecg_wavelet

% Last Modified by GUIDE v2.5 27-Oct-2016 01:03:26

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

Page 26: DETECTION OF DISEASES USING ECG

19

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @ecg_wavelet_OpeningFcn, ...

'gui_OutputFcn', @ecg_wavelet_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% --- Executes just before ecg_wavelet is made visible.

function ecg_wavelet_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to ecg_wavelet (see VARARGIN)

% Choose default command line output for ecg_wavelet

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes ecg_wavelet wait for user response (see UIRESUME)

% uiwait(handles.figure1);

flag =1;

% --- Outputs from this function are returned to the command line.

function varargout = ecg_wavelet_OutputFcn(hObject, eventdata, handles)

Page 27: DETECTION OF DISEASES USING ECG

20

% varargout cell array for returning output args (see VARARGOUT);

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

% --- Executes on button press in Select.

function Select_Callback(hObject, eventdata, handles)

% hObject handle to Select (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of Select

global nfile A flag

[fil pth]=uigetfile('.dat','Enter File Name Wich You Want to Work')

file=[pth fil];

fid=fopen(file,'r');

nfile=fread(fid);

nfile=imresize(nfile,[183 1]);

axes(handles.axes1)

plot(nfile,'-'), title('Original Signal')

figure(1),plot(nfile,'-'), title('Original Signal')

z=zeros(100,1);

A=[z;nfile;z]; % Add 100 zeros before and after the signal

axes(handles.axes2)

plot(A,'-'),title('Original Signal With Pad')

figure(2),plot(A,'-'),title('Original Signal With Pad')

flag=2;

% --- Executes on button press in Apply.

Page 28: DETECTION OF DISEASES USING ECG

21

function Apply_Callback(hObject, eventdata, handles)

% hObject handle to Apply (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Define global variables.

global nfile Qamp_mv Ramp_mv Samp_mv Tamp_mv P_1 Pamp_mv A flag c

%-----------Perform Discrete Wavelet Transform (daubechies 8)---------------

if flag==2

flag=3;

[c,l]=wavedec(nfile,8,'db8');

ca1=appcoef(c,l,'db8',1);

ca2=appcoef(c,l,'db8',2);

ca3=appcoef(c,l,'db8',3);

ca4=appcoef(c,l,'db8',4);

figure(2),plot(ca1,'-k'),title('Cofficients of Signal At l Level Decomposition')

figure(3),plot(ca2,'-k'),title('Cofficients of Signal At 2 Level Decomposition')

figure(4),plot(ca3,'-k'),title('Cofficients of Signal At 3 Level Decomposition')

figure(5),plot(ca4,'-r'),title('Cofficients of Signal At 4 Level Decomposition')

flag=3 ;

else

errordlg('First select ECG Signal')

end

% --- Executes on button press in Exit.

function Exit_Callback(hObject, eventdata, handles)

% hObject handle to Exit (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

clc

close all

clear all

% --- Executes on button press in Result.

Page 29: DETECTION OF DISEASES USING ECG

22

function Result_Callback(hObject, eventdata, handles)

% hObject handle to Result (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global nfile Qamp_mv Ramp_mv Samp_mv Tamp_mv P_1 Pamp_mv A flag c

if flag==4

%% Setting handles q p r s t assigns the specified value of the handles to the specified property

Q,P,R,S,T

set(handles.q,'string',['Q=' num2str(Qamp_mv)])

set(handles.p,'string',['P=' num2str(Pamp_mv)])

set(handles.r,'string',['R=' num2str(Ramp_mv)])

set(handles.s,'string',['S=' num2str(Samp_mv)])

set(handles.t,'string',['T=' num2str(Tamp_mv)])

set(handles.textll,'string',['PERSON HEALT:-' P_1])

else

errordlg('Calculate values/apply wavelet') % Create error dialog box

end

end

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

% str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

Page 30: DETECTION OF DISEASES USING ECG

23

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function edit2_Callback(hObject, eventdata, handles)

% hObject handle to edit2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text

% str2double(get(hObject,'String')) returns contents of edit2 as a double

% --- Executes during object creation, after setting all properties.

function edit2_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

% --- Executes on button press in Proccesing.

function Proccesing_Callback(hObject, eventdata, handles)

% hObject handle to Proccesing (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global nfile Qamp_mv Ramp_mv Samp_mv Tamp_mv P_1 Pamp_mv A flag c

flag=4;

per=get(handles.edit1,'string');

Page 31: DETECTION OF DISEASES USING ECG

24

per=str2double(per);

if per>0 & per <=60

per=per;

else

errordlg('ENTER PERTAGE IN RANGE');

end

wndw=get(handles.edit2,'string');

wndw=str2double(wndw);

if wndw>2 & wndw <=20

wndw=wndw;

else

errordlg('ENTER window IN RANGE');

end

%-------------R Peak Detection--------

m1=max(c)*(per/100);

p=find(c>=m1);

p1=p;

p2=[];

last=p1(1);

sig_fnd=length(p1);

for i=2:sig_fnd

if (p1(i)>(last+10))

% In this step we find R peaks which are atleast 10 samples apart

last=p1(i);

p2=[p2 last];

end

end

p3=p2*8 %Multiply the current location with 8 to get the actual scale.

R_position=[];

for i=1:length(p3)

range=[p3(i)-wndw:p3(i)+wndw]

m=max(A(range))

Page 32: DETECTION OF DISEASES USING ECG

25

l=find(A(range)==m)

pos=range(l)

R_position=[R_position pos]

end

Ramp=round(A(R_position));

X=R_position;

Rloc=R_position;

y1=A;

for i=1:1

for j=1:length(X)

%----------------------P Peak Detection----

a=R_position(i,j)-90:R_position(i,j)-10;

m=max(y1(a));

b=find(y1(a)==m);

b=b(1);

b=a(b);

Ploc(i,j)=round(b);

Pamp(i,j)=round(m);

%------Q Peak Detection-----

a=R_position(i,j)-40:R_position(i,j)-10;

m=min(y1(a));

b=find(y1(a)==m);

b=b(1);

b=a(b);

Qloc(i,j)=round(b);

Qamp(i,j)=round(m);

%----S Peak Detection----

a=R_position(i,j)+5:R_position(i,j)+40;

m=min(y1(a));

b=find(y1(a)==m);

b=b(1);

b=a(b);

Sloc(i,j)=round(b);

Samp(i,j)=round(m);

%-------T Peak Detection----

Page 33: DETECTION OF DISEASES USING ECG

26

a=R_position(i,j)+25:R_position(i,j)+90;

m=max(y1(a));

b=find(y1(a)==m);

b=b(1);

b=a(b);

Tloc(i,j)=round(b);

Tamp(i,j)=round(m);

end

end

clc

disp('VALUE OF AMPLITUDES(mv) OF P Q R S T ARE')

Pamp_mv=Pamp

%disp(Pamp)

Qamp_mv=Qamp

Ramp_mv=Ramp

Samp_mv=Samp

Tamp_mv=Tamp

disp('VALUE OF DURATION(ms) OF P Q R S T ARE')

Ploc_ms=Ploc

Qloc_ms=Qloc

Rloc_ms=Rloc

Sloc_ms=Sloc

Tloc_ms=Tloc

res=Ploc_ms+Qloc_ms+Rloc_ms; % P TO R İNTERVAL

res_2=Rloc_ms+Sloc_ms+Tloc_ms+Qloc_ms+Ploc_ms; % R to R interval

res

res_2

if res>=120 & res<=200

if res_2>=480 & res_2<=600

P_1='PERSON IS SUFFERING FROM BRADYCARDIA';

disp('PERSON IS SUFFERING FROM BRADYCARDIA')

elseif res_2<450 && res_2>430

P_1='PERSON IS SUFFERING FROM TACHYCARDIA';

disp('PERSON IS SUFFERING FROM TACHYCARDIA')

Page 34: DETECTION OF DISEASES USING ECG

27

elseif res_2>450 && res_2<480

P_1='PERSON IS HEALTY';

disp('PERSON IS HEALTY')

else

P_1='Not Clear in ECG Signal';

disp('Not Clear in ECG Signal')

end

end

if res>200

P_1='PERSON IS SUFFERING FIRST DEGREE HEART BLOCK';

disp('PERSON IS SUFFERING FIRST DEGREE HEART BLOCK')

end

flag=4;

Page 35: DETECTION OF DISEASES USING ECG

28

10.APPENDIX-II

Figure 19(a): Daubechies , Haar, Morlet, Symlets , Coiflets, Meyer wavelet function [17]

Figure 19 (b):Mexican Hat Wavelet Function [12]

Figure 19: Wavelet Families

Even if a signal is not well represented by one member of the Db family, it may still be efficiently

represented by another. Selecting a wavelet function which closely matches the signal to be processed

is of importance in wavelet applications [13]

Page 36: DETECTION OF DISEASES USING ECG

29

11.APPENDIX-III

FILE Disease

100.dat PERSON IS HEALTY

101.dat PERSON IS SUFFERING FROM TACHYCARDIA

102.dat PERSON IS SUFFERING FROM TACHYCARDIA

103.dat PERSON IS SUFFERING FROM TACHYCARDIA

104.dat PERSON IS HEALTY

105.dat PERSON IS SUFFERING FROM BRADYCARDIA

106.dat PERSON IS SUFFERING FROM BRADYCARDIA

108.dat PERSON IS HEALTY

109.dat Not Clear in ECG Signal

111.dat PERSON IS SUFFERING FROM BRADYCARDIA

112.dat PERSON IS SUFFERING FROM BRADYCARDIA

113.dat PERSON IS SUFFERING FROM BRADYCARDIA

114.dat PERSON IS SUFFERING FROM BRADYCARDIA

115.dat Not Clear in ECG Signal

116.dat Not Clear in ECG Signal

117.dat PERSON IS SUFFERING FROM BRADYCARDIA

118.dat PERSON IS SUFFERING FROM BRADYCARDIA

119.dat PERSON IS SUFFERING FROM BRADYCARDIA

121.dat Not Clear in ECG Signal

123.dat PERSON IS SUFFERING FROM TACHYCARDIA

124.dat PERSON IS SUFFERING FROM TACHYCARDIA

200.dat PERSON IS SUFFERING FROM BRADYCARDIA

201.dat PERSON IS SUFFERING FROM BRADYCARDIA

202.dat Not Clear in ECG Signal

203.dat Not Clear in ECG Signal

205.dat PERSON IS SUFFERING FROM TACHYCARDIA

208.dat PERSON IS HEALTY

209.dat PERSON IS HEALTY

212.dat PERSON IS HEALTY

213.dat Not Clear in ECG Signal

215.dat PERSON IS HEALTY

217.dat PERSON IS SUFFERING FROM BRADYCARDIA

219.dat PERSON IS SUFFERING FROM BRADYCARDIA

220.dat Not Clear in ECG Signal

222.dat PERSON IS SUFFERING FROM TACHYCARDIA

223.dat PERSON IS SUFFERING FROM TACHYCARDIA

228.dat PERSON IS SUFFERING FROM BRADYCARDIA

230.dat PERSON IS SUFFERING FROM BRADYCARDIA

231.dat PERSON IS HEALTY

232.dat PERSON IS SUFFERING FROM BRADYCARDIA

233.dat PERSON IS HEALTY

234.dat PERSON IS HEALTY

Figure 20: Analysis results of the signals in the data folder

Window size is 6 and 20 percent of the signal was used . Heart block 'could not be detected. But

Some signals have PR range close to 200 ms. PR need to be less than for detected bradycardia and

tachycardia.

Page 37: DETECTION OF DISEASES USING ECG

30

12.APPENDIX-IV

Figure 21: Approximation Coefficients of Signal Levels for db8

The high-frequency components are removed by wavelet transform. Therefore last signal (8.Level) is

smooth and maximum value can be found. In addition effect of scaling function can be noticed.

Page 38: DETECTION OF DISEASES USING ECG

31

Figure 22: Detail Coefficients of Signal Levels for db8

The low-frequency components are removed by wavelet transform. In addition effect of wavelet

function can be noticed.

Page 39: DETECTION OF DISEASES USING ECG

32

13.APPENDIX-V

Figure 23: atr. File for 101.dat file (N: normal beat , Sub, Chan, Num is describe

abnormal beats ) [6]

Figure 24:header File for 101.dat file (101:signal number 2:two signal is used, 650000:

number of sample, 212:format of signal 200:gain of signals 1024 : Zero value of ADC, 955-29832

The checksums of the 650000 samples, third line is similar to second line, Last line determine sex

and age of the subject and data about the recording and drugs (Diapres is name of drug ) )[6].