nobby_trussin
07-08-2006, 11:44 AM
Hi,
I intend to use nr for fft on an audio signal. I was to understand that once the transform is performed, each element of the output array corresponds to that frequency - so element 440 would contain the amplitude information for 440hz.
However, i just noticed that a lot of frequences aren't whole numbers for example A1 = 13.75hz. Does anyone know how this is represented in the output of a transform as you can't index the 13.75th element of an array!! :hum:
Hope you know what i mean
Dan
Kevin Dolan
09-28-2006, 04:39 AM
The frequency components do not directly represent Hz.
Let's say your signal has 1000 points. In general, an FFT will then give you something which is also 1000 points. Some optimized real-to-real transforms will give you 501 (n / 2 + 1). Getting the specific frequency information is then done as follows:
1) Get the sampling rate of the data. For example, if the above 1000 points of data are 1 second, then the sampling rate is 1000Hz.
2) If your FFT gives you a complex vector with the same number of points as the signal, then the frequency corresponding to the ith point is just
i * sr / n
So point 87 would correspond to 87HZ in the above example, but if the sampling rate was 2500Hz, then it would correspond to 217.5Hz. For values of i over n / 2, these actually correspond to negative frequencies. For transforms of real data, the negative frequencies are just the complex conjugates of the positive ones, so you don't really need them.
If your FFT gives you n / 2 + 1 complex points, or n real points, then this means that some sort of compact storage scheme is being used. One common scheme is to use n real values, with the real part of the positive frequencies stored in the first n / 2 + 1 points, and the imaginary part in remaining points. Since point zero is always real, and point n / 2 (for even numbers of points) is also always real, this allows all of the information to be stored in a real vector of length n. Another common scheme is to use a complex vector of length n / 2 + 1, in which case the negative frequencies are just ommitted. I do not recal which scheme NR uses, so you should check.
Kevin