How do I find location of my specific peak in ECG signal?

6 views (last 30 days)
I'm trying to find the heartbeats from my ECG signal by by finding the locations of peaks. I have written the code for butterworth filter and had to invert my signal to find signal since my T wave and R wave were the same lenght. So I'm stuck trying to write a code that passes through y= 0.10 which would hit all the inverted signal and get the location each x that coresponds to that peak. Here is what I have for my end result :
sig_filt = -(sig_filt) %inverse
figure
subplot(2,1,1)
plot(T,-(sig_filt));
xlim([0,60])
subplot(2,1,2)
plot(T,-(sig_filt));
xlim([0,5])
subplot(2,1,1)
plot(T,-(sig_filt));
xlim([0,60])
subplot(2,1,2)
plot(T,-(sig_filt));
xlim([0,5])
findpeaks(-sig_filt);
[pks,min_locs] = findpeaks(-(sig_filt),"MinPeakHeight",0.11);

Accepted Answer

Star Strider
Star Strider on 18 Jul 2022
Edited: Star Strider on 18 Jul 2022
I have written the code for butterworth filter and had to invert my signal to find signal since my T wave and R wave were the same lenght.
I hope you mean ‘height’ rather than ‘length’, since the QRS duration is ordinarly less than 120 ms while the T duration is typically about 200 ms. With this clarification, use the 'MinPeakDistance' name-value pair to force findpeaks to ignore the T deflection, since it will always be after the R deflection. (There is typically no need to invert the EKG to use findpeaks, unless the intent is to locate Q deflections.)
EDIT — (18 Jul 2022 at 15:52)
There is baseline drift (variation) that complicates things. Remove it first, then use 'MinPeakProminence' to isolate the R deflections —
F = openfig('ecg.fig');
sp211 = subplot(2,1,1);
Lines = findobj(sp211, 'Type','line');
X = Lines.XData; % Recover Data
Y = -Lines.YData; % Recover Data & Invert
Fs = 1/(X(2)-X(1)); % Sampling Frequency
Yf = highpass(Y,2,Fs, 'ImpulseResponse','iir'); % Remove Baseline Drift
[Rwa,locs] = findpeaks(Yf, 'MinPeakProminence',0.25); % Detect R-Deflections
figure
plot(X, Yf)
hold on
plot(X(locs), Rwa, '^r')
hold off
grid
title('Original')
figure
plot(X, Yf)
hold on
plot(X(locs), Rwa, '^r')
hold off
grid
xlim([10 15])
title('Zoomed')
This EKG displays significant pathology likely due to ischemia, with prominent S-T depression, notched P deflections suggestive of an intraatrial conduction delay, and prominent T deflections. I would have to see the full 12-lead version to venture a diagnosis. (This does not appear to be a Lead II EKG, and may be a Lead III.)
.
  3 Comments
Niloofar Roshanfekr
Niloofar Roshanfekr on 18 Jul 2022
Thank you, the purpuse of this project is to write a code to calculate the heart beat, so the data collection was only done by 3 electrodes since the focus was not on diagnosis.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!