Skip to main content
. 2020 Sep 22;30(9):091102. doi: 10.1063/5.0024204

Algorithm 2.

Turning point refinement (step 2)

TPSet = Sort(PeakSet TroughSet);                           Indexing begins
from 1
Initialize: CurrentPeakIndex = 2;                         Begin the peak ratio
refinement
While CurrentPeakIndex Length(TPSet) - 2 do
    i = CurrentPeakIndex, t1 = TPSet(i), t3 = TPSet(i+2);
    if x^(t3)x^(t1)δ then
        CurrentPeakIndex = i+2;
    else if x^(t3)x^(t1)<δ and i+2 = Length(TPSet) then
        Remove t3 from PeakSet;
        TPSet=Sort(PeakSet TroughSet);
    else if x^(t3)x^(t1)<δ and i+2 Length(TPSet) then
        t2 = TPSet(i+1), t4 = TPSet(i+3);
        if x^(t2)x^(t4) then
            Remove t4 from TroughSet;
        else
            Remove t2 from TroughSet;
        Remove t3 from PeakSet;
        TPSet = Sort(PeakSet TroughSet);
    Initialize: CurrentIndex = 1;                 Begin the log-grad refinement
    while CurrentIndex < Length(TPSet) do
        i = CurrentIndex, t0 = TPSet(i), t1 = TPSet(i+1);
        if |loggrad(t0,t1)|<ϵ then                                     See Equation (3)
             Remove t0 and t1 from both TroughSet and PeakSet;
             TPSet = Sort(PeakSet TroughSet);
        else
             CurrentIndex = i+1;
    Output PeakSet and TroughSet.