Help understanding FFTW3 library

Hey all,

I’ve been trying to teach myself the FFTW3 library. Eventually it’s going to be implemented in something non-JUCE that i’m trying to work on. But to learn, i’m using it within JUCE so it’s in a familiar environment. Right now i’m just trying to take audio in the process block and use FFTW3 to analyze it.

I think i understand just enough with FFTW3 to ask useful questions… (if not, sorry in advance)

The tutorial says:

“…compute a one-dimensional DFT of size N…”

with the example code:

    fftw_complex *in, *out;
    fftw_plan p;
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_execute(p); /* repeat as needed */
    fftw_free(in); fftw_free(out);

I’m doing 1D DFT real to complex, so my code looks like this:

    in  = (double*)fftw_malloc(sizeof(double) * N);
    out = (fftw_complex*) fftw_malloc( sizeof(fftw_complex) * N );
    p   = fftw_plan_dft_r2c_1d ( N, in, out, FFTW_ESTIMATE );
  • Is N the number of FFT bins, or the number of samples (buffer size) being passed into the *in array?
  • If it’s the bins, why do i set the input array to the size of the bins and not the number of samples?
  • If it’s the number of samples, how do i set the number of bins?
  • The out array is an array of Real & Complex pairs. Am i understanding correctly in that the out array’s index is the bin number, and the Real result is the level for that bin number, and the Complex result isn’t needed?