findpeaks function not finding all the peaks in data?

9 views (last 30 days)
Hello,
I am using the findpeaks function to find the number of peaks in a velocity profile, but sometimes it is failing to record a peak and I was wondering if anyone had a solution to my problem.
I am using the following code. AbsTrialVelocity=TrialDistance./(sampleinterval/1000); [PKS_V,LOCS_V]=findpeaks(AbsTrialVelocity,'minpeakheight',.1*max(AbsTrialVelocity),'minpeakdistance',8);
TrialDistance is a vector listing the euclidean distances of xy pairs. The function is working correctly, but because of the nature of the writing task used to sample xy coordinates, sometimes the velocity profile has a peak that does not have a local minima.
I have attached an image where you can see the problem. The red dots represent peaks in the velocity profile that the findpeaks function is finding. The red line at the last peak denotes peak velocity, but because findpeaks using localminima/maxima to determine a peak, it is not reporting the peak velocity as a peak. This isn't a problem if a particular velocity profile has a deacceleration at the end of the profile, but it is a problem in a situation where the writing task ends a trial during an acceleration.
I have played around with the function and have not been able to find a solution to the problem.
Any ideas?
Thank you!

Answers (1)

Image Analyst
Image Analyst on 12 Feb 2015
Pad your array with the min value on each end. Then subtract 1 from the peak locations.
minValue = min(signal);
paddedSignal = [minValue, signal, minValue];
[pks,locs] = findpeaks(paddedSignal);
locs = locs - 1;

Community Treasure Hunt

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

Start Hunting!