iOS FFT Draw spectrum

左心房为你撑大大i 提交于 2019-12-02 16:52:16
  1. Do I need to average magnitude values from a range of frequencies? Or do they just show you a magnitude for the specific frequency bar?

Yes, you definitely need to average values across the bands you've defined. Showing just one FFT bin is madness.

  1. Also, do I need to convert my magnitude values to db?

Yes: dB is a log scale. Not coincidentally, human hearing also works (roughly) on a log scale. The values will therefore look more natural to humans if you take log2() of the values before plotting them.

  1. How do I map my data to a certain range. Do I map against the max db range for my sounds bitdepth? Getting the max Value for a bin will lead to jumping max mapping values.

I find the easiest thing to do (conceptually at least) is to convert your values from whatever format into a 0..1, i.e. 'normalised and scaled' float value. Then from there you can convert if necessary to something you need to plot. For example

SInt16 rawValue = fft[0]; // let's say this comes back as 12990

float scaledValue = rawValue/32767.; // This is MAX_INT for 16-bit;
        // dividing we get .396435438 which is much easier for most people
        // to see conceptually as 39% of our max possible value

float displayValue = log2(scaledValue);

my_fft[0] = displayValue;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!