iOS FFT Draw spectrum

后端 未结 1 1584
心在旅途
心在旅途 2021-01-31 06:39

I\'ve read these question:

Using the Apple FFT and Accelerate Framework

How do I set up a buffer when doing an FFT using the Accelerate framework?

iOS FF

1条回答
  •  再見小時候
    2021-01-31 07:12

    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;
    

    0 讨论(0)
提交回复
热议问题