120 Al-Khwarizmi Engineering Journal Al-Khwarizmi Engineering Journal, Vol. 4, No.3, PP 120-127 (2008) COMPUTER-BASED ECG SIGNAL ANALYSIS AND MONITORING SYSTEM Hadeel Kassim Al-Jobouri* Nasser N. Khamiss Al-Ani** *Medical Engineering Department/ College of Engineering/ Al-Nahrain University Baghdad, Iraq, E-mail: hadeel_bme77@yahoo.com **Engineering Information College Baghdad, Iraq (Received 6 March 2008; accepted 8 July 2008) Abstract This paper deals with the design and implementation of an ECG system. The proposed system gives a new concept of ECG signal manipulation, storing, and editing. It consists mainly of hardware circuits and the related software. The hardware includes the circuits of ECG signals capturing, and system interfaces. The software is written using Visual Basic languages, to perform the task of identification of the ECG signal. The main advantage of the system is to provide a reported ECG recording on a personal computer, so that it can be stored and processed at any time as required. This system was tested for different ECG signals, some of them are abnormal and the other is normal, and the results show that the system has a good quality of diagnosis identification. Keywords: ECG, Interfacing Software Design, Data Acquisition System, Biosignals. 1. Introduction The human heart is a complex muscular pump. It is an electrically operated physiological pump that circulates the blood through the body and supplies it with oxygen and nourishment [1]. Owing to the importance of the heart, a great interest has been given to monitor the heart operation, to detect its abnormalities. Williem Einthoven devised the first electrocardiograph (ECG) in 1903 and measured the electrical changes that occurred during the beating of the heart [2]. Today the ECG has become an indispensable piece of medical equipment, and with their present wide range of applications, ECGs are found in intensive care units, general wards, clinics, physician’s consulting rooms, and medical facilities, both large and small [3]. For the past several years, computer–based analysis has been widely applied to the electrocardiogram, so that the computer would be capable of performing ECG analysis 24 hours a day. The readings are exact and always consistent and repeated readings are constant, and this analysis has proven beneficial to both patient and physician [4]. The greatest progress to date in the use of computers for the clinical analysis of physiological data has occurred in the field of cardiology. There are several reasons for this; first of all, ECG potentials are relatively easy to measure; secondly, the ECG is an extremely useful indicator for both screening and diagnosis, in addition, certain abnormalities of the ECG are quite well defined and can be readily identified. In this paper, present the interface with the personal computer (PC) as a base for ECG signal monitoring and analysis which has been designed and implemented for detecting several types of ECG abnormalities. 1. System Hardware Fig.1. shows the proposed ECG system, which consists mainly of two parts; the first is the ECG signal extraction that is responsible of ECG signal detection, filtration and amplification, while the second is the microcomputer interfacing system mailto:hadeel_bme77@yahoo.com Hadeel Kassim Al-Jobouri Al-Khwarizmi Engineering Journal, Vol. 4, No. 3, PP 120-127 (2008) 121 that interface the ECG system with the PC for a next processing of the ECG signal. Fig. 1. Proposal ECG System Blocks Diagram. 2.1 ECG Signal Extractions Fig.2. shows the main parts of the ECG signal extraction. Fig.3. shows the electronic circuits that used to implement such a system. The following is a brief description of each block from a point of implementation view: i. ECG electrodes: an Ag–AgCl electrode type is used, because of its low differences of the polarizing potential. Analog Signal Fig. 2. The Block Diagram for a Typical ECG System. . Fig. 3. Proposal ECG Systems Design. ii. Lead selector network: This network is shown in Fig.4. which consists of a combination of resistors and two 8:1 analog multiplexers to achieve the selection of a specified lead from the 12 standard leads by using the low order 6 bits of an octal latch chip to the selection–input pins of the two multiplexers. iii. Signal amplification: a precision monolithic instrumentation amplifier is used to amplify the ECG signals by a factor of 100, also a Programmable Gain Amplifier (PGA) is used, which consists of a non–inverting amplifier, and gain of this amplifier is variable which is controlled by means of software control. iv. Signal filtering: a fourth order Butterworth LPF with cutoff frequency (100Hz) has been designed to remove the base muscle artifact, second–order HPF with cutoff frequency (0.05Hz) has been used also to remove the base line drift. A hum filter or notch filter is designed to remove unwanted power line interference of cutoff frequency ( BR f =50Hz). v. Signal digitization: the analog and continuous time signals measured by the electrodes that are modified by the filtration and amplification circuitry must be converted into digital form in order to be understood by a computer, and this consists mainly of the analog–to–digital converter. The fast, low cost, complete 12–bit successive approximation ADC converter used for direct interface to a microprocessor bus[5]. Fig. 4. Lead Selector Networks. Signal Amplification Signal Filtering Signal Digitization ADC To the Interfacing Unit ECG Electrode Signal Multiplexing Instrumentation Amplifier Lead Selector Network Filter Circuits Analog Input from the Patient Leads (Electrodes) Output Latch Second Stage of Amplification Address Decoding Circuit PPI 1 8255A Buffer PPI 2 8255A Buffer A/D converter I S A B U S Hadeel Kassim Al-Jobouri Al-Khwarizmi Engineering Journal, Vol. 4, No. 3, PP 120-127 (2008) 122 2.2 Interfacing System In the ECG interfacing system, the interfacing card is designed after the DAS stage to put the ECG signal on the ISA bus to be transmitted to the PC. The currently used PCI bus has a 32–bit data bus and a clock frequency more than four times faster than that of the ISA bus. However, because many medical I/O applications don't require the performance of PCI, manufacturers of medical equipment continued to produce ISA– designed cards, which are relatively easy to customize and cost less than PCI components. An 8–bit ISA card [6] is used for this interfacing design, because it is sufficient to provide the purpose of the hardware design. Fig.5. shows a complete block diagram for the interface card design, which consists of the following sub- units: i. Programmable peripheral interface (PPI): since 12–bit ADC converter is used, here minimum of a 12–bit buffer is needed to hold the data temporarily while the ADC is converting the next analog sample, also in order to read the digital equivalent values of samples given by the ADC to the computer to be processed via an 8–bit ISA bus. For these reasons, and to obtain some flexibility in the interfacing unit, two chips of programmable peripheral interface chip are used. ii. Address Decoder: the address bus lines are decoded by two 3–8 decoders, which act as a full decoding circuit to detect the selected address on the address bus and generates the select signal to activate I/O device at the proper time, in the same time decodes the address bus to generate chip select signals going to the PPI and octal latches. iii. Latching stage: an octal D–type latch chip is used to make the process of the lead and gain selection operates under the software control. iv. Buffering stage: all the data bus, address bus and control bus are buffered through three octal buffer line drivers (bi–directional buffer). v. System Software The development of the software design must be interactive with the hardware design (as described in Fig.2.) of the desired system. Quick Basic & Visual Basic languages are used in the software development. 2.3 ECG Interfacing Systems The two programmable peripheral interface chips must be configured before the unit starts its operation. As well as, the operation of the octal latch and the 12–bit ADC are controlled through software in order to select the desired lead to be sampled and the start and end of conversion.  The operating ECG interfacing system program: ECG interfacing card program interacts with the patient to accept the ECG lead for checking all control signals of the ADC and reads all the 12 channels to ensure the operation of the ADC.  Configuration of the two PPI's: two ports A and B of the PPI1 are configured in mode 0 as input ports, and port C is configured in mode 0 as output port; while port A of the PPI2 are configured in mode 0 as output port. 2.4 Signal Conditioning Filteration process have been done physically at the analog stage, but the noise problems was not solved completely since it may be caused by electrodes, cream and skin together that form a kind of battery call with polarized voltage. On occasions this polarized voltage may amount to as much as 100mV. When polarized voltage is high, it not only affects body movement and respiration, but also causes the fluctuations of the baseline. Thus, an additional signal conditioning step is required before the ECG waveform analysis and detection, and this can be done by using the Hanning filter [7], which is a weighted moving– average algorithm, it is useful for smoothing the signal digitally, and has been extensively used in many applications because of its fast run–time speed and ease of implementation. It is frequently useful to apply this filter several times in succession, i.e. to cascade it, to achieve the desired amount of smoothing. Also, there are two main sources of additive noise are artifacts and baseline variations resulting respectively from local myographical activities and body motion. An analysis of the frequency content of the ECG signal shows that almost all the energy of the ECG signals is distributed below 40Hz and artifacts and baseline variations are predominantly concentrated above 50Hz and around the DC components respectively. The artifacts and baseline variations do not convey any medically useful information and they may affect the performance of peak detection algorithms Hadeel Kassim Al-Jobouri Al-Khwarizmi Engineering Journal, Vol. 4, No. 3, PP 120-127 (2008) 123 Fig. 5. A Complete Bloack Diagram for the Interface Card Design. L O D 0 A 1 2 2 1 A 2 5 B 3 R e s e t 3 6 U 5 A 7 4 0 0 12 3 P B 2 D 3 C S - V s PPI (8255) D B 7 B 2 7 I O W A 6 D 4 86 1 0 1 3 2 5 P C 3 P B 5 A 1 2 1 2 2 0 AD574A B 4 A 2 3 A 5 S e c o n d S ta g e O fA m p lific a tio n R D D 1 A 2 9 P A 7 R D R e s e t A n a lo g In p u tF ro m D B 8 B 2 3 D 0 A 6 D 5 3 5 3 5 1 1 1 4 P A 7 A 1 3 1 3 1 9 B 8 B 1 D 0 I O R P B 6 P A 5 L O D 2 D B 9 A 1 D 6 68 6 D 4 A 1 3 S e le c to rN e to w rk 1 7 1 8 2 4 B 1 1 A 3 1 B 5 T o T h e L e a d I O W A 2 4 P A 2 P A 3 D B 1 0 R 1 1 0 0 2 1 B 2 5 A 0 D 7 9 7 B 1 8 D 3 A 7 D 0 S ta g e O fA m p lific a tio n 1 8 1 2 3 7 1 6 B 1 5 A 2 6 A 2 P A 3 B 1 6 A 1 P A 4 R E S E T P C 6 D B 1 1 -5 V A 4 A 0 3 6 1 1 U 3 7 4 L S 3 7 3 1 1 13478 1 3 1 4 1 7 1 8 25691 2 1 5 1 6 1 9 O C C1 D 2 D 3 D 4 D 5 D 6 D 7 D 8 D 1 Q 2 Q 3 Q 4 Q 5 Q 6 Q 7 Q 8 Q B 1 7 P A 6 A 7 D 1 I B 1 41 5 1 3 3 8 1 7 -1 2 A 1 9 B 1 4 P C 2 3 4 U 1 7 4 L S 2 4 5 1 9123456789 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 GD IR A 1 A 2 A 3 A 4 A 5 A 6 A 7 A 8 B 1 B 2 B 3 B 4 B 5 B 6 B 7 B 8 B 3 1 D 2 C S D 1 U 1 7 4 L S 2 4 5 1 9123456789 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 GD IR A 1 A 2 A 3 A 4 A 5 A 6 A 7 A 8 B 1 B 2 B 3 B 4 B 5 B 6 B 7 B 8 D 7 S T A T U S ( E O C ) A 3 A 1 5 P B 0 A 8 D 2 31 4 1 7 3 9 1 9 B 2 2 A 1 7 D 5 3 3 R e f I n H B 2 9 P A 5 P A 1 P A 0 E n te r D B 0 A 1 0 W R R / C ( S O C ) A 2 0 I B 2 R 1 1 0 0 2 1 P B 6 E n te r A 8 D 3 22 5 1 6 4 0 2 02 B 1 3 P B 2 3 2 A 1 2 P A 6 A 0 A 8 P B 5 B 2 B 3 0 B 1 2 P C 1 A 9 D4 12 4 1 5 1 2 1 A 2 2 7 4 A 1 5 P B 3 3 1 U 1 7 4 L S 2 4 5 1 9123456789 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 GD IR A 1 A 2 A 3 A 4 A 5 A 6 A 7 A 8 B 1 B 2 B 3 B 4 B 5 B 6 B 7 B 8 C S A 2 8 P B 3 D 6 P A 0 D B 1 R e f O u t P C 0 A 9 D 5 4 0 2 3 1 4 2 2 2 A 2 I B 3 2 8 3 A 3 0 P A 4 3 0 B 2 1 R E S E T U 2 7 4 L S 1 3 8 1 5 1 4 1 3 1 2 1 1 1 0 97 1 52364 Y 0 Y 1 Y 2 Y 3 Y 4 Y 5 Y 6 Y 7 A G 2 B BCG 1 G 2 A H A 1 8 A 0 P B 0 D B 2 B i p R e f A 9 P A 1 PPI (8255) A 1 0 3 9 2 2 2 5 2 3 U 2 7 4 L S 1 3 8 1 5 1 4 1 3 1 2 1 1 1 0 97 1 52364 Y 0 Y 1 Y 2 Y 3 Y 4 Y 5 Y 6 Y 7 A G 2 B BCG 1 G 2 A A 3 I B 4 2 9 6 P C 6 B 1 0 + 5 V A 1 P C 2 P C 5 P B 7 D ( 0 - 7 ) R e s e t D B 3 C E 1 0 V S p a n D 7 L O A 1 1 A 1 0 3 8 2 4 B 2 0 A 3 D 6 I B 5 3 0 3 5 W R A 6 2 9 P B 4 P C 0 ISA BUS D B 4 A 0 / S C 2 0 V S p a n P A 2 U 6 A 7 4 0 0 12 3 A 1 1 3 7 2 3 A 2 2 A 4 D 7 I B 6 1 8 3 1 4 2 8 A 1 6 B 2 4 D 6 H A 1 3 2 8 D 5 D M S ( 1 2 / 6 ) A n g . G n d B 1 9 P C 3 A 1 F ig u r e 2 .5 A c o m p le te b lo c k d ia g r a m fo r th e in te r fa c e c a r d d e s ig n A ( 0 - 1 3 ) A 1 1 1 0 2 2 P C 5 A 4 D 1 I B 7 1 9 3 2 1 0 2 8 B 9 P B 1 + 1 2 B 6 2 7 B 2 6 P C 4 G N D A 2 1 P B 1 P C 7 T o T h e S e c o n d D B 5 1 1 P B 4 A 5 D 2 I B 8 2 0 3 3 9 2 7 B 7 P B 7 A 2 7 A 1 4 A 7 5 P C 7 P C 1 P C 4 + V s D 4 D B 6 B 2 8 I O R A 5 D 3 9 2 1 3 4 1 2 2 6 Hadeel Kassim Al-Jobouri Al-Khwarizmi Engineering Journal, Vol. 4, No. 3, PP 120-127 (2008) 124 (QRS complex detection algorithm and P wave detection algorithm) if they are not eliminated. In order to eliminate the artifacts and baseline variations, a digital band pass filter is applied to the input signal. This filter is composed of two low pass filters with cut-off frequencies fc1 and fc2 respectively, the filtered signal is the difference of the outputs of these two low pass filters. The first low pass filter was designed with a cutoff frequency around fc1=1.25 Hz to attenuate baseline variations, the second one was designed with a cutoff frequency around fc2=50 Hz to attenuate the artifacts and the harmonics of the power line. Fig. 6. shows the structure of the band pass filter. This filter consists of two branches, each containing two moving average filters in cascade. 2.5 ECG Waveform Analysis and Detection ECG pattern recognition must be employed to identify the various features of the ECG (QRS, P and T waves).  QRS Complex Identification: QRS complex detection has been implemented firstly by using a second order band pass filter. This filter has a sampling frequency of 200Hz and the turning point algorithm reduced the sampling rate to 100Hz. The second step in QRS complex detection is to find the first and second derivatives of the input signal and process them, to detect the complex and find QRS duration by using the three–point difference algorithm. P and T Wave Identification: a predetermined interval of the ECG signal prior to QRS complex is scanned for a positive peak to locate the P wave. Actually, P wave is often identified on the basis of both the ECG waveform and its first derivative. T wave is identified as a peak within a predetermined interval of the ECG signal following the QRS complex. 4. System Test and Results The designed system was tested on a number of cardiac patients and the results are detailed in Table 1; ECG patient’s reports are shown in Figures 7 – 11. From these results, a clear ECG signal without artifact could be interpreted and reported correctly. Smoothing of the signal is important for this purpose and it was efficiently done in most records. Fig. 7. ECG Patient’s Report Numbers One. Fig. 8. ECG Patient’s Report Numbers Two. Fig. 9. ECG Patient’s Report Numbers Three. Unfiltered ECG Filtered ECG ∑ Average fc=1.25 Hz Average fc=1.25 Hz Traingular filter Average fc=1.25 Hz Average fc=1.25 Hz Traingular filter Fig. 6. Structure of the Band Pass Filter. Hadeel Kassim Al-Jobouri Al-Khwarizmi Engineering Journal, Vol. 4, No. 3, PP 120-127 (2008) 125 Fig. 10. ECG Patient’s Report Numbers Four. Fig. 11. ECG Patient’s Report Numbers Five. Table 1 ECG Patient’s Reports Details. ECG patient’s Report No. 1 2 3 4 5 Age 52 66 48 82 63 QRS Rate Normal Fast Slow Normal Fast QRS Width Normal Normal Normal Abnormal Abnormal QRS Regularity Regular Regular Very Irregular Regular Very Irregular P'S:R'S Ratio P'S=R'S P'S=R'S – P'S=R'S – P–wave Peak Normal Normal – Normal – QRS Peak in Lead V1 S in V1 S in V1 S in V1 S in V1 S in V1 Heart Rate (Beat/Min.) 89 102 50 69 106 Max. R–R Interval 0.676 Sec. 0.596 Sec. 1.436 Sec. 0.88 Sec. 0.66 Sec. Min. R–R Interval 0.656 Sec. 0.576 Sec. 0.832 Sec. 0.848 Sec. 0.496 Sec. QRS Interval 0.101 Sec. 0.092 Sec. 0.091 Sec. 0.122 Sec. 0.135 Sec. Diagnosis Normal Sinus Rhythm Sinus Tachycardia Atrial Fibrillation Complete Left Bundle Branch Block Atrial Fibrillation with Complete Left Bundle Branch Block 5. Conclusions The benefits in this paper lead to the conclusions that the ECG interfacing system has taken the first step towards the next major advance in the relatively slow evolution of cardiology. The work conducted can be built on to eventually provide a system that will be of enormous benefit to the considerable population affected by heart disease and disorders. Overall, this system can be used in hospitals, health centers, nursing homes and clinics. The personal computer was used to provide a medical instrument for ECG signals analysis with the following features: • Low cost. • High CMRR, high input impedance and high control gain amplifier. • Easily operated and automatically functioning, instead of using manual switches. • This system can detect QRS complexes and p–wave, which help in detecting many types of heart disease. 6. Refrences [1] William McMullen, "Physiology Lessons for use with the BIOPAC Student Lab", BIOPAC Systems, Inc., Lesson 6: Electrocardiography II, 1995. http://www.biopac.com, [2] John D. Enderle, Susan M. Blanchardend Joseph D. Bronzino, "Introduction to Biomedical Engineering", Academic Press, 2000. [3] John R. Hampton, "The ECG made easy", Harcourt Brace and Company Limited, 1998. [4] Bronzino, Joseph D., "The Biomedical Engineering Handbook", IEEE Press, 2000. Hadeel Kassim Al-Jobouri Al-Khwarizmi Engineering Journal, Vol. 4, No. 3, PP 120-127 (2008) 126 [5] Travis Robinson, Marc Dowdell, Mark Mielke & Kreshka Niehaus, "A Successive Approximation ADC", an EE 552, 2000. [6] René Møller Fonseca, "Data Acquisition System for the 16 bit ISA bus", B.Sc. in Computer Systems Engineering, University of Southern Denmark, 2001. [7] Greg Hodges, Chief Geophysicist, “The Hanning Filter”, Furgo Airborne Surveys, 2003. Hadeel Kassim Al-Jobouri Al-Khwarizmi Engineering Journal, Vol. 4, No. 3, PP 120-127 (2008) 127 تحلٍل أشارج التخطٍط الكهرتائً للقلة المعتمذ على الحاسىب ونظام المراقثح **نصر نافع خمٍس العـانً *هـذٌـل قـاسن وادي الجـثـىري جايعح انُهشٌٍ / كهٍح انهُذسح/ قسى انهُذسح انطثٍح* كهٍح ذكُىنىجٍا انًعهىياخ ** الخالصح ًُخطَظ انكهشتائً نهقهة ًُخطَظ . ٌرُاول هزا انثحث ذصًٍى وذُفٍز يُظىيح ان انًُظىيح انًعشوضح ذعطً يفهىو جذٌذ نهرعايم يع أشاسج ان االجضاء انًادٌح ذرضًٍ . وهى ٌرأنف تصىسج سئٍسٍح يٍ دوائش االجضاء انًادٌح وانثشيجٍاخ انًرعهقح. و ذحشٌشها, خضَها, انكهشتائً نهقهة ًُخطَظ انكهشتائً نهقهة نرُفٍز يهًح ,Visual Basicوانثشيجٍاخ قذ كرثد تأسرخذاو نغح انـ . ويُظىيح أنشتظ انرثادنً, دوائش ذجًٍع أشاساخ ان ًُخطَظ انكهشتائً نهقهة ًُخطَظ انكهشتائً نهقهة عهى انحاسىب . ذُفٍز أشاسج ان ذكًٍ أهًٍح أنًُظىيح االساسٍح فً انقذسج عهى ذسجٍم ذقشٌش نه هزِ انًُظىيح قذ أخرثشخ . حٍث ًٌكٍ خضٌ انًعهىياخ تعذ أجشاء انقٍاساخ و يعانجرها فً أي وقد يرى يا تشصخ انحاجح انى رنك, أنشخصً ًُخطَظ انكهشتائً نهقهة وأظهشخ هزِ انُرائج أٌ , انثعض يُها هً حاالخ غٍش طثٍعٍح وانثعض االخش حاالخ طثٍعٍح, نًخرهف أشاساخ ان . انًُظىيح نها خاصٍح جٍذج فً ذحذٌذ انًشكهح