Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Øyvind Kolås
firmware
Commits
c2be6b7a
Commit
c2be6b7a
authored
Apr 10, 2020
by
schneider
Browse files
fix(spo2): Use IIR filter for offset removal
parent
2db1e62e
Changes
1
Hide whitespace changes
Inline
Side-by-side
preload/apps/spo2/__init__.py
View file @
c2be6b7a
...
...
@@ -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
:]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment