Locate peaks in an imat_fn using a tolerance
mvals=findpeaks(f)
[mvals,ind]=filterf(f,[],1e-4)
[mvals,ind,inds,inde=filterf(f,tol,thresh,type,debug)
FINDPEAKS will find peaks in a single imat_fn F, and return the peak values as a vector of doubles in MVALS, with optional index vector IND containing indices into the ordinate values corresponding to the maximum values. INDS and INDE are optional vectors that give indices to the start and end of the peaks, as defined by the change in slope to either side of the peak. If F is complex, FINDPEAKS will take the absolute value to find the peaks.
FINDPEAKS allows several optional input arguments. TOL is the tolerance to use for finding peaks. The default tolerance is 0.1. THRESH is a threshhold value below which to ignore. An empty value (the default) causes FINDPEAKS to consider all values. TYPE is a flag that determines how the tolerance is calculated. Valid arguments are 'max' and 'rel'. The default is 'max'. The paragraph below outlines what each does. Sending in an empty matrix for any of these optional arguments causes the default to be used. DEBUG is an optional logical (default false) that will display a plot of candidate and selected peaks on top of the supplied function if set to true.
The general algorithm of FINDPEAKS is as follows. FINDPEAKS first determines the sign of the slope of the ordinate. Peaks occur where the left side of a given point has positive slope, and the right side of a given point has negative slope. Valleys occur at the opposite slopes. In areas of flat slope, FINDPEAKS assumes that the slope of the ordinate to the left of the center of the flat area has the same slope as the left edge of the flat area, and the slope of the ordinate to the right of the center of the flat area has the same slope as the right edge of the flat area.
If the change in amplitude between a local maximum or local minimum and the previous maximum or previous minimum, is less than the tolerance times the function maximum, the change is ignored. This is how it works when TYPE is 'max'. When TYPE is 'rel', the tolerance is multiplied by the function local extrema. In other words, if the change in amplitude between two local extrema is less than the tolerance times the 2nd extremum, the change is ignored.