How to implement an average filter ? (solved)
# help
k
Today I wanted to implement a ripple filter for the noisy ESP32 ADC data. Searched through example sources and libs, but with used keywords I was not successful. Then i tried to implement a filter, building average of n recent values stored in a list. But got compiler errors after removing oldest/first list element (values = values[1...]. Not only the language detailed, also the concepts are hard to find. Which resources do you recommend to learn to solve such simple problems ?
i
I recently made a little package for a ringbuffer which has the function to average its values
f
I think the average in your code is correct.
Just be careful that the way you use
reduce
requires at least two elements.
If you use
--initial=0
(or a different value, depending on the context), then you can also call
reduce
with just one function.
nit: generally, we don't add a space after the
reduce
. So it should be
reduce: | a b | ...
.
aah. I can see you are actually using your own
reduce
, not the one from
List
.
And I'm now realizing I didn't actually answer to the original question...
i
but feel free to open an issue or something so the input does not get lost
f
Not sure it's worth filing an issue. I would: - remove the spaces (after
reduce
). - hide
reduce
or make it more intuitive. Currently it runs from 0 to count. I would have expected it to run from oldest to newest.
Note that the
Adc.get
function already runs 64 samples and averages them. You can change that by passing in
--samples=1
(for example).
k
Magical: on page https://libs.toit.io/gpio/adc/class-Adc, where can i find such conceptual infos?
I'm in the process of porting that document to docs.toit.io
(it's literally the tutorial I'm porting over right now).
k
🤩 thank you ... reading now (please continue porting ... 😉 )
f
preview:

https://cdn.discordapp.com/attachments/1122947975623225424/1122960886542372904/image.pngâ–¾

You have commenting rights on that document.
If something isn't clear feel free to add a comment.
k
thank for your exemplary implementation. Particulary the tests I like !
2 Views