Skip to main content
All FFT functions are accessed via the np.fft namespace and return complex128 arrays. numpy-ts uses a Cooley-Tukey radix-2 algorithm for power-of-2 sizes and Bluestein’s algorithm for arbitrary sizes.

fft

Compute the 1-D discrete Fourier Transform.
function fft(
  a: ArrayLike,
  n?: number,
  axis?: number,
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array (real or complex).
nnumbera.shape[axis]Length of the transformed axis. If shorter than the input, the input is truncated. If longer, it is zero-padded.
axisnumber-1Axis along which to compute the FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode. 'backward' applies no scaling on forward, 1/n on inverse. 'ortho' applies 1/sqrt(n) to both. 'forward' applies 1/n on forward.
Returns: NDArray — Complex128 array containing the FFT result.
import * as np from 'numpy-ts';

const signal = np.array([1, 2, 3, 4]);
const spectrum = np.fft.fft(signal);
// array([10+0j, -2+2j, -2+0j, -2-2j])

ifft

Compute the 1-D inverse discrete Fourier Transform.
function ifft(
  a: ArrayLike,
  n?: number,
  axis?: number,
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array (typically complex, from fft).
nnumbera.shape[axis]Length of the transformed axis.
axisnumber-1Axis along which to compute the IFFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array containing the IFFT result.
import * as np from 'numpy-ts';

const signal = np.array([1, 2, 3, 4]);
const spectrum = np.fft.fft(signal);
const recovered = np.fft.ifft(spectrum);
// array([1+0j, 2+0j, 3+0j, 4+0j])

fft2

Compute the 2-D discrete Fourier Transform. Equivalent to applying fft along the last two axes.
function fft2(
  a: ArrayLike,
  s?: [number, number],
  axes?: [number, number],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array (at least 2-D).
s[number, number]shape of a along axesShape of the output along the transform axes. Zero-pads or truncates as needed.
axes[number, number][-2, -1]Axes over which to compute the 2-D FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array containing the 2-D FFT result.
import * as np from 'numpy-ts';

const a = np.array([[1, 2], [3, 4]]);
const F = np.fft.fft2(a);
// 2-D complex spectrum

ifft2

Compute the 2-D inverse discrete Fourier Transform.
function ifft2(
  a: ArrayLike,
  s?: [number, number],
  axes?: [number, number],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array (complex, from fft2).
s[number, number]shape of a along axesShape of the output along the transform axes.
axes[number, number][-2, -1]Axes over which to compute the 2-D IFFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array containing the 2-D IFFT result.

fftn

Compute the N-dimensional discrete Fourier Transform.
function fftn(
  a: ArrayLike,
  s?: number[],
  axes?: number[],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array.
snumber[]shape of a along axesShape of the output along the transform axes.
axesnumber[]all axesAxes over which to compute the FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array containing the N-D FFT result.
import * as np from 'numpy-ts';

const a = np.zeros([4, 4, 4]);
const F = np.fft.fftn(a);

ifftn

Compute the N-dimensional inverse discrete Fourier Transform.
function ifftn(
  a: ArrayLike,
  s?: number[],
  axes?: number[],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array (complex, from fftn).
snumber[]shape of a along axesShape of the output along the transform axes.
axesnumber[]all axesAxes over which to compute the IFFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array containing the N-D IFFT result.