guild icon
Toit
#How to implement an average filter ? (solved)
Thread channel in help
kaxori
kaxori 06/26/2023 05:54 PM
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 ?
theHuanter
theHuanter 06/26/2023 06:13 PM
I recently made a little package for a ringbuffer which has the function to average its values
🤩1
theHuanter
theHuanter 06/26/2023 06:13 PM
A RingBuffer implementation as a data structure that stores a fixed number of elements and overwrites the oldest elements once the maximum size is reached. - GitHub - Informaticore/toit-ringbuffer:...
floitsch
floitsch 06/26/2023 06:20 PM
I think the average in your code is correct.
floitsch
floitsch 06/26/2023 06:20 PM
Just be careful that the way you use reduce requires at least two elements.
floitsch
floitsch 06/26/2023 06:21 PM
If you use --initial=0 (or a different value, depending on the context), then you can also call reduce with just one function.
floitsch
floitsch 06/26/2023 06:22 PM
nit: generally, we don't add a space after the reduce. So it should be reduce: | a b | ....
floitsch
floitsch 06/26/2023 06:23 PM
aah. I can see you are actually using your own reduce, not the one from List.
floitsch
floitsch 06/26/2023 06:24 PM
And I'm now realizing I didn't actually answer to the original question...
😅1
theHuanter
theHuanter 06/26/2023 06:24 PM
but feel free to open an issue or something so the input does not get lost
theHuantertheHuanter
but feel free to open an issue or something so the input does not get lost
floitsch
floitsch 06/26/2023 06:28 PM
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.
kaxoriOPkaxori
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 i...
floitsch
floitsch 06/26/2023 06:30 PM
Note that the Adc.get function already runs 64 samples and averages them.
You can change that by passing in --samples=1 (for example).
floitschfloitsch
Note that the Adc.get function already runs 64 samples and averages them. You can change that by passing in --samples=1 (for example).
kaxori
kaxori 06/26/2023 06:40 PM
Magical: on page https://libs.toit.io/gpio/adc/class-Adc, where can i find such conceptual infos?
floitsch
floitsch 06/26/2023 06:40 PM
Get Started with Toit This document provides simple instructions on how to get started with Toit. It is loosely inspired by Makerfab's MicroPython course and uses the same hardware. In Europe the kits are available here: https://hitechchain.se/en/makerfabs/29-iot/makepython-esp32-dev-kit If you ...
floitsch
floitsch 06/26/2023 06:41 PM
I'm in the process of porting that document to docs.toit.io
floitsch
floitsch 06/26/2023 06:41 PM
(it's literally the tutorial I'm porting over right now).
kaxori
kaxori 06/26/2023 06:44 PM
:🤩: thank you ... reading now
(please continue porting ... :😉: )
floitsch
floitsch 06/26/2023 06:45 PM
preview:
kaxoriOPkaxori
:🤩: thank you ... reading now (please continue porting ... :😉: )
floitsch
floitsch 06/26/2023 06:47 PM
You have commenting rights on that document.
floitsch
floitsch 06/26/2023 06:47 PM
If something isn't clear feel free to add a comment.
theHuantertheHuanter
kaxori
kaxori 06/27/2023 06:34 AM
thank for your exemplary implementation. Particulary the tests I like !
❤️1
22 messages in total