Page 1 of 1

Signal processing (main frequency)

Posted: Tue Dec 11, 2018 1:24 pm
by mfilip
Hi all,
I work on my new project "touch free breathing monitor". I have used ESP32 and vl53l0x TOF IR Laser ranging module. Now I have nice sine like data series (distance from chest) and I would like to get main frequency to show it on a monitor. And this is the problem. FFT is not available on ESP32 platform and all python tutorials starts like ''import numpy or scipy' so also not possible in micropython. Any ideas how to solve that problem? Thanks

Re: Signal processing (main frequency)

Posted: Tue Dec 11, 2018 1:39 pm
by Roberthh
@pythoncoder has a fft script here: https://github.com/peterhinch/micropyth ... orithms.py
If you look around at that place, you'll find a lot of useful information.

Re: Signal processing (main frequency)

Posted: Tue Dec 11, 2018 3:04 pm
by mfilip
The script works well in Python 3.7 on my laptop but in Micropython are some problems with complex numbers implementation. I got AttributeError: 'float' object has no attribute 'real'

Re: Signal processing (main frequency)

Posted: Tue Dec 11, 2018 3:18 pm
by Roberthh
Complex numbers seem to be enabled in the ESP32 build. But I never worked with them. Maybe @pythoncoder knows more. He usually reads the posts in the morning and late afternoon. I will not be able to test in on and ESP32 before tomorrow.

Re: Signal processing (main frequency)

Posted: Wed Dec 12, 2018 7:24 am
by pythoncoder
The code in algorithms.py was a quick port from C which I did to verify the results from the Arm Thumb assembler code. I evidently only ever ran it under CPython ;)

I've posted a fix. It seems that under MicroPython float instances don't have a real method, whereas under CPython they do. The bug affected only the printlist function, not the FFT code itself.

Re: Signal processing (main frequency)

Posted: Thu Dec 13, 2018 11:13 am
by mfilip
Yes, it works now. But FFT is slow and maybe overkill in my case. I am going to use measuring time between zero crossing point. It should be simple to code and working in case of simple sine wave.