@@ -19,7 +19,8 @@ namespace {
1919
2020constexpr float ALPHA{0 .95f }; // for removeDC
2121
22- void calculateButterworthCoefficients (float Fs, float Fc, float & a0, float & a1, float & b1) {
22+ void calculateButterworthCoefficients (float Fs, float Fc, float & a0, float & a1, float & b1)
23+ {
2324 float tanWc = std::tan (M_PI * Fc / Fs);
2425 float sqrt2 = std::sqrt (2 .0f );
2526
@@ -28,14 +29,16 @@ void calculateButterworthCoefficients(float Fs, float Fc, float& a0, float& a1,
2829 b1 = (tanWc - sqrt2) / (tanWc + sqrt2);
2930}
3031
31- inline dcFilter_t removeDC (const float x, const float prev_w, const float alpha) {
32+ inline dcFilter_t removeDC (const float x, const float prev_w, const float alpha)
33+ {
3234 dcFilter_t filtered;
3335 filtered.w = x + alpha * prev_w;
3436 filtered.result = filtered.w - prev_w;
3537 return filtered;
3638}
3739
38- float meanDiff (const float M, meanDiffFilter_t& filterValues) {
40+ float meanDiff (const float M, meanDiffFilter_t& filterValues)
41+ {
3942 float avg{};
4043
4144 filterValues.sum -= filterValues.values [filterValues.index ];
@@ -53,7 +56,8 @@ float meanDiff(const float M, meanDiffFilter_t& filterValues) {
5356 return avg - M;
5457}
5558
56- void lowPassButterworthFilter (const float x, butterworthFilter_t& fr) {
59+ void lowPassButterworthFilter (const float x, butterworthFilter_t& fr)
60+ {
5761 fr.v [0 ] = fr.v [1 ];
5862 fr.v [1 ] = (fr.a0 * x) + (fr.a1 * fr.v [0 ]) - (fr.b1 * fr.v [1 ]);
5963 fr.result = fr.v [0 ] + fr.v [1 ];
@@ -75,21 +79,24 @@ namespace m5 {
7579namespace max30100 {
7680
7781HeartRate::HeartRate (const uint32_t srate, const float threshold, const size_t max_data_size)
78- : _sampleRate{(float )srate}, _threshold(threshold), _maxDataSize{max_data_size} {
82+ : _sampleRate{(float )srate}, _threshold(threshold), _maxDataSize{max_data_size}
83+ {
7984 assert (srate && " SampleRate must not be zero" );
8085 if (!max_data_size) {
8186 _maxDataSize = (size_t )srate * 30U ;
8287 }
8388 calculateButterworthCoefficients (_sampleRate, 10 .0f , _bwfIR.a0 , _bwfIR.a1 , _bwfIR.b1 );
8489}
8590
86- void HeartRate::setSampleRate (const uint32_t sr) {
91+ void HeartRate::setSampleRate (const uint32_t sr)
92+ {
8793 _sampleRate = sr;
8894 calculateButterworthCoefficients (_sampleRate, 10 .0f , _bwfIR.a0 , _bwfIR.a1 , _bwfIR.b1 );
8995 clear ();
9096}
9197
92- void HeartRate::clear () {
98+ void HeartRate::clear ()
99+ {
93100 _dataIR.clear ();
94101 _peakDowns.clear ();
95102 _incrasing = false ;
@@ -99,7 +106,8 @@ void HeartRate::clear() {
99106 calculateButterworthCoefficients (_sampleRate, 10 .0f , _bwfIR.a0 , _bwfIR.a1 , _bwfIR.b1 );
100107}
101108
102- bool HeartRate::push_back (const float ir, const float red) {
109+ bool HeartRate::push_back (const float ir, const float red)
110+ {
103111 // Filtering (IR)
104112 _dcIR = removeDC (ir, _dcIR.w , ALPHA);
105113 // M5_LIB_LOGI("\n>ACIR:%f", _dcIR.result);
@@ -136,7 +144,8 @@ bool HeartRate::push_back(const float ir, const float red) {
136144 return _beat;
137145}
138146
139- float HeartRate::calculate () const {
147+ float HeartRate::calculate () const
148+ {
140149 if (_peakDowns.size () < 2 ) {
141150 return 0 .0f ;
142151 }
@@ -149,7 +158,8 @@ float HeartRate::calculate() const {
149158 return 1 .0f / avg * 60000 .0f ;
150159}
151160
152- bool HeartRate::detect_beat () {
161+ bool HeartRate::detect_beat ()
162+ {
153163 auto now = m5::utility::millis ();
154164 bool beat{};
155165
0 commit comments