FFT bin width clarification
Solution 1
The width of each bin (Hz) depends on two things: sample rate, Fs
(Hz) and number of FFT bins, N:
bin_width = Fs / N;
So if you sample at Fs = 40 kHz
and you have N = 64
bins in your FFT then each bin will be 625 Hz wide. The bins of interest will be those from 0 to N / 2 - 1:
Bin 0 0 Hz
Bin 1 625 Hz
Bin 2 1250 Hz
...
Bin 31 19,375 Hz
Solution 2
Translating Paul's example to ranges:
Bin 0: -312.5 Hz to 312.5 Hz (center: 0.0 Hz)
Bin 1: 312.5 Hz to 937.5 Hz (center: 625.0 Hz)
Bin 2: 937.5 Hz to 1562.5 Hz (center: 1250.0 Hz)
...
Bin 32: 19687,5 Hz to -19687,5 Hz (center: 20000.0 Hz)
Notice how both Bin[0]
and Bin[32]
(33th. bin in a zero based array),
receive contributions from 'negative' frequencies.
This is consistent with the periodic nature of the FFT (or any complex discrete fourier transform).
Ospho
Updated on July 02, 2022Comments
-
Ospho almost 2 years
I'm developing a spectrum analyzer for the 8bit Atmega32 that outputs onto a LCD display. The maximum sampling frequency is 40kHz, and maximum frequency is hence 20kHz, adhering to fs > 2B. At the moment, I am generating a signal internally, then applying the FFT to this signal and viewing the spectrum on the LCD.
Please note this is written in pseudo-code:
#define SIG_N 128 //Number of samples in signal buffer #define FFT_N 64 //2*Output bins uint_8 signal[SIG_N]; uint_8 spektrum[FFT_N]; for (int i = 0; i < SIG_N; i++){ signal[i] = 255*sin(2*3.14*f*i / SIG_N); } computeFFT(signal,spektrum,FFT_N); //arbitrary method computes signal outputs spektrum
The output spectrum currently has FFT_N/2 = 32 bins, each representing 1Hz. Therefore the highest frequency my spectrum currently represents (i've tested this) - 32Hz. How can I increase the "frequency width" of these bins, in so that each bin represents 625Hz? Remember, I cannot increase the size of FFT_N beyond 64~128 as I have memory restrictions.