# How to apply an FFT

Okay, round 2.

The issue I am having with implementing FFT is that different implementations require passing as arguments different types of data. From the WAV file you obtain samples of the amplitude recorded at the sample rate.

As an example, the NAudio library takes an array of complex numbers as an argument: source code

public static void FFT(bool forward, int m, Complex[] data)


On the other hand, the source code for another implementation simply takes an array of doubles:

static public double[] FFTDb(ref double[] x)


My questions are,

1. Why are they using different arguments -- is it simply a preference or some other factor?
2. How do I go from the samples in the WAV data to the form they are asking for? Do I simply cast the 16-bit integers to double? Do I zero out the imaginary part?

As for the output of the FFT function, I'm left with, in the case of the former, the original array modified by the FFT or, in the case of the latter, an array of doubles. From my understanding each index in the output represents a range of frequencies depending on the sampling rate and the time resolution (number of samples passed).

• Am I right in concluding I simply find the magnitude of that index to determine the presence of that frequency range over the time interval of samples?

• Also, how do channels factor in to all of this? Do you separate the channels and run the FFT on each channel? Do you combine the channels after words? Do you examine them independently?

• Are you trying to build a streaming application? – MBaz Jun 21 '17 at 16:38
• No. I am simply trying to get the frequencies for a pet-project involving voice data. I'm not trying to manipulate the signal or anything like that. I just want the frequencies for some analysis. – Jonathan Jun 21 '17 at 16:43
• Then, please explain in more detail what the problem is. There are hunderds of ways to obtain audio from a microphone and run an FFT on it, thus obtaining its frequency content. – MBaz Jun 21 '17 at 16:48
• Let me try explaining it like this. I have a WAVE file. I have read the WAVE file and obtained the samples from the DATA chunk. Now what? I, literally, do not know what to do with those samples. Do I just pass an array of the samples to a FFT function? Then what? What do I do with the output of the FFT function? – Jonathan Jun 21 '17 at 16:58
• Read chapter 7 of this book: homepages.cae.wisc.edu/%7esethares/telebreak.pdf or chapters 8-12 of dspguide.com/pdfbook.htm – MBaz Jun 21 '17 at 17:13