0

I have an array with N purely real points representing a spatial function:

[f_0, f_1, f_2, ... , f_{N-1}]

The function values are spaced in with a distance dx.

Therefore the Nyquist frequency is given by f_N = 1/(2*dx)

I calculate the Fourier transform of the array in C using FFTW2, with the function for purely 1d real inputs rfftw. This leads to only N/2 independent complex numbers, which are stored in a "half complex array":

[r_0, r_1, .... r_{N/2}, i_{N+1}/2-1 , ..., i_2, i_1], where r denotes the real and i the imaginary part.

Now I would like to know what the frequency domain of this array looks like. Is r_{N/2} the value at f_N or (f_N/)2?

I already have the code and it seems to work, i just don't know how to interpret the frequency axis.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
madde
  • 9
  • 2
  • 1
    You can figure it out by creating an input that's a pure sine wave of a known frequency. Then the FFT output is a single non-zero value at that frequency. – user3386109 Jul 04 '23 at 14:41

1 Answers1

2

Your notation is confused. If your input is

[f_0, f_1, f_2, …, f_{N-1}]

then f_n is the input value at position n, it is not a position itself. The inputs are at integer indices n = 0 … N-1. Thus the question asking about “the value at f_N” makes no sense.

The FFTW half-complex output is:

[r_0, r_1, r_2, …, r_{N/2}, i_{(n+1)/2-1}, …, i_2, i_1]

Here, r_n + i * i_n is the value at position n. Frequencies are the integer indices n = 0 … N-1. The Nyquist frequency is related to N, not f_N (which is not even defined in your input!). It is given by N/2.0.

If you assume a certain sampling dx in your input, such that the sample at position n has a x = n*dx, then you can also translate frequency bins to physical frequencies, with df = 1/(N*dx). Thus, the frequency at index n is n/(N*dx). With the understanding that the value for frequency n/(N*dx) is equal to that for (n+k*N)/(N*dx), with k any positive or negative integer (from which you can obtain the negative frequencies that many expect to find in a Fourier transform).

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • sorry, my notation is indeed very bad. Since i refer to the Nyquist frequency with f_N (lets call it Fnq now), and the input also denoted by f_i. From your answer I understand, that the Fourier coefficient r_N/2 + i i_N/2 would be the coefficient corresponding to the Nyquist frequency Fnq = 1/(2*dx) ? – madde Jul 04 '23 at 16:56
  • @madde That’s right. – Cris Luengo Jul 04 '23 at 18:45
  • Frequencies are also commonly indicated by the Greek letter nu, if that helps with notation – infinitezero Jul 04 '23 at 20:19