FFT for spectrum analyzer #435
Replies: 7 comments 13 replies
-
If I remember right, length 1024 gives 512 bins. The size() method will give you the number of bins
https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_f_f_t_base.html
… On 1 Nov 2022, at 16:36, venquessa ***@***.***> wrote:
Hi all!
(Hi Phil, we spoke briefly via email, "Paul" here.).
I am hoping to write a spectrum analyser for a "toe dipping" project with ESP32 Audio and a WS2812b matrix.
I did get the AudioKitFFT project sample up and running, but I was stumped on how to "choose" which "bands" I wanted for the analyser. Ideally, I thought I would want 32 bands for 32 columns of 8 LEDs.
Looking first at the code in the example and in the library behind it I thought I needed a "Window" function. That appeared to be a dead end. In my day job a Window function is a completely different thing :)
I was almost at the point where I would need to blow dust off my maths skills and go learning how FFTs work.
Thankfully I found this video: https://www.youtube.com/watch?v=Mgh2WblO5_c <https://www.youtube.com/watch?v=Mgh2WblO5_c>
Straight up described exactly my issue and the gap in communications and understanding around "the bands" or "bins" in the library code.
I haven't tried it yet, but the number of frequencies in the results is determined by the length of samples used.
total bins = Number of Samples / 2
However, half of the bins are unrelated to amplitude so, it's really "number of samples / 4"
It also quickly becomes apparent when you consider "psycho-acoustics" that I don't want 32 bins. As mentioned in the video the upper frequencies are less interesting to use than the lower ones. (I believe this is also taken into account when doing the 32-band pass filter in mp3-encoding?). So aiming for a multiple of "bins per band", such that bins can be grouped (added or averaged) together with more bins assigned to the lower bands than the upper bands. (the video presents a spreadsheet for working this out).
As a suggestion, the wiki page could elaborate a little on the point covering this:
The length defines the number of samples that are used to run the FFT. The length must be a value of the power of 2 (e.g. 1024). This parameter impacts
the calculation speed and frequency of calculation
the memory which is needed
- the frequency resolution of the result
Which is what I was actually after and looked straight past it. Maybe an example?
Length 1024 = 256 bins.
Freq 48kHz = ~ 90Hz bin spacing.
If that is right?
Cheers.
—
Reply to this email directly, view it on GitHub <#435>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAP3RRCW6EOUMHAK3R3CXZTWGE2ILANCNFSM6AAAAAARUFRPOI>.
You are receiving this because you are subscribed to this thread.
|
Beta Was this translation helpful? Give feedback.
-
I created a small test sketch, but I can't reproduce your issues: form me it's working like a charm... |
Beta Was this translation helpful? Give feedback.
-
Hey @pschatzmann I'm trying to load your basic-a2dp-fft.ino from the Audio Tools Library using Platform IO but I after numerous attempts I have never been able to successful to get the code to compile. What is the minimum required to get this basic-a2dp-fft.ino sketch to run inside Platform.IO on ESP32? Really really wanting this spectrum analyzer feature to work so it can display on the nice LCD screen along with the track info. Any help with this is greatly appreciated. |
Beta Was this translation helpful? Give feedback.
-
I don't see any reason why this should not work. |
Beta Was this translation helpful? Give feedback.
-
Just use the platformio.ini described in the Wiki and add all necessary dependencies. In your case this would be at least
But I can't guess what exact other libraries you intend to use... If you use AudioEspressifFFT or AudioRealFFT there is nothing to install for FFT. If you use an other FFT library, you will need to add that as well. The details can be found in the documentation! ps. Only if you share your errors, I will be able to help you! |
Beta Was this translation helpful? Give feedback.
-
I was testing with AudioRealFFT and it was compiling w/o any errors...
And platformio.ini
ps. I changed the example to use AudioRealFFT so that there is no need for any additional library... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all!
(Hi Phil, we spoke briefly via email, "Paul" here.).
I am hoping to write a spectrum analyser for a "toe dipping" project with ESP32 Audio and a WS2812b matrix.
I did get the AudioKitFFT project sample up and running, but I was stumped on how to "choose" which "bands" I wanted for the analyser. Ideally, I thought I would want 32 bands for 32 columns of 8 LEDs.
Looking first at the code in the example and in the library behind it I thought I needed a "Window" function. That appeared to be a dead end. In my day job a Window function is a completely different thing :)
I was almost at the point where I would need to blow dust off my maths skills and go learning how FFTs work.
Thankfully I found this video: https://www.youtube.com/watch?v=Mgh2WblO5_c
Straight up described exactly my issue and the gap in communications and understanding around "the bands" or "bins" in the library code.
I haven't tried it yet, but the number of frequencies in the results is determined by the length of samples used.
total bins = Number of Samples / 2
However, half of the bins are unrelated to amplitude so, it's really "number of samples / 4"
It also quickly becomes apparent when you consider "psycho-acoustics" that I don't want 32 bins. As mentioned in the video the upper frequencies are less interesting to use than the lower ones. (I believe this is also taken into account when doing the 32-band pass filter in mp3-encoding?). So aiming for a multiple of "bins per band", such that bins can be grouped (added or averaged) together with more bins assigned to the lower bands than the upper bands. (the video presents a spreadsheet for working this out).
As a suggestion, the wiki page could elaborate a little on the point covering this:
Which is what I was actually after and looked straight past it. Maybe an example?
Length 1024 = 256 bins.
Freq 48kHz = ~ 90Hz bin spacing.
If that is right?
Cheers.
Beta Was this translation helpful? Give feedback.
All reactions