Professional Documents
Culture Documents
FYP Report - Final Thesis
FYP Report - Final Thesis
System
By
Saif Ali
01-133172-098
Fawad Ali
01-133172-027
Supervised by
Dr. Saleem Aslam
Session 2017-21
We accept the work contained in this report as a confirmation of the required standard for the
partial fulfilment of the degree of BS(EE).
__________________ __________________
Head of Department Supervisor
__________________ __________________
Internal Examiner External Examiner
i
Dedication
Parents are the ones who dedicate their wealth and time to us, so we would like to dedicate this
project to our parents, our backbone, and our strong pillars. They did everything they could for our
prosperity and growth. They face adversity so that we can achieve our goals. They supported and
encouraged us in every way. Their support made us give everything we needed to complete what
we started. We offer this service to all our teachers throughout our knowledge journey; they have
made us what we are today. We would like to thank each one of them from the bottom of our
hearts. At last, a heartful thanks to all our friends who did not let us lose hope and motivated us to
make our dream come true.
ii
Acknowledgments
Though we have worked hard and made many efforts to make this project happen, Many thanks
to Dr. Saleem Aslam for giving us the opportunity to work on this project under his direction and
guidance throughout the project. It would probably have been impossible to complete the project
without his help and his kind generosity. We also thank Almighty Allah and thank our friends,
brothers, and colleagues for supporting and encouraging us during our project and studies at BUIC.
We also want to thank our colleagues for helping us. And at last, an exceptional thanks to our
colleagues and batchmates, who supported us, encouraged, and made us complete this project with
their kind guidance and help.
iii
Abstract
Heart Attack or stroke is one of the leading causes of death today: the ratio of people who die out
of heart attack vs. all other diseases is very high. In a report from WHO, a total of 17 million people
died from heart disease in 2016 alone. During recent decades, healthcare facilities have improved
much due to the advancement and achievement that science and technology have achieved. Sensor
working with IoT, and development boards made it easy to real-time monitor the patients. Many
wearable devices are available, like smart bands and smartwatches that can measure essential
parameters of one's health. IoT is a revolutionary tech nowadays, and it is going to be growing
fast. Whereas Machine Learning is the actual future for humans for better learning and
understanding. We have made a device that monitors the basic parameters of a person's heart, e.g.,
Heart Rate, ECG, Blood Pressure, and Chest Pain, etc. Using IoT, the device stores the data into
the cloud servers. Using Cloud Computing, the device autonomously applies the Machine
Learning algorithms to the health parameters. It predicts the chances of a Heart Attack.
iv
Table of Contents
Certificate ..................................................................................................................................................... i
Dedication .................................................................................................................................................... ii
Acknowledgments ...................................................................................................................................... iii
Abstract....................................................................................................................................................... iv
List of Tables .............................................................................................................................................. ix
Introduction ................................................................................................................................................. 1
1.1. Project Description........................................................................................................................ 2
1.2. Project Background/Overview ...................................................................................................... 2
1.3. Problem Description ..................................................................................................................... 3
1.4. Project Objectives ......................................................................................................................... 4
1.5. Project Scope ................................................................................................................................ 4
Literature Review ....................................................................................................................................... 6
2.1. Overview ....................................................................................................................................... 7
2.2. Heart ............................................................................................................................................. 7
2.3. Heart Rate ..................................................................................................................................... 8
2.4. ECG (Electrocardiograph) .............................................................................................................. 9
2.5. Blood Pressure ............................................................................................................................ 10
2.6. Chest Pain.................................................................................................................................... 10
2.7. Related Work .............................................................................................................................. 10
2.7.1 Research ................................................................................................................................... 10
Requirement Specifications...................................................................................................................... 13
3.1 Existing Systems ................................................................................................................................ 14
3.1.1 Commercial Products ............................................................................................................... 14
3.1.2 Research Work ......................................................................................................................... 16
3.1.3 Drawbacks/Limitations............................................................................................................. 17
3.2 Proposed System ............................................................................................................................. 18
3.2.1 Proposed System Explained ..................................................................................................... 18
3.2.2 Why this System? ..................................................................................................................... 19
3.3 Requirement Specifications ............................................................................................................ 19
3.3.1 Functional Requirements ......................................................................................................... 20
3.3.2 Nonfunctional Requirements ..................................................................................................... 20
3.4. Use Cases ........................................................................................................................................ 20
v
System Design ............................................................................................................................................ 22
4.1 System Architecture .......................................................................................................................... 23
4.2 Design Constraints ............................................................................................................................ 24
4.3 High-Level Design and Methodology ................................................................................................ 24
4.4 Low-Level Design............................................................................................................................... 26
4.4.1 ESP-32 Dev Module .................................................................................................................... 26
4.4.2 AD8232 ECG Sensor ................................................................................................................... 26
4.4.3 MAX30100 Pulse Oximeter and Heart-Rate Sensor................................................................... 27
4.4.4 Digital Blood Pressure Sensor .................................................................................................... 28
4.4.5 LCD ............................................................................................................................................. 28
4.4.6 Firebase Cloud............................................................................................................................ 29
4.4.7 Machine Learning Model: Support Vector Machine SVM ......................................................... 29
4.4.8 Arduino IDE ................................................................................................................................ 30
System Implementation ............................................................................................................................ 32
5.1 System Architecture (In terms of Implementation) .......................................................................... 33
5.1.1 Hardware ................................................................................................................................... 33
5.1.2 Software ..................................................................................................................................... 35
5.2 Tools and Technology Used .............................................................................................................. 37
5.2.1 Jupyter Notebook....................................................................................................................... 37
5.2.2 Google Firebase ......................................................................................................................... 38
5.3 Development Environment/Languages Used ................................................................................... 38
5.4 Processing Logic/Algorithms ............................................................................................................. 38
System Testing and Evaluation................................................................................................................ 39
6.1 Hardware Testing .............................................................................................................................. 40
6.1.1 Sensors and ESP-32 .................................................................................................................... 40
6.1.2 Data input and Transmission ..................................................................................................... 41
6.2 Software Testing ............................................................................................................................... 43
6.2.1 Firebase Cloud............................................................................................................................ 43
6.2.2 Jupyter Notebook/Machine Learning ........................................................................................ 43
6.2.3 Testing Model with Abnormal Data ........................................................................................... 45
6.3 Accuracy ............................................................................................................................................ 46
Conclusion ................................................................................................................................................. 47
7.1 Challenges and Limitations ............................................................................................................... 48
vi
7.3 Future Work ...................................................................................................................................... 49
References .................................................................................................................................................. 50
APPENDICES ........................................................................................................................................... 52
Appendix A: Code for Hardware ................................................................................................................. 52
Appendix B: Code for Machine Learning .................................................................................................... 60
vii
List of Figures
Figure 1.1: Causes of Death by Percentage [4]............................................................................... 3
viii
List of Tables
Table 2.1: Heart Rate Table [10] .................................................................................................... 9
Table 2.2: Blood Pressure by Age/Gender [13] ............................................................................ 10
Table 2. 3: Table of Literature Review ......................................................................................... 12
ix
Chapter # 01
Introduction
Every day we see people dying out of heart attacks and strokes. There was the need for a device
that can predict a heart attack or any other cardiovascular disease before it happens.
This device has been created to fulfill that space in healthcare for the betterment of society. It is
made to minimize the death toll due to CVDs increasing every year dramatically and saving the
lives of millions of people worldwide. It is made to make quick action possible and let authorities
act fast in case of emergencies to save lives. This device can be a lifesaving tech for many people.
This device deals with a loT of Electrical Engineering fields such as,
i. Communication between devices
ii. Internet of Things
iii. Sensors Interfacing
iv. Circuit Analyses
v. Machine Learning
vi. Cloud Computing
vii. Microcontrollers and Processors
viii. Datamining
ix. Servers interfacing etc.
Literature Review
2.2. Heart
Our heart is the leading and most essential part of the human body. It is responsible for supplying
blood to every corner of our body. A heart can be found at the thorax, off to the left, covered by
the lungs. Our heart comprises two separate pumps, the right one, which pumps the blood through
the lungs, and the left one, which pumps the blood through the peripheral organs. Each of these
hearts is a pulsatile two-chamber pump composed of an atrium and a ventricle.
• Person's age
• Fitness of the body
• Being a smoker or not
• Having a previous heart disease record,
• Body position (standing up or lying down, for example)
There is also a general formula to determine the average heart rate of different ages.
220 - Age = Maximum Heart Rate
Although there are various standard and abnormal heart rates, unusually high or low heart rate can
signify a problem. One should immediately consult a doctor.
ECG plays the most critical and crucial role in determining the patient's heart health and history.
ECG is to read by professional doctors because it contains information that ordinary people cannot
translate. Also, HR can be calculated by the ECG patterns [7].
To predict the heart attack, ECG can be beneficial, as it contains the whole data patterns of the
heart.
2.7.1 Research
As mentioned earlier, there are many more people who suffer from heart problems. There is
therefore a need for daily monitoring and testing related to heart problems. Since it is not possible
to go to the hospital every day, people have made many requests and solutions for health care.
According to a study by Ordonez, heart disease can be predicted by key symptoms taken from a
patient. They have introduced a system that includes individual traits according to 13 key
indicators such as gender, blood pressure, cholesterol, heart rate, ECG, and others to predict the
same. [8].
Another research done by Priyanka Kakria, in 2015 [9] was significant literature this report, they
made a heart monitoring system for remote cardiac patients in which they developed a system
consisting of the wearable sensor along with IoT technologies to send alerts in case of emergency,
their alert system was a significant achievement.
In another research done by Fizar Ahmed in 2017 [10], he made a model consisting of IoT
applications and wearable sensors like heart rate and blood pressure machine learning algorithms
to predict a heart attack. This research help is making us with this project, and we learned a lot
from the research of Fizar Ahmed.
Fares Sayah, in 2020 wrote an article in which using 13 attributes, including heart rate. Chest pain,
ECG, exercise-induced angina, he made an algorithm to predict the heart attack [11]. He used over
300 entries of the data for training the system. He proposed different algorithms for accuracy,
including KNN and random forest.
A brief table on the literature review is given below for a better understanding. Note: this is not all
possible and available data on the selected topic. This is just a chunk out of it, a tip of the iceberg.
For more detail about the Existing system, it guided you to take a look at section 2.3.
Health Monitoring
To monitor the
Priyanka System for Remote Wearable’s sensor and IoT to
health of cardiac
Kakria, 2015 Cardiac send data to healthcare centers.
patients
Patients
The main feature of the device is that it is easy, comfortable, and involves no fatigue. It can also
be worn even at night, and it will not affect sleep. This device can be used to figure out if a person's
pulse is slow, fast, or abnormal. Also, if an individual has a pacemaker, it can determine if it is
working good or not.
This device has the same model that we are going to build, and it resembles a lot of our machines.
Fitbit
Fitbit is a fitness brand made for people who want to track their fitness routine. They also make
smartwatches or smart monitors for heart health. These are fitness trackers and have all basic set
features that a heart patient would need to be notified of with every update.
Fitbit has a heart monitor that shows the person's pulse rate and is also the main feature of this
fitness device. It is an innovative yet compact addition to the heart monitors.
When it comes to the researched work and the systems that are closer to the one, we are making,
there are many honorable mentions. All of the methods that are proposed by the researcher are
mentioned and explained below.
There was a plan proposed by G. Parthiban and S. Srivatsa, where they have developed a device
that helps to bring back good encounters even in non-specific attributes of the category we are
trying to predict. They have been trying to predict the risk of heart disease using symptoms from
diabetes tests in their work. They have shown that it is possible to assess the risk of heart disease
in diabetic patients with the correct accuracy. Classifiers of this type can help detect early exposure
to a diabetic patient. That way, patients can be warned in advance about changing their habits. Use
qualities such as gender, age, Family Heredity, Weight, BP, and cholesterol, etc. [13]
A research paper by A.G.Srinivas reviewed the problem of dealing with different types of data
mining [14]. They focused on using various techniques to predict targeted behavior. This paper
presents the most automated and effective methods of predicting heart attacks using data mining
In another paper, the researchers tried to add the portability of Holter monitors and the processing
power resting ECG machines to provide diagnosis solutions using smartphones. [15].
Researchers Another project introduces a process of event planning in terms of data support
systems. This approach leads to reduced power consumption and extended battery life. Their
experiments show that their real-time classification system exceeds existing methods. [16].
Another research paper was read when it was developed by two sub-systems connected wirelessly
using Bluetooth technology. A sensory support system records the heart's electrical activity in the
chest area to produce an electrocardiogram (ECG). It refers to this sub-system in the decision-
making process where the symptoms of a heart attack are detected. It was noted that the linear
algorithm was unable to detect heart attacks with disturbed and noisy details. [17]
3.1.3 Drawbacks/Limitations
As we have divided the existing systems into two parts, we will explain the limitation and
drawbacks of both the systems step by step. There are problems and constraints on both of them,
and we are keen to cater to them all in our proposed system.
• When we talk about the commercial devices available from many brands in the market, many
of them are just using the sensor's output and then predict the chances of heart diseases based
on the abnormality of the health parameters. They do not have reliable results that can be
obtained by using machine learning algorithms. Also, they are costly systems that do not justify
the price to value ratio.
• When we talk about the proposed system, one of the major drawbacks is that they never see
the day's light and are just there on paper. Secondly, all the systems are not portable or
wearable, just like the way we are doing. Some plans are using machine learning, AI, and data
Type Drawbacks
Commercial They do not have reliable prediction algorithms; they just rely on
abnormalities in the parameters, i.e., limiting on the threshold
values
Research Pieces They do not have a completely autonomous system in a wearable
form that is both reliable and portable.
• The system takes the basic selected heart parameters for heart health and predicts the chances
of a heart attack.
• The system should allow the user to monitor and remove wrong datasets.
• The system should take the parameters continuously and monitor health 4/4.
• The system should send Alerts in case of emergencies to family members and healthcare
centers.
System Design
The whole architecture is explained in HLD and LLD in detail, starting from the hardware parts.
• Firstly, there are three sensors used for measuring ECG, Heart Rate, and Blood Pressure.
Also, there is a physical keypad for chest pain alerts. All these sensors are analog. Using
the inbuilt ADC and DAC, the signals from these sensors can be translated to the medium
of choice.
• ESP-32 gets the data from these sensors in one of the 16 ADC pins, and using the inbuilt
Wi-Fi, it sends this data to the firebase cloud for storage, where the whole history is stored.
• For the machine learning part, we have Jupyter Notebook. We have implemented our SVM
model, support vector machine, a highly efficient supervised machine learning model. This
model will be trained with the training dataset of around 1500 samples, and it will also
fetch the data from the firebase cloud.
• The training dataset has parameters like Age, Gender, Heart Rate, ECG, Blood Pressure,
and Chest Pain.
• After training our model, the data measured from the sensor comes in the model where the
final result is being calculated.
These results are shown on the LCD and also on the APP.
Figure 4 3: ESP-32
• Touch Sensor
• 32-Bit CPU
The AD8232 uses an integrated circuit for the signal conditioning to be used with microcontrollers,
making it the best device to use in electronics and biomedical projects.
The AD8232 Heart Rate Monitor has 9 pins. Also, there are Right Arm, Left Arm, and Right Leg
pins to attach to the body and get the signals from the heart. Furthermore, there is also an LED
indicator that beats with every heartbeat.
One main feature is the Operating Voltage range of 3.3V
4.4.3 MAX30100 Pulse Oximeter and Heart-Rate Sensor
The MAX30100 is an integrated pulse oximeter and heart rate sensor which can measure both the
blood oxygen level and BPM beats per minute of a person's body. It uses the photodetector to
detect the reflected light and measures both parameters using analog signal conditioning.
it usually operates in the voltage range of 1.8V and 3.3V. [20].
Figure 4 7: BP Monitor
The LCD will show your systolic blood pressure, pulse rate results in no time.
4.4.5 LCD
An individual definition comes from a liquid crystal or LCD. It is the synthesis of two types of
matter, solid and liquid. A liquid crystal is used to create a transparent LCD. Liquid crystal displays
are highly technological displays commonly used for desktops, TV, smart telephone, and video
games. LCD technology needs far slimmer displays in comparison to Cathode-Ray tube
architecture.
Numerous engineers appreciate utilizing Firebase since it lets loose them from a portion of the
difficulties they had before while building up the backend of their product or application. Firebase
gives a large number of the devices and administrations that a designer needs while completing
their work. Instead, engineers can make an extraordinary encounter inside their application for the
clients rather than get disappointed with the entirety of the specialized coding items.
4.4.7 Machine Learning Model: Support Vector Machine SVM
One of the most absurd and complex tasks that come in when working with machine learning is
selecting a proper, efficient model. After going through many research and tests, and trials, we
decided on the SVM machine learning model to perform better and accurately.
Support Vector Machine (SVM) is a supervised binary classification algorithm. Given a set of
points of two types in NN dimensional place, SVM generates an (N−1) (N−1) dimensional
hyperplane to separate those points into two groups [21].
SVM will use the trick to find the hyperplane. Now you can cut the area near the apex to separate
those red points from blue. We can think of another 2D plane that performs the task of cutting.
That 2D2D plane is our desired hyperplane.
System Implementation
There is a Pulse oximeter used to get the readings of blood oxygen level and Heart rate. It works
on 3-5 VDC, and it is also connected to the ADC pin of the ESP-32.
Figure 5. 3: Oximeter
Along with these, we have a digital Blood pressure monitor, which is serially providing the
measured readings to the ESPP-32 using the serial ports. The BP monitor has its own battery
system, so it has to be charged with external batteries.
There is a keypad for Chest Pain. It is used when a person feels pain in their chest, and by pressing
the emergency button, an alert will be generated.
ESP-32 has an integrated Wi-Fi Module that enables it to work with different IoT devices. We are
using this module to send the data measured from all the sensors to the firebase cloud for storage
and history.
A keypad is added with the device that enables it to input the data from the user, such as their age,
gender, and other necessary information, which is highly important in machine learning aspects.
Also, there is a 16x2 LCD for showing the typed information and predicted results.
This was the complete hardware architecture explained briefly.
5.1.2 Software
This section will discuss and explain the software architecture of the whole system. We will see
how the hardware part is interacting with the software and vice versa.
Arduino IDE for ESP-32
The environment used for coding the ESP-32 Module is Arduino IDE which is basically the C++
language optimized to work on Arduino or Arduino-like boards. Fortunately, ES-32 is one of them,
and it was fascinating to work on Arduino IDE.
The programming part of all the sensors has been done in the IDE. Also, the Data transfer is
done by coding the Wi-Fi module.
Figure 5. 6: Firebase
The figure above shows the ECG outputs measured by the ECG sensor. It shows the ECG curves
that can be used to see whether the heart patterns are normal or abnormal. The data can be sent to
the doctor to be analyzed. The code written for the ECG curve can predict whether the ECG
patterns are normal or abnormal. The device is capable enough to make decisions of its own to
categorize the data into different tags, such as normal or abnormal ECG graphs.
Similarly, the Heart Rate and Blood Oxygen are being measured in the figure above. Pulse
Oximeter is being used for measuring the Heart rate and blood oxygen levels of the body. As
shown in the figure, pulse and oxygen levels are being updated live on the screen. The sensor
works simply by putting the fingertip on the light source of the sensor. Similarly, the data from the
BP monitor is being measured.
6.1.2 Data input and Transmission
When all the parameters are sent into the cloud, then the machine learning part dives in. The whole
prediction stages start. While it takes a few seconds to be calculated, the device gets the results
back on the screen using the internet facility. It shows the predicted results as patient customary
or heart attack expected.
The model takes only a few minutes to predict the results, and then it shows the predicted results
on the screen.
After updating the parameters, the device predicts the heart attack.
Conclusion
7.2. Accomplishments
This project has achieved many of its proposed goals. These accomplishments are.
- Measuring the essential parameters of heart health.
- Processing of these parameters.
- Storing the data into the cloud
- Machine learning to predict the heart attack.