0

I am trying to find the frequency in hertz for every bin in the fft spectrum. Below is my code just adding the fft spectrum values inside a float list.

for (int len = 0; len < nyquistLength; ++len)
    {
        for (int channel = 0; channel < numChannels; ++channel)
        {
            channs += dspFFT.spectrum[channel][len];
            if (channel == numChannels - 1)
            {
                spectrum.Add(Math.Abs(Mathf.Log10(channs)));
                Debug.Log(spectrum[len]);
                channs = 0;
            }
        }
    }

How can I use this information to obtain the Hz of each entry in the spectrum? Thanks.

  • 1
    You need to know the sample rate in Hz as well as the FFT length in order to know the center frequency of each FFT filter bin in Hz. – hotpaw2 Aug 12 '18 at 20:30
  • @hotpaw2 So my sample rate is 44100 and my window length is 2048. I have tried to find the bin Hz before by doing something like this: _(channs/_windowLength) * (44100/2)_ but the results I got where barely above zero. – Leonidas Antoniou Aug 12 '18 at 20:59

1 Answers1

1

A N-point FFT of a signal with a sample rate of 44100 produces frequency bins with center frequencies spaced 44100/N apart from 0 Hz to 44100 Hz. From 0 to the Nyquist frequency of 22050 Hz, there are N/2+1 points inclusive. So if you want the center frequencies then compute i*44100/N where i=0,1,...,N/2.

Paul R
  • 208,748
  • 37
  • 389
  • 560
sdbol
  • 413
  • 4
  • 17
  • So the frequency calculated will correspond to the bin given out by the spectrum. Should I do this calculation for each window (hann)? etc. my window is of type hann and the length is 2048 – Leonidas Antoniou Aug 13 '18 at 15:00
  • It’s irrespective of the type of window (e.g. hanning, hamming) – sdbol Aug 13 '18 at 19:52