Merge pull request #319 from DavidVentura/use-byte-for-ppg
Use int8_t for PPG data array
This commit is contained in:
commit
e3ead332b9
2 changed files with 8 additions and 8 deletions
|
@ -11,7 +11,7 @@ using namespace Pinetime::Controllers;
|
|||
|
||||
/** Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py */
|
||||
namespace {
|
||||
int Compare(int* d1, int* d2, size_t count) {
|
||||
int Compare(int8_t* d1, int8_t* d2, size_t count) {
|
||||
int e = 0;
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
auto d = d1[i] - d2[i];
|
||||
|
@ -20,11 +20,11 @@ namespace {
|
|||
return e;
|
||||
}
|
||||
|
||||
int CompareShift(int* d, int shift, size_t count) {
|
||||
int CompareShift(int8_t* d, int shift, size_t count) {
|
||||
return Compare(d + shift, d, count - shift);
|
||||
}
|
||||
|
||||
int Trough(int* d, size_t size, float mn, float mx) {
|
||||
int Trough(int8_t* d, size_t size, uint8_t mn, uint8_t mx) {
|
||||
auto z2 = CompareShift(d, mn - 2, size);
|
||||
auto z1 = CompareShift(d, mn - 1, size);
|
||||
for (int i = mn; i < mx + 1; i++) {
|
||||
|
@ -45,13 +45,13 @@ Ppg::Ppg(float spl)
|
|||
lpf {0.11595249, 0.23190498, 0.11595249, -0.72168143, 0.18549138} {
|
||||
}
|
||||
|
||||
int Ppg::Preprocess(float spl) {
|
||||
int8_t Ppg::Preprocess(float spl) {
|
||||
spl -= offset;
|
||||
spl = hpf.Step(spl);
|
||||
spl = agc.Step(spl);
|
||||
spl = lpf.Step(spl);
|
||||
|
||||
auto spl_int = static_cast<int>(spl);
|
||||
auto spl_int = static_cast<int8_t>(spl);
|
||||
|
||||
if (dataIndex < 200)
|
||||
data[dataIndex++] = spl_int;
|
||||
|
|
|
@ -10,14 +10,14 @@ namespace Pinetime {
|
|||
public:
|
||||
explicit Ppg(float spl);
|
||||
|
||||
int Preprocess(float spl);
|
||||
int8_t Preprocess(float spl);
|
||||
float HeartRate();
|
||||
|
||||
void SetOffset(uint16_t i);
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
std::array<int, 200> data;
|
||||
std::array<int8_t, 200> data;
|
||||
size_t dataIndex = 0;
|
||||
float offset;
|
||||
Biquad hpf;
|
||||
|
@ -27,4 +27,4 @@ namespace Pinetime {
|
|||
float ProcessHeartRate();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue