Find peaks (maxima and minima) of a function

This function detects the transition points (maxima and minima) in a function like y = f(x)
701 descargas
Actualizado 28 ene 2016

Ver licencia

function [nmax,maxAt,maxValues,nmin,minAt,minValues] = peak(y,x,threshold,stepsize)
This function detects the transition points (maxima and minima) of a function like y = f(x), where x is indpendent variable and y is dependent variable. If there is no clue about x, then use x = [], which is an empty vector, and if so, it automatically defines x = 1:length(y).

Optional input arguments: threshold is the thresholding applied to y, and stepsize is the step size for computation of slopes. The smaller the stepsize is, the more accurate result is. By default stepsize = abs(x(1)-x(2))/10.
Finally, it returns, nmax: the number of peaks in y; maxAt: the x values at which peaks occur; maxValues: the peak values of y; nmin: number of minima in y; minAt: the x values at which minima occur; and
minValues: the minima of y; (all after thresholding, if any).

Examples 1: no threshodling
x = -pi:pi/100:pi;
y = sin(x)+cos(x.^2);
[nmax,maxAt,maxValues,nmin,minAt,minValues] = peak(y,x)


Example 2: thresholding at 0
x = -pi:pi/100:pi;
y = sin(x)+cos(x.^2);
[nmax,maxAt,maxValues,nmin,minAt,minValues] = peak(y,x,0)

Citar como

Shoaibur Rahman (2024). Find peaks (maxima and minima) of a function (https://www.mathworks.com/matlabcentral/fileexchange/48818-find-peaks-maxima-and-minima-of-a-function), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2014b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.1.0.0

Change in function name as it was conflicting with a built-in function
Title made shorter
Change title

1.0.0.0