How can I find the peaks of a surface (i.e. 2-D data instead of 1-D)?

151 views (last 30 days)
I know that if I have a 1-D signal, I can use the "findpeaks" function to find the peaks of that signal. However, I have 2-D data that I want to find peaks of - essentially, I have a surface for which I want to find the maxima. Since "findpeaks" only supports 1-D data, how can I do this? The most important part is to be able to find the peak locations and values, but if possible I would also like information about the peak widths.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 May 2022
Edited: MathWorks Support Team on 13 May 2022
One method would be to loop through the X and Y dimensions of the data with the "findpeaks" function, and then find the points that are maxima in both X and Y to find the overall peaks. I created a simple demo script to do this, which you can find attached. One advantage to this approach is that the "findpeaks" function has a lot of built-in functionality to check peak width & prominence, as well as doing some thresholding. The downsides of this approach are that it could be slow since it uses 2 for loops to go through the data, and I am not certain that it is very robust (although it worked well for the simple example that I tried).
Another option would be to think of this as an optimization problem and to use some of the optimization tools that we offer to find local extrama/optima. This example shows how to use the Global Optimization Toolbox to find multiple local minima (and if you are looking for maxima you can just negate your values):
Finally, if the above two options are not what you are looking for, there are various File Exchange submissions designed to do this. Please note, however, that MathWorks does not guarantee or warrant the use or content of File Exchange submissions. Any questions, issues, or complaints should be directed to the contributing author. That said, here are two options that I find that might work well for this application:
1) This function is designed to do exactly what you are looking for:
2) The "extrema2" function from the file exchange could also be a good option to find 2-D extrema:

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!