Relationship of FFT Size, Sampling Rate and Buffer Size

I am asking this question because I want to make sure I understand the relationship of FFT length, the sampling rate and the buffer size. This question is with respect to the CMSIS DSP library, although I imagine it could be any FFT processing function.

Because of configuration constraints, my ADC is sampling at a rate of 10.68ksps. Then, I am taking the average of 4 samples to end up at a rate of 2.67kbps. I need resolution of 0.5Hz for signals from 100Hz to 300Hz. So here's the part I am missing - I do not understand what sample rate I need to scale to in order to properly conserve frequency information. For example, if I wanted to run a 1024 length FFT, what sample rate should I scale to, and what buffer size should I pass to the fft function?

I do have it working, but the bin information is not quite correct - for example, it is out by 1 bin at 100Hz, but 2 bins at 300Hz. I'm sure it's related to the odd sampling rate. Do I need a sampling rate that is equal to the FFT length? And how does the buffer size passed in impact the operation?

• You might like to read The Scientist & Engineer's Guide to DSP, FFT is covered there in an understandable way. Commented Jan 14, 2015 at 6:38
• Thanks David. I will look through the sections to get more clarification. Commented Jan 15, 2015 at 2:27

There is a direct, and actually quite simple, relationship between all the figures.

Let's start with the sample size. The numbers of bins (or "buckets") is equal with half of the samples in your set. For instance, if you have 1024 samples, then you get 512 bins. As simple as that.

Now for the sample rate. The maximum frequency is half the sample rate (see Nyquist-Shannon sampling theorem). So if you have a sample rate of 2.67ksps then your frequency range is 0-1.335kHz.

Again pretty straight forward - just another divide by two.

Now the bins are spread evenly over the frequency range - so your 512 bins, over 1355Hz is 2.607421875 Hz per bin.

For 0.5Hz per bin up to 300Hz you want 600 bins. Your target sample rate would be 600Hz. How you down-sample to that would be up to you.

Most FFT code I have seen works on 2n sample sizes, so 600 bins isn't a nice number. That would be 1200 samples - not a 2n. So you'd probably want to round it up to 211, or 2048 samples. That would give you 1024 bins, and you'd want a target sample rate of 1024sps for 0-512Hz range.

• Thanks a bunch for a thorough reply. To clarify - no matter what the sampling rate or frequency, a resolution of 0.5Hz requires 2 seconds of data collection - yes? Commented Jan 14, 2015 at 3:20
• Don't forget an anti aliasing filter. You can apply an fir filter to your sample buffer and than throw away every n-th sample to down sample the signal
– Mike
Commented Jan 14, 2015 at 6:42
• Yes, I have a sharp analog anti-aliasing filter in front of the ADC, along with a suitable RC filter with the correct tau. Can you explain why the FIR should be placed ahead of any decimation? Let's say I have some odd sample buffer: 2600 samples in 1 second, so the FIR should be designed/applied at a frequency of 2.6KHz? Then down-sample to 2048 for the FFT? Excuse my lack of know-how, but how to "throw away" every nth sample is something I have not done before. Does that imply going over each element of the array, and setting every nth sample to 0? Or, not copying it to a new sample buffer? Commented Jan 14, 2015 at 19:01

Make sure you understand the following relationships:

fs = 1/dt

fs/N = 1/(N*dt)

df = 1/(N*dt)

df*dt = 1/N

So this means that the product of the spacing in the time domain and spacing in the frequency domain is a constant (1/N). Increasing the spacing in the time domain can decrease the spacing in the frequency domain while keep 'N' to be constant. However, you must be careful with 'dt' since its inverse is the sampling frequency 'fs' which must be at least twice the signal frequency.

• it would be more helpful (and you will probably get some points) if you would explain for all what fs df dt n means. Commented Jul 28, 2020 at 14:11