I'm trying to get the correct FFT bin index based on the given frequency. The audio is being sampled at 44.1k Hz
and the FFT size is 1024
. Given the signal is real (capture from PyAudio, decoded through numpy.fromstring
, windowed by scipy.signal.hann
), I then perform FFT through scipy.fftpack.rfft
, and compute the decibel of the result, in whole, magnitude = 20 * scipy.log10(abs(rfft(audio_sample)))
Based on this, and this, I originally had my mapping from the FFT bin index, k
, to any frequency, F
, as:
F = k*Fs/N for k = 0 ... N/2-1
where Fs
is the sampling rate, and N
is the FFT bin size, in this case, 1024
. And the reverse as:
k = F*N/Fs for F = 0Hz ... Fs/2-Fs/N
However, realizing that the rfft
's result is no symmetric like fft
, and provides the result, in an N
size array. I now have some questions in regarding the mapping and the function. Documentation unfortunately did not provide much information as I'm novice in this area.
My questions:
To me, the result of
rfft
on an audio sample can be used directly from the first bin to the last bin, as no symmetry occurs in the output, is that correct?Given the lack of symmetry from the above, the frequency resolution appears to have increased, is this interpretation correct?
Because of using
rfft
, my mapping function from bin indexk
to frequencyF
is nowF = k*Fs/(2N) for k = 0 ... N-1
is this correct?Conversely, the reverse mapping function from frequency
F
to bin indexk
now becomesk = 2*F*N/Fs for F = 0Hz ... Fs/2-(Fs/2/N)
, what about the correctness of this?
My general confusion arises from how rfft
is related to fft
, and how the mapping can be done correctly while using rfft
. I believe my mapping is offset by a small amount, and that is crucial in my application. Please point out the mistake or advise on the matter if possible, thank you very much.