ECG2
ECG2
ECG2
*Corresponding Author
Abstract
The electrocardiogram (ECG) signal is one of the most vital signals that can be used to investigate the
performance of heart. Based on the ECG graph, we can identify different disorders and diseases.
Therefore, monitoring this signal is of great importance. Many electrodes (usually 12) are employed to
acquire this signal in clinics and hospitals; therefore, a nurse must install them on the body of the patient
to record the signal. In this project, we built a device that can acquire the real-time ECG signal and display
it on the mobile screen with the least number of electrodes (three electrodes) without requiring a nurse
to install the electrodes using the simplest and cheapest type of ICs and transmitters including
STM32F030F4P6 microcontroller, AD620 instrumentation amplifier, TL084 amplifier, TC7660 voltage
converter, LM1117 regulator, and HC-05 Bluetooth module. Moreover, the device was designed in a way
that could operate using a single 9V battery or power adaptor. First, to amplify the signal and remove a
part of the its noise, the ECG signal is given to the primary analog circuit. Then, in the digital section, using
a microcontroller, the signal is discretized, processed, and finally transmitted to a mobile phone for final
processing, information extraction, and displaying. In the mobile-written application, we developed a
mathematical algorithm based on Pan-Tompkins algorithm to calculate the heartbeat rate, in which the
signal peaks are determined after several processing steps using a threshold. In this regard, the ECG signals
of 10 subjects were recorded and analyzed to calculate the optimum threshold. Finally, the power spectral
density (PSD) and input referred noise were calculated and plotted to check the output signal quality.
Based on the PSD and input referred noise amplitudes, we achieved a signal-to-noise ratio of 50dB.
Keywords:
Electrocardiogram (ECG), STM32F030F4P6 microcontroller, amplifier, printed circuit board (PCB), power
spectral density (PSD)
1 Introduction
The design and expansion of biosensor systems with the purpose of health monitoring has attracted a lot
of attention in the scientific community and industry in recent years [1]. Due to the increase in health
costs and the aging of the global population, the need to monitor the patient's health status in their home
and in situations where they do not have access to a hospital is intensely felt. Real-time monitoring devices
report the patient's health status to the patient, a medical center, or a specialist and can alarm in
particular situations. Moreover, these systems can be employed to manage and monitor the different
statuses of chronic diseases, older people, patients needing rehabilitation, and people with particular
disabilities. The primary motivation for using such systems is high health and maintenance costs, the
advancement of biosensor display technology, intelligent textiles, microelectronics, and wireless
communication. These systems can consist of several different types of small physiological sensors,
transmitter modules, and processing units, which can be used for health monitoring throughout the day
in any place, mental state, and activity. Simultaneous multi-parametric recording of physiological signals
and analysis of the relationship between them can be helpful in the early identification of some diseases.
This project aims to record the ECG signal, calculate the number of heartbeats, and display it on the mobile
screen. For the patient to do so conveniently, the least number of electrodes are used to record the signal,
and a Bluetooth module is employed to transmit information to the mobile phone [1]. The ECG signal is
one of the most critical biological signals, and recording and displaying it is vital; because it shows how
the heart muscle works, and if there is an arrhythmia in the heart's function, it can be discovered from
this signal. Hence, according to the problems and the necessary preparations attributed to the ECG signal
acquisition methods in hospitals and clinics, as well as some patients' need for checking their heart's signal
continuously, there is a great need for a more accessible device that can display the real-time signal and
make the acquisition process more straightforward.
Much research has been conducted in the field of ECG signal acquisition. This part reviews the projects
related to ECG signal acquisition and its wireless transmission to distant centers. In 2001, Oleg Orlovo et
al., recorded the ECG signal with a single lead and transmitted it to a medical center via telephone by
converting it into an audio signal. Many subjects participated in the performance evaluation stage of this
project. During the examinations, the subjects in their homes attached electrodes to their body, sending
their ECG signals via telephone cables to medical centers. Finally, a doctor in the center could observe the
real-time form of the subjects' ECG signals [2]. Samuel de Lucena and Daniel Sampaio, 2015, built an ECG
signal recording device in which the signal data was transmitted serially to a mobile phone via Bluetooth.
In this project, they developed a mobile phone application using Android Studio software [3]. Ying Bai and
Robert Matthews, 2006, built a device to record the ECG signal wirelessly; for ease of utility, they
employed capacitive isolation sensors instead of conventional electrodes to record the signal [4]. In
conventional electrodes, the presence of the gel, contact with the surface of the hand, their separation in
case of movement, and sweating of the skin, reduce the tendency to use them in recording vital signals.
The recorded signal using the aforementioned capacitive sensors and conventional electrodes had a 99%
correlation. Therefore, in their project, two capacitive sensors were installed on the back of the subject's
shirt (in which the electrodes stood on the chest after wearing the shirt) to record the ECG signal. After
the signal was recorded, it was sent to a laptop via transmitters attached to the electrodes [4]. Ishani
Mishra and Sanjay Jain, 2022, developed a compressive sensing framework to enhance the ECG signal
reconstruction quality while transmitting it wirelessly using Rain Optimization Algorithm (ROA) and
Sparsity Adaptive Matching Pursuit Algorithm (SAMPA) [5]. R. V. Kapse and A. S. Barhatte, 2022, fabricated
an ECG signal acquisition device for analyzing normal and abnormal signals using AD8232 sensor to
extract, amplify, and filter the ECG signal. Then, they employed an HC-05 Bluetooth and a Wi-Fi module
to transmit the signal to an android application in cell phone which was developed using MIT app inventor
[6]. G. V. Hueh et al., 2022, developed an integrated in-house ECG monitoring device for detection and
classification of different cardiovascular states including bradycardia, tachycardia, and normal sinus
rhythm. They transmitted the signal to an android application which was developed in Android Studio via
a Bluetooth device. The recorded signals in mobile phones were converted to text files and stored in cell
phone local memory. They also have implemented a Firebase Authentication and Firebase Storage based
on Google Cloud for data management which allows patients and caretakers secure access to data in the
future using Google Cloud platforms [7]. T. Dubey et al., 2022, fabricated a device to acquire ECG signal,
body temperature, and blood oxygen level to monitor vital parameters of body in real time. They sent
these parameters to an android application developed in Android Studio wirelessly using a Bluetooth
module. They employed AD8232 to record the ECG signal [8]. D. F. H. Sadok, 2023, developed a low-cost
real-time wireless ECG device for monitoring the health of newborns. They employed an ultra-low power
wireless transceiver with embedded base-band protocols and a BLE communication module to transmit
the ECG signals to an android application in mobile phone [9]. Suhiam Sarbaras J.S., 2022, fabricated an
ECG signal system for long-time heart monitoring. They employed HC-05 Bluetooth module to transmit
the signal wirelessly to an android application developed in MIT app inventor. Then, they stored the
recorded signal in cell phone SD card for later analysis of the signal [10].
The rest of this paper is organized as follows. In Section II, the designation of the hardware and software
parts of the device, along with their implementation, will be deeply investigated. In section III, our results
and findings are discussed. Finally, the conclusions are given in section IV.
2 Methodology
In this section, the required hardware and the circuit designation along with the details and tips related
to each part, will be investigated.
For designing the abovementioned filters, we used TL084 amplifier IC which has four internal
amplifiers with a high input impedance and low input bias and offset current making it suitable
for our purpose [16].
According to the resistances' values and the 3.3V power supply, the signal is biased to a 0.3V voltage as
follows:
𝑅22
𝐵𝑖𝑎𝑠_𝑜𝑢𝑡 = 3.3 × = 0.3𝑉 (1)
𝑅21 + 𝑅22
Figure 3 Low-pass (a), high-pass (b), and notch filter (c) circuits along with their amplitude and frequency responses
Figure 4 The circuit to bias the last stage output signal (top) and its frequency response (bottom)
The reason for using buffers is to prevent the effect of voltage division loading on the last stage and ADC
input. Furthermore, a relatively large 100uF capacitor is used to filter the DC components of the output
signal. Figure 4 shows the frequency response of this part of the analog circuit.
3.3
𝑀𝑖𝑛𝑖𝑚𝑢𝑚 𝐷𝑒𝑡𝑒𝑐𝑡𝑎𝑏𝑙𝑒 𝑉𝑜𝑙𝑡𝑎𝑔𝑒 𝑉𝑎𝑙𝑢𝑒 = = 0.8059𝑚𝑉 (2)
212 − 1
Considering the gain we have in the analog part, this amount of resolution is enough to quantize the signal
[17]. In the next step, we must determine at what rate the ADC should sample the signal data. According
to the explanations given in the high-pass, low-pass, and notch filter sections about the available
frequency range of the signal, the signal is sampled by a timer and a sampling frequency of 500/second.
This sampling frequency is five times the signal's highest frequency component; Therefore, Nyquist's law
regarding the sampling frequency has also been considered. For setting this sampling frequency using a
timer, first, the ADC is set to the highest sampling rate, 3.55 Mbps, and employing the microcontroller's
timer3 and setting its interrupt time to 2ms, with each interruption, the data is sampled from the ADC.
Then the sampled data amplitude is converted to the voltage range from 0 to 3.3V and sent with the
accuracy of 4 decimal places.
2-2-4 Developing a mobile phone platform for displaying the electrocardiogram signal
After sending signal data using Bluetooth, a mobile application is needed to receive these data to perform
final post-processing and display them on the mobile screen. To create such a platform, we used Android
Studio software, whose programming language is based on Java. In the following, the steps of designing
this program are explained.
This part is related to the coding part of the platform for receiving and processing data; without this part,
the program's front-end has practically no usage. The back-end design of this project includes three parts:
searching, connecting, and receiving Bluetooth data, processing data, and displaying them using the
lineChart class.
Figure 6 The amplitude (a), phase response (b), and group delay (c) of the implemented IIR digital filter in mobile platform
(𝐹𝐿 − 1)
𝑑= (3)
2 × 𝑆𝑅
In which SR is the sampling rate in Hz and FL is the length of the used filter [15]. Considering that the
length of the used digital filters is 500 and the sampling rate is 500Hz, the output signal delay is
approximately 0.5s. Figure 8 shows the ECG signal in two modes. The right and left figures correspond to
the filtered and unfiltered signal modes.
Figure 7 The amplitude (a) and phase response (b) and group delay of the implemented FIR digital filter in mobile platform
60 × 𝑆𝑅
𝐵𝑃𝑀 = (4)
(𝑛𝑖+1 − 𝑛𝑖 )
Figure 8 The signal displayed on the mobile screen in two modes, unfiltered (left) and filtered (right) modes
Where 𝑛𝑖 and 𝑛𝑖+1 are 𝑖𝑡ℎ and 𝑖 + 1𝑡ℎ samples taken from the ECG and SR signals, respectively. There are
different methods to find the occurrence time of R waves. In this project, we used the most basic pulse
rate extraction algorithm written by Pan Tomkins, in which the amount of error in the calculation is
minimized [18]. This algorithm calculates the pulse rate in two ways; firstly, after performing
preprocessing on the signal and filtering the interfering signals using identified R-waves; secondly, using
the algorithm shown in Figure 9, the beat rate is calculated. Finally, the results obtained from both
approaches are compared with each other, and if the R wave is correctly identified in both cases, an R
wave is reported in the output; otherwise the R wave is rejected [18,19]. Each of these approaches cannot
be used alone to identify the beat rate because in the algorithm used in Figure 9, if the noise amplitude is
high, the derivative block can amplify it and cause an error in the identified R waves. Also, in some
patients, due to the high amplitude of the P wave, there is a possibility that this wave will be recognized
as an R wave. As a result, it is not possible to use only the main signal to calculate the heart rate [18,19].
Combining the results of these two approaches will reduce the percentage of the abovementioned errors.
A point that must be considered in comparing the results of these two approaches is the value of signal
delay in each of them; this way, by calculating the delay that digital processing creates in each of the
approaches, the signals must also be equally time shifted, and the results should be compared with each
other [18,19]. Since in both approaches, the signal first passes through the notch and bandpass filters, the
delay in both of them is equal after pre-processing. In the second case, the signal passes through a
derivative block in which its memory is 13 samples; a 26ms delay is added to the previous delays. The
square block has no delay; therefore, the difference between the first and second approaches is only 26ms
meaning that the first state must be shifted by 26ms in time. After the explained time shift, the results
related to the first and second approaches can be aligned.
Figure 9 Block diagram of the method of detecting ECG signal peaks and calculating the heart rate [18,19]
Since the first step of the algorithm shown in Figure 9 has already been done, the derivative of the ECG
signal is first calculated and then squared. The ECG signal, its derivative, and the squared data of the
derivative signal are displayed in the mobile application as Figure 10. Finally, thresholding is used to
distinguish the peaks and their distance from each other; after comparing the output results of the two
different approaches to heart rate calculation in the algorithm written by Pan-Tomkins; if the results of
both modes are correct, the time index corresponding to the detected R peak is stored in a local variable.
The BPM rate is calculated by detecting the next peak and using equation 4.
𝑁−1
2𝜋
𝑋[𝑘] = ∑ 𝑥[𝑛]𝑒 −𝑗𝑘 𝑁 𝑛 0 <𝑘 <𝑁−1 (5)
𝑛=0
Figure 10 Display of the ECG signal, its derivative (left) and the square of the signal derivative (right) in the mobile platform
(note that the derivative of the signal is shifted to the right by 26ms in time compared to the signal itself)
Where X[k] is the Fourier transform, x[n] is the discrete time signal, and N is the number of points used to
calculate the FFT. According to the above relationship, the bigger N is, the more frequency resolution we
will have. Hence, 4096 points are used in the FFT calculation for sufficient resolution in the frequency
domain. After calculating the FFT, the power spectral density of the signal and noise is calculated using
the following formula:
Where |𝑋[𝑘]|2 is the square of the signal FFT, and SR is the sampling rate. Figure 11 shows the power
spectral density of the noise referred to the input and the ECG signal acquired from Lead I; in which the
signal-to-noise ratio is about 50dB.
The sudden decrease in the power spectral density in the Figure 11 is the stop band used in the low-pass
filter, which filters the frequencies above 102Hz. Figure 12 shows the ECG signals acquired from Leads I
and II, each of which has a different gain. It can be seen that the signal amplitude is stronger in Lead II,
and the quality of the acquired signal is also better. The value of the gains in Lead I are equal to 600 and
1800, and in Lead II are equal to 250 and 300.
Figure 11 The noise power spectral density referred to the input (left) and the resulting ECG signal power
spectral density from lead I (right)
According to the figure above, when the threshold value is low, many local maxima, in addition to the
main peaks, are wrongly detected; increasing the threshold value decreases the number of found maxima
such that after a specific value, the main peaks are also missed. The receiver operating characteristic (ROC)
curve of the algorithm written for determining the heart rate of one subject is shown in Figure 14. To
choose the optimal threshold value, the ECG signals of 10 persons were recorded, and their ROC curve
was calculated; then, the thresholds, shown with a red arrow in the ROC curve, in which the true positive
rate (TPR) and true negative rate (TNR) criteria were 100% were averaged and the obtained value was
considered as the final threshold.
Figure 12 The recorded ECG signal from Lead I (a,b) and Lead II (c,d)
Figure 13 ECG signal recording and thresholding to detect the signal peaks (it can be seen that in steps 1 and 2, a very low
threshold was used to detect the peaks; therefore, many points in addition to the valid points have been detected. By increasing
the threshold value in step 3, the number of incorrectly detected points vanishes. From steps 4 to 7, the number of correctly
detected peaks decreases with the threshold increase. Finally, the number of the detected points reaches zero in the 8th step)
Supplementary material
The picture of the fabricated device is illustrated in Figure 15. Also, a video demonstration of the ECG
signal acquisition on the mobile screen can be found at:
https://drive.google.com/file/d/1Wmv8YtMftGVUnlr0LrX8gYYeRRrKpqN3/view?usp=sharing
[7] Goh, Voon Hueh, Muhammad Akmal Ayob, Nurul Izzati Darul Zaman, and Yuan Wen Hau. "Mobile
Electrocardiogram Monitoring System with Cloud-Based Approach." Journal of Human Centered
Technology 1, no. 2 (2022): 105-115.
[8] Dubey, Tithil, Md Tanvir Hossain, Mohammad Ismail Hossain, KM Shihab Hossain, and
Mohammad Monirujjaman Khan. "Development of Wireless Electrocardiogram, Body
Temperature and Blood Oxygen Level Monitoring System." In 2022 6th International Conference
on Computing Methodologies and Communication (ICCMC), pp. 394-399. IEEE, 2022.
[9] Sadok, Djamel FH, Daniele Wanderley Brooman, Andrea Maria Nogueira Cavalcanti Ribeiro,
Jacinaldo Balbino de Medeiros Junior, Judith Kelner, and José Henrique Silva Moura. "WeECG: a
low-cost real-time wireless ECG for new born monitoring with error concealment." International
Journal of Ad Hoc and Ubiquitous Computing 42, no. 2 (2023): 83-94.
[10] Suhaim, Sarbaras JS, and Israj Ali. "A Portable Android Based ECG System for Long-Time Heart
Monitoring." In 2022 IEEE Delhi Section Conference (DELCON), pp. 1-6. IEEE, 2022.
[11] STMicroelectronics, "STM32F030x4 STM32F030x6 STM32F030x8 STM32F030xC datasheet,"
STM32F030F4, 2021. https://www.st.com/resource/en/datasheet/stm32f030f4.pdf (accessed:
Feb 11 2023)
[12] Microchip Technology, "TC7660 (Charge Pump DC-to-DC Voltage Converter)," 2002.
https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/
DataSheets/21465C.pdf (accessed: Feb 11 2023)
[13] Analog Devices, "AD620 (Low Cost Low Power Instrumentation Amplifier)," 2003.
https://www.analog.com/media/en/technical-documentation/data-sheets/ad620.pdf (accessed:
Feb 11 2023).
[14] C. Saritha, V. Sukanya, and Y. N. Murthy, "ECG signal analysis using wavelet transforms," Bulg. J.
Phys, vol. 35, pp. 68-77, 2008.
[15] T. Dave and U. Pandya, "Simultaneous monitoring of motion ECG of two subjects using Bluetooth
Piconet and baseline drift," Biomedical Engineering Letters, vol. 8, pp. 365-371, 2018.
[16] STMicroelectronics, " TL084 (GENERAL PURPOSEJ-FET QUAD OPERATIONAL
AMPLIFIERS),"1999.https://pdf1.alldatasheet.com/datasheetpdf/view/25385/STMICROELECTRO
NICS/TL084.html (accessed: Feb 11 2023).
[17] A. V. Oppenheim and R. W. Schafer, Discrete-time signal processing. London UK: Pearson
Education, 2014.
[18] J. Pan and W. J. Tompkins, "A real-time QRS detection algorithm," IEEE transactions on biomedical
engineering, pp. 230-236, 1985.
[19] L. Sathyapriya, L. Murali, and T. Manigandan, "Analysis and detection R-peak detection using
Modified Pan-Tompkins algorithm," in 2014 IEEE International Conference on Advanced
Communications, Control and Computing Technologies, pp. 483-487, 2014.