loupe.dft2#
- class loupe.dft2(x, alpha, shape=None, shift=(0, 0), offset=(0, 0), unitary=True, axes=None)[source]#
Compute the 2-dimensional discrete Fourier Transform.
This function allows independent control over input shape, output shape, and output sampling by implementing the matrix triple product algorithm described in [1].
- Parameters:
x (array_like) – Input array, can be complex. Must
alpha ((2,) array_like) – Output plane sampling frequency in terms of (row, col).
shape ((2,) arrqy_like, optional) – Shape of the output. If shape is None (default), the shape of the input is used.
shift (sequence of floats, optional) – Number of pixels in (r,c) to shift the DC pixel in the output plane with the origin centrally located in the plane. Default is (0, 0). Can be 2-dimensional to provide independent shifts for each Fourier transform if x is 3-dimensional.
offset (sequence of floats, optional) – Offset of the center of the input x in terms of number of pixels in (r,c). Default is (0, 0). Can be 2-dimensional to provide independent offsets for each Fourier transform if x is 3-dimensional.
unitary (bool, optional) – Normalization flag. If True, a normalization is performed on the output such that the DFT operation is unitary. Default is True.
axes (sequence of ints, optional) – Axes over which to compute the Fourier transform. If not given, the last two axes are used.
- Returns:
out – The discrete Fourier transform of the input.
- Return type:
Notes
dft2 expects the DC pixel to be centered in the input array. The center is assumed to be at
np.floor(n/2) + 1
for length n. Note this is consistent with a shifted FFT performed as:F = ifftshift(fft2(fftshift(f)))
Performing the DFT with
alpha = 1/f.shape
,unitary = False
, andshape = f.shape
is equivalent to a shifted FFT:
>>> f = loupe.rand(size=(10, 10)) >>> F = loupe.dft2(f, alpha=(1/10, 1/10), unitary=False, shape=f.shape) >>> G = np.fft.ifftshift(np.fft.fft2(np.fft.fftshift(f))) >>> np.allclose(F, G) True
References
[1] Soummer, et. al. Fast computation of Lyot-style coronagraph propagation (2007)