Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views29 pages

Group Project

The document outlines a group project titled 'A Study on AI-supported Health Monitor System' conducted by students at the University of Science and Technology of Hanoi, supervised by Dr. Nguyen Van Trung. The project focuses on developing a low-cost Smart Health Monitoring system that utilizes an AD8232 ECG sensor, STM32 microcontroller, and Raspberry Pi to analyze and classify ECG signals for detecting heart rhythm disorders using AI and deep learning. The system aims to improve accessibility and efficiency in cardiovascular diagnostics, particularly in resource-limited settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views29 pages

Group Project

The document outlines a group project titled 'A Study on AI-supported Health Monitor System' conducted by students at the University of Science and Technology of Hanoi, supervised by Dr. Nguyen Van Trung. The project focuses on developing a low-cost Smart Health Monitoring system that utilizes an AD8232 ECG sensor, STM32 microcontroller, and Raspberry Pi to analyze and classify ECG signals for detecting heart rhythm disorders using AI and deep learning. The system aims to improve accessibility and efficiency in cardiovascular diagnostics, particularly in resource-limited settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

UNIVERSITY OF SCIENCE AND TECHNOLOGY OF HANOI

DEPARTMENT OF ADVANCED MATERIALS SCIENCE AND


NANOTECHNOLOGY

Research and Development


GROUP PROJECT

Title
A Study on AI-supported Health Monitor
System

Supervisor : Dr. Nguyen Van Trung

Group members:
Nguyen Trong Dat BA12-047
Dam Duy Tien BA12-172
Tran Manh Tu BA12-181

Hanoi, 2024
To whom it may concern,

I, …………………….……………………………… (instructor’s name), certify that the


group project report of Mr. Nguyen Trong Dat, Dam Duy Tien, Nguyen Manh Tu is qualified
to be presented in the Group project Jury 2022-2023.

Hanoi,

Instructor’s signature

1
Contents

Acknowledgement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
List of Abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

I INTRODUCTION 8

II OBJECTIVES 10

III MATERIALS AND METHODS 11


1 Hardware Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.1 AD8232 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2 STM32F103C8T6 . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3 Raspberry Pi 3 Model B+ . . . . . . . . . . . . . . . . . . . . . . . 14
2 System Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Deep Learning Model Using CNN . . . . . . . . . . . . . . . . . . . . . . . 17
3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.3 Designed Network Architectures . . . . . . . . . . . . . . . . . . . . 18
4 GUI Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

IV RESULTS AND DISCUSSIONS 22

V CONCLUSION AND PERSPECTIVE 26

2
Acknowledgement

We would like to express our deepest gratitude to all those who have supported us in complet-
ing this research project, ”A Study on AI-supported Health Monitor System.” Their guidance,
encouragement, and expertise have been invaluable throughout our research journey.
Firstly, we would like to extend our sincere thanks to our supervisors, Professor Nguyễn
Văn Trung , for their continuous support, insightful feedback, and patience. Their expertise
and valuable suggestions have greatly contributed to the success of this study.
Additionally, we would like to thank our professors, colleagues, and friends at the Uni-
versity of Science and Technology of Hanoi for their academic support and motivation. Their
knowledge and encouragement have been a great source of inspiration for us.

3
List of Abbreviations

Abbreviation Definition
ADC Analog-to-Digital Converter
CNN Convolutional Neural Network
CSV Comma-Separated Values
GPIO General-Purpose Input/Output
CMRR Common-Mode Rejection Ratio
ECG Electrocardiogram
GUI Graphical User Interface
ISR Interrupt Service Routine
SHM Smart Health Monitoring
UART Universal Asynchronous Receiver-Transmitter

4
List of Figures

II.1 Main Structure of SHM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

III.1 AD8232 ECG Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11


III.2 Pin configuration of AD8232 sensor . . . . . . . . . . . . . . . . . . . . . . 12
III.3 STM32F103C8T6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
III.4 Raspberry Pi 3 Model B+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
III.5 Block diagram of the proposed system . . . . . . . . . . . . . . . . . . . . . 15
III.6 Working Principle of Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
III.7 Working Diagram of Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
III.8 Convolutional Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . 17
III.9 Categories of heartbeats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
III.10A diagram of convolutional layers used in the proposed model. . . . . . . . . 20
III.11ECG Monitoring Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

IV.1 The signal before go to rasperry pi . . . . . . . . . . . . . . . . . . . . . . . 22


IV.2 The obtained results are displayed on the screen after go to rasperry pi . . . . 23
IV.3 Connecting real devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
IV.4 Actual measurements on different people . . . . . . . . . . . . . . . . . . . 25

5
List of Tables

III.1 Technical Specifications of AD8232 . . . . . . . . . . . . . . . . . . . . . . 12


III.2 Technical Specifications of STM32F103C8T6 . . . . . . . . . . . . . . . . . 13
III.3 Technical Specifications of Raspberry Pi 3B+ . . . . . . . . . . . . . . . . . 14
III.4 Categories of heartbeats in the MIT-BIH database based on AAMI . . . . . . 18

6
Abstract

We present an AI-supported Smart Health Monitoring (SHM) system designed to analyze and
classify electrocardiogram (ECG) signals for detecting heart rhythm disorders. The system
integrates an AD8232 ECG sensor, an STM32 microcontroller for data acquisition, and an
embedded Raspberry Pi computer as the main processing unit. The Raspberry Pi receives
ECG data via the UART protocol, processes the data, and applies machine learning algo-
rithms for real-time classification and anomaly detection. Additionally, the system features
a graphical user interface (GUI) to display information and analysis results clearly, allowing
users to monitor their cardiovascular health more effectively.
Keywords: Smart Health Monitoring, IoT, ECG, Heart Rhythm , AI, Embedded System .

7
I INTRODUCTION

The electrocardiogram (ECG) is a common medical device used in hospitals and clinics world-
wide. It plays a crucial role in diagnosing heart diseases by recording the heart’s electrical
activity over a period of time[14]. Early detection of cardiovascular conditions is essential,
as heart diseases remain the leading cause of mortality worldwide. According to the Global
Burden of Disease Study 2010[9], cardiovascular diseases were responsible for a significant
proportion of deaths globally, highlighting the urgent need for efficient diagnostic tools to
prevent severe complications and reduce mortality rates.
When the heart beats, it produces electrical signals. The ECG machine detects these sig-
nals and displays them as wave patterns on a graph. By analyzing these patterns, doctors can
assess heart rhythms, detect irregularities, and diagnose conditions such as arrhythmias, heart
attacks, and ischemic heart disease. This allows for timely medical intervention and better
management of heart conditions. ECG is a non-invasive and painless procedure, making it
widely accessible and an essential tool in modern healthcare.
However, analyzing ECG signals requires skilled specialists who can accurately interpret
the data [3]. This presents a significant challenge, especially in resource-limited healthcare
settings where there is often a shortage of trained professionals. Additionally, conventional
ECG machines are typically expensive, making them inaccessible to many remote and under-
served areas. The high cost and limited availability of these essential diagnostic tools create
barriers to timely and effective cardiac care.
To overcome these challenges, automated systems powered by artificial intelligence (AI)
and deep learning models have received growing attention. AI technology is increasingly be-
ing applied in cardiology due to its ability to optimize diagnostic processes, lower costs, and
improve decision-making efficiency in healthcare [6][10]. These AI-driven models utilize
deep neural networks to analyze raw ECG data, identifying meaningful patterns that help in
detecting heart rhythm disorders and anomalies with high precision in real time. By reducing
dependency on human expertise and making ECG analysis more accessible, AI has the poten-
tial to bridge the gap in cardiovascular diagnostics, particularly in areas with limited medical
resources.
To improve accessibility and affordability in heart health monitoring, our project focuses
on developing a low-cost system for measuring and classifying heart rhythms. This system
integrates multiple hardware and software components to ensure efficient data acquisition,
processing, and analysis. At its core, the system utilizes the AD8232 ECG sensor, which
captures human electrocardiogram (ECG) signals. These signals are then sent to the STM32
microcontroller, which reads, pre-processes, and transmits the data to an embedded Raspberry
Pi computer via the UART protocol. The Raspberry Pi serves as the main processing unit,

8
where it analyzes the received ECG data using machine learning algorithms to classify heart
rhythm disorders and detect anomalies in real time.
Our system has demonstrated high performance in ECG signal classification, achieving
over 90% accuracy in detecting arrhythmias when tested on the PhysioNet MIT-BIH Arrhyth-
mia database. This result highlights the effectiveness of AI-driven analysis in accurately
identifying heart rhythm disorders, paving the way for its application in real-world diagnostic
settings.
To enhance usability, we have developed a graphical user interface (GUI) using Python,
enabling users to control the system and visualize ECG data on a touchscreen display. This
intuitive interface provides clear real-time feedback, making it easier for users to monitor their
cardiovascular health effectively.
By integrating AI-driven analysis with low-cost hardware, our system offers an intelligent
and accessible solution for early detection of heart-related conditions. This innovation has the
potential to improve healthcare accessibility, particularly in underserved regions, and enhance
the efficiency of heart disease diagnosis and prevention.
The primary objective of this project is to develop an AI-powered Smart Health Monitor-
ing (SHM) system designed to monitor and classify heart rhythms. By integrating an AD8232
ECG sensor, STM32 microcontroller, and Raspberry Pi, the system collects real-time ECG
data, processes it, and uses machine learning algorithms for heart rhythm classification. The
goal is to create an affordable and efficient system that can provide continuous heart health
monitoring, offering early detection of potential cardiovascular issues.
The system integrates several key components, including the AD8232 ECG sensor, which
captures accurate heart signal data, and the STM32 microcontroller for signal processing.
These components work in tandem with the Raspberry Pi as the main processing unit to clas-
sify heart rhythm abnormalities using AI-driven deep learning models, achieving high levels
of accuracy. One of the key goals of this project is to improve accessibility, particularly in
resource-limited settings where traditional ECG equipment is often not available. By provid-
ing a user-friendly graphical interface (GUI), the system allows both healthcare professionals
and general users to visualize ECG data in real time, enhancing monitoring and improving
heart disease management.
Furthermore, the project aims to automate ECG signal analysis by using deep neural net-
works, thus reducing the reliance on human expertise for interpreting the data. The system’s
ability to classify arrhythmias and detect abnormal heart rhythms accurately can aid in early
intervention, reducing mortality rates from cardiovascular diseases. The user interface will
also provide alerts to potential health risks, making it more proactive in nature, which is a
significant step toward effective cardiovascular disease prevention and management.

9
II OBJECTIVES

The AI-Supported Smart Health Monitoring System project aims to develop an advanced,
real-time heart rate monitoring solution. The system utilizes an AD8232 sensor module to
measure and display ECG signals in real time, ensuring continuous cardiac health assessment.
To enhance accuracy, ECG data is processed using an STM32 microcontroller (MCU) and
analyzed by AI models on a Raspberry Pi, enabling the classification of heart conditions.
Additionally, a live data visualization feature will be implemented on a 7-inch touchscreen,
providing real-time ECG waveforms, heart rate, and health status updates. The system also
incorporates an AI-driven health alert mechanism, designed to detect abnormalities and issue
warnings for potential health risks. To ensure accessibility for both medical professionals and
general users, a user-friendly graphical interface will be developed for seamless interaction.
The expected outcomes of this project include a fully functional Smart Health Monitor-
ing (SHM) prototype, capable of real-time ECG monitoring and classification, along with an
AI-powered warning system to identify possible heart conditions. Furthermore, a compre-
hensive report documenting the project’s methodology, implementation, and outcomes will
be produced to facilitate future research and development.

Figure II.1: Main Structure of SHM

10
III MATERIALS AND METHODS

1 Hardware Component
1.1 AD8232
The AD8232 is a specialized, low-power ECG (Electrocardiogram) analog front-end designed
for capturing and processing heart bioelectrical signals with high accuracy. This compact
sensor integrates an instrumentation amplifier, right leg drive (RLD) amplifier, operational
amplifier, and mid-supply reference buffer, ensuring precise signal acquisition in noisy envi-
ronments.

Figure III.1: AD8232 ECG Sensor

In addition, the AD8232 features lead-off detection circuitry and a fast recovery circuit,
which allows for rapid signal restoration once the electrodes are reconnected. Its indirect cur-
rent feedback architecture enhances performance while reducing size and power consump-
tion compared to traditional designs. With an integrated high common-mode rejection ratio
(CMRR) of 80 dB, adaptive high-pass and low-pass filters, and low power consumption (170
µA), the AD8232 is an ideal choice for wearable and portable ECG monitoring applications.
The below Figure III.10 shows pin configuration of AD8232 sensor:

11
Figure III.2: Pin configuration of AD8232 sensor

The table below shows the technical specifications of the AD8232:

Parameter Specification
Supply Voltage DC 3.3V
Output Type Analog
Output Interface 2.54 mm pin header or headphone jack
Dimensions 36 x 31 x 18 mm
Operating Temperature -40°C to +85°C
ECG Front-End Integration Fully integrated with ECG guidance
Virtual Ground Created via internal reference
Internal RFI Filter Yes
Supply Current 170 µA
Output Signal Type Rail-to-rail
Shutdown Pin Available
Common-Mode Rejection Ratio (CMRR) 80 dB
Right-Leg Drive (RLD) Amplifier Integrated
Electrode Configuration 2 or 3 electrodes
Operational Amplifier Uncommitted
Half-Cell Potential Handling ±300 mV
Low-Pass Filter (LPF) Adaptive 3-pole filter
High Signal Gain with DC Block Yes
Improved Settling Filter Fast recovery
Adaptive High-Pass Filter (HPF) 2-pole filter
Package Type 4 mm × 4 mm, 20-lead LFCSP
Table III.1: Technical Specifications of AD8232

12
1.2 STM32F103C8T6
The STM32F103C8T6 microcontroller, based on the ARM Cortex-M3 core running at 72
MHz, was chosen for its balance of performance, versatility, and cost-effectiveness. It is
widely used in embedded systems, IoT applications, and automation due to its strong pro-
cessing capabilities and diverse communication interfaces, including USART, SPI, I2C, and
USB.
Additionally, the development board includes a Mini USB port for power supply, pro-
gramming, and debugging. It features two MCUs: one dedicated to programming and the
other for application development, ensuring flexibility. An external power input is also avail-
able when USB power is not in use.
This microcontroller meets our system’s requirements for real-time signal processing and
efficient data handling, making it an ideal choice for our application

Figure III.3: STM32F103C8T6

The table below shows the technical specifications of the STM32F103C8T6:

Parameter Specification
Microcontroller STM32F103C8T6
Supply Voltage 5V DC via Micro USB (converted to 3.3V DC)
Main Crystal Oscillator 8 MHz
RTC Crystal Oscillator 32 kHz
GPIO Full access to all pins
Communication Interfaces CAN, I²C, SPI, UART, USB
Onboard Indicators Power LED, PC13 LED, Reset Button
Dimensions 53.34 x 15.24 mm
Supported Programmers ST-Link Mini, J-Link, USB to COM
Programming Interface SWD (Serial Wire Debug)
SWD Pin Configuration
TCK SWCLK
TMS SWDIO
GND GND
3.3V 3.3V
Table III.2: Technical Specifications of STM32F103C8T6

13
1.3 Raspberry Pi 3 Model B+
The Raspberry Pi 3 Model B+ was chosen for this project due to its balance of performance,
affordability, and energy efficiency. It provides sufficient processing power for real-time ECG
data acquisition while supporting essential communication protocols like UART, SPI, I2C,
and USB, ensuring seamless integration with the STM32F103C8T6 microcontroller.
Its well-established software and hardware ecosystem simplifies development and reduces
integration time compared to newer models. While the Raspberry Pi 4 and Pi 5 offer higher
performance, they come with increased costs and power consumption. Thus, the Raspberry
Pi 3 Model B+ remains the ideal choice for the Smart Health Monitoring System, offering an
optimal blend of reliability, efficiency, and affordability.

Figure III.4: Raspberry Pi 3 Model B+

The table below shows the technical specifications of the Raspberry Pi 3B+

Parameter Specification
Processor Broadcom BCM2837B0, Cortex-A53 64-bit Quad-Core 1.4GHz
RAM 1GB LPDDR2 SDRAM
Networking Gigabit Ethernet (over USB 2.0), Dual-band 802.11ac Wi-Fi, Bluetooth 4.2
Ports 4 USB 2.0, 1 HDMI, 1 3.5mm audio jack, 1 CSI camera, 1 DSI display
GPIO 40-pin GPIO for peripheral connections
Power Supply 5V/2.5A via micro-USB
Storage Supports microSD cards

Table III.3: Technical Specifications of Raspberry Pi 3B+

2 System Design
Figure III.5 below illustrates the architecture of the Smart Health Monitoring system The sys-
tem consists of several key components working together to acquire, process, and display

14
Figure III.5: Block diagram of the proposed system

ECG signals. The Heart Sensor AD8232 collects ECG signals from the user and transmits an
analog signal to the STM32 microcontroller, where the ADC module converts it into a digital
format for processing. The STM32 timer module is configured to sample at a frequency of
280 samples per second, and upon expiration, it triggers an interrupt service routine (ISR).
The ISR handles the sampling process and transmits the data to the Raspberry Pi via UART
communication. The Raspberry Pi 3B+ receives the ECG data, processes the signals, and
classifies heart rhythms according to medical conditions. Finally, the processed heart rate
data and classified heart rhythms are displayed on a screen for real-time monitoring. This
architecture ensures accurate and efficient ECG signal acquisition, processing, and classifi-
cation, providing reliable heart monitoring and analysis.
The AD8232 sensor is used in this project to collect an ECG signal, which is then pro-
cessed by the STM32F103C8T6 microcontroller and sent to a laptop via USART1 for analysis
and display. An Arduino Uno is utilized as an interface for real-time signal charting, and the
STM32CubeIDE is used for firmware development. In order to continually sample the ana-
log ECG signal, the ADC is set up with channel ADC1-IN0 in continuous conversion mode.
To ensure a consistent sampling rate, Timer 1 (TIM1) is utilized with a clock source derived
from HCLK, which operates at 56 MHz. The prescaler (PSC) is set to 1999, and the counter
period (PR) is configured to 99, leading to a sampling frequency of 280 samples per second,

15
calculated using the formula:
Fs
Ft =
(P SC + 1)(P R + 1)
Where PSC (prescaler) is 1999, PR (counter period) is 99, and F s (system clock) is 56
MHz. With this configuration, the sampling rate is guaranteed to correspond with the input
velocity needed for TensorFlow Lite (TFLite) processing. After every time interval t, the

Figure III.6: Working Principle of Timer

timer increments the counter register (CNT) without requiring input from the CPU. To ensure
exact timing control for data acquisition, the CNT resets and initiates an update interrupt as it
reaches the auto-reload register (ARR) value.

Figure III.7: Working Diagram of Timer

For smooth connection with the laptop, the USART1 peripheral is set up in asynchronous
mode with a baud rate of 19200. By adjusting the baud rate to correspond with the STM32CubeIDE

16
settings, the Arduino Serial Plotter visualizes the received ECG signal. The obtained data is
sent to a Raspberry Pi, which uses Python 3.9.18 to show the ECG signal on an external screen
in order to further process and categorize it. To execute a pre-trained TFLite model for ECG
classification, a virtual environment is constructed. The timer-based ADC sampling guaran-
tees conformity with the model’s criteria because it requires input data at a rate of 280 samples
per second. This system allows for high-accuracy real-time ECG monitoring and categoriza-
tion by combining Python-based signal processing with the timer and ADC capabilities of the
STM32.

3 Deep Learning Model Using CNN


3.1 Overview
Artificial Intelligence (AI) encompasses systems that perform tasks requiring human intelli-
gence. A branch of AI, Machine Learning (ML), enables computers to learn from data, while
Deep Learning (DL), a subset of ML, uses deep neural networks to automatically extract fea-
tures. We use Deep Learning due to the complexity and volume of data. Unlike traditional
ML, DL models, especially Convolutional Neural Networks (CNNs), automatically extract
spatial hierarchies of features, making them ideal for processing physiological signals such
as ECG.
CNNs are well-suited for ECG classification as they can automatically learn important
features like the P, QRS, and T waves that represent different stages of the cardiac cycle.
They detect spatial hierarchies of features, enabling the model to identify subtle abnormalities,
such as arrhythmias, without manual feature extraction. CNNs also handle both time-domain
(ECG signals) and frequency-domain representations (e.g., spectrograms), which enhances
their ability to recognize complex patterns in the data. This makes them a powerful tool for
automatic and accurate ECG analysis in medical applications.

Figure III.8: Convolutional Neural Networks

17
3.2 Dataset
This project utilizes the PhysioNet MIT-BIH Arrhythmia database[7][5], a widely recognized
dataset for developing systems that assist in detecting abnormal heart rhythms. The dataset
consists of electrocardiogram (ECG) recordings from 47 patients, totaling 48 records, each
lasting approximately 30 minutes. Medical experts have annotated these records to classify
various types of heartbeats, including both normal and abnormal rhythms.
The data is processed and structured based on the methodology outlined in the paper
”Inter- and Intra-Patient ECG Heartbeat Classification For Arrhythmia Detection: A Se-
quence to Sequence Deep Learning Approach’” by Sajad Mousavi, Fatemeh Afghah, and
U. Rajendra Acharya[8]. According to this approach, 44 records from the MIT-BIH database
(following the AAMI standard) are divided into two sets:DS1 = 101, 101, 106, 108, 109, 112,
114, 115, 116, 118, 119, 122, 124, 201, 203, 205, 207, 208, 209, 215, 220, 223,230 and DS2
= 100, 103, 105, 111, 113, 117, 121, 123, 200, 202, 210, 212, 213, 214, 219, 221, 222, 228,
231, 232, 233, 234. DS1 is used to build the classification model and DS2 is utilized to test
the model.
This separation ensures that heartbeats from the same patient do not appear in both the
training and testing sets, thereby preventing data leakage and improving the reliability of the
model’s performance evaluation.

3.3 Designed Network Architectures


Pre-processing
The dataset was pre-processed according to the steps outlined in the study by Sajad Mousavi,
Fatemeh Afghah, and U. Rajendra Acharya[8]. The processing steps include:

1. Normalizing the provided ECG signal to a range between 0 and 1.

2. Identifying the set of T waves based on the ECG R-peaks from the corresponding an-
notation file in the MIT-BIH Arrhythmia database..

3. Segmenting the continuous ECG signal into individual heartbeats using the extracted
T waves and labeling each heartbeat according to the corresponding annotation file.

Table III.4: Categories of heartbeats in the MIT-BIH database based on AAMI

Category Class
N (Normal) Normal beat (N), Left and right bundle branch block beats (L, R),
Atrial escape beat (e), Nodal (junctional) escape beat (j)
S (Supraventricular) Atrial premature beat (A), Aberrated atrial premature beat (a),
Nodal (junctional) premature beat (J), Supraventricular premature beat (S)
V (Ventricular) Premature ventricular contraction (V), Ventricular escape beat (E)
F (Fusion) Fusion of ventricular and normal beat (F)
Q (Unknown) Paced beat (/), Fusion of paced and normal beat (f), Unclassifiable beat (U)

18
4. Adjusting the length of each heartbeat to a fixed size of 280 samples.

After performing the data preprocessing process, we obtained heart rate signal samples with a
length of 280 samples, normalized to the range [0,1] to ensure consistency and facilitate easier
processing for machine learning models.The test set contains a total of 49,639 labeled samples,
while the training set has 50,935 labeled samples. Next, we proceed with data visualization
to check the integrity and distribution of the signals.

(a) Normal (b) Supraventricular

(c) Ventricular) (d) Fusion

Figure III.9: Categories of heartbeats

The architecture
Fig III.10 illustrates the detailed network architecture used for automatic heartbeat classi-
fication. The CNN model consists of three 1-D convolutional layers, each followed by a
max-pooling layer. The first convolutional layer applies 32 one-dimensional filters with a
kernel size of 1 × 3 and a stride of 2, using the ReLU activation function. The second convo-
lutional layer consists of 64 one-dimensional filters with the same kernel size and stride, also
activated using ReLU. The third convolutional layer contains 128 one-dimensional filters,
maintaining the same kernel size and stride, followed by ReLU activation. Each convolu-
tional layer is succeeded by a max-pooling layer with a pooling size of 1 × 2 and a stride of 2.
Once the input data passes through the convolutional and pooling layers, it is flattened from
a two-dimensional shape (128 × 35 = 4480) into a one-dimensional vector and fed into fully
connected layers. The first fully connected layer consists of 100 nodes, while the second fully
connected layer has 4 nodes, corresponding to the 4 classification categories. The final output
consists of logits, representing the predicted class probabilities for heartbeat classification.

19
Figure III.10: A diagram of convolutional layers used in the proposed model.

Result
After 99 epochs, the model has achieved the following results:

Dataset Accuracy Recall Precision


T rain 0.9749 0.9749 0.9736
T est 0.9328 0.9328 0.9042

The model achieves 93.28% accuracy on the test set, demonstrating good generalization abil-
ity. The recall of 93.28% indicates that the model effectively identifies most positive samples.
Additionally, the precision of 90.42% is a strong result, showing that the model correctly clas-
sifies the majority of its positive predictions.
Although there is a slight difference compared to the training set, the results remain im-
pressive, suggesting that the model does not suffer from severe overfitting. With its high ac-
curacy and strong detection capability, the model is reliable for practical applications. Further
fine-tuning of hyperparameters or applying data augmentation techniques could help enhance
its performance even more

4 GUI Display
PyQt5 is used to design the graphical user interface (GUI), where QT Designer was employed
for layout creation, and Pyuic5 was used to convert the design into a Python class. Matplotlib
is implemented for plotting ECG signals, chosen over QtCharts due to its better support for
real-time data updates. PySerial facilitates serial communication, enabling data transmission
between the GUI application and the embedded system
The GUI is designed to display and analyze ECG signals in real-time, enabling users to
monitor heart activity effectively. The main functions include:

20
Figure III.11: ECG Monitoring Display

• Receiving data from STM32 via UART: The GUI receives digitized ECG signals from
the STM32F103C8T6 microcontroller through UART communication, ensuring accu-
rate and continuous data transmission.

• Real-time ECG signal visualization: The ECG data is displayed dynamically as a wave-
form, updating continuously to provide a clear and real-time representation of heart
activity.

• Heart rhythm classification: The ECG data is processed to classify different heart
rhythms, potentially aiding in the early detection of cardiac abnormalities.

The GUI provides an intuitive and interactive interface, making it suitable for real-time heart
monitoring applications

21
IV RESULTS AND DISCUSSIONS

An initial check was carried out to evaluate the raw signal quality prior to sending the ECG
signal to the Raspberry Pi for additional processing. At this point, the STM32 microcontroller
used its integrated ADC to transform the analog ECG data from the AD8232 sensor into dig-
ital information. As seen in Figure IV.1, these raw ADC readings were subsequently sent
straight to a computer via UART and displayed using the Arduino Serial Plotter. Upon exam-
ination, it was challenging to distinguish important ECG components like the P-QRS-T waves
since the signal showed notable oscillations and lacked a distinct waveform pattern. There
were several causes of this instability. First, signal consistency was impacted by sensor noise
from electrode placement and muscle movements. Second, differences in ADC conversion
caused slight irregularities that were made worse by the STM32’s ADC’s low resolution. The
received signal was further distorted by timing anomalies generated by the UART transfer.
Direct examination of the raw ECG data was not feasible because of these difficulties. The
observed instability made it clear that more signal processing was required prior to catego-
rization. A more consistent and organized ECG signal for precise classification and real-time
monitoring was ensured by integrating the Raspberry Pi into the system to carry out prepro-
cessing tasks including noise reduction and normalization.

Figure IV.1: The signal before go to rasperry pi

22
During the first phase of signal acquisition, the AD8232 sensor’s ECG data was sent
straight from the STM32 microcontroller to the computer using UART so that it could be
seen (Figure IV.1). However, there were noticeable oscillations and inconsistencies in this
raw data, which made it challenging to detect important ECG waveform components such the
P-QRS-T complex. Variations in ADC sampling, sensor noise, and inconsistent data transfer
were the main causes of these changes. The signal was unstable in the absence of proper
preprocessing, which can have an adverse effect on later classification tasks, especially those
requiring machine learning models. The Raspberry Pi was used to preprocess the signals in
order to overcome these difficulties. A normalization step was used to scale the signal within
the range [0,1] once the ECG data was received. By standardizing the signal, this procedure
helped to provide a more uniform representation throughout time intervals and lessen ampli-
tude variations brought on by ADC drift. Normalization greatly improved signal clarity and
made it simpler to identify important ECG signals, even while it did not totally remove noise.
This preprocessing stage caused the previously erratic signal to become more comprehensi-
ble and organized (Figure IV.2). With less amplitude fluctuation and better overall stability,
the processed ECG waveform on the Raspberry Pi amply demonstrated the P-QRS-T compo-
nents. Real-time monitoring and analysis were made possible by this transformation, which
also made sure the data was in the best possible shape for subsequent categorization using
deep learning models. The Raspberry Pi’s successful preprocessing implementation showed
how well it can improve signal quality, enable more precise cardiac rhythm identification,
and increase system dependability for practical uses.

Figure IV.2: The obtained results are displayed on the screen after go to rasperry pi

Comparison of the Signal Before and After Processing on Raspberry Pi


The AD8232 sensor gathers the ECG signal in the first step, and the STM32F103C8T6 mi-
crocontroller’s ADC transforms it into digital numbers. The Arduino IDE’s Serial Plotter is

23
then used to display this unprocessed digital signal once it has been transmitted to a computer
via UART. At this point, though, the signal seems extremely unstable, exhibiting erratic am-
plitude fluctuations and an ambiguous waveform pattern. It is difficult to recognize important
ECG features, including the P-QRS-T waves, which makes additional analysis difficult. A
Python script is run to process the signal once the data has been delivered to the Raspberry
Pi. The signal is specifically normalized, which means that its amplitude is changed to fall
inside a predetermined range between 0 and 1. This makes the signal more consistent and
simpler to understand by guaranteeing that all values are scaled proportionately. Although
noise is not eliminated by this technique, the signal’s constancy is much increased, avoiding
sharp swings and improving its suitability for additional processing. It is clear by comparing
the signal before and after normalization that the treated signal is more organized and stable,
which enhances readability and facilitates real-time ECG categorization. Prior to normaliza-
tion, the signal was erratic and challenging to decipher; however, following processing on
the Raspberry Pi, it became more lucid and appropriate for applications involving intelligent
cardiac monitoring. In order to properly interpret and use the ECG signal in deep learning
models for heart rhythm categorization, this step is essential.

The final result


We thoroughly assessed the deep learning model—more especially, a Convolutional Neural
Network (CNN)—for ECG signal categorization in the findings and discussion section. With
a remarkable accuracy of 97.49% on the training set and 93.28% on the test set, the model
was trained on a dataset that included a variety of heart rhythm patterns. This excellent per-
formance shows how well the model generalizes, which means it can classify ECG signals
even when given data that hasn’t been seen before.

Figure IV.3: Connecting real devices

24
We examined important evaluation criteria including precision and recall in order to fur-
ther gauge the model’s efficacy. Both measures displayed high values, suggesting that the
system decreases misclassifications in addition to accurately identifying normal and patho-
logical heart rhythms. For medical applications where false negatives could have major reper-
cussions, a high recall score indicates that the model can identify the majority of irregular car-
diac beats. The Raspberry Pi serves as the system’s central processing unit and is in charge of
using UART connectivity to receive raw ECG signals from the STM32 microcontroller. The
AD8232 sensor, which is attached to the individual by means of three electrode pads placed
on the chest, is responsible for obtaining these signals. After processing and normalizing the
signal, the Raspberry Pi feeds it into the CNN model for classification.
Real-time ECG waveform visualization is possible on a monitor that is linked to the Rasp-
berry Pi through the use of a graphical user interface (GUI) created with PyQt5. As new data
is received, this interface is updated continuously, enabling users to effectively monitor heart
rate patterns and identify anomalies. The system can function independently without the need
for a powerful computer thanks to the Raspberry Pi, which makes it more useful for embedded
and portable applications. The Raspberry Pi, STM32 microcontroller, power supply, and dis-
play device are all part of the full system, as seen in Figure IV.3 . From the capture of ECG
signals to the categorization and visualization in real time, this setup guarantees a smooth
workflow. The system’s usefulness in real-time cardiac monitoring is greatly increased by
combining deep learning-based classification with an embedded processing system, provid-
ing a dependable and effective solution for heart rhythm analysis.

(a) (b)

(c)

Figure IV.4: Actual measurements on different people

25
V CONCLUSION AND PERSPECTIVE

This project successfully developed a cost-effective, AI-powered ECG monitoring system


for early heart disease detection. By integrating the AD8232 ECG sensor, STM32 microcon-
troller, and Raspberry Pi, our system efficiently processes and classifies ECG signals with
over 90% accuracy. The use of AI enhances diagnostic precision while reducing reliance
on human expertise, making it suitable for resource-limited areas. Additionally, the intu-
itive GUI improves usability, providing real-time feedback for users. Future improvements
could include optimizing AI models, integrating cloud-based health monitoring, and expand-
ing functionality with additional biosensors. This innovation offers a promising solution for
accessible and efficient cardiovascular diagnostics.
One significant issue during the implementation is signal noise due to body movement,
which affects the real-time collection of accurate ECG signals. Additionally, the dataset used
for training was sourced from the Internet, which presents challenges regarding the diversity
of the data, as these datasets may not fully capture the variety of heart rhythms seen in real-
world scenarios. Furthermore, real-world data collected from the AD8232 sensor may differ
from the training data due to hardware differences, which could impact the model’s reliability
and accuracy. Although the model has shown promising results, the lack of real-time test-
ing on patients with cardiovascular diseases prevents a full evaluation of its performance in
practical settings.
To overcome these limitations, future work should focus on expanding the training dataset
by collecting real-world ECG data from patients, which will help the model generalize better
and detect rare heart rhythms more accurately. Further improving the model’s accuracy can be
achieved by exploring more advanced machine learning algorithms, and clinical trials with
real patients are essential to validate the system’s effectiveness. To improve accuracy and
performance, upgrading the hardware and utilizing more precise sensors will also be important
in optimizing the system in future versions.

26
Bibliography

[1] Components101. AD8232 ECG Module. https://components101.com/modules/


ad8232-ecg-module. 2023.
[2] Analog Devices. AD8232 Low Power, High Performance, Heart Rate Monitor Front-
End. https://www.analog.com/en/products/ad8232.html. 2023.
[3] B. J. Drew et al. “Practice Standards for Electrocardiographic Monitoring in Hospi-
tal Settings: An American Heart Association Scientific Statement From the Coun-
cils on Cardiovascular Nursing, Clinical Cardiology, and Cardiovascular Disease in
the Young: Endorsed by the International Society of Computerized Electrocardiology
and the American Association of Critical-Care Nurses”. In: Circulation 110.17 (2024).
URL: https://doi.org/10.1161/01.CIR.0000145144.56673.59.
[4] SparkFun Electronics. SparkFun Single Lead Heart Rate Monitor - AD8232. https:
//www.sparkfun.com/sparkfun-single-lead-heart-rate-monitor-ad8232.
html. 2023.
[5] A. Goldberger et al. “PhysioBank, PhysioToolkit, and PhysioNet: Components of a
new research resource for complex physiologic signals”. In: Circulation 101.23 (2000).
Online, e215–e220. DOI: 10.1161/01.CIR.101.23.e215.
[6] Mohit D. Gupta et al. “Artificial intelligence in cardiology: The past, present and fu-
ture”. In: Indian Heart Journal 74.4 (2022), pp. 265–269. DOI: 10.1016/j.ihj.
2022.07.004.
[7] G.B. Moody and R.G. Mark. “The impact of the MIT-BIH arrhythmia database”. In:
IEEE Engineering in Medicine and Biology Magazine 20.3 (May 2001), pp. 45–50.
DOI: 10.1109/51.932724.
[8] Sajad Mousavi and Fatemeh Afghah. “Inter- and Intra- Patient ECG Heartbeat Classifi-
cation for Arrhythmia Detection: A Sequence to Sequence Deep Learning Approach”.
In: ICASSP 2019 - 2019 IEEE International Conference on Acoustics, Speech and Sig-
nal Processing (ICASSP). IEEE, 2019, pp. 1308–1312. DOI: 10.1109/ICASSP.2019.
8683140.
[9] Christopher J. L. Murray et al. “Global and regional mortality from 235 causes of death
for 20 age groups in 1990 and 2010: a systematic analysis for the Global Burden of
Disease Study 2010”. In: The Lancet 380.9859 (2012), pp. 2095–2128. DOI: 10.1016/
S0140-6736(12)61728-0.

27
[10] Sulaiman Somani et al. “Deep learning and the electrocardiogram: review of the current
state-of-the-art”. In: Europace 23.8 (2021), pp. 1179–1191. DOI: 10.1093/europace/
euaa377.
[11] STMicroelectronics. STM32F103C8T6 - STMicroelectronics | Mouser Electronics. URL:
https://www.mouser.vn/ProductDetail/STMicroelectronics/STM32F103C8T6.
[12] STMicroelectronics. STM32F103C8T6 - STMicroelectronics eStore. URL: https://
estore.st.com/stm32f103c8t6-cpn.html.
[13] Waveshare. Raspberry Pi 3 Model B+ - Waveshare. URL: https://www.waveshare.
com/raspberry-pi-3-model-b-plus.htm.
[14] R. Yagi et al. “Routine Electrocardiogram Screening and Cardiovascular Disease Events
in Adults”. In: JAMA Internal Medicine 184.9 (2024), pp. 1035–1044. DOI: 10.1001/
jamainternmed.2024.2270.

28

You might also like