FindPeakPoints - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

SignalProcessing

 FindPeakPoints
 find peak and valley points of one-dimensional data sets

 Calling Sequence FindPeakPoints( X, Y, options ) FindPeakPoints( XY, options ) FindPeakPoints( Y, options )

Parameters

 X - one-dimensional rtable or list of independent data values Y - one-dimensional rtable or list of dependent data values XY - two-dimensional rtable or list of independent and dependent data values, with each row representing a single point

Options

 • sortdata - Either true or false, this specifies whether to sort the data when both independent and dependent values are provided. The default is true.
 • tolerance - Threshold used to detect a peak or a valley. See the precise definition of "peaks" and "valleys" in terms of tolerance below. Typically, a peak must be higher by more than tolerance than the closest valleys on the left and right. The default is 0.0.
 • breadthtype - The definition used to determine the breadth of a peak or valley. There are three options:
 baseradius: The smaller of the positive horizontal distances from the peak (valley) to the valleys (peaks) on either side which determine the prominence. This is the default.
 basewidth: The horizontal distance between the valleys (peaks) on either side of the peak (valley) which determine the prominence.
 halfprominence: The horizontal distance between the intersection points of the (imaginary) lines from the peak (valley) to the valleys (peaks) which determine the prominence, and the (imaginary) horizontal line that is halfway between the peak (valley) and the valley (peak) which determines the prominence.
 • includeendpoints - Specifies if the endpoints of the data should be kept or filtered out if they're found to be peaks or valleys. The default is true.
 • minimumprominence - Specifies the smallest allowed prominence to filter the peaks/valleys. The default is 0.0.
 • minimumbreadth - Specifies the smallest allowed breadth to filter the peaks/valleys. The default is 0.0.
 • minimumheight - Specifies the smallest allowed height to filter the peaks and valleys. The default is -infinity.
 • maximumheight - Specifies the largest allowed height to filter the peaks and valleys. The default is infinity.
 • minimumseparation - Specifies the smallest horizontal distance of a candidate extremum from the previous extremum of the same variety (peak or valley) to be included. for a successive point (of the same variety) to count. The default is 0.0.
 • output - The type of output. The supported options are:
 peaks: For a Matrix of the peak points. This is the default.
 valleys: Similar to peaks, but for valleys.
 extremes: For a Matrix of both the peak and valley points.
 peakindices: For a column Vector of the indices of the peak points.
 valleyindices: For a column Vector of the indices of the valley points.
 extremeindices: For a column Vector of the indices of the extreme points.
 peakbreadths: For a column Vector of the breadths of the peak points.
 valleybreadths: For a column Vector of the breadths of the valley points.
 peakprominences: For a column Vector of the prominences of the peak points.
 valleyprominences: For a column Vector of the prominences of the valley points.
 plot: Returns a plot of all the points, using the plot options below or any options which can be passed to plots:-display.
 record: Returns a record with the previous options.
 list of any of the above options: Returns an expression sequence with the corresponding outputs, in the same order.
 • plotincludepoints - A list of point types (chosen from peaks, regular, and valleys) to include in the plot. The default is [peaks].
 • curveplotoptions - A list of options to be passed to the internal call to plot when generating the curve through all the points. The default is [connect=true,thickness=1,color=black]. Note: Any passed options will not overwrite the remaining default ones.
 • peakpointplotoptions - A list of options to be passed to plots:-pointplot when generating the point plot for peaks. The default is [color=blue,symbol=solidcircle,symbolsize=15]. Note: Any passed options will not overwrite the remaining default ones.
 • valleypointplotoptions - A list of options to be passed to plots:-pointplot when generating the point plot for valleys. The default is [color=green,symbol=solidcircle,symbolsize=15]. Note: Any passed options will not overwrite the remaining default ones.
 • regularpointplotoptions - A list of options to be passed to plots:-pointplot when generating the point plot for regular points. The default is [color=black,symbol=solidcircle,symbolsize=10]. Note: Any passed options will not overwrite the remaining default ones.

Description

 • The FindPeakPoints command is used to find the "peak" and "valley" points of one-dimensional data sets.
 • The command can be accessed by using either the long form or the short form of the command name in the calling sequence.
 • The long form, SignalProcessing:-FindPeakPoints, is always available.  The short form can be used after loading the package.
 • For the FindPeakPoints(X,Y) calling sequence, X and Y must be of the same size.
 • The FindPeakPoints(XY) calling sequence is reduced to the FindPeakPoints(X,Y) calling sequence by taking X and Y to be, respectively, the first and second columns of XY. Similarly, the FindPeakPoints(Y) calling sequence is reduced to the FindPeakPoints(X,Y) calling sequence by taking X to be a Vector of the positive integers from 1 to numelems(Y).
 • Any input rtable/list is converted to an rtable of float[8] datatype, and an error is thrown if this is not possible. For this reason, it is most efficient for any input to already be an rtable having the appropriate datatype. Note: The rtables cannot have an indexing function, and they need to have rectangular storage.
 • When both independent and dependent data are passed, if sortdata=true then the independent values are sorted in increasing order, and the dependent values are sorted in tandem. If sortdata=false, on the other hand, the onus is on the user to ensure that the data is sorted.
 • Prior to filtering based on breadth, height, prominence, and separation, the command determines a "peak" ("valley") to be a point which satisfies the following recursive conditions:
 1 The closest "extremum" on the left of the point, if it exists, is a "valley" ("peak") which is lower (higher) by more than tolerance.
 2 When moving to the right of the point, before a point that is of greater (lower) height is encountered, one reaches either an endpoint in the situation where a point to the left has already been determined to be a "valley" ("peak"), or a point lower (higher) in height by more than tolerance.
 • Note: Points passed over between the starting and final points during this sweep to the right are "regular".
 • Note: Peaks and valleys are found by considering the entire neighborhood of the candidate points, not just the closest points on the left and right.
 • The "left-prominence" of a peak is defined as the height difference between the peak and the lowest valley between it and the closest peak (or endpoint) on the left of equal or greater height. Note: In the event of a tie, the lowest valley furthest from the peak is taken. The "right-prominence" is similarly defined, and the overall "prominence" is taken to be the smaller of the positive one-sided prominences. The prominence of a valley is defined in the same manner. Note: The missing one-sided prominences for the endpoints are taken to be zero.
 • Starting with Maple 2024, FindPeakPoints uses external code for the intensive computations, and runs considerably faster than in previous versions.

Examples

 > $\mathrm{with}\left(\mathrm{SignalProcessing}\right):$

Simple Examples

 • For a simple example, consider:
 > $X≔\left[1,5,8,10\right]$
 ${X}{≔}\left[{1}{,}{5}{,}{8}{,}{10}\right]$ (1)
 > $Y≔\left[5,10,1,4\right]$
 ${Y}{≔}\left[{5}{,}{10}{,}{1}{,}{4}\right]$ (2)
 > $P,V≔\mathrm{FindPeakPoints}\left(X,Y,\mathrm{includeendpoints}=\mathrm{false},\mathrm{output}=\left[\mathrm{peaks},\mathrm{valleys}\right]\right)$
 ${P}{,}{V}{≔}\left[{?}\right]{,}\left[{?}\right]$ (3)
 > $\mathrm{FindPeakPoints}\left(X,Y,\mathrm{includeendpoints}=\mathrm{false},\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 • Saw:
 > $\mathrm{FindPeakPoints}\left(\left[1,2,1,2,1,2,1\right],\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 • Plateau:
 > $\mathrm{FindPeakPoints}\left(\left[1,2,2,2,1\right],\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 • Step:
 > $\mathrm{FindPeakPoints}\left(\left[1,2,2,2,3\right],\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 • Hat:
 > $\mathrm{FindPeakPoints}\left(\left[1,1,2,1,1\right],\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 • Plain:
 > $\mathrm{FindPeakPoints}\left(\left[2,2,2,2\right],\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$

Illustrative Example

 • Consider now a more illustrative example:
 > $\mathrm{data}≔\mathrm{Vector}\left[\mathrm{row}\right]\left(\left[5,10,8,9,8,10,10,10,7,7.1,7.2,7.3,7.4,7.5,2,12,12,12,15.1,14.9,15.2,10,20.1,20.2,20.1,25,15\right]\right)$
 ${\mathrm{data}}{≔}\left[\right]$ (4)
 • Options:
 > $\mathrm{opts}≔\mathrm{output}=\mathrm{record},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right],\mathrm{curveplotoptions}=\left[\mathrm{connect}=\mathrm{true},\mathrm{color}=\mathrm{red},\mathrm{thickness}=2\right],\mathrm{peakpointplotoptions}=\left[\mathrm{symbolsize}=20,\mathrm{color}=\mathrm{blue}\right],\mathrm{valleypointplotoptions}=\left[\mathrm{symbolsize}=20,\mathrm{color}=\mathrm{green}\right],\mathrm{regularpointplotoptions}=\left[\mathrm{symbolsize}=15,\mathrm{color}=\mathrm{black}\right],\mathrm{title}="Peaks and Valleys":$
 > $L≔\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{opts}\right)$
 • The peaks and valleys:
 > $P,V≔L\left[\mathrm{peaks}\right],L\left[\mathrm{valleys}\right]$
 ${P}{,}{V}{≔}\left[{?}\right]{,}\left[{?}\right]$ (5)
 • The plot:
 > $L\left[\mathrm{plot}\right]$
 • If we increase the tolerance, some extrema are excluded:
 > $L≔\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{tolerance}=0.2,\mathrm{opts}\right):$
 • The remaining peaks and valleys:
 > $P,V≔L\left[\mathrm{peaks}\right],L\left[\mathrm{valleys}\right]$
 ${P}{,}{V}{≔}\left[{?}\right]{,}\left[{?}\right]$ (6)
 • The plot:
 > $L\left[\mathrm{plot}\right]$

Minimum and Maximum Height

 • Peaks and valleys can be filtered based on the height:
 > $\mathrm{data}≔\left[-5,12,6,7,3,15,-10\right]$
 ${\mathrm{data}}{≔}\left[{-5}{,}{12}{,}{6}{,}{7}{,}{3}{,}{15}{,}{-10}\right]$ (7)
 > $\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right],\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{minimumheight}=0,\mathrm{maximumheight}=10,\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right],\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{PeakIndices},\mathrm{ValleyIndices}≔\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{minimumheight}=0,\mathrm{maximumheight}=10,\mathrm{output}=\left[\mathrm{peakindices},\mathrm{valleyindices}\right]\right)$
 ${\mathrm{PeakIndices}}{,}{\mathrm{ValleyIndices}}{≔}\left[{?}\right]{,}\left[{?}\right]$ (8)

Prominence

 • The command can be used to isolate the most prominent peak. Consider:
 > $\mathrm{data}≔\mathrm{Vector}\left[\mathrm{row}\right]\left(\left[8,10,5,7,1,6,5,15,4,6,5,7,3,10,8\right]\right)$
 ${\mathrm{data}}{≔}\left[\right]$ (9)
 > $L≔\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{output}=\mathrm{record},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right],\mathrm{gridlines}=\mathrm{true}\right)$
 • Isolating the peaks, along with the breadths and prominences:
 > $P,\mathrm{PB},\mathrm{PP}≔L\left[\mathrm{peaks}\right],L\left[\mathrm{peakbreadths}\right],L\left[\mathrm{peakprominences}\right]$
 ${P}{,}{\mathrm{PB}}{,}{\mathrm{PP}}{≔}\left[{?}\right]{,}\left[{?}\right]{,}\left[{?}\right]$ (10)
 • Isolating the valleys, along with the breadths and prominences:
 > $V,\mathrm{VB},\mathrm{VP}≔L\left[\mathrm{valleys}\right],L\left[\mathrm{valleybreadths}\right],L\left[\mathrm{valleyprominences}\right]$
 ${V}{,}{\mathrm{VB}}{,}{\mathrm{VP}}{≔}\left[{?}\right]{,}\left[{?}\right]{,}\left[{?}\right]$ (11)
 • Isolating the plot:
 > $L\left[\mathrm{plot}\right]$
 • One peak stands out with a prominence of 12, and can be singled out:
 > $\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{minimumprominence}=10,\mathrm{output}=\mathrm{plot}\right)$

 • The breadth of a peak/valley can be measured in multiple ways:
 > $A≔\left[6,10,6,2,6,10,6\right]$
 ${A}{≔}\left[{6}{,}{10}{,}{6}{,}{2}{,}{6}{,}{10}{,}{6}\right]$ (12)
 > $\mathrm{FindPeakPoints}\left(A,\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 > $\mathrm{PB1},\mathrm{VB1}≔\mathrm{FindPeakPoints}\left(A,\mathrm{output}=\left[\mathrm{peakbreadths},\mathrm{valleybreadths}\right],\mathrm{breadthtype}=\mathrm{baseradius}\right)$
 ${\mathrm{PB1}}{,}{\mathrm{VB1}}{≔}\left[{?}\right]{,}\left[{?}\right]$ (13)
 > $\mathrm{PB2},\mathrm{VB2}≔\mathrm{FindPeakPoints}\left(A,\mathrm{output}=\left[\mathrm{peakbreadths},\mathrm{valleybreadths}\right],\mathrm{breadthtype}=\mathrm{basewidth}\right)$
 ${\mathrm{PB2}}{,}{\mathrm{VB2}}{≔}\left[{?}\right]{,}\left[{?}\right]$ (14)
 > $\mathrm{PB3},\mathrm{VB3}≔\mathrm{FindPeakPoints}\left(A,\mathrm{output}=\left[\mathrm{peakbreadths},\mathrm{valleybreadths}\right],\mathrm{breadthtype}=\mathrm{halfprominence}\right)$
 ${\mathrm{PB3}}{,}{\mathrm{VB3}}{≔}\left[{?}\right]{,}\left[{?}\right]$ (15)
 • An appropriate measure of breadth can also be used to retain specific peaks. For instance:
 > $B≔\mathrm{Vector}\left[\mathrm{column}\right]\left(\left[5,10,4,8,4,9,3,7,3,8,2,6,2,7,1\right]\right)$
 > $\mathrm{FindPeakPoints}\left(B,\mathrm{breadthtype}=\mathrm{basewidth},\mathrm{minimumbreadth}=3,\mathrm{output}=\mathrm{plot}\right)$

Minimum Separation

 • The FindPeakPoints command can filter out peaks and valleys that are too close:
 > $\mathrm{data}≔\mathrm{Matrix}\left(\left[\mathrm{seq}\left(\left[i,2+{\left(-1\right)}^{i}\right],i=1..11\right)\right]\right)$
 > $\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 > $\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{minimumseparation}=4.0,\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$
 > $\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{minimumseparation}=5.0,\mathrm{output}=\mathrm{plot},\mathrm{plotincludepoints}=\left[\mathrm{peaks},\mathrm{regular},\mathrm{valleys}\right]\right)$

Extremes

 • All extremes (peaks and valleys) can be returned together:
 > $T,X≔\mathrm{GenerateSignal}\left(\mathrm{sin}\left(2t\right)+\frac{1}{2}\mathrm{cos}\left(5t\right),t=0..2\mathrm{\pi },{10}^{3},\mathrm{output}=\left[\mathrm{times},\mathrm{signal}\right]\right):$
 > $\mathrm{FindPeakPoints}\left(T,X,\mathrm{output}=\mathrm{plot}\right)$
 > $E≔\mathrm{FindPeakPoints}\left(T,X,\mathrm{output}=\mathrm{extremes}\right)$
 > $\mathrm{plots}:-\mathrm{pointplot}\left(E,\mathrm{connect},\mathrm{color}=\mathrm{blue},\mathrm{title}="Plot of Extremes",\mathrm{font}=\left[\mathrm{Verdana},15\right]\right)$

Sunspot Periodicity

 • For a real-world, so-to-speak, example, we can look to the sun (well, don't, that's dangerous), and find the period of the number of sunspots. First, obtain the data:
 > $\mathrm{datafile}≔\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left[\mathrm{kernelopts}\left(\mathrm{datadir}\right),"datasets","sunspots.csv"\right]\right)$
 ${\mathrm{datafile}}{≔}{"/maple/cbat/active/277890/data/datasets/sunspots.csv"}$ (16)
 > $\mathrm{data}≔\mathrm{ImportMatrix}\left(\mathrm{datafile},\mathrm{delimiter}=","\right)\left[2..\right]$
 • Now, plot the data:
 > $P≔\mathrm{plots}:-\mathrm{pointplot}\left(\mathrm{data},\mathrm{labels}=\left["Year","Wolf Number"\right],\mathrm{labeldirections}=\left[\mathrm{horizontal},\mathrm{vertical}\right],\mathrm{connect}=\mathrm{true},\mathrm{title}="Sunspot Data",\mathrm{font}=\left[\mathrm{Verdana},15\right],\mathrm{labelfont}=\left[\mathrm{Verdana},15\right],\mathrm{thickness}=0,\mathrm{gridlines},\mathrm{size}=\left[800,"golden"\right]\right)$
 • Find the peaks:
 > $B≔\mathrm{FindPeakPoints}\left(\mathrm{data},\mathrm{output}=\mathrm{record},\mathrm{plotincludepoints}=\left[\mathrm{peaks}\right],\mathrm{peakpointplotoptions}=\left[\mathrm{symbolsize}=10\right],\mathrm{minimumprominence}=25,\mathrm{labels}=\left["Year","Wolf Number"\right],\mathrm{labeldirections}=\left[\mathrm{horizontal},\mathrm{vertical}\right],\mathrm{size}=\left[1000,500\right],\mathrm{view}=\left[1650..2050,0..300\right],\mathrm{xtickmarks}=\left[\mathrm{seq}\left(1700..2050,50\right)\right]\right):$
 • We choose a minimum prominence here to be 25 in order to filter out the spurious peaks. The option, say, tolerance=15 would achieve this as well.
 • Display the plot:
 > $B\left[\mathrm{plot}\right]$
 • Finally, determine the period:
 > $Q≔B\left[\mathrm{peaks}\right]\left[..,1\right]$
 > $\mathrm{\alpha }≔\mathrm{Mean}\left(Q\left[2..\right]-Q\left[..-2\right]\right)$
 ${\mathrm{\alpha }}{≔}{11.}$ (17)

Compatibility

 • The SignalProcessing[FindPeakPoints] command was introduced in Maple 2019.
 • For more information on Maple 2019 changes, see Updates in Maple 2019.
 • The 'sortdata' and 'maximumheight' options were introduced in Maple 2021.
 • For more information on Maple 2021 changes, see Updates in Maple 2021.
 • The SignalProcessing[FindPeakPoints] command was updated in Maple 2024.
 • The 'output' option was updated in Maple 2024.