Disclaimer: This repository currently makes no effort to support any environment other than the my local machine.
Building the fortran code:
export CMAKE_PREFIX_PATH="/opt/homebrew/Cellar/fftw/3.3.10_2/:${CMAKE_PREFIX_PATH}"
$ cmake -B ./build -G Ninja --fresh
$ cmake --build ./buildExamples of 1D, 2D and 3D FFTs using scipy in python, and FFTW3 called from fortran, respectively.
Scipy defines their forward transform as:
$$
Y[k] = \sum_{n=0}^{N-1} x[n];e^{-2\pi i,k n/N}.
$$
Given a sin wave at
Substituting this into the definition of the forward transform gives:
[ \begin{aligned} Y[k] &= \sum_{n=0}^{N-1} \frac{A}{2i}\bigl(e^{2\pi i,k_0 n/N}-e^{-2\pi i,k_0 n/N}\bigr), e^{-2\pi i,k n/N},\ &= \frac{A}{2i}\Bigl[ \sum_{n=0}^{N-1} e^{-2\pi i,n,(k - k_0)/N} -\sum_{n=0}^{N-1} e^{-2\pi i,n,(k + k_0)/N} \Bigr]. \end{aligned} ]
Using the geometric‐series identity:
$$
\sum_{n=0}^{N-1} e^{-2\pi i,n,m/N}
=
\begin{cases}
N, & m \equiv 0 \pmod N,\
0, & \text{otherwise}
\end{cases}
$$
one can rewrite the forward transform in terms of delta functions (note
The magnitudes at
-
At
$k = k_0$ : $$ Y[k_0] = \frac{NA}{2i} \quad\Longrightarrow\quad \bigl|Y[k_0]\bigr| = \frac{NA}{2}, $$ -
At
$k = N - k_0$ : $$ Y[N-k_0] = -\frac{NA}{2i} \quad\Longrightarrow\quad \bigl|Y[N-k_0]\bigr| = \frac{NA}{2}, $$
hence the need to multiply by
Python:
python python/real1d.pyFortran:
./build/real1d