Talk:Fast Fourier transform: Difference between revisions

Thanks and summing up discoveries
mNo edit summary
(Thanks and summing up discoveries)
Line 34:
 
::: Is this within the realm of things you feel comfortable experimenting with? --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 21:11, 14 December 2013 (UTC)
 
 
Hi Rdm, Happy New Year
Just wanted to say thanks a lot for your explanation. I have successfully generated a frequency chart from my WAV data based on what you said. Interesting that only half of the output from the FFT function is useful.
 
So just to clarify for anybody else who is reading this:
WAV sample values (for example) go into the FFT function in batches of say 2048 (or any multiple of 2 because that is how the FFT works, and requires it) and 2048 complex numbers are then output.
Just input the raw sample values in groups of a multiple of 2 into the FFT function. The same number of <complex> numbers will be output from the FFT.
 
Only half of the numbers that the FFT function outputs are useful for plotting the frequency spectrum. The other half are a mirror image of the first half so can be disregarded in most common cases.
Because the FFT function outputs complex numbers (made up of a real part an an imaginary part) you need to convert the complex numbers back to real numbers for plotting.
This is done as follows (C++):
 
// Calculate magnitude using:
double FFTABSValue = sqrt( real(data[i])*real(data[i]) + imag(data[i])*imag(data[i]) );
 
You take the square of the real portion of the complex number and add it to the square of the imaginary part of the complex number, and then take the square root of sum of those two. This gives a plottable "magnitide" - might need to adjust it for scale. (in C++, "real" and "imag" are built in functions to take the appropriate part of a complex number separately)
 
Note: this also makes the result absolute due to its squaring, and absolute values is what you want to plot.
 
Once you have plotted the 1024 frequencies (frequency bins I believe they are referred to as) you can then choose a different part of your WAV file, read in another 2048 values into the FFT function and plot a new frequency chart from the results. Each chart will probably only represent a few milliseconds of your WAV file, but by passing in successive chunks of 2048 samples from your wav file, you should get a dynamic moving frequency chart (FFT) which if you plot in 3D (one chart behind the other) you will see how frequencies change with time.
 
Any comments or corrections to what I have just said would be welcome - but I just wanted to write what I have figured out, and what I understand so far.
 
-Sam
Anonymous user