AudioKit FFT conversion to dB?
Asked Answered
D

2

6

First time posting, thanks for the great community!

I am using AudioKit and trying to add frequency weighting filters to the microphone input and so I am trying to understand the values that are coming out of the AudioKit AKFFTTap.

Currently I am trying to just print the FFT buffer converted into dB values

for i in 0..<self.bufferSize {
    let db = 20 * log10((self.fft?.fftData[Int(i)])!)
    print(db)
}

I was expecting values ranging in the range of about -128 to 0, but I am getting strange values of nearly -200dB and when I blow on the microphone to peg out the readings it only reaches about -60. Am I not approaching this correctly? I was assuming that the values being output from the EZAudioFFT engine would be plain amplitude values and that the normal dB conversion math would work. Anyone have any ideas?

Thanks in advance for any discussion about this issue!

Dialectical answered 1/11, 2017 at 22:35 Comment(3)
hey, Dan Jensen have achieved the solution of this question? cuz i have the same question as ur questionExtrasensory
Hi Paulo, I actually was never able to make this work correctly in AudioKit. AudioKit is amazing but I have found a different solution that works better for my situation called Superpowered. I was able to make that one work the way I expected for this application. superpowered.comDialectical
did you achieved to solution did you get dB(A)?Unconquerable
C
4

You need to add all of the values from self.fft?.fftData (consider changing negative values to positive before adding) and then change that to decibels

Cutlerr answered 14/11, 2017 at 14:33 Comment(2)
I have tried your idea of summing the absolute values in self.fft?.fftData and I definitely get a more reasonable result, however, the results are still way too sensitive. To test this I am adding an offset value to get the readings to match a dedicated SPL meter I have here at my desk. And if I talk, whistle, blow, or generate pink noise and compare results, my app jumps 40dB+ while the SPL meter only increases by 7-10 dB. I compared to some iOS apps for viewing dB readings and they seem to have similar results with the SPL meter. Any ideas why this would be so much more sensitive?Dialectical
how much samples are you using for one calculation? full buffer? i was using standard Tap, i have no experience with AKFFTTap so maybe i'm missing somethingCutlerr
V
4

The values in the array correspond to the values of the bins in the FFT. Having a single bin contain a magnitude value close to 1 would mean that a great amount of energy is in that narrow frequency band e.g. a very loud sinusoid (a signal with a single frequency).

Normal sounds, such as the one caused by you blowing on the mic, spread their energy across the entire spectrum, that is, in many bins instead of just one. For this reason, usually the magnitudes get lower as the FFT size increases.

Magnitude of -40dB on a single bin is quite loud. If you try to play a tone, you should see a clear peak in one of the bins.

Violone answered 15/11, 2017 at 20:23 Comment(2)
In AudioKit, the bin values are not in a scale of 0-1 they are magnitudes that can contain values from zero to upwards of 700-1000. If I could get this into a scale of 0-1 that would help greatly, but I don't see how to do that without a clear maximum value for reference. I was blowing on the mic to try and obtain that reference, but there was never a consistent upper end to the magnitudes produced by the fft.Dialectical
Your question gives the impression that the values are in range 0..1, only closer to 0 than you expect.Violone

© 2022 - 2024 — McMap. All rights reserved.