c++signal-processingfftkissfft

Kiss FFT seems to multiply data by the number of points that it transforms


My limited understanding of the Fourier transform is that you should be able to toggle between the time and frequency domain without changing the original data. So, here is a summary of what I (think I) am doing:

  1. Using kiss_fft_next_fast_size(994) to determine that I should use 1000.

  2. Using kiss_fft_alloc(...) to create a kiss_fft_cfg with nfft = 1000.

  3. Extending my input data from size 994 to 1000 by padding extra points as zero.

  4. Passing kiss_fft_cfg to kiss_fft(...) along with my input and output arrays.

  5. Using kiss_fft_alloc(...) to create an inverse kiss_fft_cfg with nfft = 1000.

  6. Passing the inverse kiss_fft_cfg to kiss_fft(...) inputting the previous output array.

  7. Expecting the original data back, but getting each datum exactly 1000 times bigger!

I have put a full example here, and my 50-odd lines of code can be found right at the end. Although I can work around this by dividing each result by the value of OPTIMAL_SIZE (i.e. 1000) that fix makes me very uneasy without understanding why.

Please can you advise what simply stupid thing(s) I am doing wrong?


Solution

  • This is to be expected: the inverse discreet Fourier transform (which can be implemented using the Fast Fourier Transform), requires a division by 1/N:

    The normalization factor multiplying the DFT and IDFT (here 1 and 1/N) and the signs of the exponents are merely conventions, and differ in some treatments. The only requirements of these conventions are that the DFT and IDFT have opposite-sign exponents and that the product of their normalization factors be 1/N. A normalization of \sqrt{1/N} for both the DFT and IDFT makes the transforms unitary, which has some theoretical advantages. But it is often more practical in numerical computation to perform the scaling all at once as above (and a unit scaling can be convenient in other ways).

    http://en.wikipedia.org/wiki/Dft