Closed Kameeno closed 5 years ago
Hi, thanks for your interest! I guess you mean using the code within the Arduino framework for ESP32. I'm not an expert in peak detection, but I would check there is a maximum and that the neighboring bins are smaller, then check how stable the maximum is over time (over a few frames, as long as you expect your signal to be). There are several peak detection codes you could use for inspiration available online I think (e.g., here's a python one).
About the speed difference, there might be different compile options selected by the ESP-IDF and the Arduino IDE. If debug is enabled, the code will run slower. Also, the speed options -O2
or -O3
should be selected for maximum speed.
hi! thanks a lot for your answer, yesterday i found this : https://github.com/whyengineer/esp32-lin is a kind of ARM CMSIS libraries porting for xtensa (?) i tested it, it's very cool and really really fast! to detect my frequency peak from my buffer array of 4096 samples takes only 7ms! 2048 in 3ms! there's also Finite Impulse Response functions, lot of cool stuff to do with! :)
@Kameeno Thanks for the pointer. This looks like a useful library! Do I read correctly that the code I wrote is still faster though ? Or did you test it in the Arduino IDE ?
Closing this. Do not hesitate to re-open if necessary.
Closing this. Do not hesitate to re-open if necessary.
hi! thanks a lot for your answer, yesterday i found this : https://github.com/whyengineer/esp32-lin is a kind of ARM CMSIS libraries porting for xtensa (?) i tested it, it's very cool and really really fast! to detect my frequency peak from my buffer array of 4096 samples takes only 7ms!
Could you post some example on how you achieved these?
Hi Robin! i'm very interested to fork and port it on Arduino, for now i'm running this on ESP-IDF sdk but.. i don't have much experience on FFT but... what you think is the best way to implement a frequency Peak Detection? Thanks for your help.
ps. i tried on on Arduino environment, i don't understand the reason but the benchmark results are slower than the firmware compiled on C in ESP-IDF
arduino
// Now measure execution time tStart = millis(); digitalWrite(GPIO_OUTPUT, 1); for (k = 0 ; k < REP ; k++) fft_execute(fft_analysis); digitalWrite(GPIO_OUTPUT, 0); printf(" FFT size=%d runtime=%d ms\n", NFFT, (millis() - tStart));
' FFT size=64 runtime=2 ms iFFT size=64 runtime=3 ms Transform seems to work! FFT size=128 runtime=5 ms iFFT size=128 runtime=6 ms Transform seems to work! FFT size=256 runtime=10 ms iFFT size=256 runtime=12 ms Transform seems to work! FFT size=512 runtime=21 ms iFFT size=512 runtime=27 ms Transform seems to work! FFT size=1024 runtime=48 ms iFFT size=1024 runtime=58 ms Transform seems to work! FFT size=2048 runtime=104 ms iFFT size=2048 runtime=126 ms Transform seems to work! FFT size=4096 runtime=225 ms iFFT size=4096 runtime=269 ms Transform seems to work! Real FFT size=64 runtime=1 ms Real iFFT size=64 runtime=1 ms Transform seems to work! Real FFT size=128 runtime=3 ms Real iFFT size=128 runtime=3 ms Transform seems to work! Real FFT size=256 runtime=5 ms Real iFFT size=256 runtime=7 ms Transform seems to work! Real FFT size=512 runtime=12 ms Real iFFT size=512 runtime=15 ms Transform seems to work! Real FFT size=1024 runtime=26 ms Real iFFT size=1024 runtime=32 ms Transform seems to work! Real FFT size=2048 runtime=57 ms Real iFFT size=2048 runtime=69 ms Transform seems to work! Real FFT size=4096 runtime=123 ms Real iFFT size=4096 runtime=146 ms'
' FFT size=64 runtime=0.018380 ms iFFT size=64 runtime=0.027940 ms Transform seems to work! FFT size=128 runtime=0.041850 ms iFFT size=128 runtime=0.058130 ms Transform seems to work! FFT size=256 runtime=0.095090 ms iFFT size=256 runtime=0.125000 ms Transform seems to work! FFT size=512 runtime=0.211900 ms iFFT size=512 runtime=0.269020 ms Transform seems to work! FFT size=1024 runtime=0.469330 ms iFFT size=1024 runtime=0.580850 ms Transform seems to work! FFT size=2048 runtime=1.028650 ms iFFT size=2048 runtime=1.249040 ms Transform seems to work! FFT size=4096 runtime=2.239450 ms iFFT size=4096 runtime=2.677460 ms Transform seems to work! Real FFT size=64 runtime=0.010620 ms Real iFFT size=64 runtime=0.016860 ms Transform seems to work! Real FFT size=128 runtime=0.024330 ms Real iFFT size=128 runtime=0.034250 ms Transform seems to work! Real FFT size=256 runtime=0.053820 ms Real iFFT size=256 runtime=0.070890 ms Transform seems to work! Real FFT size=512 runtime=0.119000 ms Real iFFT size=512 runtime=0.150520 ms Transform seems to work! Real FFT size=1024 runtime=0.259810 ms Real iFFT size=1024 runtime=0.320190 ms Transform seems to work! Real FFT size=2048 runtime=0.565280 ms Real iFFT size=2048 runtime=0.683220 ms Transform seems to work! Real FFT size=4096 runtime=1.220650 ms Real iFFT size=4096 runtime=1.453830 ms'
Arduino Millis() does not return milliseconds value?