InfiniTime.git

ref: 0ce98c7ac7ba66acaf504be9bb042796e12f2733

src/components/heartrate/Ptagc.cpp


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
  SPDX-License-Identifier: LGPL-3.0-or-later
  Original work Copyright (C) 2020 Daniel Thompson
  C++ port Copyright (C) 2021 Jean-François Milants
*/

#include <cmath>
#include "Ptagc.h"

using namespace Pinetime::Controllers;

/** Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py */
Ptagc::Ptagc(float start, float decay, float threshold) : peak {start}, decay {decay}, boost {1.0f / decay}, threshold {threshold} {
}

float Ptagc::Step(float spl) {
  if (std::abs(spl) > peak)
    peak *= boost;
  else
    peak *= decay;

  if ((spl > (peak * threshold)) || (spl < (peak * -threshold)))
    return 0.0f;

  spl = 100.0f * spl / (2.0f * peak);
  return spl;
}