lentil.fourier.dft2#
- lentil.fourier.dft2(f, alpha, shape=None, shift=(0, 0), offset=(0, 0), unitary=True, out=None)[source]#
Compute the 2-dimensional discrete Fourier Transform.
The DFT is defined in one dimension as
\[A_k = \sum_{m=0}^{n-1} a_n \exp \left(-2\pi i\frac{mk}{n}\right) \hspace{3em} k=0, \dots, n-1\]This function allows independent control over input shape, output shape, and output sampling by implementing the matrix triple product algorithm described in [1].
- Parameters:
f (array_like) – 2D array to Fourier Transform
alpha (float or array_like) – Output plane sampling interval (frequency). If
alpha
is an array,alpha[1]
represents row-wise sampling andalpha[2]
represents column-wise sampling. Ifalpha
is a scalar,alpha[1] = alpha[2] = alpha
gives uniform sampling across the rows and columns of the output plane.shape (int or array_like, optional) – Size of the output array
F
. Ifshape
is an array,F.shape = (shape[0], shape[1])
. Ifshape`
is a scalar,F.shape = (shape, shape)
. Default isf.shape
.shift (array_like, 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)
.offset (array_like, optional) – Number of pixels in (r,c) that the input plane is shifted relative to the origin. Default is
(0,0)
.unitary (bool, optional) – Normalization flag. If
True
, a normalization is performed on the output such that the DFT operation is unitary and energy is conserved through the Fourier transform operation (Parseval’s theorem). In this way, the energy in in a limited-area DFT is a fraction of the total energy corresponding to the limited area. Default isTrue
.out (ndarray or None) – A location into which the result is stored. If provided, out.shape == shape and out.dtype == np.complex. If not provided or None, a freshly-allocated array is returned.
- Returns:
F
- Return type:
complex ndarray
Notes
Setting
alpha = 1/f.shape
andshape = f.shape
is equivalent toF = np.fft.ifftshift(np.fft.fft2(np.fft.fftshift(f)))
dft2()
is designed to place the DC pixel in the same location as a well formed call to any standard FFT for both even and odd sized input arrays. The DC pixel is located atnp.floor(shape/2) + 1
, which is consistent with calls to Numpy’s FFT method where the input and output are correctly shifted:np.fft.ifftshift(np.fft.fft2(np.fft.fftshift(f)))
.If the y-axis shift behavior is not what you are expecting, you most likely have your plotting axes flipped (matplotlib’s default behavior is to place [0,0] in the upper left corner of the axes). This may be resolved by either flipping the sign of the y component of
shift
or by passingorigin = 'lower'
toimshow()
.
References
[1] Soummer, et. al. Fast computation of Lyot-style coronagraph propagation (2007)