1

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.

Kaminari
  • 1,387
  • 3
  • 17
  • 32
  • 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 Aug 26 '17 at 16:57
  • 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 Aug 27 '17 at 04:52

1 Answers1

0

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
user3386109
  • 34,287
  • 7
  • 49
  • 68
  • Not exactly, there may be samples that are: `300 300 500 700 900 700 500 300 300`, that would be considered a peak but none of them will be over 270W – Kaminari Aug 26 '17 at 18:40
  • @Kaminari Direct quote from your question: *"Has static thresholds - detects peaks that are over 270 Watts "* – user3386109 Aug 26 '17 at 19:16
  • Yes but whole peaks, not a difference between two points. I meant whole peaks. – Kaminari Aug 26 '17 at 21:28