(Food for Thought) Peak Detection on ECG signal

7 views (last 30 days)
Hey guys,
I've been working on a ECG signal collected during exercise through my chest mount heart rate monitor. My goal is to accurately detect the location of the R-wave. (For those who are new to ECG signal, R-wave is the narrow peak similar to the ones I circled in red.) Can you guys suggest any method for preprocessing the data so that it will be easier to extract the signal? Like anything! I am just trying to learn new skills right now
I have tried wavelet transform but I am not getting any luck. Come on guys, show me the power of the internet! haha
if you want to try it out, this is the data.
The sampling frequency is 150 Hz.

Accepted Answer

David Wilson
David Wilson on 21 Jun 2019
OK, here's my (ugly) solution (withou using findpeaks). I've re-named your data set, and did some pre-processig.
load ecg
y = ecgSamplePreProc;
Ts = 1/150; % sampling freq = 150 Hz;
t = Ts*[0:length(y)-1]';
%% Do some preliminary cleaning
idx = [1:600];
t(idx) = []; y(idx) = []; % drop start-u transients
y = y - mean(y); % remove any bias
Now we are ready to identify the peaks. (I'm not sure if that's the same as your R-wave, but it's a start.)
n = length(y);
thresh = 0.7;
pauseOn = false;
irange = [-5:5];
pk = [1];
pauseOn = true;
for i=10:n-10
if y(i) > thresh
yr = y(i+irange);
if y(i) >= max(yr) && pauseOn && (i > pk(end)+50)
pk = [pk;i];
pauseOn = true;
if y(i) < -thresh
pauseOn = false;
end % if
plot(t,y, ...
t(pk), y(pk), 'ro')
The results look like:
and a zoomed version is:
Of course you could try findpeaks as well.
  1 Comment
lt c
lt c on 28 Feb 2022
I'm new to matlab. Without annotation, I'm not fully understand your work.
1. what does "t(idx) = []; y(idx) = []; % drop start-u transients" mean?
I try to google start-u transients, unfortunately get start-up transients.
2. Also, what does following lines get us?
if y(i) >= max(yr) && pauseOn && (i > pk(end)+50)
pk = [pk;i];
pauseOn = true;
Do not mind me asking questions that may seem pretty simple to others, thank you.

Sign in to comment.

More Answers (0)


Find more on Applications in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!