prtools.fftconv#

fftconv(array, kernel, axes=(-2, -1), normalize_kernel=True, fft_array=True, fft_kernel=False, fftshift_kernel=False)[source]#

Convolve an array with a kernel using the FFT.

The convolution is computed as

\[u*v = \mathcal{F}^{-1}\left\{\mathcal{F}\{u\}\cdot\mathcal{F}\{v\}\right\}\]
Parameters:
  • array (array_like) – Array to be convolved with kernel.

  • kernel (array_like) – Convolution kernel. Should have the same shape as array. May be given in either the frequency or spatial domain, as indicated by fft_kernel. The kernel is applied exactly as supplied. See Notes for normalization details.

  • axes (sequence of ints, optional) – Axes over which to apply the convolution. If not given, the last two axes are used.

  • fft_array (bool, optional) – If True (default), the array is assumed to be provided in the spatial domain and its FFT will be computed by this function. If False, the array is assumed to be provided in the frequency domain.

  • fft_kernel (bool, optional) – If True, the kernel is assumed to be provided in the spatial domain and its FFT will be computed by this function. If False (default), the kernel is assumed to be provided in the frequency domain.

  • fftshift_kernel (bool, optional) – If True, the supplied kernel will be shifted so that its zero-frequency (DC) term is placed at the upper left (0,0) corner of the array. Default is False.

Return type:

ndarray

Notes

Kernel normalization This function does not normalize or scale the supplied kernel in any way.

The sum of array is conserved when the kernel’s transfer function is unity at zero frequency. Depending on which domain the kernel is supplied in, the kernel normaliztion approach is different:

  • A frequency-domain kernel (fft_kernel=False) should be scaled such that kernel[0,0] == 1. Note that kernel[0,0] is the zero-frequency term only for a kernel in standard (unshifted) FFT layout. If the kernel origin lies at the center of the array (fftshift_kernel=True), the DC term is at kernel[nr//2, nc//2].

  • A spatial-domain kernal(fft_kernel=True) should have

sum(kernel) == 1.