0% found this document useful (0 votes)
8 views

Final Report

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Final Report

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

KATHMANDU UNIVERSITY

SCHOOL OF ENGINEERING
DEPARTMENT OF ELECTRICAL & ELECTRONICS ENGINEERING

MINI PROJECT REPORT

EXTRACTION OF ECG SIGNAL AND PATTERN RECOGNITION


ALGORITHM FOR ARRHYTHMIA DETECTION
ETEG 321: Principles of Biomedical Engineering

Submitted by:
Niranjan Luitel (31016)
Kabir Rajbanshi (31023)

Submitted to:
Mr. Sachin Shrestha
Associate Professor

June 2024
ABSTRACT
Extraction of ECG Signal and Pattern Recognition Algorithm for Arrhythmia Detection focuses
on developing a methodology for ECG signal processing and arrhythmia detection. The system
works by preprocessing ECG signals, extracting features such as mean R-R interval and standard
deviation, and classifying segments as normal or indicative of arrhythmia. The system aims to
accurately identify cardiac abnormalities from ECG signals. This is done to enhance cardiac health
monitoring by providing early detection of arrhythmias, which is crucial for timely medical
intervention and patient care.

Keywords: ECG signal processing, arrhythmia detection, mean R-R interval, standard deviation,
adaptive thresholding

i
LIST OF TABLES AND FIGURES

List of Tables
Table 1: Segment Classification ................................................................................................................. 11

List of Figures
Figure 1: Electrocardiogram (ECG) Wave Features .................................................................................... 1
Figure 2: Block Diagram ............................................................................................................................. 5
Figure 3: MATLAB Outputs.......................................................................................................................11
Figure 4: Analysis of Segment 1................................................................................................................ 12
Figure 5:Analysis of Segment 2 ................................................................................................................ 13
Figure 6: Analysis of Segment 3................................................................................................................ 14

ii
TABLE OF CONTENTS
ABSTRACT ................................................................................................................................................. i
LIST OF TABLES AND FIGURES ............................................................................................................ ii
1. INTRODUCTION ............................................................................................................................... 1
1.1. Background .................................................................................................................................. 1
1.2. Objectives .................................................................................................................................... 1
1.3. Arrhythmia................................................................................................................................... 1
2. LITERATURE REVIEW..................................................................................................................... 3
3. METHODOLOGY .............................................................................................................................. 5
3.1. Implementing Strategy................................................................................................................. 5
3.2. Data Preprocessing and Filtering ................................................................................................. 6
3.3. Peak Detection and Feature Extraction........................................................................................ 6
3.4. Classification and Result Visualization ....................................................................................... 7
3.5. MATLAB Code ........................................................................................................................... 7
4. RESULTS ........................................................................................................................................... 11
4.1. Segment Classification ............................................................................................................... 11
4.2. Segment Classification Results...................................................................................................11
4.3. Visualization ............................................................................................................................... 11
4.4. Clinical Relevance ..................................................................................................................... 15
5. CONCLUSION AND FUTURE WORKS ........................................................................................ 16
5.1. Future Works.............................................................................................................................. 16
REFERENCES .......................................................................................................................................... 17

iii
1. INTRODUCTION
1.1.Background
An electrocardiogram is a graph depicting the electrical activity generated by the depolarization
and repolarization of atria and ventricles. An ECG wave is a periodic wave with one cycle
consisting of a P wave, the QRS complex and a T wave.

Figure 1: Electrocardiogram (ECG) Wave Features

ECG signal analysis is vital for making the data useful in the diagnosis of heart diseases. Thus,
the development of efficient ECG feature extraction algorithms is of great value and importance.
Most of the clinically useful information in an ECG signal is present in the intervals and
amplitudes defined by its features. An ECG feature extraction algorithm is also helpful in the
detection of cardiac problems known as arrhythmias including tachycardia, bradycardia, heart rate
variation etc. Beat detection is used to determine the heart rate and identify arrhythmias while
further processing is performed to detect abnormal beats.

1.2.Objectives
 Extract ECG signals from the provided dataset.
 Preprocess the signals by filtering to enhance relevant information.
 Detect R-peaks in the ECG signals.
 Calculate features such as mean R-R interval and standard deviation.
 Implement a pattern recognition algorithm to classify segments as normal or indicating
arrhythmia.
 Visualize the raw and filtered ECG signals, along with the detected R-peaks and adaptive
threshold.

1.3.Arrhythmia
Arrhythmia refers to an abnormal heart rhythm or irregular heartbeat. In a healthy heart, the
heartbeats follow a regular pattern, controlled by the heart's electrical system. However, in
arrhythmia, the heart may beat too fast (tachycardia), too slow (bradycardia), or irregularly. [1]

1
There are several types of arrhythmias, including:
 Bradycardia: A slow heartbeat, typically less than 60 beats per minute.
 Tachycardia: A fast heartbeat, typically more than 100 beats per minute.
 Atrial Fibrillation (AFib): The heart's upper chambers (atria) beat irregularly and rapidly,
causing an irregular heartbeat.
 Atrial Flutter: Similar to AFib but with a more organized rhythm.
 Ventricular Fibrillation: The heart's lower chambers (ventricles) quiver instead of pumping
blood effectively, leading to a rapid and erratic heartbeat. It's life-threatening and requires
immediate medical attention.

Arrhythmias can occur due to various factors, including heart disease, electrolyte imbalances, high
blood pressure, thyroid disorders, stress, and substance abuse. Some arrhythmias may not cause
any noticeable symptoms and are only detected during medical tests. However, others can cause
symptoms such as palpitations, dizziness, chest pain, shortness of breath, and fainting.

Arrhythmias can be diagnosed through electrocardiography (ECG or EKG), Holter monitoring,


event monitoring, echocardiogram, and other cardiac tests. Treatment depends on the type and
severity of the arrhythmia and may include medication, lifestyle changes, implanted devices like
pacemakers or defibrillators, or procedures like catheter ablation.

Early detection and management of arrhythmias are crucial to prevent complications such as
stroke, heart failure, or sudden cardiac arrest. Therefore, developing accurate arrhythmia detection
algorithms, as in the project discussed, plays a vital role in improving patient outcomes and
reducing the risks associated with heart rhythm disorders. [2]

2
2. LITERATURE REVIEW
Research in the field of ECG signal processing and arrhythmia detection has advanced
significantly over the years, driven by the need for accurate and efficient methods for diagnosing
heart conditions. Here, we review relevant literature focusing on signal processing techniques, R-
peak detection, feature extraction methods, classification algorithms, threshold-based
classification, and the clinical implications of arrhythmia detection algorithms.
a. Signal Processing Techniques: Signal processing techniques are crucial for enhancing the
quality of ECG signals by reducing noise and artifacts while preserving important signal
components. Butterworth filters have been widely used in ECG signal processing due to
their ability to provide a flat frequency response and good roll-off characteristics [3]. These
filters effectively remove noise and baseline wander, improving the signal quality for
further analysis.
b. R-Peak Detection: Accurate detection of R-peaks is fundamental for analyzing ECG
signals and identifying abnormal heart rhythms. Various methods have been proposed for
R-peak detection, including threshold-based methods, wavelet transform-based
approaches, and template matching algorithms [4]. These methods aim to accurately locate
the peaks corresponding to the QRS complexes, which are essential for determining heart
rate and rhythm.
c. Feature Extraction: Feature extraction is critical for capturing relevant information from
ECG signals to differentiate between normal and abnormal heart rhythms. Commonly used
features include R-R interval duration, heart rate variability, and morphology
characteristics of the ECG waveform [5]. The mean and standard deviation of R-R
intervals are particularly important features for characterizing heart rate variability and
detecting arrhythmias.
d. Classification Algorithms: Various machine learning and pattern recognition algorithms
have been applied for arrhythmia detection. Support vector machines (SVM), artificial
neural networks (ANN), decision trees, and k-nearest neighbors (KNN) are among the
commonly used classifiers [6]. Ensemble methods, which combine multiple classifiers,
have been shown to improve classification accuracy by leveraging the strengths of
individual classifiers.
e. Threshold-Based Classification: Threshold-based classification methods are widely used
for distinguishing normal and abnormal ECG segments. These methods define thresholds
for mean R-R interval and standard deviation of R-R intervals based on normal
physiological ranges [7]. Segments falling outside these thresholds are classified as
indicating arrhythmia, enabling the detection of abnormal heart rhythms.
3
f. Clinical Application: The development of accurate arrhythmia detection algorithms has
significant clinical implications, offering timely diagnosis and intervention for patients
with heart conditions. These algorithms can assist healthcare professionals in making
informed decisions, leading to improved patient outcomes and better management of
cardiac disorders.
In conclusion, the reviewed literature highlights the importance of signal processing techniques,
feature extraction methods, and classification algorithms in the development of arrhythmia
detection systems. Ongoing research aims to improve the accuracy, robustness, and real-time
applicability of these algorithms for clinical use.

4
3. METHODOLOGY
3.1.Implementing Strategy

Feature
Signal Data Preprocessing Extraction
(Raw ECG (Filtering, Peak (R-R Interval,
Signal) Detection) Mean, Standard
Deviation)

Result &
Classification
Visualization
(Threshold-
(Print, Plot
Based)
Segments)

Figure 2: Block Diagram

The implementation strategy for extracting ECG signals and applying a pattern recognition
algorithm for arrhythmia detection involves several key steps to ensure accurate signal processing
and classification. Initially, the raw ECG signal data is subjected to preprocessing steps to enhance
its quality and suitability for analysis. This includes making the entire ECG signal positive to
maintain consistency, followed by filtering techniques such as a Butterworth filter to remove noise
and baseline wander. Additionally, peak detection algorithms are applied to identify R-peaks,
which represent the QRS complexes and individual heartbeats.
After preprocessing, feature extraction is performed on the preprocessed ECG signal to quantify
relevant characteristics for arrhythmia detection. Key features include calculating the R-R
intervals between consecutive R-peaks, along with determining the mean and standard deviation
of these intervals. These features provide insights into heart rate variability and serve as inputs for
the classification algorithm.
In the classification stage, a threshold-based approach is utilized to categorize segments of the
ECG signal as either "Normal" or indicative of "Arrhythmia." The mean RR interval and standard
deviation of RR intervals are compared against predefined thresholds corresponding to normal
and abnormal ranges. Segments falling within the normal range are classified as "Normal," while
those outside this range are labeled as "Arrhythmia."
Finally, the classification results are visualized to aid interpretation and diagnosis. Results,
including the classification outcome (Normal/Arrhythmia) along with the mean and standard
deviation values, are displayed. Moreover, segments of the ECG signal are plotted to visualize the

5
raw data, filtered signal, detected R-peaks, and adaptive threshold, providing clinicians with
insights into the underlying cardiac rhythm.
This comprehensive implementation strategy facilitates the extraction of meaningful information
from ECG signals, aiding in the detection of arrhythmias and supporting clinical decision-making.
The combination of signal processing techniques and pattern recognition algorithms enables
accurate diagnosis and management of cardiac arrhythmias, ultimately improving patient care and
outcomes.

3.2.Data Preprocessing and Filtering


Raw ECG data is loaded, assumed to be in the variable 'ecgsig'. The entire ECG signal is made
positive using abs_sig=∣ecgsig∣ to ensure consistency in subsequent analysis.
 Low-pass Filter Transfer Function:
1
𝐻 =
𝑠
1+
𝑤𝑐
 High-pass Filter Transfer Function:
1
𝐻 =
𝑤𝑐
1+
𝑠
where s represents the Laplace variable, 𝑤𝑐 and 𝑤𝑐 are the low-pass and high-pass cutoff
frequencies, and 𝑛 is the filter order.

3.3.Peak Detection and Feature Extraction


An adaptive threshold is calculated as a percentage of the filtered signal amplitude:
𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑_𝑎𝑑𝑝 = 𝑓𝑖𝑙𝑡𝑒𝑟𝑒𝑑_𝑠𝑖𝑔 × 𝑘
where k is a constant.

R-R intervals are calculated as the time intervals between consecutive R-peaks:
𝑅𝑅 = 𝑅 − 𝑅

Mean and standard deviation of R-R intervals are computed as follows:

1
mean_rr = 𝑅𝑅
𝑁

6
1
std_rr = (𝑅𝑅 − mean_rr)
𝑁−1

3.4.Classification and Result Visualization


Segments are classified based on predefined thresholds for mean and standard deviation:
Normal Range Thresholds:
Mean: 0.6 to 1.2 seconds
Standard Deviation: 0.025 to 0.05 seconds [8]
Classification results are displayed alongside mean and standard deviation values. ECG signal
segments are plotted to visualize raw data, filtered signal, detected R-peaks, and adaptive
threshold.

3.5.MATLAB Code
% Load ECG data
close all; clear all; clc;
load mit200;
fs = 360; % Sampling frequency

% Make the entire ECG signal positive


abs_sig = abs(ecgsig);

% Define segments
segment1 = abs_sig(1:3639); % segment 1
segment2 = abs_sig(3640:6197); % segment 2
segment3 = abs_sig(6198:10000); % segment 3

% Process and classify each segment


disp('Processing Segment 1:');
classification1 = process_segment(segment1, fs, 1);
disp(['Classification of Segment 1: ', classification1]);

disp('Processing Segment 2:');


classification2 = process_segment(segment2, fs, 2);
disp(['Classification of Segment 2: ', classification2]);

disp('Processing Segment 3:');


classification3 = process_segment(segment3, fs, 3);

7
disp(['Classification of Segment 3: ', classification3]);

% Function to process and classify each segment


function classification = process_segment(segment, fs, segment_num)
% Adaptive Filtering
fc_lp = 12; % Low-pass filter cutoff frequency
fc_hp = 0.5; % High-pass filter cutoff frequency
n = 4; % Filter order

% Low-pass filter
[b_lp, a_lp] = butter(n, fc_lp/(fs/2), 'low');
% High-pass filter
[b_hp, a_hp] = butter(n, fc_hp/(fs/2), 'high');
% Apply high-pass and low-pass filtering
filtered_sig = filtfilt(b_hp, a_hp, filtfilt(b_lp, a_lp,
segment));

% Adaptive threshold (acting as an adaptive filter)


threshold_adp = zeros(size(filtered_sig));
window_size = 100; % Window size for local calculation
for i = 1:length(filtered_sig)
if i <= window_size
local_mean = mean(filtered_sig(1:i));
local_std = std(filtered_sig(1:i));
else
local_mean = mean(filtered_sig(i-window_size+1:i));
local_std = std(filtered_sig(i-window_size+1:i));
end
threshold_adp(i) = local_mean + 2 * local_std; % Adjust the
threshold according to local characteristics
end

% Detectecting peaks
peak_indices_gt_threshold = find(filtered_sig > threshold_adp);
peak_indices_selected = [];
region_start = 1;
region_end = 0;

for i = 1:length(peak_indices_gt_threshold)
8
if peak_indices_gt_threshold(i) - region_end > 1 % Start of a
new region
[~, max_idx] = max(filtered_sig(region_start:region_end));
peak_indices_selected = [peak_indices_selected,
region_start - 1 + max_idx];
region_start = peak_indices_gt_threshold(i);
end
region_end = peak_indices_gt_threshold(i);
end
[~, max_idx] = max(filtered_sig(region_start:end));
peak_indices_selected = [peak_indices_selected, region_start - 1 +
max_idx];

% Calculate R-R intervals


RR_intervals = diff(peak_indices_selected) / fs;
mean_rr = mean(RR_intervals);
std_rr = std(RR_intervals);

% Classification based on R-R interval variability


mean_threshold_low = 0.6; % in seconds
mean_threshold_high = 1.2; % in seconds
std_threshold_low = 0.020; % in seconds
std_threshold_high = 0.06; % in seconds

if mean_rr >= mean_threshold_low && mean_rr <= mean_threshold_high


&& ...
std_rr >= std_threshold_low && std_rr <= std_threshold_high
classification = 'Normal';
else
classification = 'Arrhythmia';
end

% Display results
disp(['Segment ', num2str(segment_num), ' - Mean R-R Interval: ',
num2str(mean_rr), 's']);
disp(['Segment ', num2str(segment_num), ' - Standard Deviation of
R-R Intervals: ', num2str(std_rr), 's']);
disp(['Segment ', num2str(segment_num), ' - Classification: ',
classification]);
9
% Plot results for each segment
figure;
subplot(3,1,1);
plot(segment);
title(['Raw ECG Signal (Segment ', num2str(segment_num), ')']);
xlabel('Sample Number');
ylabel('Amplitude');
grid on;

subplot(3,1,2);
plot(filtered_sig);
title(['Filtered ECG Signal (Segment ', num2str(segment_num),
')']);
xlabel('Sample Number');
ylabel('Amplitude');
grid on;

subplot(3,1,3);
plot(filtered_sig);
hold on;
plot(peak_indices_selected, filtered_sig(peak_indices_selected),
'rs');
plot(threshold_adp);
title(['Filtered ECG Signal with Adaptive Threshold (Segment ',
num2str(segment_num), ')']);
xlabel('Sample Number');
ylabel('Amplitude');
grid on;
legend('Filtered ECG', 'R-peaks', 'Adaptive Threshold');
end

10
4. RESULTS
4.1.Segment Classification
Three segments of the ECG signal were classified based on the calculated mean R-R interval
and standard deviation. The classification results are as follows:

Table 1: Segment Classification

Segment Mean R-R Interval Standard Deviation Classification


1 0.54363s 0.22797s Arrhythmia
2 0.65s 0.051587s Normal
2 0.51944s 0.28234s Arrhythmia

4.2.Segment Classification Results


The classification results indicate that the proposed methodology effectively differentiated
between normal and arrhythmic segments of the ECG signal. Segments 1 and 3 containing noise
or irregularities, identified as Arrhythmia ECG signals due to deviations from normal ranges,
while Segment 2, which was a clean ECG Signal was classified as normal.

The chosen thresholds for mean and standard deviation proved effective in distinguishing normal
and arrhythmic segments. The narrow range of thresholds ensured sensitivity to variations in heart
rate variability, enabling accurate classification even in the presence of noise or artifacts. The
adaptive thresholding technique demonstrated robust peak detection, ensuring accurate
identification of R-peaks despite variations in signal quality. This adaptive approach enhances the
algorithm's performance in handling different types of ECG signals.

4.3.Visualization
The visualizations of ECG signal segments provided insights into the signal processing steps and
the classification outcomes. Raw data, filtered signals, detected R-peaks, and adaptive thresholds
were visualized, helping in the interpretation of results and algorithm performance assessment.

Figure 3: MATLAB Outputs

11
Figure 4: Analysis of Segment 1

12
Figure 5:Analysis of Segment 2

13
Figure 6: Analysis of Segment 3

14
4.4.Clinical Relevance
The implemented methodology adheres to clinical standards for ECG signal analysis. Accurate
arrhythmia detection is vital for timely diagnosis and treatment of cardiac abnormalities,
highlighting the clinical significance of the proposed approach in cardiac health monitoring.

Overall, the results demonstrate the effectiveness of the proposed methodology in accurately
classifying ECG signal segments and detecting arrhythmia, paving the way for further research
and clinical applications in cardiac health monitoring.

15
5. CONCLUSION AND FUTURE WORKS
The project successfully implements a pattern recognition algorithm for arrhythmia detection
using ECG signals. The algorithm shows promise in accurately classifying segments as normal or
indicating arrhythmia. Further refinement and validation on larger datasets can improve its
robustness and reliability.
5.1.Future Works
 Explore advanced signal processing techniques for noise reduction and feature extraction.
 Incorporate machine learning algorithms for automated arrhythmia classification.
 Test the algorithm on a larger dataset with diverse arrhythmia types to evaluate its
performance comprehensively.

16
REFERENCES

[1] D. J. J. (. Zipes, Cardiac Electrophysiology: From Cell to Bedside, Elsevier, 2018.

[2] P. K. P. Podrid, "Cardiac Arrhythmia: Mechanisms, Diagnosis, and Management." Lippincott


Williams & Wilkins," 2001.

[3] S. Smith, Digital Signal Processing: A Practical Guide for Engineers and Scientists, Newnes, 2002.

[4] C. Z. C. a. T. C. Li, "Detection of ECG characteristic points using wavelet transforms.," IEEE
Transactions on Biomedical Engineering, vol. 42, no. 1, 1995.

[5] P. M. R. a. G. Laguna, "A Database for Evaluation of Algorithms for Measurement of QT and Other
Waveform Intervals in the ECG," Computers in Cardiology,, 1997.

[6] T. a. K. S. Ince, "Signal processing and classification methods for arrhythmia detection." In "Deep
Learning for Medical Image Analysis," 2017.

[7] P. a. J. J. Gomes, "A robust QRS detection algorithm for real-time ECG analysis." In "Computing in
Cardiology," 2012.

[8] "Heart rate variability: standards of measurement, physiological interpretation and clinical use.,"
Task Force of the European Society of Cardiology and the North American Society of Pacing and
Electrophysiology., vol. 93, no. 5, pp. 1043-1065, 1996.

17

You might also like