Signal processing (main frequency)

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
mfilip
Posts: 3
Joined: Tue Dec 11, 2018 11:50 am

Signal processing (main frequency)

Post by mfilip » Tue Dec 11, 2018 1:24 pm

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

User avatar
Roberthh
Posts: 1518
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Signal processing (main frequency)

Post by Roberthh » Tue Dec 11, 2018 1:39 pm

@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.

mfilip
Posts: 3
Joined: Tue Dec 11, 2018 11:50 am

Re: Signal processing (main frequency)

Post by mfilip » Tue Dec 11, 2018 3:04 pm

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'

User avatar
Roberthh
Posts: 1518
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Signal processing (main frequency)

Post by Roberthh » Tue Dec 11, 2018 3:18 pm

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.

User avatar
pythoncoder
Posts: 3509
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Signal processing (main frequency)

Post by pythoncoder » Wed Dec 12, 2018 7:24 am

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.
Peter Hinch

mfilip
Posts: 3
Joined: Tue Dec 11, 2018 11:50 am

Re: Signal processing (main frequency)

Post by mfilip » Thu Dec 13, 2018 11:13 am

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.

Post Reply