Class PeakFinderSavitzkyGolay uses smooth Savitzky-Golay derivatives to find peaks in data. A peak is defined as a smoothed derivative zero crossing.
PeakFinderSavitzkyGolay extends PeakFinderBase, the abstract base class for all peak finding algorithms, and an enumerable collection of all found peaks.
A PeakFinderSavitzkyGolay instance is constructed from a vector of data, a window width, and the degree of polynomial used to fit the data. For instance, this code builds a data set from a sinc() function, then constructs a peak finder with a width of 6, and 4th degree smoothing polynomial:
DoubleVector x = new DoubleVector(5000, 0.01, 0.1); DoubleVector data = NMathFunctions.Sin(x) / x; PeakFinderSavitzkyGolay pf = new PeakFinderSavitzkyGolay(data, 6, 4);
The constructor parameters must satisfy the following rules:
Typically, the degree of the smoothing polynomial is between 3 and 5.
Once you've constructed a PeakFinderSavitzkyGolay object, the LocatePeaks() method finds all peak abscissae and their smoothed ordinates in current data set:
pf.LocatePeaks();
The provided indexer on PeakFinderSavitzkyGolay gets each peak as an instance of struct Extrema. Property NumberPeaks gets the total number of peaks found. For example, this code dump all peaks to the console:
for (int i = 0; i < pf.NumberPeaks; i++)
{
Extrema peak = pf[i];
Console.WriteLine("Found peak at = ({0},{1})", peak.X, peak.Y);
}
Additional properties on PeakFinderSavitzkyGolay control the set of peaks that are found by the LocatePeaks() method:
pf.AbscissaInterval = 0.1; pf.SlopeSelectivity = 0; pf.LocatePeaks();TOC | Previous | Next | Index