SlideShare a Scribd company logo
1 of 8
Download to read offline
ECG Signal Peaks/Bottoms Finder Using Baseline
Approach
2013
By
Ahmed Fawzy Gad
Faculty of Computers and Information (FCI)
Menoufia University
Egypt
ahmed.fawzy@ci.menofia.edu.eg
MENOUFIA UNIVERSITY
FACULTY OF COMPUTERS AND
INFORMATION
INFORMATION TECHNOLOGY
DEPARTMENT
DIGITAL SIGNAL PROCESSING
‫المنوفية‬ ‫جامعة‬
‫والمعلومات‬ ‫الحاسبات‬ ‫كلية‬
‫قسم‬‫المعلومات‬ ‫تكنولوجيا‬
‫الرقمية‬ ‫اإلشارات‬ ‫معالجة‬
‫المنوفية‬ ‫جامعة‬
Introdution
If you have asked a mathematician how to find peaks or either bottoms of a re-
gion, he/she will simply say that it is the highest/lowest point on the region.
But how computer learns about this? This is what I am going to explain in this
file.
IDEA
As stated in the earlier approach, I can find the peaks or bottoms by finding
means of the columns, and depending on the result of the mean of each column
I have determined whether this is a separation point between parts of the signal
or not and so on.
This approach has not aided so much in extraction of all needed peak and bot-
tom points.
So, as we have agreed, I have tried to use the baseline to find such points and it
have given a better results.
Steps used are as follows:
1. Find baseline.
2. Find peaks.
3. Find bottoms.
Find Baseline
So first step is to find the baseline of the signal.
Baseline is defined to be the row that has the largest number of pixels that are
defined to be signal pixels.
It is also defend to be the row that has the lowest mean in the signal regarding
that signal pixels are defined in black and non-signal are white.
After checking all rows, I have successfully found baseline using the two meth-
ods and both gives the same result.
This is what shown in the following figure:
Find Peaks
I have followed a new simple approach to find peaks of the signal rather than
the one we have discussed in Monday 16/6/2014.
It can be described simply using an example:
If you are asked to find the peak of the following figure, how can you reach it?
You will simply say the peak is the highest pixel that is zero. WHY?
This is because no higher pixel is above the choose pixel.
So to say that a pixel is a peak, you will simply check if there is no pixels that
are neighbors to and higher than the current pixel and have a value of zero.
Find Bottoms
This is similar to finding peaks.
To say that a pixel is a bottom, you will simply check if there is no pixels that are
neighbors to and lower than the current pixel and have a value of zero.
This is shown in the next figure:
Applying the Approach
After determining the baseline, all peaks, and all bottoms, the result is as fol-
lows:
As you can note, there are a heavy number of peaks and bottoms that will not
aid in examining the signal.
To eliminate noise from the signal, I`ll not scan 7 lines above and below the
baseline and this is the only adjustment that can be done for the code.
Result is as follows:
MATLAB Code
%% Function to find base line of the signal.
function baseLineRow = baseLineFinder2(signal)
sig = imread(signal);
bSig = im2bw(sig);
imwrite(bSig,'npSignal.png');
bSig = imread('npSignal.png');
info = imfinfo('npSignal.png');
resultArray = zeros(1,info.Height);
for hit=1:info.Height
rowUnderProcessing = bSig(hit,:);
resultArray(hit)=sum(~rowUnderProcessing);
end
baseLineRowCounter =max(resultArray);
baseLineRowCounter = find(baseLineRowCounter==resultArray);
for hit=1:info.Height
rowUnderProcessing = bSig(hit,:);
resultArray(hit)=mean(rowUnderProcessing);
end
baseLineRowMean = min(resultArray);
baseLineRowMean = find(baseLineRowMean==resultArray);
%[0, info.Width],[baseLineRowMean, baseLineRowMean]
figure('Name','Detected Base Line');
imshow(bSig);
hold on;
plot([0, info.Width],[baseLineRowMean, baseLineRowMean],'Color','b','LineWidth',2);
%plot([0, info.Width],[baseLineRowCounter, baseLineRowCounter],'Color','r','LineWidth',2);
% disp(['Base line detected using counter is in row : ',num2str(baseLineRowCounter)]);
% disp(['Base line detected using mean is in row : ',num2str(baseLbaseLineRowMean)]);
baseLineRow = baseLineRowMean;
bSig(baseLineRow-7:baseLineRow+7,:)=1;
BoundingBox=uint16([1,baseLineRow-7,info.Width,14]);
rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','c');
%Now I`ll delete the pre-written images.
delete('npSignal.png');
peakFi(signal ,baseLineRow);
bottomFi(signal ,baseLineRow);
%% Function to find the peaks of the signal.
function peakFi(signal,baseLine)
peakY=0;
peakX=0;
detectedPeaks=[];%Creating an array that holds the vertices of the peaks detected.
portionBeingProcessed=imread(signal);
portionBeingProcessed=im2bw(portionBeingProcessed);
%Special case for first column.
for m=1:baseLine-7
if portionBeingProcessed(m,1)==0
if portionBeingProcessed(m-1,2)~=0
%pointFound=1;
peakY=m;
%Now, drawing a rectangle over the peak to highlight it.
BoundingBox=uint16([1,peakY-1,2,2]);
rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','r');
else
break;
end
end
end
k=2;
kk=2;
while k<=size(portionBeingProcessed,2)-1
while kk<=baseLine-7
if portionBeingProcessed(kk,k)==0
if portionBeingProcessed(kk-1,k+1)~=0 & portionBeingProcessed(kk-1,k-1)~=0
%pointFound=1;
peakY=kk;
peakX=k;
%Now, drawing a rectangle over the peak to highlight it.
BoundingBox=uint16([peakX-1,peakY-1,2,2]);
rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','r');
k=k+1;
kk=1;
else
k=k+1;
kk=1;
if k>=size(portionBeingProcessed,2)
break;
end
end
else
kk=kk+1;
if(kk==baseLine-7)
k=k+1;
if k>=size(portionBeingProcessed,2)
break;
end
kk=1;
end
end
end
end
end%End of peakFi function.
%% Function to find the bottoms of the signal.
function bottomFi(signal,baseLine)
peakY=0;
peakX=0;
detectedBottoms=[];%Creating an array that holds the vertices of the bottoms detected.
portionBeingProcessed=imread(signal);
portionBeingProcessed=im2bw(portionBeingProcessed);
%Special case for last column.
for m=baseLine-7:-1:1
if portionBeingProcessed(m,info.Width)==0
if portionBeingProcessed(m-1,info.Width-1)~=0
%pointFound=1;
peakY=m;
%Now, drawing a rectangle over the peak to highlight it.
BoundingBox=uint16([info.Width-1,peakY-1,1,1]);
rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','g');
else
break;
end
end
end
k=2;
kk=size(portionBeingProcessed,1)-1;
while k<=size(portionBeingProcessed,2)-1
while kk>=baseLine+7
if portionBeingProcessed(kk,k)==0
if portionBeingProcessed(kk+1,k-1)~=0 & portionBeingProcessed(kk+1,k+1)~=0
%pointFound=1;
peakY=kk;
peakX=k;
%Now, drawing a rectangle over the peak to highlight it.
BoundingBox=uint16([peakX-1,peakY-1,2,2]);
rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','g');
k=k+1;
kk=size(portionBeingProcessed,1)-1;
else
k=k+1;
kk=size(portionBeingProcessed,1)-1;
if k>=size(portionBeingProcessed,2)
break;
end
end
else
kk=kk-1;
if(kk==baseLine+7)
k=k+1;
if k>=size(portionBeingProcessed,2)
break;
end
kk=size(portionBeingProcessed,1)-1;
end
end
end
end
end%End of bottomFi function.
%%
export_fig signal221
end%End of baseLineFinder

More Related Content

More from Ahmed Gad

Avoid Overfitting with Regularization
Avoid Overfitting with RegularizationAvoid Overfitting with Regularization
Avoid Overfitting with RegularizationAhmed Gad
 
Genetic Algorithm (GA) Optimization - Step-by-Step Example
Genetic Algorithm (GA) Optimization - Step-by-Step ExampleGenetic Algorithm (GA) Optimization - Step-by-Step Example
Genetic Algorithm (GA) Optimization - Step-by-Step ExampleAhmed Gad
 
ICCES 2017 - Crowd Density Estimation Method using Regression Analysis
ICCES 2017 - Crowd Density Estimation Method using Regression AnalysisICCES 2017 - Crowd Density Estimation Method using Regression Analysis
ICCES 2017 - Crowd Density Estimation Method using Regression AnalysisAhmed Gad
 
Backpropagation: Understanding How to Update ANNs Weights Step-by-Step
Backpropagation: Understanding How to Update ANNs Weights Step-by-StepBackpropagation: Understanding How to Update ANNs Weights Step-by-Step
Backpropagation: Understanding How to Update ANNs Weights Step-by-StepAhmed Gad
 
Computer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientComputer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientAhmed Gad
 
Python for Computer Vision - Revision
Python for Computer Vision - RevisionPython for Computer Vision - Revision
Python for Computer Vision - RevisionAhmed Gad
 
Anime Studio Pro 10 Tutorial as Part of Multimedia Course
Anime Studio Pro 10 Tutorial as Part of Multimedia CourseAnime Studio Pro 10 Tutorial as Part of Multimedia Course
Anime Studio Pro 10 Tutorial as Part of Multimedia CourseAhmed Gad
 
Brief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNsBrief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNsAhmed Gad
 
Operations in Digital Image Processing + Convolution by Example
Operations in Digital Image Processing + Convolution by ExampleOperations in Digital Image Processing + Convolution by Example
Operations in Digital Image Processing + Convolution by ExampleAhmed Gad
 
MATLAB Code + Description : Real-Time Object Motion Detection and Tracking
MATLAB Code + Description : Real-Time Object Motion Detection and TrackingMATLAB Code + Description : Real-Time Object Motion Detection and Tracking
MATLAB Code + Description : Real-Time Object Motion Detection and TrackingAhmed Gad
 
MATLAB Code + Description : Very Simple Automatic English Optical Character R...
MATLAB Code + Description : Very Simple Automatic English Optical Character R...MATLAB Code + Description : Very Simple Automatic English Optical Character R...
MATLAB Code + Description : Very Simple Automatic English Optical Character R...Ahmed Gad
 
Graduation Project - Face Login : A Robust Face Identification System for Sec...
Graduation Project - Face Login : A Robust Face Identification System for Sec...Graduation Project - Face Login : A Robust Face Identification System for Sec...
Graduation Project - Face Login : A Robust Face Identification System for Sec...Ahmed Gad
 
Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...
Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...
Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...Ahmed Gad
 
Introduction to Digital Signal Processing (DSP) - Course Notes
Introduction to Digital Signal Processing (DSP) - Course NotesIntroduction to Digital Signal Processing (DSP) - Course Notes
Introduction to Digital Signal Processing (DSP) - Course NotesAhmed Gad
 
AI Heuristic Search - Beam Search - Simulated Annealing
AI Heuristic Search - Beam Search - Simulated AnnealingAI Heuristic Search - Beam Search - Simulated Annealing
AI Heuristic Search - Beam Search - Simulated AnnealingAhmed Gad
 
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...Ahmed Gad
 
Artificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-StepArtificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-StepAhmed Gad
 
Cisco Certified Network Associate (CCNA) - R&S - Semester 2 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 2 NotesCisco Certified Network Associate (CCNA) - R&S - Semester 2 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 2 NotesAhmed Gad
 
Cisco Certified Network Associate (CCNA) - R&S - Semester 1 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 1 NotesCisco Certified Network Associate (CCNA) - R&S - Semester 1 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 1 NotesAhmed Gad
 
Prolog Task - Family Tree
Prolog Task - Family TreeProlog Task - Family Tree
Prolog Task - Family TreeAhmed Gad
 

More from Ahmed Gad (20)

Avoid Overfitting with Regularization
Avoid Overfitting with RegularizationAvoid Overfitting with Regularization
Avoid Overfitting with Regularization
 
Genetic Algorithm (GA) Optimization - Step-by-Step Example
Genetic Algorithm (GA) Optimization - Step-by-Step ExampleGenetic Algorithm (GA) Optimization - Step-by-Step Example
Genetic Algorithm (GA) Optimization - Step-by-Step Example
 
ICCES 2017 - Crowd Density Estimation Method using Regression Analysis
ICCES 2017 - Crowd Density Estimation Method using Regression AnalysisICCES 2017 - Crowd Density Estimation Method using Regression Analysis
ICCES 2017 - Crowd Density Estimation Method using Regression Analysis
 
Backpropagation: Understanding How to Update ANNs Weights Step-by-Step
Backpropagation: Understanding How to Update ANNs Weights Step-by-StepBackpropagation: Understanding How to Update ANNs Weights Step-by-Step
Backpropagation: Understanding How to Update ANNs Weights Step-by-Step
 
Computer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientComputer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and Gradient
 
Python for Computer Vision - Revision
Python for Computer Vision - RevisionPython for Computer Vision - Revision
Python for Computer Vision - Revision
 
Anime Studio Pro 10 Tutorial as Part of Multimedia Course
Anime Studio Pro 10 Tutorial as Part of Multimedia CourseAnime Studio Pro 10 Tutorial as Part of Multimedia Course
Anime Studio Pro 10 Tutorial as Part of Multimedia Course
 
Brief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNsBrief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNs
 
Operations in Digital Image Processing + Convolution by Example
Operations in Digital Image Processing + Convolution by ExampleOperations in Digital Image Processing + Convolution by Example
Operations in Digital Image Processing + Convolution by Example
 
MATLAB Code + Description : Real-Time Object Motion Detection and Tracking
MATLAB Code + Description : Real-Time Object Motion Detection and TrackingMATLAB Code + Description : Real-Time Object Motion Detection and Tracking
MATLAB Code + Description : Real-Time Object Motion Detection and Tracking
 
MATLAB Code + Description : Very Simple Automatic English Optical Character R...
MATLAB Code + Description : Very Simple Automatic English Optical Character R...MATLAB Code + Description : Very Simple Automatic English Optical Character R...
MATLAB Code + Description : Very Simple Automatic English Optical Character R...
 
Graduation Project - Face Login : A Robust Face Identification System for Sec...
Graduation Project - Face Login : A Robust Face Identification System for Sec...Graduation Project - Face Login : A Robust Face Identification System for Sec...
Graduation Project - Face Login : A Robust Face Identification System for Sec...
 
Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...
Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...
Introduction to MATrices LABoratory (MATLAB) as Part of Digital Signal Proces...
 
Introduction to Digital Signal Processing (DSP) - Course Notes
Introduction to Digital Signal Processing (DSP) - Course NotesIntroduction to Digital Signal Processing (DSP) - Course Notes
Introduction to Digital Signal Processing (DSP) - Course Notes
 
AI Heuristic Search - Beam Search - Simulated Annealing
AI Heuristic Search - Beam Search - Simulated AnnealingAI Heuristic Search - Beam Search - Simulated Annealing
AI Heuristic Search - Beam Search - Simulated Annealing
 
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
 
Artificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-StepArtificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-Step
 
Cisco Certified Network Associate (CCNA) - R&S - Semester 2 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 2 NotesCisco Certified Network Associate (CCNA) - R&S - Semester 2 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 2 Notes
 
Cisco Certified Network Associate (CCNA) - R&S - Semester 1 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 1 NotesCisco Certified Network Associate (CCNA) - R&S - Semester 1 Notes
Cisco Certified Network Associate (CCNA) - R&S - Semester 1 Notes
 
Prolog Task - Family Tree
Prolog Task - Family TreeProlog Task - Family Tree
Prolog Task - Family Tree
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

MATLAB Code + Description : ECG Signal Peaks/Bottoms Finder Using Baseline Approach

  • 1. ECG Signal Peaks/Bottoms Finder Using Baseline Approach 2013 By Ahmed Fawzy Gad Faculty of Computers and Information (FCI) Menoufia University Egypt ahmed.fawzy@ci.menofia.edu.eg MENOUFIA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATION INFORMATION TECHNOLOGY DEPARTMENT DIGITAL SIGNAL PROCESSING ‫المنوفية‬ ‫جامعة‬ ‫والمعلومات‬ ‫الحاسبات‬ ‫كلية‬ ‫قسم‬‫المعلومات‬ ‫تكنولوجيا‬ ‫الرقمية‬ ‫اإلشارات‬ ‫معالجة‬ ‫المنوفية‬ ‫جامعة‬
  • 2. Introdution If you have asked a mathematician how to find peaks or either bottoms of a re- gion, he/she will simply say that it is the highest/lowest point on the region. But how computer learns about this? This is what I am going to explain in this file. IDEA As stated in the earlier approach, I can find the peaks or bottoms by finding means of the columns, and depending on the result of the mean of each column I have determined whether this is a separation point between parts of the signal or not and so on. This approach has not aided so much in extraction of all needed peak and bot- tom points. So, as we have agreed, I have tried to use the baseline to find such points and it have given a better results. Steps used are as follows: 1. Find baseline. 2. Find peaks. 3. Find bottoms. Find Baseline So first step is to find the baseline of the signal. Baseline is defined to be the row that has the largest number of pixels that are defined to be signal pixels. It is also defend to be the row that has the lowest mean in the signal regarding that signal pixels are defined in black and non-signal are white. After checking all rows, I have successfully found baseline using the two meth- ods and both gives the same result. This is what shown in the following figure:
  • 3. Find Peaks I have followed a new simple approach to find peaks of the signal rather than the one we have discussed in Monday 16/6/2014. It can be described simply using an example: If you are asked to find the peak of the following figure, how can you reach it? You will simply say the peak is the highest pixel that is zero. WHY? This is because no higher pixel is above the choose pixel. So to say that a pixel is a peak, you will simply check if there is no pixels that are neighbors to and higher than the current pixel and have a value of zero. Find Bottoms This is similar to finding peaks. To say that a pixel is a bottom, you will simply check if there is no pixels that are neighbors to and lower than the current pixel and have a value of zero. This is shown in the next figure:
  • 4. Applying the Approach After determining the baseline, all peaks, and all bottoms, the result is as fol- lows: As you can note, there are a heavy number of peaks and bottoms that will not aid in examining the signal. To eliminate noise from the signal, I`ll not scan 7 lines above and below the baseline and this is the only adjustment that can be done for the code. Result is as follows:
  • 5. MATLAB Code %% Function to find base line of the signal. function baseLineRow = baseLineFinder2(signal) sig = imread(signal); bSig = im2bw(sig); imwrite(bSig,'npSignal.png'); bSig = imread('npSignal.png'); info = imfinfo('npSignal.png'); resultArray = zeros(1,info.Height); for hit=1:info.Height rowUnderProcessing = bSig(hit,:); resultArray(hit)=sum(~rowUnderProcessing); end baseLineRowCounter =max(resultArray); baseLineRowCounter = find(baseLineRowCounter==resultArray); for hit=1:info.Height rowUnderProcessing = bSig(hit,:); resultArray(hit)=mean(rowUnderProcessing); end baseLineRowMean = min(resultArray); baseLineRowMean = find(baseLineRowMean==resultArray); %[0, info.Width],[baseLineRowMean, baseLineRowMean] figure('Name','Detected Base Line'); imshow(bSig); hold on; plot([0, info.Width],[baseLineRowMean, baseLineRowMean],'Color','b','LineWidth',2); %plot([0, info.Width],[baseLineRowCounter, baseLineRowCounter],'Color','r','LineWidth',2); % disp(['Base line detected using counter is in row : ',num2str(baseLineRowCounter)]); % disp(['Base line detected using mean is in row : ',num2str(baseLbaseLineRowMean)]); baseLineRow = baseLineRowMean; bSig(baseLineRow-7:baseLineRow+7,:)=1; BoundingBox=uint16([1,baseLineRow-7,info.Width,14]); rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','c'); %Now I`ll delete the pre-written images. delete('npSignal.png'); peakFi(signal ,baseLineRow); bottomFi(signal ,baseLineRow); %% Function to find the peaks of the signal. function peakFi(signal,baseLine)
  • 6. peakY=0; peakX=0; detectedPeaks=[];%Creating an array that holds the vertices of the peaks detected. portionBeingProcessed=imread(signal); portionBeingProcessed=im2bw(portionBeingProcessed); %Special case for first column. for m=1:baseLine-7 if portionBeingProcessed(m,1)==0 if portionBeingProcessed(m-1,2)~=0 %pointFound=1; peakY=m; %Now, drawing a rectangle over the peak to highlight it. BoundingBox=uint16([1,peakY-1,2,2]); rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','r'); else break; end end end k=2; kk=2; while k<=size(portionBeingProcessed,2)-1 while kk<=baseLine-7 if portionBeingProcessed(kk,k)==0 if portionBeingProcessed(kk-1,k+1)~=0 & portionBeingProcessed(kk-1,k-1)~=0 %pointFound=1; peakY=kk; peakX=k; %Now, drawing a rectangle over the peak to highlight it. BoundingBox=uint16([peakX-1,peakY-1,2,2]); rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','r'); k=k+1; kk=1; else k=k+1; kk=1; if k>=size(portionBeingProcessed,2) break; end end else kk=kk+1; if(kk==baseLine-7) k=k+1; if k>=size(portionBeingProcessed,2)
  • 7. break; end kk=1; end end end end end%End of peakFi function. %% Function to find the bottoms of the signal. function bottomFi(signal,baseLine) peakY=0; peakX=0; detectedBottoms=[];%Creating an array that holds the vertices of the bottoms detected. portionBeingProcessed=imread(signal); portionBeingProcessed=im2bw(portionBeingProcessed); %Special case for last column. for m=baseLine-7:-1:1 if portionBeingProcessed(m,info.Width)==0 if portionBeingProcessed(m-1,info.Width-1)~=0 %pointFound=1; peakY=m; %Now, drawing a rectangle over the peak to highlight it. BoundingBox=uint16([info.Width-1,peakY-1,1,1]); rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','g'); else break; end end end k=2; kk=size(portionBeingProcessed,1)-1; while k<=size(portionBeingProcessed,2)-1 while kk>=baseLine+7 if portionBeingProcessed(kk,k)==0 if portionBeingProcessed(kk+1,k-1)~=0 & portionBeingProcessed(kk+1,k+1)~=0 %pointFound=1; peakY=kk; peakX=k; %Now, drawing a rectangle over the peak to highlight it. BoundingBox=uint16([peakX-1,peakY-1,2,2]); rectangle('Position',BoundingBox,'LineWidth',2,'LineStyle','-','EdgeColor','g'); k=k+1; kk=size(portionBeingProcessed,1)-1;