How do I find location of my specific peak in ECG signal?
6 views (last 30 days)
Show older comments
Niloofar Roshanfekr
on 18 Jul 2022
Commented: Star Strider
on 18 Jul 2022
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);
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!