[Previous]
[Next]
NAME:
LocalExtrema
PURPOSE:
Return location of local maxima and minima in an array
CATEGORY:
Math
CALLING SEQUENCE:
R = LocalExtrema(Array, [/minima, /float])
INPUTS:
Array array[*]; type: 1-dim array
input array to be searched for extrema
OPTIONAL INPUT PARAMETERS:
By default the locations of an alternating sequence of
maxima and minima are returned.
/maxima if /maxima is set then the locations of maxima are returned
/minima if /minima is set then the locations of minima are returned
/float by default integer indices are returned for the location of the extrema.
If /float is set then the location is refined by fitting a quadratic to
the minimum element and its two neighbours. The extremum of the
quadratic is returned as a floating point number.
OUTPUTS:
R scalar or array; type: integer or float
indices of minima or maxima
OPTIONAL OUTPUT PARAMETERS:
fnc=fnc array[*]; same size as R, same type as 'Array'
function values in locations R. If the /float keyword is set it
returns the function values in the extremum of the quadratic fit.
count=count scalar; type: integer
# extrema
INCLUDE:
@compile_opt.pro ; On error, return to caller
CALLS: ***
BadValue, InitVar
CALLED BY:
even_light_pedestal, smei_frm_hbar
RESTRICTIONS:
> Only genuine maxima and minima are detected,
> The edges of the array are excluded, i.e. only the locations of
'internal' extrema (with neighbour on both sides) are returned
PROCEDURE:
Let 'array' represent a function f(x) in points x=[0,1,.]
Let f have an extremum in grid point j, i.e. f(j) > f(j-1) and f(j) > f(j+1)
Define dx = x-j and g(dx) = f(j+dx)-f(j), i.e. g(0) = 0 is an extremum of g
The quadratic for g through 0 and its two neighbours -1 and +1 is:
y(dx) = 0.5*dx*{ g(-1)*(dx-1)+g(+1)*(dx+1) }
which has a maximum at
dx = 0.5*(g(-1)-g(1))/(g(-1)+g(1))
MODIFICATION HISTORY:
MAR-2000, Paul Hick (UCSD/CASS)
FEB-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
Introduced /maxima keyword to return maxima. This used to be the default.
The default now is to return an alternating sequence of minima and maxima.