SofaPirate / Plaquette

Object-oriented Arduino library for creative physical computing
https://sofapirate.github.io/Plaquette/
GNU General Public License v3.0
15 stars 4 forks source link

Develop #117

Open possibly-human opened 2 months ago

possibly-human commented 2 months ago

PeakDetector was not triggering correctly when in apex mode (PEAK_MAX, PEAK_MIN). It would trigger at the moment of crossing the triggerThreshold (behaving like crossing mode) rather than triggering when falling back beyond the fallbackTolerance.

peak_test_0

The issue was due to _peakValue being reset to -FLT_MIN when fallingBack was true, but then immediately taking on the value of the next value at the next step :

  if (isMax)
    _peakValue = value;

(because value is always higher than -FLT_MIN, so isMax is true!)

Issue was fixed by adding if (_crossing) conditional to ensure that _peakValue will only be updated again after the next crossing.

  if (isMax && _crossing)
    _peakValue = value;

peak_test_simulator