Merge pull request #319 from DavidVentura/use-byte-for-ppg

Use int8_t for PPG data array
This commit is contained in:
JF002 2021-05-02 14:55:43 +02:00 committed by GitHub
commit e3ead332b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -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 */ /** Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py */
namespace { namespace {
int Compare(int* d1, int* d2, size_t count) { int Compare(int8_t* d1, int8_t* d2, size_t count) {
int e = 0; int e = 0;
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
auto d = d1[i] - d2[i]; auto d = d1[i] - d2[i];
@ -20,11 +20,11 @@ namespace {
return e; 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); 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 z2 = CompareShift(d, mn - 2, size);
auto z1 = CompareShift(d, mn - 1, size); auto z1 = CompareShift(d, mn - 1, size);
for (int i = mn; i < mx + 1; i++) { 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} { 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 -= offset;
spl = hpf.Step(spl); spl = hpf.Step(spl);
spl = agc.Step(spl); spl = agc.Step(spl);
spl = lpf.Step(spl); spl = lpf.Step(spl);
auto spl_int = static_cast<int>(spl); auto spl_int = static_cast<int8_t>(spl);
if (dataIndex < 200) if (dataIndex < 200)
data[dataIndex++] = spl_int; data[dataIndex++] = spl_int;

View File

@ -10,14 +10,14 @@ namespace Pinetime {
public: public:
explicit Ppg(float spl); explicit Ppg(float spl);
int Preprocess(float spl); int8_t Preprocess(float spl);
float HeartRate(); float HeartRate();
void SetOffset(uint16_t i); void SetOffset(uint16_t i);
void Reset(); void Reset();
private: private:
std::array<int, 200> data; std::array<int8_t, 200> data;
size_t dataIndex = 0; size_t dataIndex = 0;
float offset; float offset;
Biquad hpf; Biquad hpf;
@ -27,4 +27,4 @@ namespace Pinetime {
float ProcessHeartRate(); float ProcessHeartRate();
}; };
} }
} }