Skip to content

Commit 4f7d5ac

Browse files
committed
renamed files and defined new frequency macros
1 parent 0205297 commit 4f7d5ac

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,21 @@ void get_oxygen_level(float *ppg_ir, float *ppg_red, int data_size, float *oxyge
3030
detrend (red_raw, data_size, (int)DetrendOperations::CONSTANT);
3131
detrend (ir_raw, data_size, (int)DetrendOperations::CONSTANT);
3232

33-
const double start_f = 0.7;
34-
const double stop_f = 1.5;
35-
36-
auto start_filter = butter<FILTER_ORDER>(2 * start_f / FILTER_SAMPLING_RATE);
37-
auto stop_filter = butter<FILTER_ORDER>(2 * stop_f / FILTER_SAMPLING_RATE);
33+
auto high_pass = butter<FILTER_ORDER>(2 * START_FREQUENCY / FILTER_SAMPLING_RATE);
34+
auto low_pass = butter<FILTER_ORDER>(2 * STOP_FREQUENCY / FILTER_SAMPLING_RATE);
3835

3936
for (int i = 0; i < data_size; i++) {
40-
red_raw[i] = red_raw[i] - start_filter(red_raw[i]);
41-
red_raw[i] = stop_filter(red_raw[i]);
37+
red_raw[i] = red_raw[i] - high_pass(red_raw[i]);
38+
red_raw[i] = low_pass(red_raw[i]);
4239
}
4340

4441
// TODO better way to reset internal state of filters?
45-
start_filter = butter<FILTER_ORDER>(2 * start_f / FILTER_SAMPLING_RATE);
46-
stop_filter = butter<FILTER_ORDER>(2 * stop_f / FILTER_SAMPLING_RATE);
42+
high_pass = butter<FILTER_ORDER>(2 * START_FREQUENCY / FILTER_SAMPLING_RATE);
43+
low_pass = butter<FILTER_ORDER>(2 * STOP_FREQUENCY / FILTER_SAMPLING_RATE);
4744

4845
for (int i = 0; i < data_size; i++) {
49-
ir_raw[i] = ir_raw[i] - start_filter(ir_raw[i]);
50-
ir_raw[i] = stop_filter(ir_raw[i]);
46+
ir_raw[i] = ir_raw[i] - high_pass(ir_raw[i]);
47+
ir_raw[i] = low_pass(ir_raw[i]);
5148
}
5249

5350
// calculate AC & DC components using mean & rms:
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#ifndef SPO2_ALGORITHM_H
22
#define SPO2_ALGORITHM_H
33

4-
#include <math.h>
4+
#include <cmath>
55
#include <string.h>
66
#include <stdlib.h>
77

88
#include <Filters.h>
9-
#include <AH/Timing/MillisMicrosTimer.hpp>
109
#include <Filters/Butterworth.hpp>
1110

1211
// These constants are from Table 1 (https://www.analog.com/en/resources/technical-articles/guidelines-for-spo2-measurement--maxim-integrated.html)
@@ -17,6 +16,9 @@
1716
#define FILTER_SAMPLING_RATE 50 // Hz
1817
#define FILTER_ORDER 4
1918

19+
#define START_FREQUENCY 0.7 // Hz
20+
#define STOP_FREQUENCY 1.5 // Hz
21+
2022
enum class DetrendOperations : int
2123
{
2224
NO_DETREND = 0,

0 commit comments

Comments
 (0)