Skip to content
Snippets Groups Projects
Commit c2be6b7a authored by schneider's avatar schneider
Browse files

fix(spo2): Use IIR filter for offset removal

parent 2db1e62e
Branches
No related tags found
1 merge request!414SpO2 sensor improvements
......@@ -23,6 +23,7 @@ class SPO2:
self.last_sample = 0.0
self.filtered_value = 0.0
self.source = "Red"
self.average = 0
def open(self):
def callback(datasets):
......@@ -45,7 +46,9 @@ class SPO2:
while buttons.read(buttons.BOTTOM_RIGHT): pass
def update_history(self, datasets):
alpha = 0.995
for val in datasets:
"""
if self.source == "Red":
self.avg[self.avg_pos] = val.red
else:
......@@ -63,6 +66,17 @@ class SPO2:
)
self.last_sample = avg_data
self.history.append(self.filtered_value)
"""
#print("%d,%d" % (val.red, val.infrared))
if self.source == "Red":
d = val.red
else:
d = val.infrared
self.average = alpha * self.average + (1 - alpha) * d
d -= self.average
self.history.append(d)
# trim old elements
self.history = self.history[-self.HISTORY_MAX :]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment