Fourier Interpolation Classes
In today's post, we are going to review how to interpolate periodic, uniform data using the discrete Fourier transform.
Intro
This is a brief review of three interpolation methods using the Fourier transform with the aim of providing short code snippets that work in \(d=2\) dimensions with obvious generalisations to higher dimensions for odd input and output sizes. For the definitions of the Discrete Fourier Transform (DFT) and its inverse (IDFT) used in the following see the excellent NumPy FFT documentation. In the following, we are going to make use of NumPy’s fftfreq, ifftfreq, fftshift and ifftshift functions that account for the different spectra for even and odd \(N\). You may find the accompanying Python code on GitHub . The repository also includes code to up- and downscale images using the Fourier transform.
Setup
For testing different interpolation strategies, we sample a periodic test function on a squared-sized 2D grid with side length \(L\) and 1D subgrids like \(\{0, \Delta x, ..., (N-1)\cdot \Delta x\}\) for \(\Delta x = L/N\). We are going to verify the interpolation result on the 2D grid with 1D subgrids with \(2\cdot N\) points like \(\{0, \Delta x/2, 2\cdot \frac{\Delta x}{2}, ..., (N_i-1)\cdot \frac{\Delta x}{2}\}\).
Direct Evaluation of IDFT
One way to interpolate data using the DFT, is to directly evaluate the definition of the IDFT at the \(N_i\) interpolation points \(t_{i} \in \mathbb{R}\). This method allows the interpolation of the input data at non-uniform interpolation points, but has the disadvantage of requiring \(\mathcal{O}(N^d\cdot N_i)\) operations.
Evaluation via Time-Shifting property
A second method to interpolate data is to make use of the fact that a phase rotation in the frequency domain equals a shift in the position domain. This method allows the interpolation of the input data on a uniform grid with \(N\cdot (2^d - 1)\) complex multiplications in frequency space plus \(\mathcal{O}(N^d\cdot \log(N))\) operations by leveraging the speed of the Fast Fourier Transform (FFT).
Zero-Padding
The third and final method for data interpolation using the DFT is zero-padding. It exploits the fact that adding additional high-frequency modes with vanishing amplitude to the data in frequency space and then computing the IDFT is equal to sampling the input function on a finer grid with grid spacing \(\Delta x_i = \frac{L}{N_{i}}\). Likewise, we can subtract high-frequency modes and downscale the input data with an IDFT. While we cannot freely choose interpolation points using zero-padding, the method is fast since it only requires one FFT with \(\mathcal{O}(N^d\cdot \log(N))\).