BeginPackage["Wikicode`DigitalFilter`"]
FindPeaks::usage = "FindPeaks[data,windowWidth,cutoff] extracts \
significant local peaks from the given data. The window width affects \
the minumum spacing between found peaks and the cutoff affects the \
minumum amplitude of found peaks."
Begin["`Private`"]
Wikicode`Load["Moving average"]
FindPeaks =
Compile[{{data, _Real,
1}, {width, _Integer}, {cut, _Real}}, {#, data[[#]]} & /@
Position[(ConstantArray[0, width]~Join~
UnitStep[
Take[data, {1 + width, -1 - width}] -
MovingAverage`CompiledMovingAverage[data, 1 + 2 width] -
cut]~Join~ConstantArray[0, width])*({0}~Join~
Table[If[
Sign[{data[[ii + 1]] - data[[ii]],
data[[ii + 2]] - data[[ii + 1]]}] == {1, -1}, 1, 0], {ii,
1, Length[data] - 2}]~Join~{0}), 1][[All, 1]],
CompilationTarget -> "C"]
End[]
EndPackage[]