finding peaks when axis are non-uniform

6 views (last 30 days)
I have been using “findpeaks” to locate and plot the peaks that have a prominence of at least 0.05.
findpeaks(data,position,'MinPeakProminence',0.00005,'Annotate','extents')
My current data “position” values are generally increasing but not strictly. As expected I get the following error:
“Error using findpeaks. Expected X to be strictly increasing.”
Is there another way to find the max values that have minimum peak prominence of 0.05?
I would appreciate any suggestion.
in the example below (data and position attached) findpeak is ignoring the position and it is using indeces instead. This is due to not strickly increasing / nonlinear position values (changing position vector to a linearly spaced vector is not an option). The general trend of position data is increasing.
figure(1);
plot(position,data)
findpeaks(data,position,'MinPeakProminence',0.00005,'Annotate','extents')

Accepted Answer

Image Analyst
Image Analyst on 29 Nov 2020
I've never used a second input argument like that but if it wants it increasing, then try this:
[sortedX, sortOrder] = sort(x, 'ascend');
% Not sure if PeakSig also needs to be sorted the same way. But if it does:
%PeakSig = PeakSig(sortOrder);
[peakValues, indexesOfPeaks] = findpeaks(PeakSig, sortedX,'MinPeakProminence',0.05,'Annotate','extents')
  6 Comments
Amin
Amin on 30 Nov 2020
Thanks for your help. The second plot is what I was looking for ( .vs X). For some reason my plotting lines and how I used findpeak was totally ignoring the X when plotting (I was getting .vs index plot and the error with X). Would you by any chance know how to get prominence and width displayed on the plots same as the image below?
Image Analyst
Image Analyst on 1 Dec 2020
No - I've never done that before. I'd have to read the documentation just like you, but you can do that as well as I can.

Sign in to comment.

More Answers (1)

Mathieu NOE
Mathieu NOE on 29 Nov 2020
hi
my 2 cent suggestion if x is not strictly increasing, resample your data on a vector that is 100% sure strictly increasing
like this : create a new x data vector , linearly spaced, 100 values and interpolate the new y data on it
new_x_data = linspace(min(x),max(x),100); % my new x data
new_y_data = interp1(x,y,new_x_data) % my new y data
  1 Comment
Amin
Amin on 30 Nov 2020
Thanks for your comment. Unfortunately, resampling is not the solution given that the collection of position data is intentionally none linear. sometimes a section needs denser sampling (closer position data), sometimes there are few sample at the same position, and rarely due to positional uncertainty x2>x1. However, the general trend is in increasing order. By resampling points of interest will not be in their actual location anymore.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!