input signal f(t)
smoothed signal lp(t) (filtered windowed)
get_sample() - returns lp(t)
report_peak() - it is called upon peak detection
sign = 0; // sign of derivation lp(t) - lp(t-1)
prev = 0; // lp(t-1)
current = 0; // lp(t)
CONST; // constant value to be added to floating threshold base
bottom; // floating threshold base
prev = get_sample();
current = get_sample();
sign = current >= prev? 1: -1;
if(sign == 1)
bottom = prev;
for(;;)
{
prev = current;
current = get_sample();
if(sign == -1)
{
if(current >= prev)
{
sign = 1;
bottom = prev;
}
}
else
{
if(current < prev)
{
sign = -1;
if((bottom + CONST) < prev)
report_peak();
}
}
}