0
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Are you trying to build a streaming application? $\endgroup$ – MBaz Jun 21 '17 at 16:38
  • 1
    $\begingroup$ 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. $\endgroup$ – Jonathan Jun 21 '17 at 16:43
  • 1
    $\begingroup$ 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. $\endgroup$ – MBaz Jun 21 '17 at 16:48
  • 1
    $\begingroup$ 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? $\endgroup$ – Jonathan Jun 21 '17 at 16:58
  • 1
    $\begingroup$ Read chapter 7 of this book: homepages.cae.wisc.edu/%7esethares/telebreak.pdf or chapters 8-12 of dspguide.com/pdfbook.htm $\endgroup$ – MBaz Jun 21 '17 at 17:13
0
$\begingroup$

The data section of a WAVE file is often an array of 16-bit signed integers. You may need to convert each element of that array from an integer into a floating-point double, and put that converted value into the real component of an element of a complex array, in order to use many common floating point FFTs.

Many FFT implementations requires a complex input vector. If you have strictly real data (for instance from a WAVE file), the imaginary component of every complex element will be zero (e.g. set it to zero if needed).

Some FFT implementations only take real data (as a convenience), so you just give them a real data array, as they probably invisibly internally add any imaginary components of zero needed.

Note that if the FFT provides a complex output, then you will need to compute the magnitude of each complex element (square root of the sum of the squares, etc.) in the result array.

$\endgroup$
  • $\begingroup$ What about channels? How do those factor into it? Do you separate the channels and pass them individually or is there some way you should go about merging them? Do you analyze them separately after running them through the FFT? $\endgroup$ – Jonathan Jun 23 '17 at 0:20
  • $\begingroup$ Depend on what you want: All channels mixed together for mono. Or separate data for each channel L & R etc. $\endgroup$ – hotpaw2 Jun 23 '17 at 0:33
  • $\begingroup$ So, if I'm reading a wave file and it has 2 channels, I should separate the channels and pass each channel to the FFT and analyze the results of each channel separately? $\endgroup$ – Jonathan Jun 23 '17 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.