[Math] Computing wavenumbers for discrete Fourier transform

algorithmsderivativesfourier analysisnumerical methods

I'm trying to implement a Fortran program to compute the derivative of a function using the FFT. To begin with, just to test my installation of fftpack, I computed the Fourier transform of $\mathrm{sin}(x^{2})$, followed by the inverse transform of that result, which gave me back $\mathrm{sin}(x^{2})$ as expected.

So once I was satisfied that the FFT routines were working, I began trying to use it to find the derivative, via the formula $$\frac{\mathrm{d}f(x)}{\mathrm{d}x}=\mathcal{F}^{-1}[ik\hat{f}(k)],$$ where $f(x) = \mathrm{sin}(x^{2})$, for $x$ between $0$ and $2\pi$. There are $N=256$ points on the mesh, so $x_{n}=2\pi n/N.$ My simple problem is, I can't work out how to compute the values of $k$. I've tried some stuff, but it resulted in garbage. I'd really appreciate any help, thanks.

Best Answer

You perform FFT on $N=256$ points with equal distance $2\pi/N$ between them and as a result you get $256$ points in frequency domain. You want to know which frequency values these correspond to. You can consider them to be indexed as [-128,128) or [-128,127] (integers)

The leftmost point will be $-\frac{\pi}{\Delta x}$ where $\Delta x$ is the distance between your points before FFT. Rightmost point will not be $\frac{\pi}{\Delta x}$ since it will be non symmetric.

So, for k, you need 256 linearly spaced points starting from $-\pi/(2\pi/N)$ increasing with increments $2\pi /(N\Delta x)=1$

Related Question