FFTW simply will not return values other than infinity, values that approach zero, or negative infinity
You’re allocating an array of
fftw_complexes, which consist of two elements — the real and complex components — but you’re only initializing the real component of each sample. This is probably leaving the complex components containing random data, causing unexpected crazy results!
If you don’t need to deal with complex samples — which is likely — you may want to use one of FFTW’s real-data DFT functions, which takes a
double array as input. Otherwise, initialize all the complex components (
in[i]) to zero.
Additionally, you’re not looking at the complex component of the output. There may be something significant there you’re missing out on.
Your input are 10 periods of a pure real sine wave. This means:
- Your output is pure imaginary caused by the odd sine function (sin(x) = -sin(-x))
In the case of a cosine function the output were pure real
because cosines is an even function (cos(x) = cos(-x)
- There are only two frequency lines, one in the positive frequency band
and one in the negative band.
- Because you have 10 periods in your input, your lines should occur
at out and out[N-10].
- Because you didn’t normalize the output and the number of samples is 500,
the amplitudes should be out = -250 and out = +250.
- All other values should be zero.
Read more here: Source link