MATLAB Answers

0

(Food for Thought) Peak Detection on ECG signal

Asked by Lok Yiu To on 21 Jun 2019
Latest activity Answered by David Wilson on 21 Jun 2019
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.

  0 Comments

Sign in to comment.

1 Answer

Answer by David Wilson on 21 Jun 2019
 Accepted Answer

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
plot(t,y,'.-')
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;
end
if y(i) < -thresh
pauseOn = false;
end % if
end
end
plot(t,y, ...
t(pk), y(pk), 'ro')
yline(thresh,'--','color',0.5*[1,1,1])
The results look like:
tmp.png
and a zoomed version is:
tmp2.png
Of course you could try findpeaks as well.

  0 Comments

Sign in to comment.