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.

2
  • 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. Commented Aug 12, 2018 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. Commented Aug 12, 2018 at 20:59

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
It’s irrespective of the type of window (e.g. hanning, hamming)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.