As a result of ageing population and a progressively greedy will of better healthcare, new medical devices have arisen. Some focus on prevention, others in treating. The prototype developed here focus in the acquisition of the heart’s electrical activity with a simple electrical circuit embedded in an Arduino microcontroller, with the possibility of early heart diseases detection. An effective and affordable solution was proposed and dozens of trials were performed with the device. These pointed to a high rate of detection of R, S and T-peaks (~100%, 78, 3% and 72, 5%, respectively) with an accurate heart rate measure. Despite of the good results obtained, this device, for now, must not be used for other purposes than monitoring.
IntroductionBig efforts to provide good healthcare at affordable prices have become a central issue in the last decades. Along with wide technological developments, it has been possible to create more efficient devices and with new available features. Wearables are a class of devices with an exponential growth in the last years, as problems with battery life get overpassed.
This electrocardiograph joins Arduino features with ananalog circuit and acquires, amplifies and filters a very weak signal obtained from the chest.
A set of algorithms were then proposed to detect arrhythmias, heart muscle necrosis, hypertrophic ventricles, variations in the heart rate depending on the position (lying down, seated or standing) of the person.
A set of trials were then carried out to evaluate the sensibility and reliability of the obtained measurements. Despite we were only able to test our device in healthy people (thus, no pathologic recordings were obtained), different and representative results were obtained among all candidates.
Given the results obtained versus the simplicity of the circuit, great improvements are expected to be achieved in a reduced time scale. Observing the world’s tendency, in a near future, it is expected to see ECG (wearable) devices at home, automatically detecting many pathologies without clinician intervention.
Physiological Basis---------------------------- Cardiac Cycle and Electrical Activity ----------------------------
The cardiac cycle is controlled by the sinoatrial node (SA node) via electrical stimulation. The node consists of a group of very peculiar cells with the ability to spontaneously produce an electrical impulse that propagates through a network of specialized fibers (atrioventricular node, His bundle, Purkinje fibers), regulating heart muscle’s contraction. Because it is responsible for setting the heart’s rhythm, the SA node is often called the natural pacemaker.
This electrical activity of the heart is the biological fundament behind the electrocardiogram (ECG) register. In fact, each feature of the ECG is related to some phase of the cardiac cycle.At the beginning of the cardiac cycle, both the atria and ventricles are relaxed (diastole), and the blood is flowing into the right and left atria from venae cavae and the four pulmonary veins, respectively. Since both the tricuspid and mitral valves are opened, blood flows unimpeded from the atria to the ventricles.
Following atrial depolarization, represented by the P wave of the ECG, the atrial muscles contract from the superior portion of the atria toward the atrioventricular septum, pumping the blood into the ventricles through the open atrioventricular valves. At the start of atrial systole, the ventricles are usually filled with approximately 70–80% of their capacity, during the atrial systole the ventricles are completely filled. Atrial systole lasts approximately 100ms and ends before the ventricular systole.
Ventricular systole follows the depolarization of the ventricles and is represented by the QRS complex in the ECG. Initially, the pressure generated in the ventricles is not sufficient to eject the blood from the heart, the blood flowsback and closes the atrioventricular valves, it’s the isovolumetric contraction phase since blood’s volume remains constant. When the contraction of the ventricular muscle counterbalances the pressures in the pulmonary trunk and aorta, the ejection phase of theventricular systole begins and the blood is pumped from the heart.
Ventricular relaxation, or diastole, follows repolarization of the ventricles and is represented by the T-wave of the ECG.
--------------------------- ECG Features and Anomalies Detection ---------------------------
P wave – Represents atrial depolarization during atrial systole, with a usual duration smaller than 120ms. An increased or decreased P-wave can indicate hypo or hyperkalemia, respectively. Right and left atrial hypertrophy can also be detected by observing P-wave morphology.
QRS complex – Indicates ventricular depolarization and contraction during ventricular systole, with a usual duration between 60 and 100ms. Prolonged duration indicates hyperkalemia or bundle branch block and increased amplitude indicates cardiac hypertrophy, which is a common condition in athletes. Other anomalies reveal the presence of infarction.
The time between RR-peaks may be used to compute the heart rate.ST-segment – Refers to the gap between the S-wave and the T-wave, represents the time between ventricular depolarization and repolarization and has a usual duration between 80 and 120ms. Flat, down sloping, or depressed ST-segments may indicate coronary ischemia. ST-elevation is the classical indicator for myocardial infarction.T-wave – Represents ventricular repolarization. T-wave inversion (negative curvature) can be an indicator for several heart disorders.U-wave – Represents repolarization of the Purkinje fibers. It is not always visible on an ECG because it is a very small wave in comparison to the others.
The circuit used to measure heart’s electric activity can divided in several blocks. Signal acquisition, amplification, filtration and offsetting were the 4 main procedures used to extract a very weak signal from ones’ chest. All the connections were performed in a breadboard and then an Arduino Mega 2560 was chosen to achieve all the digital processing.
----------------------------------------------- Acquisition -----------------------------------------------
The circuit proposed in this paper was based on a standard circuit of ECG acquisition. The input electrodes are connected directly to the ampop’s positive terminals. Therefore, it was possible to amplify a very weak signal without disturbing the body voltage (due to high input impedances). To do so, ECG specific electrodes (Tiga-Med Gold) were used to detect the signal and transmit it through a set of 3 coaxial cables created to better insulate the circuit from external electromagnetic interferences. Along with this, another big advantage of these cables is the electromagnetic fields carrying the signal exist only in the space between the inner and outer conductors. This allows coaxial cable runs to be installed next to other metallic objects (e.g. - other cables).
The position of each electrode greatly influences the polarity and the shape of the electric heart activity registered. Different positions empower one to study different specific ECG curve parameters. This is why in a clinical environment, it’s expected to perform these tests with more than 3 electrodes.
---------------------------------------------- Amplification ----------------------------------------------
Taking into consideration that biosignals tend to have small and weak amplitudes, ranging from micro to milivolts, it is essential to amplify the signal before processing and display it. In order to achieve that, it was used an Instrumentation Amplifier INA126, which was supplied with ±9V. Since it is intended to get a signal ranging Volts (able to be read by the Arduino, after passing through the analog filters), it is necessary to dimension the gain in the order of magnitude of 1000, to do so we used 2 amplification stages. At the end, the amplification in our targeted frequencies (1 to 5Hz) was 2010×. We verified experimentally by amplifying a signal generated with a known amplitude.
One way of improving our circuit would be to purchase the INA126 in a chip, in order to get a better amplification with the lowest noise (the right ampops would allow a higher CMRR). Due to cost containment criteria, this wasn’t done.
The energy supplied to each ampop was provided by a set of two 9 V batteries (maximum voltage at the output of each one). To amplify the difference between the signal from each electrode (V3 and V4) we had to remove the DC component, which was done adding a capacitor in series (C1 and C2).
------------------------------------------------- Filtration -------------------------------------------------
The human body is a good conductor acting as an antenna which picks up electromagnetic radiation present in the environment. In the current project, the most common electromagnetic radiation, that was necessary to deal with, was the one coming from the power line, which has a fundamental frequency around 50Hz. To reduce its preponderance, both ampops and the Arduino were supplied with batteries. Other possible interference sources are muscular activity (apart the one from the heart), including respiration and movement. It is also important to refer the limitations of breadboards and the enormous number of connections which has interfered in the circuit stability and contributed to signal distortions. Moreover, the electrodes should also be as tighten as possible to the skin. To improve conductivity in the interface between the skin and the electrode, a conductor gel could be used (although we didn’t use it for the sake of model simplicity and low cost). To remove all these distortions sources, we designed 2 analog low-pass filters and 1 analog high-pass.
Low-Pass Filters2 low-pass filters with 2 different cutoff frequencies (24Hz and 44Hz) were used to eliminate power line frequency at a higher rate than 20 db/dec (Fig. 6). Since, we got an acceptable frequency response with these 2 passive filters, we avoid using active filtration (with ampops) to get a circuit as energetically efficient as possible, considering energy limitations present in portable devices.
High-Pass FilterThis high-pass passive (same reason as before) filter aimed to remove DCcomponent and slow undesirable oscillations in the signal (Fig. 7).ECG signal got undeniably better, although it still had some noise due to thepresence of a transition band in each frequency response. To complement these 3 filters, another 2 (digital) were added. Using ‘iirnotch’ and ‘butter’ functions inMatlab, we extracted the corresponding IIR coefficients and implemented the filters through the Arduino interface. In order to calculate each coefficient, sampling frequency had to be provided. We will explain in further detail, how we were able to sample an analog signal from the circuit with a constant and well-defined time step.
------------------------------------------------ Offsetting ------------------------------------------------
Arduino’s analog input pins are only able to read frequencies between 0 and 5V. Since our output signal varied between positive and negative voltages, a voltage divider had to be added to ensure the total signal was detected. 1 resistance of 1.1MΩ and another of 200kΩ between Vcc and the ground, allowed us to sum 1.4V (DC) to the body signal.
------------------------------------------------ Arduino ------------------------------------------------
To visualize the obtained signal, we connected the prototype's output to Arduino Mega 2560 microcontroller.The output signal (amplified and filtered) from the circuit was then received by the analogic pin A0 and the ground reference of the circuit connected to GRD pin of the hardware.
In Arduino IDE the signal was filtered by an IIR notch filter (from 40 to 60Hz) and another IIR low-pass Butterworth (cut-off frequency 100Hz) of 3rd and 4th orders, respectively:
Notch Filter
y(t) = 0.2012*x(t) − 0.3256*x(t−1) + 0.2012*x(t−2) + 0.3256*y(t−1) + 0.5975*y(t−2)
Low-Pass Filter
z(t) = 0.0495*y(t) + 0.1486*y(t−1) + 0.1486*y(t−2) + 0.0495*y(t−3) + 1.1619*z(t−1) − 0.6959*z(t−2) + 0.1378*z(t−3);
These coefficients were obtained using the Matlab function iirnotch and butter, respectively (see Matlab script attached to this report to know exactly which parameters do these functions receive and the frequency response of each one).
An important criterion for the filters’ parameter definition is the sampling frequency. To monitor this, an interrupt was set. Every time the interrupt is ON, it interrupts the loop cycle and some previously defined operations in the ISR function are performed, including the signal acquisition from pin A0. We chose a sampling period of 2ms, or equivalently, a sampling frequency of 500Hz. By the Nyquist theorem we should be able to acquire frequencies below 250Hz without aliasing (we note the low-pass filters at 24 and 44Hz plus the digital at 100Hz). We tested the sampling frequency acquiring a 50Hz generated signal and confirming we had 10 samples per period.
After collecting signal from the circuit and filtering it using 2 digital filters, some peak detection algorithms were applied to detect heart rate (4 digit 7 segment display showing it), QRS and ST time interval in the ISR function. Finally, based on this value, a simple algorithm to detect arrhythmias was proposed.
------------------------------- Complete Electric Circuit Scheme -------------------------------
After joining each block explained before, a final electric ECG circuit can be represented.On the left side, the voltage source represents the expected signal from the body, 2 electrodes are connected to the chest of the person under clinical analysis. The 3rd reference electrode (left wrist) will be in contact with the circuit’s ground.The circuit output signal is in the node V10 and is connected to an Arduino analog port.
Check PartSim reference [8], where all our ideas were brainstormed before implementation.
-------------------------------- ECG Real & Schematic Prototype --------------------------------
Schematic PrototypeAll the physical connections performed in the lab in a common breadboard are represented in Fig. 10. Due to the lack of some components in circuits.io (software used to design the circuit), assume functions generator as the electrodes connected to the body; the isolated 9V battery is connected to a specific adapter, which is plugged to the Arduino and 4 yellow cables were connected to extra digital pins which are not present in the scheme (pretend the pins used are possible digital inputs).
Real PrototypeThe actual board, with all the circuitry, is represented in Fig. 11. Because it is reasonably less perceivable, the previous scheme was added for a better understanding.
In the end, we were successful in obtaining a good-looking ECG signal (Fig. 12 and 13) and plot it in the computer.
Heart Rate (HR)We were able to compute either the instantaneous heart rate (from the time between each R-peak) as the average heart rate (from the time of a 5 sequence of R-pulses). We chose to show in the 4 digits – 7 segments an average of both (so the displayed value was not as volatile as the instantaneous HR nor as static as the 5 sample HR). We also compared our HR computed valueswith the ones obtained with the plethysmography smartphone app Instant Heart Rate©, from Azumio Inc., and found them to be similar.
It was also possible to note the HR increase with deep inhalation and decrease with exhalation.
Features DetectionIn the Arduino, we implemented algorithms for R, S and T-wave detection. After trying both derivative and threshold based algorithms we went for the latter due to the better results, for the T-wave detection we experimented several empirical conditions.In a still person, in the absence of artifacts, our algorithm detects practically 100% of the R-peaks! (Thus, the very good results in HR calculation).The results, however are not so good in S and T-wave detection, in three 2 minute tests we missed 21, 7% of the S-wave and 27, 5% of the T-wave (S and T-wave misses appear to be uncorrelated). As we can see from Fig. 12, ECG varies from person to person, in one of our tests there were also some false detection of Q-wave peaks as S-wave. We had already identified some systematic errors in our S-wave detection algorithms and think that with more time we would be able to perform in S-wave detection as good as in R-wave. T-wave detection is a more complicated challenge, a literature search revealed that T-wave real-time detection is a hard problem, we think the solution would have to include derivatives (or even a conjugation of derivatives and thresholding).
QRS AmplitudeWe computed a naive algorithm for the detection of sinus arrhythmia, based on the variations of the QRS-complex amplitude. However, we did not test it because all our tests were performed on healthy subjects. Nevertheless, arrhythmia detection seems easy to achieve with our ECG prototype.
Segment DurationIn the beginning of this paper, we mentioned that segment duration was important to determine several heart disorders. With this in mind, we also designed an algorithm to compute RS-segment duration (and estimate QRS-complex duration by duplicating this value) and also ST-segment duration. However, in the latter, the obtained results are largely compromised due to the S and T-wave missed detections. Also, we only had the possibility to test the prototype in healthy subjects and thus we don’t know how helpful these could be in anomalies detection.
The coaxial cables, the analogue and digital filters along with the reduction in the number and length of wires made possible the 50 Hz noise removal from the body’s ECG signal. Nevertheless, the output signal slightly contains its information compromised due to the noise. Its attenuation was not entirely achieved since the design and the choice of certain compounds may not be the most correct:
1. Different ampops have different common mode rejection ratios;2. Depending upon the diameter of the coaxial cables, they will better conduct low or high frequency signals.
These points were only slightly addressed due to time constraints.Nevertheless, we were able to detect practically 100% of all R-wave peaks, 78, 3% of S-wave and 72, 5% T-wave peaks, in real time, present in the signal. Last one with less accuracy due to the reduced dimensions and location in the signal, more difficult to threshold.Relatively to the processing task, we were able to develop an algorithm to measure heartbeat, the ST-segment time interval, as well as, the time across the QRS-complex. The maximum amplitude of this complex was also determined.
ConclusionSince the world's population is ageing and particular regions are becoming depopulated, the healthcare assistance with continuous monitoring of physiological parameters (allowing preventive care, which is more effective and less costly than treating) for patients who live in remote locations can be a crucial device. Moreover, it would allow teleconsulting, patient medication, diagnosis and the prevention of unnecessary specialist consultations or laboratory examinations.
In this project, an electrocardiograph was designed and developed. A small prototype which acquires, with three electrodes, one placed in the arm and 2 in the chest, the cardiac electrical activity.Despite the tremendous difficulty in recognizing the cardiac activity from the input signal (acquired with the electrodes) we managed to greatly attenuate the noise and obtain a clean, feature recognizable, final signal.
The signal acquisition and instrumentation part of the prototype is working properly, we obtained a good-looking signal with a very simple circuit embedded in a highly portable system.However, we fell short on the signal processing part, real-time feature detection algorithms needed more time to be refined, and more controlled tests had to be performed to validate those detections, this however was out of the scope of this course.
A future improvement, besides algorithm refinement, would be to attach a wireless emitter to the system to allow signal monitoring without being connected to a computer. With the acquired signal stored on a computer, harder algorithms for feature detection that cannot be performed on real time, as Wavelet decomposition or Empirical Mode Detection, could also be used.
References[1] “Electrocardiography Circuit Design”. Available at: http://www.egr.msu.edu/classes/ece480/capstone/spring13/group03/documents/ElectrocardiographyCircuitDesign.pdf [Consult. 06/07/2017];
[2] Instructables, “DIY EEG (and ECG) Circuit”. Available at: http://www.instructables.com/id/DIY-EEG-and-ECG-Circuit/ [Consult. 06/07/2017];
[3] Instructables, “Super Simple Electrocardiogram (ECG) Circuit “. Available at: http://www.instructables.com/id/Super-Simple-Electrocardiogram-ECG-Circuit/ [Consult. 06/07/2017];
[4] Picotech, “Electrocardiogram (ECG) circuit for use with oscilloscopes”. Available at: https://www.picotech.com/library/application-note/electrocardiogram-ecg-circuit-for-use-with-oscilloscopes [Consult. 06/07/2017];
[5] Engineers Labs, “ECG Circuit Analysis and Design”. Available at: http://engineerslabs.com/2012/01/ecg-circuit-analysis-and-design-simulation-by-multisim/ [Consult. 06/07/2017];
[6] “ECG Signal Acquisition Hardware Design”. Available at: https://courses.cs.washington.edu/courses/cse474/17wi/pdfs/lectures/Electrocardiography.pdf [Consult. 06/07/2017];
[7] “ECG Measurement System”. Available at: http://www.cisl.columbia.edu/kinget_group/student_projects/ECG%20Report/E6001%20ECG%20final%20report.htm [Consult. 06/07/2017];
[8] Partsim, ECG circuit designed. Available at: http://www.partsim.com/simulator/#79736;
[9] Autodesk Circuits, ECG prototype. Available at: https://circuits.io/circuits/5139757-iasb-ecg;
[10] Instant Heart Rate App. Available at: https://play.google.com/store/apps/details?id=si.modula.android.instantheartrate&hl=en
Comments