how can i solve my problem with findpeaks

1 view (last 30 days)
as you can see in the pic ,I am trying to find peaks of whole Curve or graph or ECG .... but i dont know why in my code show peaks in y vector, while i need it in whole of ecg
If someone could point me in the right direction it would be greatly appriciated.
x = load ('C:\ekg\example_ecg.txt');
y= x ( : , 2);
[pks,locs] = findpeaks(y);
plot (y);
hold on ;
plot(pks,y(locs),'rv','MarkerFaceColor','r' );
grid on

Answers (2)

Star Strider
Star Strider on 19 Aug 2014
I don’t have your data so I can’t test your code, but see if changing your code and plot call to:
t = x(:,1);
y = x( : , 2);
plot (t,y);
hold on ;
plot(t(locs),y(locs),'rv','MarkerFaceColor','r' )
grid on
improves things.

Image Analyst
Image Analyst on 19 Aug 2014
When you say this:
plot(pks,y(locs),'rv','MarkerFaceColor','r' );
your "x" value is pks, which is the height of the peaks, which are values in the range [-1 to +2]. That doesn't make sense. That's why all your "red" data is down around -1 to 2 instead of over the range 0-1000.
locs is your "x" and pks is your "y". Try
plot(locs, pks, 'rv','MarkerFaceColor','r');

Community Treasure Hunt

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

Start Hunting!