pylops.signalprocessing.FFTND¶
-
pylops.signalprocessing.FFTND(dims, dirs=(0, 1, 2), nffts=None, sampling=1.0, norm='ortho', real=False, ifftshift_before=False, fftshift_after=False, dtype='complex128', engine='scipy')[source]¶ N-dimensional Fast-Fourier Transform.
Apply N-dimensional Fast-Fourier Transform (FFT) to any n axes of a multi-dimensional array depending on the choice of
dirs.Using the default NumPy engine, the FFT operator is an overload to either the NumPy
numpy.fft.fftn(ornumpy.fft.rfftnfor real models) in forward mode, and tonumpy.fft.ifftn(ornumpy.fft.irfftnfor real models) in adjoint mode, or their CuPy equivalents. Alternatively, when the SciPy engine is chosen, the overloads are ofscipy.fft.fftn(orscipy.fft.rfftnfor real models) in forward mode, and toscipy.fft.ifftn(orscipy.fft.irfftnfor real models) in adjoint mode.When using
real=True, the result of the forward is also multiplied by \(\sqrt{2}\) for all frequency bins except zero and Nyquist along the last direction ofdirs, and the input of the adjoint is multiplied by \(1 / \sqrt{2}\) for the same frequencies.For a real valued input signal, it is advised to use the flag
real=Trueas it stores the values of the Fourier transform of the last direction at positive frequencies only as values at negative frequencies are simply their complex conjugates.Parameters: - dims :
tuple Number of samples for each dimension
- dirs :
tupleorint, optional Direction(s) along which FFTND is applied
- nffts :
tupleorint, optional Number of samples in Fourier Transform for each direction. In case only one dimension needs to be specified, use
Nonefor the other dimension in the tuple. The direction with None will usedims[dir]asnfft. When supplying a tuple, the order must agree with that ofdirs. When a single value is passed, it will be used for both directions. As such the default is equivalent tonffts=(None,..., None).- sampling :
tupleorfloat, optional Sampling steps for each direction. When supplied a single value, it is used for all directions. Unlike
nffts, anyNonewill not be converted to the default value.- norm : {“ortho”, “none”, “1/n”}, optional
New in version 1.17.0.
- “ortho”: Scales forward and adjoint FFT transforms with \(1/\sqrt{N_F}\),
where \(N_F\) is the number of samples in the Fourier domain given by
product of all elements of
nffts. - “none”: Does not scale the forward or the adjoint FFT transforms.
- “1/n”: Scales both the forward and adjoint FFT transforms by \(1/N_F\).
Note
For “none” and “1/n”, the operator is not unitary, that is, the adjoint is not the inverse. To invert the operator, simply use
Op \ y.- “ortho”: Scales forward and adjoint FFT transforms with \(1/\sqrt{N_F}\),
where \(N_F\) is the number of samples in the Fourier domain given by
product of all elements of
- real :
bool, optional Model to which fft is applied has real numbers (
True) or not (False). Used to enforce that the output of adjoint of a real model is real. Note that the real FFT is applied only to the first dimension to which the FFTND operator is applied (last element ofdirs)- ifftshift_before :
tupleorbool, optional New in version 1.17.0.
Apply ifftshift (
True) or not (False) to model vector (before FFT). Consider using this option when the model vector’s respective axis is symmetric with respect to the zero value sample. This will shift the zero value sample to coincide with the zero index sample. With such an arrangement, FFT will not introduce a sample-dependent phase-shift when compared to the continuous Fourier Transform. When passing a single value, the shift will the same for every direction. Pass a tuple to specify which dimensions are shifted.- fftshift_after :
tupleorbool, optional New in version 1.17.0.
Apply fftshift (
True) or not (False) to data vector (after FFT). Consider using this option when you require frequencies to be arranged naturally, from negative to positive. When not applying fftshift after FFT, frequencies are arranged from zero to largest positive, and then from negative Nyquist to the frequency bin before zero. When passing a single value, the shift will the same for every direction. Pass a tuple to specify which dimensions are shifted.- engine :
str, optional New in version 1.17.0.
Engine used for fft computation (
numpyorscipy).- dtype :
str, optional Type of elements in input array. Note that the
dtypeof the operator is the corresponding complex type even when a real type is provided. In addition, note that the NumPy backend does not support returningdtypedifferent thancomplex128. As such, when using the NumPy backend, arrays will be force-cast to types corresponding to the supplieddtype. The SciPy backend supports all precisions natively. Under both backends, when a realdtypeis supplied, a real result will be enforced on the result of thermatvecand the input of thematvec.
Raises: - ValueError
- If
nfftsorsamplingare not either a single value or tuple with the same dimensiondirs. - If
normis not one of “ortho”, “none”, or “1/n”.
- If
- NotImplementedError
If
engineis neithernumpy, norscipy.
Notes
The FFTND operator (using
norm="ortho") applies the N-dimensional forward Fourier transform to a multi-dimensional array. Considering an N-dimensional signal \(d(x_1, \ldots, x_N)\). The FFTND in forward mode is:\[D(k_1, \ldots, k_N) = \mathscr{F} (d) = \frac{1}{\sqrt{N_F}} \int\limits_{-\infty}^\infty \cdots \int\limits_{-\infty}^\infty d(x_1, \ldots, x_N) e^{-j2\pi k_1 x_1} \cdots e^{-j 2 \pi k_N x_N} \,\mathrm{d}x_1 \cdots \mathrm{d}x_N\]Similarly, the three-dimensional inverse Fourier transform is applied to the Fourier spectrum \(D(k_z, k_y, k_x)\) in adjoint mode:
\[d(x_1, \ldots, x_N) = \mathscr{F}^{-1} (D) = \frac{1}{\sqrt{N_F}} \int\limits_{-\infty}^\infty \cdots \int\limits_{-\infty}^\infty D(k_1, \ldots, k_N) e^{-j2\pi k_1 x_1} \cdots e^{-j 2 \pi k_N x_N} \,\mathrm{d}k_1 \cdots \mathrm{d}k_N\]where \(N_F\) is the number of samples in the Fourier domain given by the product of the element of
nffts. Both operators are effectively discretized and solved by a fast iterative algorithm known as Fast Fourier Transform. Note that the FFTND operator (usingnorm="ortho") is a special operator in that the adjoint is also the inverse of the forward mode. For other norms, this does not hold (seenormhelp). However, for any norm, the N-dimensional Fourier transform is Hermitian for real input signals.Attributes: - dims_fft :
tuple Shape of the array after the forward, but before linearization.
For example,
y_reshaped = (Op * x.ravel()).reshape(Op.dims_fft).- fs :
tuple Each element of the tuple corresponds to the Discrete Fourier Transform sample frequencies along the respective direction given by
dirs.- real :
bool When
True, usesrfftn/irfftn- rdtype :
bool Expected input type to the forward
- cdtype :
bool Output type of the forward. Complex equivalent to
rdtype.- shape :
tuple Operator shape
- clinear :
bool New in version 1.17.0.
Operator is complex-linear. Is false when either
real=Trueor whendtypeis not a complex type.- explicit :
bool Operator contains a matrix that can be solved explicitly (
True) or not (False)
- dims :