Electrocardiogram analyser with a mobile phone André Baptista1 and João Sanches2 1 Instituto Superior Técnico, Lisbon, Portugal andrefsmbaptista@ist.utl.pt 2 Systems and Robotics Institute, Instituto Superior Técnico, Lisbon Portugal jmrs@isr.ist.utl.pt Abstract—The Electrocardiogram (ECG) signal measures the potential of the heart and their beats. A real normal ECG signal is composed for some important waves that traduce the different states of the heart at each beat, this waves are P, Q, R, S, T and U. By using three electrodes located at bust, in particular positions with a meticulous orders, it is possible to measure the electrical activity of the heart. This paper describes a system that detects cardiac anomalies in ECG trace based on the mobile phone. This system analyses the different periods and/or the different durations of some waves, the P, the QRS complex, de T wave, the QT interval, the RR period and the rhythm cardiac. The goal is detect some anomalies that could happen in a cardiovascular patient and warn some entity with a message SMS using the mobile phone. The acquisition system inject a modulate signal in a bluetooth headset to communicate and transmit with a mobile phone that is paired the ECG signal of the patient. The mobile phone demodulates the PWM signal containing the ECG, detect and store the different waves and before this, the mobile phone find abnormal intervals as periods in all of this waves. The whole system and the corresponding hardware and software modules are described and results are presented for illustrative purposes in this paper. Index Terms—ECG, opamp, PWM, python, electrocardiogram, bluetooth. 1. INTRODUCTION The acquisition of several physiological signals, such as the electrocardiogram (ECG), is a current practice since several decades, mainly for diagnosis purposes. More recently these signals are being used for control and interface purposes. In this scope, the brain computer interface (BCI) systems have received particular attention in the last decades. Currently, some types of systems are capable to read the electrophysiological signals and make possible a diagnosis of some diseases. To diagnose the ECG diseases the most important systems are the Holter, ECG at rest, ECG with exercise test between others. The cardiac diseases are one of the most causes of death in occidental population. Is estimated that cardiovascular diseases have caused the deaths of 26.3% of Portuguese people[1]. At this article is presented a modern type of system that is capable to make diagnosis exams to cardiovascular diseases. This cardiac anomalies system detect works in mobile phone with a particularity that is possible to use all day. With this system, it is possible detect some different types of cardiac diseases like Branch block, Ventricular hypertrophy, Atrial tachycardia, Wolff-Parkinson-White syndrome, Atrioventricular block 1st block, Atrial fibrillation , bradycardia, tachycardia and arrhythmia[2]. This work was developed in Nokia N81 with S60 series, a mobile phone with big computational power that was made to run specific applications like games. The decision to use this phone has forced the SymbianOS operating system were and that would be the python programming language[3]. There are some equipment, both measurements and monitoring the signal output, but none with the features listed in the equipment described in this article, namely, using the audio channel of the bluetooth headset to transmit the ECG signal [7], to analyze the ECG signal directly on the phone and use the phone to make emergency call in case of stroke [8]. This paper is organized as follows. In section 2 is described the electric cardiac system and some of diseases verified. In section 3 is described the system. In section 4 are described the experimental results and the section 5 concludes this paper. chambers of the heart, the atria, which represents activation in the P wave. Next, the electric current flowing in the direction of inferior’s chambers of the heart, the ventricles, thus creating the QRS complex, is representing the activation of these. The T wave represents the wave of recovery, while the electrical current spreads back over the ventricles in the opposite direction. 2. CARDIAC ELECTRICAL SYSTEM AND SOME OF THEIR ANOMALIES The heart is a modular organ in the middle of the chest that has both the right and the left side, a cavity higher (atrium) that receives the blood and a lower cavity (ventricle) that takes him out. To ensure that the blood flow in one direction, the ventricles have a valve entrance and one exit. The diagnosis of heart disease tends to become established from the clinical history and physical examination of the patient. There is a wide series of tests and procedures to facilitate and make more accurate the diagnosis. They include records of electrical activity of the heart as the ECG, Holter, echocardiography, magnetic resonance imaging, positron emission tomography and cardiac catheterization and the most used are the ECG and these will be that the article will be based. 2.1. ECG 2.3. Anomalies In this work, the anomalies that will be detected are the Branch block, Ventricular hypertrophy, Atrial tachycardia, Wolff-Parkinson-White syndrome, Atrioventricular block 1st block, Atrial fibrillation, bradycardia, tachycardia and arrhythmia [4] [6]. To detect all of this anomalies, the system need to detect some characteristics in ECG signal, this characteristics are: Wave P duration; QRS duration; Interval PR duration; Rhythm. 3. SYSTEM DESCRIPTION The developed system is composed by the components that could see in Fig. 1. The ECG is a fast, simple and painless, in which amplify the electrical impulses of the heart. To identify the natural pacemaker that initiates each new beating heart, the nerve pathways leading to the stimuli, the speed (frequency) and heart rate.[5] To record an ECG arise small metal contacts (electrodes) according to a given derivation, obeying the triangle of Einthoven and according to the derivation of type II. 2.2. ECG waves An ECG represents the electrical current flows through the heart during a contraction and every part of this stream is designated alphabetically. Each heartbeat starts with a boost primary physiological pacemaker of the heart, the sinoatrial node. This impulse active first the upper Fig. 1 - Circuit and their components. The components of this system are: 1. Box with acquisition circuit and amplifier circuit and with Bluetooth headset; 2. 3. 4. 5. On/Off button; USB port to power the circuit; Audio output for connection to PC; Telephone token female used to entrance of the three contacts of ECG signal acquisition; 6. Telephone token male used for entry of the three contacts of ECG signal acquisition; 7. Pin positive; 8. Pin mass; 9. Pin negative; 10. Electrodes; 11. Audio cable for PC connection. As described above, the developed system has six main modules: the acquisition, the modulation and transmission, the demodulation, the processing and the alarm generation. Each of the developed modules will be described in detail in the following sections. is used. The first stage is a voltage follower to isolate the acquisition circuit from the amplification chain. Each one of the other three stages is a low gain low-pass filter to reduce the high frequency noise. After the buffering stage, it is placed a bandpass filter so that its frequency response can capture only the ECG signal characteristics, leaving a clean signal to amplify. The gain and offset controls are important to adjust the output dynamic range of the processed signal to the input dynamic range of the modulator [9]. Acquisition circuit Signal conditioning Band-pass filter [0.218, 113.532]Hz First stage K1=10 Second stage K2<10 Third stage K3=2.2 3.1. Acquisition system, hardware and signal transmission Fig. 2. Acquisition module block diagram. According to the stated objectives, using a bluetooth headset for the transmission of the signal picked up by electrodes placed according to the derivation chosen, the transmitted signal is an audio signal. This signal is "injected" into the microphone of the headset and will be sent with bluetooth transfer to the phone, then this signal is demodulated and analyzed. The acquisition of the ECG signal is performed by three electrodes, one electrode is placed below the second vertebra towards right scapula, the positive electrode, and one in the same direction but on the left, the mass pin, the third electrode is placed one inch below the electrode on the left, the negative pin. The system used consists of an acquisition circuit, a band-pass filter where the bandwidth was reduced, and three floors of amplification with a final gain of 220. The ECG signal works in a band ranging from 0.05 Hz up to 100Hz band passes very close to ideal for an ECG signal, Fig. 2. To do that, an amplification chain with four stages (based on rail-to-rail operational amplifier) The filtered and amplified ECG signal is used to modulate in pulse (PWM) a 480𝐻𝑧 square wave carrier to be transmitted by the audio channel. The modulated signal is injected into the audio input of the bluetooth headset and this signal is transmitted to the mobile phone, which will be analysed. The PWM modulator is described in next section. 3.2. PWM modulation The PWM was created from the integrated circuit NE555. The circuit was designed which is in datasheet the same integrated circuit, that circuit could be seen in the Fig. 3. thus introducing a resistive divider in order to lower the output voltage while ensuring no overrun bluetooth headset microphone. The signal was obtained to meet the objectives set for an output frequency below 1𝑘ℎ𝑧 and with an output voltage around 1𝑉 . 3.3. Demodulation Fig. 3 - Modulation PWM circuit. In developing this circuit, referred to the Protel2004 program to create the design of printed circuit board PWM modulator with the distinction of being designed in order to use the space previously occupied by the integrated circuit LM331, packaging dip-8, developed to the FM modulator which was used on this circuit board, see Fig. 4. The PWM signal is a signal modulated by pulse width. To demodulate this signal it used one lowpass filter second order Butterworth, as it was intended demodulation with a minimum number of calculations possible. The pass-band of the signal ECG it’s between 0.05ℎ𝑧 and 100ℎ𝑧 and because this, it was used a cut frequency of the 100ℎ𝑧. With this cut frequency and a 𝜉 = 0.9999 ≅ 1, we obtain the next equations. 𝑤𝑛2 ⟺ 𝑠 2 + 2𝜉𝑤𝑛 ∙ 𝑠 + 𝑤𝑛2 (2) 1002 ⟺ 𝑠 2 + 2 × 1 × 100 ∙ 𝑠 + 1002 (3) 𝐻(𝑠) = Fig. 4 – Design top and bottom of the circuit board PWM modulator. 𝐻(𝑠) = 𝐻(𝑠) = After the design to be used in printed circuit board, went to the creation of its circuit, and the board is on the Fig. 5 Fig. 5 - Circuit board PWM. It was desired output frequency of less than 1𝑘ℎ𝑧, and scaled to the values of resistors and the capacitor to archive this objective. It was used the 𝑅1 = 𝑅2 = 10𝑘Ω and 𝐶 = 100𝑛𝐹, this values are shown in equation (1). 𝑓0 = 1.44 = 480ℎ𝑧 (𝑅1 + 2 × 𝑅2 ) × 𝐶 (1) After completion of the circuit and the scaling of output frequency, changed manually the circuit 𝑠2 10000 + 200 ∙ 𝑠 + 10000 (4) With a sampling frequency of the 8𝑘ℎ𝑧, the discrete system is: 𝐻(𝑧) = 7.748 ⋅ 10−5 ⋅ 𝑧 + 7.684 ⋅ 10−5 𝑧 2 − 1.975 ⋅ 𝑧 + 0.9753 (5) 𝐻(𝑧 −1 ) = 7.748 ⋅ 10−5 ⋅ 𝑧 −1 + 7.684 ⋅ 10−5 ⋅ 𝑧 −2 1 − 1.975 ⋅ 𝑧 −1 + 0.9753 ⋅ 𝑧 −2 (6) Using the Z transform, the equation low-pass filter is given for equation 𝑦(𝑛) = 7.748 ⋅ 10−5 ⋅ 𝑥(𝑛 − 1) + 7.684 ⋅ 10−5 ⋅ 𝑥(𝑛 − 2) + 1.975 ⋅ 𝑦(𝑛 − 1) − 0.9753 ⋅ 𝑦(𝑛 − 2) (7) The results of the demodulation are in line with expectations and in accordance with the desired one. This demodulation made the phone work quickly enough, and the system is only dependent on the absence of current hypothesis of direct access to stream audio bluetooth headset 3.4. Processing The application has been developed in Python programming language. Python is being used more often by programmers, because it is a programming language platform and operating system independent. Python also uses several modules, developed by users from all around the world with all kind of different purposes. Here, it is used mainly the PyAudio module, for audio stream input acquisition. The application takes 3𝑠 of the ECG signal modulated PWM and demodulates it renders the detection algorithm of the various intervals, checks for abnormalities and collects more 3𝑠 signal. After receive and demodulate the ECG signal in PWM, the mobile phone need to search some periods and the different waves in the real signal ECG. When all the wave intervals are discovered, will find some combinations of the signal ECG characteristics and will find if this signal has some anomaly. If the system finds some anomaly, it will send a SMS to a competent entity. The relevant intervals discovered are the duration of the P wave, the T wave, the QRS complex, the PR interval and the QT interval. The system discovered yet the RR, PP intervals and the rhythm. In the Fig. 6 is represented the algorithm used. The algorithm begins by finding represented a positive peak in the signal. When this peak is found, the peak voltage, determines whether it is a peak P, T, R, for each of these peaks is at different levels of tension. In the case of P and T waves, the program through two cycles, one advancing and one retreating into the signal, determines the limits of the waves, looking for the point where it gives the reversal of the slope on each side. In the case of the QRS complex, the program searches the limits of the R wave and hence the peak Q and S using the algorithm described above, but in this case, the algorithm searches for the beginning of the Q wave and the end of the S wave and thereby obtaining the QRS PR and QT. For each signal cycle, all intervals are collected for delivery and all conditions of all the anomalies selected are checked. If the algorithm finds any abnormalities in the ECG tracing, the program collects information from the time and type of fault to a log file. Next, the program sends the same information to an authority by SMS in accordance with the number set in your phone. 4. EXPERIMENTAL RESULTS At this chapter it will be described the different experimental signals, all of them are very satisfactory like we will see. The acquisition system is able to easily acquire the ECG signal, filter it and amplify it. At the first step, when the system acquire the real signal we obtain a signal like a signal in Fig. 7 where we can be seen all the important waves like P and T waves and the QRS complex. Fig. 6 - Flowchart that represents the algorithm to detect the waves. Fig. 7 - ECG signal acquired original. When we obtain the original signal, this signal will pass in the three amplifier steps in the amplifier circuit. This circuit will clean some noise at the signal and we will see the signal amplified at the Fig. 8. Fig. 10 - Signal ECG demodulated. This signal is used to detect the important waves to a correct detection of the cardiac anomalies. So, to detect the waves, are used the different levels of the signal like we could see in the next figure and like is explained in the chapter before, see the Fig. 11. Fig. 8 - Signal ECG amplified and filtered. After the amplification step the signal are modulated with PWM circuit described in the chapter before. This signal is transferred and received in the mobile phone. We could see the signal in the Fig. 9. Fig. 9 - Signal ECG modulated in PWM. When the signal is received in the mobile phone, the program use the algorithm described in the chapter 3.3 and obtain the Fig. 10 signal. Fig. 11 - Figure illustrates the tensions of the levels chosen. 5. CONCLUSIONS AND FUTURE WORK With this system it is possible to prove that mobile phones are an important factor for the continuous monitoring of cardiovascular patients by giving them a better and more guarded quality of life. This system is still possible to create algorithms for the detection of other cardiac anomalies. We could tell that the mobile phones have a lot of computational power at this time and this is very important with biological and monitoring systems. This paper concludes that the use of conventional bluetooth headset is possible, and even a cost effective and robust, as evidenced in the developed system. For the portability of the system in future will have to seek a solution that will pass through, place the electrodes in order to be closer, making the system more comfortable for the patient. I predict that in future, with increased computing power, this system can have better results and it is also possible in the near future direct access to streaming audio headset. For the circuit of the acquisition, future work to develop, is to create an even more dedicated circuit, operating in a frequency band ideal for a range of [0.05 Hz-100 Hz] and with a lower sampling frequency in order to reduce volume of calculations. ACKNOWLEDGMENT The authors of this paper would like to thank the coach of the Laboratories of electronics Campus Taguspark of the Instituto Superior Técnico, Mr. João Pina dos Santos.His knowledge provided vital support for the conclusion of this system. REFERENCES [1] Clayman P. D., O coração, Circulo dos Leitores, 1992. [2] Mariana Avelar, S. S., Alarme de acidente cardiovascular, 2005. [3] M. Lutz, Leaning Python, 3rd Edition, O’Reilly, 2007. [4] Davidson, C., Compreender as doenças de coração, Porto Editora, 2006 [5] Edward K. Chung, M. , Pocket Guide to ECG Diagnosis. Blackwell Science, 1996. [6] Merck Sharp & Dohme, Enciclopédia Médica – Volume 1: Doençãs cardiovasculares, Editoral Oceano, S. L. [7] Medgadget, internet journal of emerging medical thecnologies: http://medgadget.com/archives/2008/01/micro _ecg_for_mobile_monitoring.html,2008. [8] Forum nokia, http://blogs.forum.nokia.com/index.php?op= ViewArticle&blogld=38462&articled=648,20 07. [9] João Raminhos, Aquisição de Sinais Fisiológicos – Aplicação ao control de uma plataforma móvel a partir do EOG, 2009..