The principle of core peak search algorithm reference Ronny, Link: The peak of the projection curve to find,
C # Translation Principle code reference sowhat4999, Link: C # translate Findpeaks method in MATLAB
Ancestors planted trees, posterity. Thank the original author for a detailed explanation.
Here first the translation code (slightly modified in the sowhat4999 code of several parameter types)
Calling methods
list<double> data = {25, 8, 15, 5, 6, 10, 10, 3, 1, 20, 7}; List<int> index = Getpeaksindex (Trendsign (Onediff (Constant.data)));
First Peak search (base peak distance of 1) algorithm
Private double[] Onediff (list<double> data)
{
Double[] result = new Double[data. COUNT-1];
for (int i = 0; I < result. Length; i++)
{
Result[i] = data[i + 1]-data[i];
}
return result;
}
Private int[] Trendsign (double[] data)
{
int[] Sign = new Int[data. Length];
for (int i = 0; i < sign. Length; i++)
{
if (Data[i] > 0) sign[i] = 1;
else if (data[i] = = 0) Sign[i] = 0;
else Sign[i] =-1;
}
for (int i = sign. Length-1; I >= 0; i--)
{
if (sign[i] = = 0 && i = = sign. LENGTH-1)
{
Sign[i] = 1;
}
else if (sign[i] = = 0)
{
if (Sign[i + 1] >= 0)
{
Sign[i] = 1;
}
Else
{
Sign[i] =-1;
}
}
}
return sign;
}
Private list<int> Getpeaksindex (int[] diff)
{
list<int> data = new list<int> ();
for (int i = 0; I! = diff. Length-1; i++)
{
if (Diff[i + 1]-diff[i] = =-2)
{
Data. ADD (i + 1);
}
}
Return data;//is equivalent to the subscript of the original array
}
Simple optimization of C # Implementation of peak-seeking algorithm