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!

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
Dan Jensen
  • 61
  • 4
  • hey, Dan Jensen have achieved the solution of this question? cuz i have the same question as ur question – Mahesh Dangar Sep 12 '18 at 12:53
  • 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. https://superpowered.com – Dan Jensen Sep 13 '18 at 14:02
  • did you achieved to solution did you get dB(A)? – NLU Apr 05 '20 at 22:16

2 Answers2

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

Lu_
  • 2,577
  • 16
  • 24
  • 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? – Dan Jensen Nov 15 '17 at 20:48
  • 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 something – Lu_ Nov 16 '17 at 10:27
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.

Matti Jokipii
  • 561
  • 1
  • 6
  • 20
  • 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. – Dan Jensen Nov 15 '17 at 20:29
  • Your question gives the impression that the values are in range 0..1, only closer to 0 than you expect. – Matti Jokipii Nov 16 '17 at 21:38