Sunteți pe pagina 1din 9

A Two-Lead ECG Using DAQ and Python

By

Biplab Dutta and Anshuman Dey

Report submitted to the Faculty of the Indian Institute of Technology, Kanpur in partial fullment of the requirements for the course PHY692

APPROVED :

Dr. K. P. Rajeev Course Instructor

April 30, 2012 Kanpur, Uttar Pradesh India

Contents
1 Introduction 2 Project Objective 3 A bit of Electrical Theory 3.1 Measurement . . . . . . 3.2 Amplication . . . . . . 3.3 Noise . . . . . . . . . . . 3.4 Data Acquisition . . . . 4 Parts and Cost 5 ECG in the Making 5.1 ECG Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 The Electrodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Setting Up the Complete Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 ECG Visualization 7 Diagrams and Pictures 8 ECG Setup 9 Plots of ECG 2 2 2 2 2 3 3 3 3 4 4 4 4 5 6 7

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

Introduction

Electrocardiograph(ECG) is a device that can be used to amplify, measure and record the natural electrical activity of the heart. It generally measures and records the electrical potential generated by the natural pacemaker - Sinoatrial Node(SAN). Although all of the hearts cells have the ability to generate the electrical impulses(or action potentials) that trigger cardiac contraction, the SAN normally initiates it, simply because it generates impulses slightly faster than the other areas. The ECG(sometimes EKG) is today used world over as a relatively simpler way of diagnosing heart conditions. The fundamental function of the ECG as known today was developed by the Dutch scientist Willem Einthoven in the beginning of the 20th century for which he was awarded the Nobel prize in Physiology or Medicine ...for his discovery of the mechanism of the electrocardiogram. One should note that the cardiac electrical signals are dierent from than the heart beats. ECG is used to study the electrical activity of the heart and heart sounds are listened to with a stethoscope. SAN initiates the electrical signal which serve to command and coordinate contraction of the four chambers at the heart at the appropriate intervals, and their analysis reveals a wealth of information about cardiac regulation, as well insights into the pathological conditions. Each heartbeat produces a periodic pattern in the ECG signal, called a PQRST wave. The smooth curve in the ECG(P) is caused by the simulation of the atria via the SAN in the right atrium. There is a brief pause, as the electrical impulse is slowed by the Atrioventricular node (AVN) and Purkinje bers in the bundle of His. The prominent spike in the ECG(the QRS complex) is caused by this step, where the electrical impulse travels through the inter-ventricular septum and up through the outer walls of the ventricles. The sharp peak is the R component, and exact heart rate can be calculated as the inverse of R-to-R interval(RRi).

Project Objective

Our objective was to build a portable and extremely cheap ECG machine using a data acquisition (DAQ) card and Python (of course excluding the cost of a computer and a DAQ card!). There are some reasons which made us select this project: 1. Firstly, we wanted to do something dierent and very cool! 2. Secondly, we wanted to visualize and analyze our own heartbeat. This project can be divided into two main parts: 1. Hardware - This consist of an Instrumentation amplier, a DAQ card and a computer. 2. Software - Data and post-processing has been done using Python. Before going into the details of the our own ECG machine, let us consider some of challenges which had to be overcome in order to build the ECG.

3
3.1

A bit of Electrical Theory


Measurement

The electrical signals generated in the heart is transmitted along with blood throughout the whole body. These signals can be detected on the surface of the skin. One can simply see these signals as voltage change as their heartbeats if one holds the two leads of a multimeter, one on each hand. These uctuations are rapid and the signals reaching the skin become extremely weak(of the order of few millivolts) and dicult to be detected without proper amplication.

3.2

Amplication

One can simply use an op-amp to amplify the signal. But due to too much background noise we need something which had a very high common-mode rejection ratio. In the beginning of the project we were

to use in-chip instrumentation amplier which are built specially for medical instrumentation(AD624, AD620) but these chips were not easily available. So we decided to go chips which are easily available in an electronics lab. Our instructor suggested us to use op-amp OP07 for instrumentation amplier and op-amp 741 for post amplication. These chips also operate at low voltages.

3.3

Noise

This was the biggest challenge of all! It is unfortunate that the heart is not the only source of voltage on the skin. Radiation from a variety of electrical devices is absorbed by our skin. Our body is a very good receiver. These signals are also measured with our ECG, thus burying the ECG signal in a sea of electrical noise. One can use either hardware(bandpass lters) or software(post processing using python). We did not use any hardware lter. All the ltering is done using python.

3.4

Data Acquisition

For data acquisition we used PMD-1208FS - low-cost USB-based Personal Measurement device. This DAQ card has 8 channels, 12 bit input. For acquiring data we use PyUniversalLibrary (PyUL) which is a Python wrapper for Measurement Computings Universal Library for data acquisition on Microsoft Windows operating systems.

Parts and Cost

This section accounts for the parts and cost in making only the instrumentation amplier and the skin electrodes. Most of the parts we required were available in our Electronics lab. The list of parts used: 3 low voltage op-amp OP07 1 low voltage op-amp 741 6 1k resistors 1 18k resistor 1 33k resistor Electrodes - 2 coins with shampoo (Rs. 5) and 16 Skin Electrodes (Rs. 240) 2Universal PCB (Rs. 90) - Although we didnt use them in our nal demo. 1Stereo pin (Rs. 15) - To check our earlier signal from the instrumentation amplier connecting it the sound card of the computer and using a sound editor (Goldwave) to process the signal.

ECG in the Making

In the beginning we tried setting up the circuit on a Universal PCB but due some error arising every time we decided to use breadboard instead. The circuit for instrumentation amplier was borrowed from Paul Horowitz and Wineld Hill(see References). The schematics (Section 8) shows the circuit layout in details. The gain for the instrumentation amplier is given by [11] Gain = vout = v2 v1 1+ 2R1 Rgain R3 R2 (1)

where vout - output voltage, v2 - +ve input, v1 - -ve input, R1 , R2 , R3 , Rgain - resistors. In our case we obtained a gain of 3 from the instrumentation amplier since we used R1 = R2 = R3 = Rgain and then fed its output to the inverting amplier(using op-amp 741) with a gain of 51. The total gain achieved is 153. This is enough for us to visualize the signal coming from the skin.

5.1

ECG Circuit Diagram

The circuit shown in the gure is divided into parts - an instrumentation amplier and an inverting amplier. The instrumentation amplier with a gain of 3 is used to amplify and reduce noise in the signal coming from the skin. We could have used only the instrumentation amplier to get the output of desired gain but using all equal resistors in the instrumentation amplier made it easy to troubleshoot. In the beginning we had trouble with loose connections since the breadboards werent good enough. Taking the output from the instrumentation amplier with a gain of 3 and feeding it to the input of an inverting amplier with a gain of 51 made it easier to troubleshoot.

5.2

The Electrodes

In the beginning we got the skin electrodes from a medical store. But those werent good enough as they were use-and-throw type. We had think of something which could be used over and over again. Although the skin electrodes gave the best results. For our preliminary testing purposes we used two One rupee coins along with crocodile clips as our electrodes. Shampoo was applied to the skin and electrode interface to provide better conductivity. Electrical tapes were used to attach the electrodes to the skin.

5.3

Setting Up the Complete Circuit

Finally the output from the electronic circuit is connected to the input of DAQ card and the other input of DAQ card is grounded. The circuit diagram shows the connections made.

ECG Visualization

The ECG signal is acquired by DAQ and a code written in python (ecg.py). This piece of code does the following things: Acquires data from the card Plots the raw data in realtime Processes the raw data and outputs the ltered and smoothed data along with the heart rate. The ltering is done digitally using a low pass lter code. The low pass lter reduces the inuence of 60 Hz interference and other background noise. The desirable passband to maximize the QRS energy is approximately 5-15 Hz [1]. But since our hardware is very simple with only two leads we cannot use a bandpass at that range(it completely distorts the ECG waveform). So we have to go with a low pass lter with cuto frequency of 40 Hz. The electrodes have to be properly connected to skin otherwise we end up getting a bad signal. The following steps were implemented to get the nal ECG signal and the heart rate: Acquire the raw data and plot its time series. Filter the data using low pass (cuto frequency 40 Hz) using scipy.signal module. Using Savitzky-Golay lter to smooth the ltered output. All the plots are plotted in realtime with a time lag of the total post processing time of the raw data.

Diagrams and Pictures

(a) Heart and an ECG trace

(b) ECG Circuit Diagram (R1 = R2 = R3 = Rgain = R4 = 1k, R5 = 51k)

ECG Setup

(c) ECG Signal Amplier

(d) Complete ECG Setup

Plots of ECG

Figure 1: Plots of Original Signal, Filtered Signal, Smoothed Signal (xlabel: Time (in seconds), ylabel: Voltage (in Volts))

Acknowledgements: The authors acknowledge Dr. K. P. Rajeev for his support and guidance.

References
[1] J. Pan, W. J. Tompkis, A Real-Time QRS Detection Algorithm, IEEE Transactions on BioMedical Engineering, Vol. BME-32, No. 3 (1985). [2] P. K. Gakare, A. M. Patel, A. N. Cheeran Real Time Analysis and Diagnosis of ECG Signal for Tachycardia Condition, International Journal of Computer Applications, (2012). [3] P. Horowitz, W. Hill, The Art of Electronics, Second Edition, Cambridge University Press (2011) [4] Electrocardiography, http://en.wikipedia.org/wiki/Electrocardiography. [5] DIY ECG Machine on the Cheap, 2009-08-14-diy-ecg-machine-on-the-cheap/. http://www.swharden.com/blog/

[6] Measure Biopotential / ECG, http://www.emant.com/ecg.page. [7] S. Raja, QRS detection in ECGs, http://ggeek.googlecode.com/svn/trunk/qrsdetect/ ecgpy.py. [8] Savitzky-Golay-Smoothing filter.py. with Python, http://public.procoders.net/sg_filter/sg_

[9] PyUniversalLibrary, https://code.astraw.com/projects/PyUniversalLibrary/ [10] Cookbook / Data Acquisition Acquisition_with_PyUL with PyUL, http://www.scipy.org/Cookbook/Data_

[11] Instrumentation Amplier, http://en.wikipedia.org/wiki/Instrumentation_amplifier

S-ar putea să vă placă și