1
votes

I was searching for some effective peak counter algorithm but couldn't find one that suits my needs:

  • C-like language (it will be in PHP but I could translate from JS/C/Cpp)
  • Data is not traversable forward
  • Has static thresholds - detects peaks that are over 270 Watts AND those peaks are short so there is also a time restriction.

I already checked here: Peak signal detection in realtime timeseries data But that does not seem to be a viable solution for me.

Here is some example data: example chart

Data has following format:

$a = [
    'timestamp' = 1500391300.342
    'power' => 383.87
];

On this chart there are 14 peaks. So i need algorithm to count them in loop. Surprisingly each peak can have more than 10 points. Peak is continuous array that keeps filling itself. There is access to at least 100 previous points but there is no access to future data.

I have also prepared Calc (ODC) document with 15 peaks and some example data. Here it is

Spreadsheet

So far I have simple algorithm that counts rising slopes but that does not work correctly (because there may be no slope over 270W, it may be divided to 5 points or jump may be too long to count as peak):

if ($previousLog['power'] - $deviceLog['power'] > 270) {
    $numberShots++;
}

Thanks in advance, any tips could be help.

1
Unclear: are you asking for a library recommendation (off-topic), a critique of the 3 lines of posted code or someone to write the code for you (also off- topic)? - Richard Critten
either library recommendation or ready algorithm (that already exists), i'm not asking for someone to write code for me but algorithms from pure math languages are not easily translatable to C-like language - Kaminari

1 Answers

0
votes

Simple hysteresis should work:

  1. Find a sample that is above 270W
  2. While sample are above 240W keep track of the largest sample seen, and its timestamp
  3. When you find a sample that is below 240W, go back to step 1