6

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.

Ospho
  • 2,756
  • 5
  • 26
  • 39

2 Answers2

19

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
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Because i'm not sampling this signal, im generating it internally, this is then affected? – Ospho May 25 '12 at 12:47
  • When you generate a signal internally you can still have a notional sample rate, but of course this can be anything you like. However if you want to play back this signal at any time then the sample rate will be that of your DAC. – Paul R May 25 '12 at 12:49
  • Sorry one more quick question, is there a limitation on how large the signal buffer SIG_N needs to be to sample at 40kHz? – Ospho May 25 '12 at 12:52
  • Not really - typically it will be a power of 2 and you will make it sufficiently large so that your FFT will have enough resolution for your particular application (assuming that you are going to be working in the frequency domain). – Paul R May 25 '12 at 12:54
9

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).

villoren
  • 319
  • 3
  • 5