FFT bin width clarification

Ospho picture Ospho · May 25, 2012 · Viewed 14.7k times · Source

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.

Answer

Paul R picture Paul R · May 25, 2012

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