How to get the frequency from FFT data

I’m pretty new to JUCE and how FFT works in general. I’ve taken a look at the example FFT program and wanted to try borrowing parts of the example to make a program myself that would convert data from the FFT spectrum to frequency (in Hz) and then to print it out in a window so that the user could easily understand it, if that makes any sense. Would that be possible to do, and if so how? Any help is appreciated.

1 Like

Yes, that is possible.
Just use “performFrequencyOnlyForwardTransform”.
It gives you the frequency straight away. See also API doc:

From the data, which performFrequencyOnlyForwardTransform gives you, you can calculate the actual frequency the following way:
Freq = (sampleRate * fftBufferIdx) / bufferSize
(i.e. that formula maps the index of each element of the transformed buffer to the corresponding frequency)


Thanks. I think I understand it now. However, I can’t really tell where the buffer index and buffer size values are located on the example program. Are the fifoIndex and fftsize variables the ones I should be looking at? Thanks again.

Which example program are you referring to?

The SimpleFFTExample one in the examples folder

In that case you have to look at forwardFFT.
You get the the size of the FFT by writing:

int size = forwardFFT.getSize();

In turns out, the size is 1024 (I just checked in the demo).
So that is your buffer size.
The forwardFFT is called with fftData as its argument. That means, it is going to store the FFT data in fftData.
The index depends on which index of the fftData array you are looking at.

For example, assume you are looking at index number 256 and you are running at a sample rate of 44100 Hz.
Then the formula says:
Freq = 44100 * 256 / 1024= 11025

In other words: the frequeny for the index 256 is 11025 Hz.