MATLAB: Find specific peaks and their positions

find peaksMATLAB

Good afternoon,
I have an ongoing problem where I want to find the specific peaks and localities within a data set automatically. The test data shows 4 typical data plots that can be found in a simulation that I am running. What I need jpeg shows 9 locations in total, the problem I have is that I cannot capture these points across all the data sets because the peak count is different owing to different areas of the simulation they were taken.
My method has been to find the peak locations, plot these as these changes (2nd figure) represent the change in water level, then find the gradient and where these changes occur from positve to negative. However, this has not worked because some of the trends continue to be negative. So, I tried interpolating, "ischange" with variance, mean etc and including filtering, smoothing, islocal max, findpeakpts and I still cannot capture what I need.
Is there a way to do this?

Best Answer

This is quick and dirty, but it finds 8 of the 9 peaks you specified (technically #9 is not a peak, so I leave it to you to determine how to handle it).
Basically, I compute the abs difference of the signal you indicated. This creates peaks at each step change. I can then use findpeaks to identify the location of these peaks. I used the MinPeakProminence name-value pair to help select just the desired peaks.
Here's the code (first 2 lines) plus a visualization to check the results.
stpData = abs(diff(ppks{4}));
[pks,loc]=findpeaks(stpData,"MinPeakProminence",0.25);
figure
plot(ppks{4})
hold on
plot(stpData)
plot(loc,ppks{4}(loc),'ro')
peaks_richardRees.png