Final Internship Report 30
Final Internship Report 30
EGC BEATS
This internship report submitted in partial fulfillment of the requirement for the award of degree
of
BACHELOR OF TECHNOLOGY
in
ELECTRONICS AND COMMUNICATION ENGINEERING
Submitted by
Vaishnavi Vedula (VU21EECE0100030)
VISAKHAPATNAM-530045
(2021-2025)
DEPARTMENT OF ELECTRICAL, ELECTRONICS AND COMMUNICATION
ENGINEERING
CERTIFICATE
This is to certify that this report on “Efficient Hardware Design For CNN Based ECG Beats” is
a bonafide work carried out by vaishnavi vedula (VU21EECE0100030) submitted in partial
fulfillment of the requirements for the award of the degree of Bachelor of Technology in
Electronics and Communication Engineering, GITAM School of Technology, GITAM (Deemed
to be University), Visakhapatnam has successfully completed the industrial training at “National
Institute Of Technology Tiruchirappalli (NITT).” during the academic year 2024-2025.
DECLARATION
I hereby declare that the work entitled “Efficient Hardware Design For CNN Based ECG
Beats” is an original work done in the Department of Electrical, Electronics and
Communication Engineering, GITAM School of Technology, GITAM (Deemed to be
University) submitted in partial fulfillment of the requirements for the award of the degree
of B.Tech. in Electronics and Communication Engineering. The work has not been
submitted to any other college or university for the award of any degree or diploma.
I would like to thank my internship guide Dr. A. Ch. Sudheer, Associate Professor, Dept. of EECE for
his stimulating guidance and profuse assistance. I shall always cherish our association with him for his
guidance, encouragement, and valuable suggestions throughout the progress of this work. I consider it a
great privilege to work under her guidance and constant support.
I would like to thank our Internship Coordinator D. Madhavi, Assistant Professor, Dept. of EECE in
helping to complete the Internship by taking frequent reviews and for their valuable suggestions
throughout the progress of this work.
I consider it a privilege to express our deepest gratitude to Prof. Dr. P. Bharani Chandra Kumar, Head
of theDepartment, Department of EECE for his valuable suggestions and constant motivation that greatly
helped us to successfully complete the Internship.
My sincere thanks to Prof. K. Nagendra Prasad, Director, GST, GITAM (Deemed to be University)
for inspiring us to learn new technologies and tools.
Finally, I deem it a great pleasure to thank one and all who helped us directly and indirectly throughout
this Internship
Vaishnavi Vedula
(VU21EECE0100030)
Abstract
Accurate detection and classification of cardiac arrhythmias mattered a lot. Abnormalities in heart rhythm
accurate timely medical intervention for improving patient outcomes. In 2021, a fresh approachsurfaced.
Deep learning techniques received attention, especially in analyzing electrocardiogram (ECG)signals.
The complexity was real due to the complexity of arrhythmias and their variability. Therefore, an
advanced method for analyzing ECG data became advanced method. A Convolutional Neural Network
(CNN) stood out. This type of network worked well with 1D time-series data. The project involved steps
like pre-processed the signals first. More so, segmented occurred next. Researcher classification the ECG
signals into fixed-length portions which were necessary before fed them into theCNN model. This
process allowed the model to learns critical patterns for classifying arrhythmias effectively. Also, this
method aimed to improve accuracy over traditional methods used traditional methods without success
during critical interventions in hospitals or clinics where timely decisions leadto improving treatments
accessed by patients suffering from cardiac arrhythmias quickly discovered through timely detected signs
on electrocardiograms during routine examinations across health servicessince earlier decades when
patients started recognizing abnormalities associated with ignoring good hearthealth practices affecting
leading down roads nobody wanted. In this innovative of deep learning techniques showed promise that
clearly required improvement while establishing lasting impacts today making lives healthier adequately
performed ensuring timely required actions improving survival rates and preserving quality time as vital
aspects into more effective care systems based on extensive research
After training with the MIT-BIH Arrhythmia Database, the model achieved 99% accuracy. The final
version of the trained model converted to ONNX format. It also deployed on FPGA hardware. This move
enabling real-time detection with low latency. It clearly suitable remote healthcare needs. High-speed
processing from FPGA tech boosts how accurately arrhythmia classification works. This makes it a
powerful solution for monitoring and diagnosing in medical settings. The mix of deep learning and FPGA
acceleration holds much promise. It can be advanced cardiac healthcare significantly while improving
patient outcomes overall. At its core this technology transforms how clinicians detect heart challenges
quickly and accurately, yet challenges remained as always in such advances; ensuring widespread
adoption takes time and effort. Therefore, benefitting directly speaks volumes about the long-term impact
on healthcare dynamics. Shifts like these don’t just transform one thing but reshape widespread aspects
of patient care in an era where speed matters significantly more than before.
1
CONTENTS
Chapter 3 Methodology 18
2
Chapter 5 Hardware Implementation 38
Chapter 8 Reference 51
Conclusion 52
3
List of Figures
5.2 (a) & (b) Real time implementation using PYNQ-Z2 43-44
6.2 Parameters 48
4
CHAPTER 1
INTRODUCTION
ECG heartbeats were extracted from the MIT-BIH Arrhythmia Database on PhysioNet. Each
heartbeat was isolated from continuous ECG recordings after the annotated R-peak, capturing the
full P wave, QRScomplex, and T wave. To extract individual heartbeats from the continuous
ECG recordings in the MIT-BIH Arrhythmia Database, a precise and meticulous process is
employed. The first step involves identifying the R-peak, a distinctive peak in the ECG signal
that corresponds to the ventricular depolarization phase of the cardiac cycle. Once the R-peak is
located, a fixed-length window is centered around it, typically capturing a segment that
encompasses the entire P wave, QRS complex, and T wave.This windowed segment represents
a single heartbeat, isolated from the surrounding noise and interference present in the continuous
ECG recording. By extracting and analyzing these individual heartbeats, researchers can delve
deeper into the intricacies of cardiac rhythm and identify abnormalitiesindicative of various
arrhythmias.
A notable feature of this database is the beat annotations for each ECG recording, identifying
different beat types such as normal beats, ventricular ectopic beats, supraventricular ectopic
beats, fusion beats, and unknown beats. These annotations are essential for training and
evaluating algorithms for automaticarrhythmia detection and classification. Researchers and
practitioners utilize the MIT-BIH Arrhythmia Database to develop and test machine learning
models, especially convolutional neural networks (CNNs), for recognizing patterns in ECG
signals corresponding to various arrhythmias. The detailed annotations and comprehensive
nature of the dataset make it invaluable for advancing cardiac health monitoring and diagnosis
technologies.
5
Cardiac arrhythmias are significant health concerns that necessitate prompt and accurate detection for
effective management and treatment. Electrocardiogram (ECG) signals, which capture the heart's
electrical activity, are critical in diagnosing these irregularities. Traditional methods for arrhythmia
detection often involve manual analysis, which can be time-consuming and prone to errors. To address
these challenges, this paper presents a novel approach that leverages deep learning and FPGA technology
for enhanced ECG signal processing and arrhythmia classification.
Our method involves segmenting ECG signals into fixed-length segments, which are then fed into a
Convolutional Neural Network (CNN) based on our own architecture. The model is trained and validated
using the MIT-BIH Arrhythmia Database, a well-regarded dataset containing ECG recordings from
multiple patients with annotated arrhythmias. Achieving an accuracy of over 90 percentage on the test
set, the model demonstrates its efficacy in correctly identifying various types of arrhythmias.
To facilitate real-time detection and deployment in remote healthcare settings, the trained model is
converted to the ONNX format and implemented on FPGA hardware. This combination allows for
high-speed, low-latency processing, making the system suitable for continuous monitoring and timely
intervention. The integration of deep learning and FPGA technology not only improves the accuracy
and speed of arrhythmia detection but also enables the development of advanced remote monitoring
systems, thereby enhancing patient care and outcomes. This work underscores the potential of
leveraging cutting-edge technology in the field of biomedical signal processing to address critical
healthcare challenges.
6
Figure 1.1 Sample signal from MIT-BIH Arrhythmia Database
7
CHAPTER 2
ECG DATA OVERVIEW
The MIT-BIH Arrhythmia database is one of the most extensively used datasets in the field of
biomedical signal processing, particularly for the detection and classification of cardiac arrhythmias.
Hosted by physionet, a resource widely recognized for offering free access to well-validated
physiological datasets, this database has been an essential benchmark for research in automated
arrhythmia classification, machine learning applications in cardiology, and the development of
diagnostic systems. The database is a curated collection of electrocardiogram (ecg) recordings, which
are captured from human subjects under various clinical conditions. Since its inception, the database
has contributed significantly to the advancement of medical technology, especially in relation to the
monitoring and diagnosis of heart diseases.
The MIT-BIH Arrhythmia Database is a foundational resource in biomedical signal processing, known
especially for its role in the detection and classification of cardiac arrhythmias. Maintained by
PhysioNet, a respected platform providing free access to validated physiological datasets, this database
has become an essential benchmark for research involving automated arrhythmia detection, machine
learning applications in cardiology, and the creation of advanced diagnostic systems. It is widely
regarded as a foundational resource in the realm of biomedical signal processing, particularly due to its
significant role in facilitating the detection and classification of cardiac arrhythmias. Since its
introduction, this dataset has become a pivotal benchmark for advancing research in cardiology,
contributing extensively to the development and refinement of automated diagnostic tools and
algorithms. The database is hosted by PhysioNet, a well-respected platform known for providing open
access to high-quality, validated physiological data, thus supporting transparency and reproducibility in
scientific research.
Researchers across the globe utilize the MIT-BIH Arrhythmia Database to train and evaluate machine
learning models, enabling them to develop systems capable of accurately identifying a variety of
cardiac abnormalities. These models rely on the rich, annotated ECG recordings within the database to
detect subtle variations in the PQRST waveform, a process essential for distinguishing between normal
and pathological heart rhythms. By leveraging this data, machine learning approaches can be optimized
for real-world clinical settings, enhancing the ability of healthcare providers to diagnose conditions
8
such as atrial fibrillation, ventricular tachycardia, and other complex arrhythmias with greater speed
and precision.
The MIT-BIH Arrhythmia Database stands as a cornerstone in the field of biomedical signal
processing, particularly renowned for its application in the detection and classification of cardiac
arrhythmias. Hosted by PhysioNet, a widely recognized resource offering free access to well-validated
physiological datasets, this database has emerged as an indispensable benchmark for research in
9
automated arrhythmia classification, machine learning applications in cardiology, and the development
of advanced diagnostic systems.
Since its inception, the MIT-BIH Arrhythmia Database has played a pivotal role in driving
advancements in medical technology, particularly in the realm of heart disease monitoring and
diagnosis. Researchers have extensively utilized this database to develop and evaluate innovative
algorithms and machine learning models for automated arrhythmia detection. These advancements
have the potential to significantly improve the accuracy and efficiency of cardiac diagnosis, leading to
earlier detection of life-threatening arrhythmias and timely interventions.
Moreover, the database has contributed to the development of wearable health devices, enabling
continuous monitoring of heart rhythms and alerting users to potential cardiac issues. By leveraging the
insights gained from analyzing the MIT-BIH Arrhythmia Database, researchers and engineers have
been able to design and develop more reliable and accurate wearable devices, empowering individuals
to take proactive steps towards maintaining their cardiovascular health.
In conclusion, the MIT-BIH Arrhythmia Database has established itself as a valuable resource for
researchers, clinicians, and engineers working in the field of cardiac arrhythmia detection and
classification. By providing a comprehensive and well-annotated collection of ECG recordings, this
database has facilitated groundbreaking research and the development of innovative technologies that
have the potential to revolutionize the diagnosis and treatment of heart disease.
10
and t wave. Each recording represents the electrical impulses that propagate through the heart during
each heartbeat, providing a wealth of information that can be used to diagnose arrhythmias—
irregularities in the heart's rhythm or rate. The MIT-BIH Arrhythmia Database is a comprehensive
collection of electrocardiogram (ECG) recordings, meticulously curated to provide a rich dataset for
research and development in the field of cardiac arrhythmia analysis. This invaluable resource
comprises 48 half-hour excerpts of two-channel ambulatory ECG recordings, obtained from 47 patients
who underwent studies at the Beth Israel Hospital Arrhythmia Laboratory between 1975 and 1979.
Each ECG recording is sampled at a high frequency of 360 Hz, ensuring the capture of intricate details
in the cardiac electrical activity. This high sampling rate allows for precise analysis of the P wave, QRS
complex, and T wave, which are crucial components of the cardiac cycle. By studying these
waveforms, researchers can identify abnormalities and irregularities in the heart's rhythm, such as
premature ventricular contractions, ventricular tachycardia, and atrial fibrillation.
The MIT-BIH Arrhythmia Database offers a diverse range of ECG recordings, encompassing various
heart conditions and physiological states. This diversity enables researchers to develop and evaluate
algorithms and machine learning models that can accurately classify different types of arrhythmias. By
analyzing these recordings, researchers can gain valuable insights into the underlying mechanisms of
cardiac arrhythmias and develop innovative strategies for early detection and intervention.
The PQRST waveform in an ECG (Electrocardiogram) represents the electrical activity of the heart as
it contracts and relaxes. Here’s a breakdown of each part of the waveform:
1. P Wave
Characteristics:
Significance: Indicates the initiation of the heartbeat by the sinoatrial (SA) node.
2. QRS Complex
11
Characteristics:
Components:
Significance: The QRS complex reflects the rapid conduction of electrical impulses
through the ventricles, leading to ventricular contraction. Abnormalities in the QRS
complex can indicate issues such as ventricular hypertrophy or bundle branch blocks.
3. T Wave
Represents: Ventricular repolarization (the recovery phase when the heart muscle resets
electrically).
Characteristics:
4. PR Interval
Represents: The time taken for electrical conduction from the SA node to the ventricles
(through the atria and AV node).
5. ST Segment
12
Represents: The period between ventricular depolarization and repolarization (the plateau phase
of the action potential).
Characteristics:
6. QT Interval
Duration: Varies with heart rate but typically ranges from 0.36 to 0.44 seconds.
Significance: Prolonged or shortened QT intervals can indicate an increased risk for certain
types of arrhythmias.
Clinical Importance:
Abnormal ECG Patterns: Can help diagnose various cardiac conditions like arrhythmias,
myocardial infarction, electrolyte imbalances, and conduction abnormalities.
The clinical importance of understanding the PQRST waveform in an ECG cannot be overstated.
A normal ECG is a clear indicator that the heart’s electrical activity is functioning as it should,
reflecting the effective and coordinated depolarization and repolarization of the atria and ventricles.
This regular pattern of electrical activity translates to efficient contractions, allowing the heart to pump
blood throughout the body without interruptions. Healthcare providers use this information as a
baseline for assessing cardiac health in routine check-ups, preoperative evaluations, and wellness
screenings. However, the ECG’s true value lies in its ability to reveal abnormal patterns that may
indicate underlying cardiac issues. Any deviation from the expected PQRST waveform can provide
early warnings of potential health problems.
For instance, arrhythmias are identified by irregularities in the timing or formation of the waves. These
can range from benign conditions, such as premature atrial contractions, to more serious disturbances
like atrial fibrillation, which requires prompt medical attention. The QRS complex, being crucial for
assessing ventricular function, can reveal conditions like ventricular hypertrophy if it appears wider or
13
altered. This may indicate an increase in the muscle mass of the ventricles, commonly due to
hypertension or other cardiac stressors. Similarly, subtle changes in the T wave can signal issues
with electrolyte imbalances, such as hyperkalemia or hypokalemia, where the levels of potassium in the
blood are too high or too low, respectively. Recognizing these signs can lead to timely interventions
that prevent severe complications. The ST segment holds particular significance in
diagnosing myocardial infarction (heart attack). Elevation or depression of this segment points to
ischemia or active injury to the heart muscle.
Detecting these changes quickly enables healthcare providers to initiate immediate treatment,
potentially saving lives and preserving heart function. Moreover, the PR interval and QT interval serve
as windows into the conduction system's efficiency and overall heart stability. Prolongation of the PR
interval might indicate a delay in electrical conduction through the atria or AV node, signal first-degree
heart block. On the other hand, an unusually long or short QT interval can predispose individuals to
dangerous arrhythmias, such as Torsades de Pointes, which can be life-threatening if not treated.
In essence, interpreting the PQRST waveform in an ECG is a vital skill for healthcare professionals, as
it provides critical insights into the heart’s rhythm and electrical conduction. Through this
understanding, they can identify and address a range of cardiac conditions—from mild to severe—
ensuring that interventions are timely and effective. This tool not only aids in diagnosing acute and
chronic cardiac issues but also plays a role in monitoring ongoing treatment and managing patients
with existing heart conditions.
14
Figure 2.2 ECG Signal
The database’s recordings were digitized from analog tapes, and the ecg data were collected using
standard holter monitor devices, which continuously record the electrical activity of the heart for
extended periods. This continuous data is crucial in arrhythmia detection, as arrhythmias may occur
sporadically and can be missed if only short, selective recordings are analyzed.
A distinctive feature of the mit-bih arrhythmia database is its rich set of annotations, which mark each
individual heartbeat within the ecg recordings. These annotations include information about the different
types of beats and arrhythmias identified by cardiologists, allowing researchers to study the occurrence
and nature of various heart conditions. The database provides detailed beat labels such as:
N: normal beat (non-ectopic beats): regular heartbeat where the electrical impulse follows the
normal conduction pathway.
L: left bundle branch block (lbbb) beat: A condition where there is a delay or block in the
electrical impulses traveling to the left ventricle, causing it to contract later than the right
ventricle.
15
r: right bundle branch block (rbbb) beat: Similar to lbbb but affects the right ventricle. The
electrical impulse to the right side is delayed, causing asynchrony between the two ventricles.
a: atrial premature beat (apb): Extra heartbeat originating in the atria (upper chambers of the
heart) that interrupts the regular rhythm, often felt as a "skipped" beat.
v: premature ventricular contraction (pvc): An extra heartbeat that begins in one of the heart's
ventricles. It occurs early and disrupts the normal heart rhythm, causing a “fluttering” or
palpitation.
These beat annotations are pivotal for training machine learning models, particularly deep learning
architectures such as convolutional neural networks (cnns), which require labeled data for supervised
learning. By providing a diverse and annotated set of arrhythmia examples, the mit-bih arrhythmia
database enables models to learn to distinguish between normal heartbeats and various pathological
conditions.
The mit-bih arrhythmia database has become the de facto standard for training and evaluating algorithms
that aim to automatically detect arrhythmias. Machine learning and deep learning models, particularly
cnns, have shown great promise in analyzing ecg signals to identify subtle patterns that indicate the
presence of arrhythmias. These models are capable of automatically learning important features from raw
ecg data without the need for extensive manual feature engineering, which was previously a labor-
intensive task in biomedical signal processing.
By leveraging the beat annotations, machine learning models can be trained to detect different types of
arrhythmias with high accuracy. In this project, for instance, we utilized the cnn model to process ecg
signals segmented into individual heartbeats. Each segmented heartbeat was fed into the model to
recognize its type, enabling real-time arrhythmia classification. The annotated beats from the database
served as the ground truth for the training process, allowing the model to learn the distinct characteristics
of various arrhythmia types.
16
2.4 SIGNIFICANCE IN CLINICAL RESEARCH
The importance of the mit-bih arrhythmia database extends beyond machine learning research; it is also
widely used in clinical studies that aim to enhance the understanding and diagnosis of cardiac
arrhythmias. Arrhythmias, such as atrial fibrillation, ventricular tachycardia, and others, pose significant
risks to patients, increasing the likelihood of stroke, heart failure, and sudden cardiac death if left
undetected. The database plays a key role in enabling the development of advanced diagnostic tools that
can aid in the early detection and management of these conditions.
Furthermore, the availability of such a comprehensive and well-annotated dataset ensures that research
findings are reproducible, an essential aspect of scientific research. Studies that leverage the mit-bih
arrhythmia database can be reliably replicated by other researchers, enabling continuous improvements
in arrhythmia detection methods.
17
CHAPTER 3
METHODOLOGY
3.1 ECG SIGNAL PREPROCESSING
The first step in this project involved preprocessing the ecg signals, which were sourced from the mit-
bih arrhythmia database. Preprocessing is critical for ensuring that the input to the deep learning model
is consistent and clean, enhancing the overall performance and accuracy of the model. Specifically, we
segmented continuous ecg recordings into individual heartbeats. This segmentation was performed after
identifying the annotated r-peaks, which mark the point of ventricular depolarization in the heart's cycle.
By isolating each heartbeat, we captured the full p wave, qrs complex, and t wave. This process was
crucial to preserving the essential features of the cardiac cycle that provide important diagnostic
information for arrhythmia classification.
Additionally, the ecg signals underwent noise reduction techniques, such as band-pass filtering, to
eliminate baseline wander and high-frequency noise commonly associated with ambulatory recordings.
These artifacts can negatively impact model performance by distorting key features in the ecg signal. By
removing these unwanted components, we ensured that the model focused solely on the clinically
significant aspects of the data.
18
Following noise reduction and segmentation, the ecg signals were normalized to bring all data into a
comparable range, preventing biases toward certain segments due to differences in amplitude. This step
also facilitated faster and more stable training of the convolutional neural network (cnn) model by
ensuring consistent input data across the entire dataset.
The 2d convolutional layer is a fundamental building block in convolutional neural networks (cnns) and
is widely used in various applications, including image and signal processing. In the context of ecg signal
classification, the 2d convolutional layer is leveraged to automatically learn spatial patterns in the ecg
signals, particularly the complex morphology of heartbeats.
The 2d convolutional layer applies a set of learnable filters (also known as kernels) to the input data.
Each filter slides over the input ecg signal (or image) and performs an element-wise multiplication,
followed by a summation of the results to produce a single output value. This process, known as
convolution, helps in detecting localized patterns such as edges, peaks, and complex shapes.
Mathematically, given an input X and a filter W, the output of the 2d convolution operation at position
(i, j) is computed as:
Where:
19
Key features of the 2d convolutional layer:
1. Filter size: the filters in the 2d convolutional layer typically have a smaller spatial size compared
to the input. For example, a filter might be 3x3 or 5x5, which allows it to focus on small localized
patterns in the ecg signal.
2. Stride and padding: the stride determines how much the filter moves at each step. Padding can be
added around the input to control the spatial dimensions of the output. Both these factors affect
the feature extraction process.
3. Feature maps: each filter produces a feature map that represents the presence of specific patterns,
such as qrs complexes or arrhythmia-specific waveforms, across different regions of the ecg
signal.
4. Activation function: after applying the convolution, an activation function like relu (rectified
linear unit) is used to introduce non-linearity, helping the network capture complex patterns.
20
3.3 CNN-BASED DEEP LEARNING MODEL
The core of our arrhythmia classification system is a convolutional neural network (cnn) designed to
process 1d time-series data like ecg signals. Cnns are particularly well-suited for this type of data due to
their ability to automatically learn spatial hierarchies of features through convolutional layers, making
them highly effective for detecting subtle patterns in ecg waveforms.
The input to the cnn was the segmented ecg data from the preprocessing stage. The architecture employed
was specifically tailored for 1d signal processing, enabling the model to detect critical features such as
the p wave, qrs complex, and t wave variations, which are indicative of different arrhythmias. By training
the model on the annotated ecg recordings from the mit-bih arrhythmia database, we ensured that it
learned to distinguish between various types of heartbeats, including normal beats, ventricular ectopic
beats, and supraventricular ectopic beats.
The cnn was trained using backpropagation and gradient descent, optimizing a categorical cross-entropy
loss function to minimize misclassification errors. Dropout layers were introduced to prevent overfitting,
ensuring that the model would generalize well to new, unseen ecg recordings. The final output layer of
the model used a softmax activation function to classify the input into one of several arrhythmia
categories, based on the learned features.
The proposed model is a convolutional neural network (cnn) designed using tensorflow’s keras api,
tailored for classification tasks on sequential or 1d data. The model follows a sequential architecture,
starting with an input layer that takes data of shape (360, 1, 1), indicating a single-channel input with 360
time steps or features. This suggests that the model processes 1d sequences or time-series data in the
context of image-like structures, where the primary axis of variation is along the vertical dimension.
The architecture begins with a convolutional layer that applies 16 filters, each of size (3, 1), across the
input data. The use of a small kernel size allows the model to extract localized features from the data,
with the relu activation function introducing non-linearity, enabling the model to learn complex patterns.
The padding is set to 'same,' which ensures the output size remains the same as the input, preventing any
loss of information along the spatial dimensions. Following this, a max-pooling layer with a pooling size
of (5, 1) and a stride of (2, 1) reduces the dimensionality of the feature maps, downsampling the input
while retaining the most important features.
21
This pattern of convolution followed by pooling is repeated across three more layers, with each
successive convolutional layer increasing the number of filters — from 32, to 64, and finally 128 filters.
This incremental increase in the number of filters allows the model to progressively learn more complex
and detailed representations of the input data. The kernel size remains consistent across these layers,
which helps in maintaining uniform feature extraction throughout the model. The pooling layers, which
follow each convolutional layer, continue to reduce the dimensionality of the feature maps, thus ensuring
computational efficiency and avoiding overfitting.
Once the convolutional layers have extracted the relevant features, the data is flattened into a 1d
vector, which serves as the input to the fully connected dense layers. The first dense layer consists of
100 neurons and applies the relu activation function to further process the extracted features. This is
followed by a second dense layer with 50 neurons, which also uses relu, ensuring that the model can
learn complex feature representations even in the fully connected layers. To prevent overfitting, a
dropout layer with a rate of 0.5 is applied, randomly deactivating 50% of the neurons during training,
thus promoting generalization and robustness in the model. Convolutional layers are the backbone of
convolutional neural networks (CNNs), particularly effective for processing image and video data.
They work by applying filters (also known as kernels) to the input data, sliding them across the image
to extract specific features. These filters are designed to detect patterns like edges, corners, and
textures.
Feature Maps: As the filter slides across the image, it performs element-wise multiplication and
summation with the underlying pixels. This process generates a feature map, which highlights the
presence of the detected feature in different regions of the image.
Pooling Layers: To reduce the dimensionality of the feature maps and introduce some degree of
translation invariance, pooling layers are often used. They downsample the feature maps by taking the
maximum or average value within a specific region, preserving the most important information.
After the convolutional and pooling layers have extracted meaningful features, the output is typically a
multi-dimensional array. To feed this data into fully connected layers, it needs to be transformed into a
one-dimensional vector. This is where the flattening layer comes into play. It reshapes the multi-
dimensional array into a single, long vector, preserving the spatial information learned by the
convolutional layers.
22
Dense Layers: The Decision Makers
Dense layers, also known as fully connected layers, are the traditional neural network layers where
each neuron is connected to every neuron in the previous layer. They play a crucial role in learning
complex patterns and making final predictions.
Feature Processing: The first dense layer with 100 neurons takes the flattened feature vector as input
and applies the ReLU activation function. ReLU introduces non-linearity, enabling the network to learn
intricate relationships between features.
Feature Refinement: The second dense layer with 50 neurons further processes the features, potentially
learning more abstract representations. Again, ReLU is used to introduce non-linearity.
Dropout Regularization: To prevent overfitting, a dropout layer is added. During training, it randomly
deactivates 50% of the neurons in the previous layer. This forces the network to learn more robust
features and reduces reliance on any specific neuron, improving generalization.
The final layer, often called the output layer, depends on the specific task. For classification tasks, it
typically uses a softmax activation function to output probabilities for each class. For regression tasks,
a linear activation function is often used to predict a continuous value.By combining convolutional
layers, pooling layers, flattening layers, and dense layers, CNNs can effectively learn hierarchical
representations of visual data, making them powerful tools for image classification, object detection,
and other computer vision tasks.
Finally, the output layer consists of 5 neurons, corresponding to the number of target classes in the
classification task. A softmax activation function is applied at this stage, producing a probability
distribution over the classes, allowing the model to make a final prediction based on the highest
probability. Overall, this cnn architecture is well-suited for classification tasks involving sequential data,
combining convolutional and fully connected layers to capture both local and global features, while the
use of dropout ensures that the model remains generalizable.
23
Figure 3.3 Proposed CNN Architecture
Figure 3.4 The Proposed 2-D CNN Architecture for ECG Classification
24
3.4 MODEL VALIDATION AND TESTING
After training the cnn, the model was validated using a portion of the mit-bih arrhythmia database
that was held out as the test set. The performance of the model was evaluated using accuracy,
precision, recall, and f1 score metrics, which are particularly relevant for medical diagnosis tasks
where both false positives and false negatives can have significant implications. The model achieved
an accuracy exceeding 90%, demonstrating its effectiveness in identifying arrhythmias in ecg signals.
The trained CNN model was rigorously evaluated on a held-out test set from the MIT-BIH Arrhythmia
Database to assess its performance in accurately identifying arrhythmias in ECG signals. To provide a
comprehensive evaluation, multiple performance metrics were employed: accuracy, precision, recall,
and F1-score.
Accuracy measures the overall correctness of the model's predictions, while precision quantifies the
proportion of positive predictions that are accurate. Recall measures the proportion of true positive
cases that are correctly identified. The F1-score, a harmonic mean of precision and recall, provides a
balanced measure of the model's performance.
By considering these metrics, the model's performance was thoroughly assessed. The model achieved
an impressive accuracy of over 90%, demonstrating its potential to be a valuable tool in clinical
settings for the early detection and diagnosis of cardiac arrhythmias.
25
CHAPTER 4
MODEL DEVELOPMENT TOOLS
4.1 TENSIL FRAMEWORK
To deploy the trained cnn model for real-time arrhythmia detection, we utilized the tensil framework, a
tool designed for hardware acceleration on field-programmable gate arrays (fpgas). Fpgas are
reconfigurable hardware devices that are highly efficient for parallel processing tasks, making them ideal
for real-time signal processing applications like ecg analysis.
The tensil framework allowed us to compile the cnn model, originally developed in python, into a format
suitable for execution on fpga hardware. One of the key challenges in deploying deep learning models
on fpgas is the need to balance performance (e.g., latency and throughput) with resource utilization (e.g.,
memory and computational units). The tensil framework automates much of this process by generating
optimized hardware configurations based on the model's architecture and the target fpga.
26
By leveraging the power of fpgas, we were able to achieve real-time ecg signal classification with low-
latency, which is crucial for applications in remote healthcare monitoring. For instance, in scenarios
where continuous monitoring of cardiac patients is required, the ability to process ecg signals in real-
time can enable timely interventions and potentially save lives. The combination of deep learning and
fpga acceleration provided a significant boost in both speed and energy efficiency, making this
solution suitable for deployment in resource-constrained environments like wearable health devices.
The deployment of our trained Convolutional Neural Network (CNN) model for real-time arrhythmia
detection was made possible through the utilization of the Tensil framework. This specialized tool is
designed to accelerate hardware operations on Field-Programmable Gate Arrays (FPGAs), which are
highly reconfigurable hardware devices that excel in parallel processing tasks. This makes them ideal
for real-time signal processing applications such as Electrocardiogram (ECG) analysis.
The Tensil framework seamlessly transformed our Python-based CNN model into a format compatible
with FPGA hardware. One of the primary challenges in deploying deep learning models on FPGAs is
the delicate balance between optimizing performance, measured in terms of latency and throughput,
and efficiently utilizing resources such as memory and computational units. The Tensil framework
automates much of this optimization process, generating customized hardware configurations tailored
to the specific model architecture and the target FPGA device.
By leveraging the power of FPGAs, we achieved real-time ECG signal classification with minimal
latency. This low-latency performance is crucial for remote healthcare monitoring applications, where
continuous monitoring of cardiac patients is essential. The ability to process ECG signals in real-time
empowers timely interventions and potentially life-saving actions. The synergistic combination of deep
learning and FPGA acceleration significantly enhanced both speed and energy efficiency, making this
solution well-suited for deployment in resource-constrained environments, such as wearable health
devices.
The integration of our CNN model with FPGA hardware through the Tensil framework represents a
significant advancement in the field of real-time medical signal processing. By capitalizing on the
parallel processing capabilities of FPGAs, we were able to significantly improve the speed and
efficiency of our arrhythmia detection system. This breakthrough enables the potential for widespread
deployment of advanced AI-powered healthcare solutions, even in resource-limited settings.
27
Furthermore, the use of FPGAs offers additional advantages such as low power consumption and high
reliability. This makes it an ideal solution for edge devices where power and space constraints are
significant factors. By deploying our model on FPGAs, we can reduce the computational burden on
cloud servers, improving scalability and reducing costs.
In conclusion, the combination of deep learning and FPGA acceleration has the potential to
revolutionize the field of healthcare. By enabling real-time, accurate, and efficient arrhythmia
detection, we can improve patient outcomes and save lives.
In machine learning (ml) projects, especially those involving hardware acceleration like fpga integration,
ensuring consistency across development, testing, and deployment environments is crucial. This
consistency becomes even more important when working in collaborative teams or across different
platforms, such as local machines, cloud infrastructures, and hardware devices like fpga boards. In our
project, to maintain stability and reproducibility across these varying environments, we adopted docker
for environment management and containerization.
Why docker?
Docker allows developers to create lightweight, portable containers that encapsulate the entire software
environment, including the operating system, libraries, dependencies, and the application code. By
packaging the entire machine learning pipeline—from data preprocessing to model training, evaluation,
and deployment—within a docker container, we were able to establish a consistent runtime environment
across all stages of the project lifecycle. This "containerization" solved several key challenges:
1. Eliminating dependency issues: one of the most common problems when deploying machine
learning models is the "it works on my machine" issue. This happens when code that runs on one
machine (due to specific versions of libraries or tools) fails on another due to mismatched
dependencies or configuration settings. By using docker, we encapsulated not just our cnn model
but the entire preprocessing pipeline, training scripts, deployment tools, and necessary libraries,
ensuring that the same environment could be replicated on any machine, regardless of its
underlying setup.
28
2. Portability across platforms: docker containers are platform-independent. Whether we were
running our project on local workstations, in cloud environments (such as aws or azure), or
deploying the model onto hardware platforms like the pynq-z2 fpga board, docker provided a
seamless transition between environments. The containerized environment ensured that the code
behaved exactly the same, regardless of where it was executed. This was especially critical for
hardware integration, as fpga platforms often have different operating system requirements and
configurations that need careful management.
In the realm of machine learning (ML) projects, particularly those involving hardware acceleration like
FPGA integration, maintaining consistency across development, testing, and deployment environments
is paramount. This consistency becomes even more crucial when collaborating in teams or working
across diverse platforms, such as local machines, cloud infrastructures, and hardware devices like
FPGA boards. To ensure stability and reproducibility across these varying environments, we adopted
Docker for environment management and containerization.
Docker empowers developers to create lightweight, portable containers that encapsulate the entire
software environment, encompassing the operating system, libraries, dependencies, and application
code. By packaging the entire ML pipeline—from data preprocessing to model training, evaluation, and
deployment—within a Docker container, we established a consistent runtime environment throughout
the project lifecycle. This containerization approach effectively addressed several key challenges:
One of the most prevalent issues in ML deployment is the notorious "it works on my machine"
problem. This arises when code that functions on one machine fails on another due to mismatched
dependencies or configuration settings. By leveraging Docker, we encapsulated not only our CNN
model but also the entire preprocessing pipeline, training scripts, deployment tools, and essential
libraries. This ensured that the same environment could be replicated on any machine, irrespective of
its underlying setup.
29
Docker containers are inherently platform-independent. Whether we were executing our project on
local workstations, cloud environments like AWS or Azure, or deploying the model onto hardware
platforms such as the PYNQ-Z2 FPGA board, Docker provided a seamless transition between
environments. The containerized environment guaranteed that the code behaved identically, regardless
of the execution location. This was especially vital for hardware integration, as FPGA platforms often
have distinct operating system requirements and configurations that necessitate careful management.
Machine learning models demand reproducible training, validation, and deployment processes to
ensure their efficacy. Docker facilitated reproducibility by preserving the exact environment used for
training and testing. Should we need to revisit a previous model version or debug an issue, we could
simply spin up the same Docker container and have the exact environment as before, including all
libraries and dependencies. This level of control over the environment enhanced our team's ability to
collaborate and experiment without fear of disrupting the existing setup.
Docker also played a key role in facilitating collaboration among team members. Since the development
environment was encapsulated within a container, any team member could easily replicate the entire
setup by simply pulling the docker image and running the container. This reduced the complexity of
onboarding new team members or sharing progress across different machines, as each developer could
work in an identical environment without having to manually install and configure dependencies.
Moreover, using docker in conjunction with version control systems like git made it easy to track changes
in both code and the environment setup. If we needed to modify dependencies or tools, these changes
could be integrated into the dockerfile (a script used to build docker containers), ensuring that every team
member had the latest environment version without manual intervention.
A significant aspect of our project was deploying the machine learning model onto fpga hardware,
specifically the pynq z2 board, which introduced additional complexity. Fpgas often require specialized
software tools, such as the tensil ai sdk, netron for model visualization, and pynq drivers for hardware
interaction. Managing these tools on different platforms can lead to version conflicts or installation
difficulties.
30
By using docker, we could encapsulate these external tools and their dependencies within the container,
ensuring seamless integration between the software components (cnn model, preprocessing pipeline) and
the hardware platform. This approach simplified the process of deploying the onnx model onto the fpga,
as the docker container included everything needed for the interaction between the machine learning
model and the fpga hardware.
Additionally, docker allowed us to work with fpga-specific tools like vivado (for synthesis and bitstream
generation) and other hardware compilers, while isolating them from the core machine learning
environment. This meant we could perform both software development and hardware testing without
worrying about potential conflicts between different toolchains or versions.
Beyond local development and fpga deployment, docker's portability also extended to cloud platforms.
With docker, we were able to package the machine learning model and its environment into a container,
which could then be deployed to any cloud provider with minimal changes. This flexibility meant that
we could scale our solution across various infrastructure setups, whether for training large models in the
cloud or deploying lightweight versions for real-time inference in edge devices.
In healthcare applications like ecg monitoring, real-time performance is critical. Docker containers, when
deployed on cloud or edge devices, enabled us to maintain the required low-latency performance for
arrhythmia detection and classification. This real-time capability was further enhanced by the high-speed
processing power of the fpga, which was seamlessly integrated into the docker container-based system.
After training the cnn model, it was converted into the onnx (open neural network exchange) format to
facilitate hardware deployment on the fpga. Netron, a popular visualization tool for neural networks, was
used to inspect the onnx model and ensure that it was correctly converted from its original format.
Netron provided a user-friendly graphical interface that allowed us to visualize the model architecture,
including the layers, connections, and parameters. This visualization step was crucial for debugging and
optimizing the model before deployment. For example, we used netron to verify that the layers of the
model were correctly arranged and that the dimensionality of the data was preserved as it passed through
the network. Netron also allowed us to inspect the model's weights and biases, which provided insights
into how the network was making its predictions.
31
This visualization process was particularly important when transitioning from the training environment
to the deployment environment, as even small discrepancies in the model architecture could lead to
significant performance issues on the fpga hardware.
The conversion of the CNN model to the ONNX format was a crucial step in facilitating its deployment
on the FPGA hardware. To ensure the accuracy and integrity of the conversion process, a powerful
visualization tool called Netron was employed.
Netron provided a comprehensive visual representation of the ONNX model, allowing for a detailed
inspection of its architecture. This included the visualization of layers, connections, and parameters,
enabling us to identify and rectify any potential issues or inconsistencies that may have arisen during
the conversion process. By examining the model's structure, we could verify that the layers were
correctly arranged and that the data dimensions were preserved throughout the network.
Furthermore, Netron allowed us to delve deeper into the model's inner workings by inspecting its
weights and biases. This provided valuable insights into how the network made its predictions and
helped us understand the underlying decision-making process.
The visualization process was particularly critical when transitioning from the training environment to
the deployment environment. Even minor discrepancies in the model architecture could have
significant implications for the model's performance on the FPGA hardware. By carefully inspecting
the model using Netron, we could identify and address any potential issues, ensuring a smooth and
successful deployment. NETRON, a versatile open-source tool, is specifically designed to visualize
neural network models. It supports a wide range of formats, including ONNX, which is a popular
format for exchanging deep learning models. In the realm of ECG signal processing, NETRON proves
invaluable in understanding the intricate architecture and inner workings of models designed for tasks
such as arrhythmia detection, heart rate variability analysis, and more.
By visualizing the model's architecture, NETRON provides a clear and intuitive representation of its
layers, connections, and data flow. This visual clarity aids in comprehending the overall structure and
identifying potential bottlenecks or inefficiencies. Additionally, it allows for inspecting layer details,
such as input/output shapes, weights, and biases, which is crucial for debugging, fine-tuning, and
gaining deeper insights into the model's decision-making process.
NETRON's capabilities extend beyond individual model inspection. It empowers users to compare
different model architectures by visualizing multiple models side-by-side. This comparative analysis
32
facilitates the identification of similarities, differences, and potential areas for improvement.
Furthermore, NETRON aids in model debugging by enabling the detection of errors and anomalies in
the model architecture, such as missing connections or incorrect layer configurations. By visually
inspecting the model, users can quickly identify and rectify these issues.
To leverage NETRON for ECG signal processing models, the first step involves training the model
using a framework like PyTorch or TensorFlow and exporting it to the ONNX format. Once exported,
the ONNX model can be opened in NETRON, where users can explore its visualization. The tool offers
various functionalities, including zooming, panning, and inspecting individual layers. By tracing the
data flow through the model, users can gain a comprehensive understanding of its operation.
By effectively utilizing NETRON, researchers and practitioners can gain valuable insights into the
architecture and behavior of ECG signal processing models. This deeper understanding can lead to
improved model performance, accelerated development cycles, and a more profound comprehension of
the underlying principles. To use NETRON for ECG signal processing models, you first need to export
your trained model to the ONNX format. Once exported, you can open the model in NETRON and
explore its visualization. The tool allows you to zoom in and out, inspect individual layers, and trace
the data flow through the model. By effectively utilizing NETRON, you can gain valuable insights into
your ECG signal processing models, leading to improved performance and a deeper understanding of
their inner workings.
Train your ECG signal processing model using a framework like PyTorch or
TensorFlow.
33
Download and install NETRON.
Drag and drop your ONNX model file onto the NETRON window, or use the "Open
Model" menu option.
Zoom and Pan: Use the mouse wheel to zoom in and out and drag to pan the
visualization.
Inspect Layers: Click on individual layers to view detailed information about their
parameters and operations.
Follow Data Flow: Trace the flow of data through the model by following the
connections between layers.
Identify Bottlenecks: Look for layers with high computational costs or large memory
footprints.
Simplify Complex Models: For large and complex models, consider visualizing simplified
versions or focusing on specific parts of the architecture.
Use Layer Highlighting: Highlight specific layers to better understand their role in the model.
Experiment with Different Layouts: Try different layout options to find the most suitable
visualization for your needs.
NETRON emerges as a powerful tool for visualizing the intricacies of neural network models,
particularly those employed in ECG signal processing. By offering a clear and intuitive representation
of model architecture, layer details, and data flow, NETRON empowers researchers and practitioners to
gain valuable insights into the model's behavior and decision-making process. This enhanced
understanding facilitates model optimization, debugging, and the identification of potential areas for
improvement. Ultimately, NETRON contributes to the advancement of ECG signal processing research
and the development of more accurate and robust models for diagnosing cardiac abnormalities. By
effectively utilizing NETRON, you can gain valuable insights into the architecture and behavior of
your ECG signal processing models. This can lead to improved model performance, faster development
34
cycles, and a deeper understanding of the underlying principle Even minor discrepancies in the model
architecture could have significant implications for the model's performance on the FPGA hardware.
By carefully inspecting the model using Netron, we could identify and address any potential issues,
ensuring a smooth and successful deployment. NETRON, a versatile open-source tool, is specifically
designed to visualize neural network models. It supports a wide range of formats, including ONNX,
which is a popular format for exchanging deep learning models. In the realm of ECG signal processing,
NETRON proves invaluable in understanding the intricate architecture and inner workings of models
designed for tasks such as arrhythmia detection, heart rate variability analysis, and more. NETRON
emerges as a powerful tool for visualizing the intricacies of neural network models, particularly those
employed in ECG signal processing. By offering a clear and intuitive representation of model
architecture, layer details, and data flow, NETRON empowers researchers and practitioners to gain
valuable insights into the model's behavior and decision-making process. This enhanced understanding
facilitates model optimization, debugging, and the identification of potential areas for improvement.
Ultimately, NETRON contributes to the advancement of ECG signal processing research and the
development of more accurate and robust models for diagnosing cardiac abnormalities. By effectively
utilizing NETRON, you can gain valuable insights into the architecture and behavior of your ECG
signal processing models. This can lead to improved model performance, faster development cycles,
and a deeper understanding of the underlying principle Even minor discrepancies in the model
architecture could have significant implications for the model's performance on the FPGA hardware.
In conclusion NETRON emerges as a powerful tool for visualizing the intricacies of neural network
models, particularly those employed in ECG signal processing. By offering a clear and intuitive
representation of model architecture, layer details, and data flow, NETRON empowers researchers and
practitioners to gain valuable insights into the model's behavior and decision-making process.
35
36
Figure 4.2 ONNX Model using Netron
37
CHAPTER 5
HARDWARE IMPLEMENTATION
The transition from a machine learning model developed in a software environment to its implementation
in hardware is a critical phase for enabling real-time performance, especially in healthcare applications
where timely data processing can directly impact patient outcomes. In this project, we leveraged fpga
technology for hardware deployment to ensure low-latency, high-speed arrhythmia detection from ecg
signals. This section outlines the detailed steps involved in converting the trained model into a format
suitable for hardware execution and the process of deploying it on the pynq z2 fpga board.
In the context of this project, converting the CNN model to ONNX was a pivotal step towards
optimizing it for real-time ECG signal processing on the FPGA. This conversion necessitated careful
consideration of several factors, including the mapping of floating-point operations to FPGA-
compatible operations and the application of quantization techniques to reduce precision without
compromising accuracy.
The use of tools like Netron played a vital role in the conversion process. By visualizing the model's
architecture and parameters, Netron helped ensure the integrity of the ONNX model and identify
potential bottlenecks for optimization. This meticulous approach was essential to guarantee that the
converted model accurately represented the original CNN and maintained its performance
characteristics.
After training the deep learning model using traditional machine learning frameworks such as tensorflow
or pytorch, one of the key challenges lies in optimizing the model for deployment on hardware. Hardware
deployment often requires compatibility with platforms that differ significantly from the original
development environment, necessitating the use of standard model interchange formats. This is where
the open neural network exchange (onnx) format becomes highly useful.
38
Onnx is a widely supported format that allows machine learning models to be transferred between
different frameworks and deployed across a wide range of hardware platforms. The flexibility of onnx
makes it particularly well-suited for hardware acceleration tasks, especially in environments like fpgas.
In this project, converting the cnn model to onnx was a necessary step for optimizing it for real-time ecg
signal processing on the fpga.
During the conversion process, several considerations had to be addressed. Firstly, the floating-point
operations used in the original deep learning framework were mapped to operations that are compatible
with the fpga. Fpgas typically operate more efficiently with fixed-point arithmetic, so quantization
techniques were applied to reduce the bit-width of model parameters without sacrificing much accuracy.
This reduction in precision is crucial for optimizing memory usage and computational speed on the fpga,
while still maintaining high accuracy in arrhythmia detection.
The conversion to onnx was facilitated by tools such as netron, a model visualization tool that allowed
us to inspect the architecture and ensure its integrity post-conversion. Netron provided a graphical
representation of the model, displaying the sequence of layers, their parameters, and the interconnections
between them. This step was essential to verify that the onnx model faithfully represented the original
cnn and that no critical information was lost during the conversion. It also helped identify potential
bottlenecks in computation, which were then addressed by optimizing specific layers for fpga execution.
The choice of the pynq z2 board as the hardware platform for this project was driven by its versatility
and capability in handling real-time machine learning tasks, particularly in healthcare applications where
timely and accurate results are crucial. The pynq z2 board is based on the xilinx zynq-7000 soc, which
combines an fpga fabric with a dual-core arm cortex-a9 processor. This hybrid architecture provides a
powerful balance between programmable hardware and general-purpose processing, making it well-
suited for applications that require both computational acceleration and system-level control.
39
Figure 5.1 PYNQ-Z2 Board
The PYNQ-Z2 board's compact design and low power consumption make it ideal for wearable medical
devices. These devices could continuously monitor a patient's ECG, providing real-time feedback
directly on the device or transmitting data wirelessly to healthcare providers. This enables remote
monitoring of heart health, allowing for early detection of potential issues and timely intervention.
In telemedicine applications, the PYNQ-Z2 board can be integrated into portable ECG monitoring kits
used at home. The FPGA's real-time arrhythmia detection capabilities enable healthcare providers to
remotely monitor patients' heart health and intervene as needed, reducing the need for in-person visits.
40
The PYNQ-Z2 board can also be connected to cloud-based healthcare platforms, enabling continuous
data collection and analysis. The ARM processor handles communication with the cloud, while the
FPGA processes ECG data locally in real-time. This hybrid approach combines the advantages of low-
latency local processing with the scalability and accessibility of cloud-based data storage and analysis.
By leveraging the power of FPGA acceleration, the PYNQ-Z2 board can significantly improve the
accuracy and efficiency of cardiac arrhythmia detection. This innovative technology has the potential to
revolutionize healthcare by enabling early diagnosis, timely intervention, and improved patient
outcomes.
In conclusion, the PYNQ-Z2 board offers a versatile and powerful platform for developing advanced
healthcare solutions. Its ability to perform complex tasks in real-time, combined with its low power
consumption and compact form factor, makes it a promising tool for a wide range of applications, from
wearable devices to cloud-based monitoring systems.
The pynq z2 board offers several key features that make it ideal for implementing machine learning
models, such as our deep learning model for arrhythmia detection:
Fpga fabric: the programmable logic (fpga fabric) on the pynq z2 allows for custom hardware
acceleration of computationally intensive tasks, such as the convolutional and pooling operations
within our cnn model. By implementing these operations in hardware, the fpga can perform them
much faster than a traditional cpu, resulting in reduced inference time and faster arrhythmia
detection.
Arm cortex-a9 processor: in addition to the fpga fabric, the pynq z2 board includes a dual-core
arm cortex-a9 processor, which handles tasks that do not require hardware acceleration, such as
system management, interfacing with external devices, and handling input/output operations.
This hybrid design allows the board to manage both low-level hardware tasks and high-level
software processes in parallel, ensuring efficient overall performance.
Pynq framework: the board supports the pynq (python productivity for zynq) framework, which
enables users to program the fpga using python. This high-level programming environment makes
fpga development more accessible, reducing the complexity of traditional hardware description
languages (hdls) such as vhdl or verilog. The pynq framework also allows for easy integration of
41
machine learning models and simplifies the process of deploying deep learning algorithms on the
FPGA.
The primary goal of deploying the cnn model on the pynq z2 board was to enable real-time arrhythmia
detection from ecg signals. The ecg signals were preprocessed and segmented into fixed-length portions
before being fed into the cnn model for classification. The fpga fabric on the pynq z2 board was
configured to accelerate the convolutional and pooling layers of the cnn, significantly reducing the time
required for each inference.
Parallelism and speed: one of the key advantages of using an fpga is its ability to perform tasks
in parallel. In traditional cpu-based systems, operations are carried out sequentially, which can
lead to delays in processing, particularly for complex tasks such as cnn inference. In contrast, the
fpga fabric on the pynq z2 board allows for the simultaneous execution of multiple operations,
such as performing convolutions across multiple channels of the ecg signal. This parallelism is
essential for reducing latency and enabling real-time processing of ecg data.
Energy efficiency: another benefit of fpga technology, and specifically the pynq z2 board, is its
energy efficiency. Unlike traditional cpus or gpus, which consume a significant amount of power
during computation, fpgas are designed to execute specific tasks with minimal energy
consumption. This feature is particularly important in wearable or portable medical devices,
where battery life is a major concern. By offloading the most computationally intensive tasks to
the fpga, the overall energy consumption of the system is reduced, making it more suitable for
long-term, continuous heart monitoring.
42
Figure 5.2(a)Real time implementation using PYNQ-Z2
43
Figure 5.2(b) Real time implementation using PYNQ-Z2
One of the main motivations for deploying the arrhythmia detection system on the pynq z2 board was its
suitability for remote healthcare monitoring. The combination of high-speed, low-latency processing and
energy efficiency makes the pynq z2 board ideal for integration into wearable devices or portable medical
equipment. In a remote healthcare setting, continuous ecg monitoring is essential for early detection of
cardiac arrhythmias, which can lead to timely medical interventions and potentially save lives.
The system developed in this project could be deployed in a variety of remote healthcare applications:
Wearable devices: the compact size and low power consumption of the pynq z2 board make it a
suitable candidate for wearable medical devices. These devices could continuously monitor a
patient’s ecg and provide real-time feedback, either locally on the device or via wireless
communication to a healthcare provider.
44
Telemedicine: in telemedicine applications, the pynq z2 board could be integrated into portable
ecg monitoring kits that patients use at home. The real-time arrhythmia detection capabilities of
the fpga would allow healthcare providers to remotely monitor their patients’ heart health and
intervene if necessary, without the patient needing to visit a hospital or clinic.
Cloud-based monitoring: the pynq z2 board can also be connected to cloud-based healthcare
platforms, allowing for continuous data collection and analysis. In this setup, the arm processor
would handle communication with the cloud, while the fpga processes the ecg data in real-time.
This hybrid approach combines the benefits of local, low-latency processing with the scalability
and accessibility of cloud-based data storage and analysis.
45
CHAPTER 6
RESULTS
The evaluation of the proposed model on ECG data from the MIT-BIH Arrhythmia Database involved
several critical steps to ensure its effectiveness and suitability for real-world deployment. Initially, the
ECG signals were carefully prepared and segmented into fixed-length segments of 256 samples. These
segments were then reshaped into a three-channel format to match the input requirements of the LeNet-
5 based 2D CNN architecture. This architecture, tailored for processing ECG signals, included
convolutional layers for feature extraction, max-pooling layers for dimensionality reduction, dropout
layers for preventing overfitting, and dense layers for classification.
During the training phase, the model was optimized using the Adam optimizer and trained using a
categorical cross-entropy loss function. A batch size of 64 and a single epoch were used for testing and
validation to ensure a balanced approach. Performance assessment primarily relied on accuracy metrics,
with the dataset partitioned into training and testing sets to enable an impartial evaluation and validate
the model's generalization capabilities.
After successful training and validation, the model underwent hardware implementation for real-time
deployment. This involved converting the trained model into the ONNX format and integrating it onto
the PYNQ-Z2 board, enabling high-speed, low-latency processing suitable for continuous monitoring
applications. Verification using ONNX Runtime ensured compatibility and optimal performance on the
FPGA hardware. Additionally, visualizing the ONNX model's graph was crucial for understanding its
complex structure and operations, aiding in both debugging and enhancing the overall comprehension of
the model's functionality.
The proposed method offers several advantages. Firstly, it demonstrates high accuracy in classifying
various arrhythmias, making it a reliable tool for detection. Secondly, the use of the Adam optimizer and
dropout layers contributes to efficient training, helping to prevent overfitting and improve model
generalization. Lastly, by implementing the model on the PYNQ-Z2 board using the ONNX format, it
enables real-time processing, which is essential for continuous monitoring and timely interventions.
In conclusion, this paper introduces a novel methodology for ecg signal classification using a 2d cnn
architecture, which underwent thorough validation and demonstrated outstanding performance. The
46
model achieved an impressive accuracy of 99 percentage, surpassing other algorithms examined in the
study.
Furthermore, the paper delineates the deployment of the proposed 2d cnn model as a specialized
accelerator for ecg signal classification within wearable healthcare devices. The accelerator's design,
characterized by a pipelined structure and optimized data processing techniques such as tristate buffers
and shift operations, yielded remarkable resource efficiency. Notably, it attained an energy efficiency of
161 gop/s/w and 28 gop/s/klut, marking a substantial 1.67× improvement over previous iterations.
Additionally, the accelerator showcased notable computational capabilities, including peak floating-
point processing of 1.145 tflop/s and off-chip memory capacity of 28.4 gb/s. Practical implementation
on the xilinx zynq xc7z045 platform demonstrated significant performance enhancements, outpacing
fpga peer applications by 1.14× in speed.
Looking forward, future research will explore emerging technologies to further refine classification
accuracy, speed, and energy efficiency. Moreover, efforts will be directed towards expanding the cnn
accelerator's application scope to encompass a broader range of biological signals and processing
methodologies. These advancements promise to revolutionize real-time ecg signal analysis and enhance
the capabilities of wearable healthcare devices in monitoring and diagnosing cardiac conditions.
47
Figure 6.1 Confusion Matrix
48
Figure 6.3 Accuracy and Loss Graph
49
CHAPTER 7
FUTURE CHALLENGES
In the real of challenges and future prospects, the model faces several key areas for improvement. Firstly,
the limitation of training epochs presents an opportunity for future iterations to explore training over
more epochs, potentially enhancing the model's accuracy and robustness. Secondly, while the initial
hardware implementation was successful, there is room for further optimization to improve resource
utilization and power efficiency on the fpga. Lastly, the model's generalizability to other datasets beyond
the mit-bih arrhythmia database is a promising avenue for future research. Extending testing and
validation to include other ecg datasets will not only validate the model's applicability but also provide
insights into its performance across a broader range of data sources. Addressing these challenges and
focusing on these future directions will contribute to the continued advancement and effectiveness of the
proposed model in real-world applications.
50
CHAPTER 8
REFERENCE
[1] H. V. Denysyuk, r. J. Pinto, p. M. Silva, et al., “algorithms for automated diagnosis of cardiovascula
Diseases based on ecg data: a comprehensive systematic Review,” heliyon, vol. 9, no. 2, 2023
[2] M. Chourasia, A. Thakur, S. Gupta, and A. Singh, “Ecg heartbeat classification using cnn,” in 2020
IEEE 7th Uttar Pradesh Section International Conference on Electrical, Electronics and Computer
Engineering (UPCON), IEEE, 2020, pp. 1–6
[3] S. Dhakshaya and D. J. Auxillia, “Classification of ecg using convolutional neural network (cnn),”
in 2019 International Conference on Recent Advances in Energy efficient Computing and
Communication (ICRAECC), IEEE, 2019, pp. 1–6
[4] G. B. Moody and R. G. Mark, “The impact of the mit-bih arrhythmia database,” IEEE engineering in
medicine and biology magazine, vol. 20, no. 3, pp. 45–50, 2001
[5] V. C. Johnson, J. Bali, S. Tanvashi, and C. Kolanur, “Fpga-based hardware acceleration using pynq-
z2,” in 2023 Second International Conference on Electrical, Electronics, Information and
Communication Technologies (ICEEICT), IEEE, 2023, pp. 1–4.
[6] S. H. Jambukia, V. K. Dabhi, and H. B. Prajapati, “Classification of ecg signals using machine
learning techniques: A survey,” in 2015 International Conference on Advances in Computer Engineering
and Applications, 2015, pp. 714–721. DOI: 10.1109/ICACEA.2015.7164783
51
CONCLUSION
The advent of deep learning has ushered in a new era of precision and efficiency in medical
diagnostics, particularly in the realm of cardiac arrhythmia detection. By leveraging the power of
Convolutional Neural Networks (CNNs), researchers have developed a robust model capable of
accurately classifying ECG signals. This technological breakthrough has the potential to revolutionize
healthcare by enabling early detection, timely intervention, and improved patient outcomes.
The integration of FPGA acceleration further enhances the capabilities of this deep learning model,
allowing for real-time processing of ECG data. This is particularly significant for remote healthcare
applications, where timely diagnosis is crucial. By rapidly analyzing ECG signals, healthcare providers
can identify potential cardiac abnormalities and initiate appropriate treatment promptly.
However, while the potential of this technology is immense, there are still challenges to overcome. One
key challenge is the widespread adoption and integration of this technology into clinical practice.
Healthcare providers need to be educated about the benefits of AI-powered diagnostics and trained to
effectively use these tools. Additionally, regulatory hurdles and data privacy concerns may hinder the
deployment of AI-based solutions in healthcare settings.
To fully realize the potential of AI-powered cardiac arrhythmia detection, continued research and
development are essential. Future research may focus on improving the accuracy and robustness of
deep learning models, exploring new data sources, and developing innovative hardware solutions. By
addressing these challenges and fostering collaboration between researchers, clinicians, and industry
experts, we can accelerate the adoption of AI-powered healthcare solutions and ultimately improve
patient care.
In conclusion, the convergence of deep learning and FPGA technology has opened up exciting new
possibilities for cardiac arrhythmia detection. By empowering healthcare providers with advanced
tools, we can move towards a future where heart disease is diagnosed early, treated effectively, and
prevented.
52