port oxullo library Arduino

Dependents:   MAX30100_oxullo

Committer:
AVELARDEV
Date:
Fri Nov 25 00:52:54 2016 +0000
Revision:
0:010b908e2187
max30100 example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AVELARDEV 0:010b908e2187 1 /*
AVELARDEV 0:010b908e2187 2 Arduino-MAX30100 oximetry / heart rate integrated sensor library
AVELARDEV 0:010b908e2187 3 Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org>
AVELARDEV 0:010b908e2187 4 This program is free software: you can redistribute it and/or modify
AVELARDEV 0:010b908e2187 5 it under the terms of the GNU General Public License as published by
AVELARDEV 0:010b908e2187 6 the Free Software Foundation, either version 3 of the License, or
AVELARDEV 0:010b908e2187 7 (at your option) any later version.
AVELARDEV 0:010b908e2187 8 This program is distributed in the hope that it will be useful,
AVELARDEV 0:010b908e2187 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
AVELARDEV 0:010b908e2187 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
AVELARDEV 0:010b908e2187 11 GNU General Public License for more details.
AVELARDEV 0:010b908e2187 12 You should have received a copy of the GNU General Public License
AVELARDEV 0:010b908e2187 13 along with this program. If not, see <http://www.gnu.org/licenses/>.
AVELARDEV 0:010b908e2187 14 */
AVELARDEV 0:010b908e2187 15
AVELARDEV 0:010b908e2187 16 #ifndef MAX30100_BEATDETECTOR_H
AVELARDEV 0:010b908e2187 17 #define MAX30100_BEATDETECTOR_H
AVELARDEV 0:010b908e2187 18
AVELARDEV 0:010b908e2187 19 #include "mbed.h"
AVELARDEV 0:010b908e2187 20 #include <stdint.h>
AVELARDEV 0:010b908e2187 21 #include <algorithm>
AVELARDEV 0:010b908e2187 22
AVELARDEV 0:010b908e2187 23 #define BEATDETECTOR_INIT_HOLDOFF 2000 // in ms, how long to wait before counting
AVELARDEV 0:010b908e2187 24 #define BEATDETECTOR_MASKING_HOLDOFF 200 // in ms, non-retriggerable window after beat detection
AVELARDEV 0:010b908e2187 25 #define BEATDETECTOR_BPFILTER_ALPHA 0.6 // EMA factor for the beat period value
AVELARDEV 0:010b908e2187 26 #define BEATDETECTOR_MIN_THRESHOLD 20 // minimum threshold (filtered) value
AVELARDEV 0:010b908e2187 27 #define BEATDETECTOR_MAX_THRESHOLD 800 // maximum threshold (filtered) value
AVELARDEV 0:010b908e2187 28 #define BEATDETECTOR_STEP_RESILIENCY 30 // maximum negative jump that triggers the beat edge
AVELARDEV 0:010b908e2187 29 #define BEATDETECTOR_THRESHOLD_FALLOFF_TARGET 0.3 // thr chasing factor of the max value when beat
AVELARDEV 0:010b908e2187 30 #define BEATDETECTOR_THRESHOLD_DECAY_FACTOR 0.99 // thr chasing factor when no beat
AVELARDEV 0:010b908e2187 31 #define BEATDETECTOR_INVALID_READOUT_DELAY 2000 // in ms, no-beat time to cause a reset
AVELARDEV 0:010b908e2187 32 #define BEATDETECTOR_SAMPLES_PERIOD 10 // in ms, 1/Fs
AVELARDEV 0:010b908e2187 33
AVELARDEV 0:010b908e2187 34
AVELARDEV 0:010b908e2187 35 typedef enum BeatDetectorState {
AVELARDEV 0:010b908e2187 36 BEATDETECTOR_STATE_INIT,
AVELARDEV 0:010b908e2187 37 BEATDETECTOR_STATE_WAITING,
AVELARDEV 0:010b908e2187 38 BEATDETECTOR_STATE_FOLLOWING_SLOPE,
AVELARDEV 0:010b908e2187 39 BEATDETECTOR_STATE_MAYBE_DETECTED,
AVELARDEV 0:010b908e2187 40 BEATDETECTOR_STATE_MASKING
AVELARDEV 0:010b908e2187 41 } BeatDetectorState;
AVELARDEV 0:010b908e2187 42
AVELARDEV 0:010b908e2187 43
AVELARDEV 0:010b908e2187 44 class BeatDetector
AVELARDEV 0:010b908e2187 45 {
AVELARDEV 0:010b908e2187 46 public:
AVELARDEV 0:010b908e2187 47 BeatDetector();
AVELARDEV 0:010b908e2187 48 bool addSample(float sample);
AVELARDEV 0:010b908e2187 49 float getRate();
AVELARDEV 0:010b908e2187 50 float getCurrentThreshold();
AVELARDEV 0:010b908e2187 51
AVELARDEV 0:010b908e2187 52 private:
AVELARDEV 0:010b908e2187 53 bool checkForBeat(float value);
AVELARDEV 0:010b908e2187 54 void decreaseThreshold();
AVELARDEV 0:010b908e2187 55
AVELARDEV 0:010b908e2187 56 BeatDetectorState state;
AVELARDEV 0:010b908e2187 57 float threshold;
AVELARDEV 0:010b908e2187 58 float beatPeriod;
AVELARDEV 0:010b908e2187 59 float lastMaxValue;
AVELARDEV 0:010b908e2187 60 uint32_t tsLastBeat;
AVELARDEV 0:010b908e2187 61 Timer t;
AVELARDEV 0:010b908e2187 62 };
AVELARDEV 0:010b908e2187 63
AVELARDEV 0:010b908e2187 64 #endif