Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB FFT - stuck understanding relationship of results to frequency

Trying to understand an fft (Fast Fourier Transform) routine I'm using (stealing)(recycling)

Input is an array of 512 data points which are a sample waveform. Test data is generated into this array. fft transforms this array into frequency domain. Trying to understand relationship between freq, period, sample rate and position in fft array. I'll illustrate with examples:

========================================

Sample rate is 1000 samples/s. Generate a set of samples at 10Hz.

Input array has peak values at arr(28), arr(128), arr(228) ... period = 100 sample points

peak value in fft array is at index 6 (excluding a huge value at 0)

========================================

Sample rate is 8000 samples/s Generate set of samples at 440Hz

Input array peak values include arr(7), arr(25), arr(43), arr(61) ... period = 18 sample points

peak value in fft array is at index 29 (excluding a huge value at 0)

========================================

How do I relate the index of the peak in the fft array to frequency ?

like image 323
David Shields Avatar asked Nov 17 '25 21:11

David Shields


1 Answers

If you ignore the imaginary part, the frequency distribution is linear across bins:

Frequency@i = (Sampling rate/2)*(i/Nbins).

So for your first example, assumming you had 256 bins, the largest bin corresponds to a frequency of 1000/2 * 6/256 = 11.7 Hz. Since your input was 10Hz, I'd guess that bin 5 (9.7Hz) also had a big component. To get better accuracy, you need to take more samples, to get smaller bins.

Your second example gives 8000/2*29/256 = 453Hz. Again, close, but you need more bins. Your resolution here is only 4000/256 = 15.6Hz.

like image 100
AShelly Avatar answered Nov 20 '25 13:11

AShelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!