Skip to main content
The real FFT functions exploit the Hermitian symmetry of the spectrum of real-valued signals. Instead of returning the full n-point spectrum, rfft returns only the first n//2 + 1 unique complex coefficients, cutting storage roughly in half.

rfft

Compute the 1-D FFT of a real-valued array.
function rfft(
  a: ArrayLike,
  n?: number,
  axis?: number,
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeReal-valued input array.
nnumbera.shape[axis]Number of points in the transform.
axisnumber-1Axis along which to compute the FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array of length n//2 + 1 along the transformed axis.
import * as np from 'numpy-ts';

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

irfft

Compute the inverse of rfft. Reconstructs the full real-valued signal from its positive-frequency spectrum.
function irfft(
  a: ArrayLike,
  n?: number,
  axis?: number,
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array from rfft (complex, length n//2 + 1).
nnumber(a.shape[axis] - 1) * 2Length of the output along the transformed axis.
axisnumber-1Axis along which to compute the inverse FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Real-valued float64 array of length n.
import * as np from 'numpy-ts';

const signal = np.array([0, 1, 0, 0]);
const spectrum = np.fft.rfft(signal);
const recovered = np.fft.irfft(spectrum);
// array([0, 1, 0, 0])

rfft2

Compute the 2-D FFT of a real-valued array. Applies fft along the first axis and rfft along the last axis, so the last axis is truncated to n//2 + 1.
function rfft2(
  a: ArrayLike,
  s?: [number, number],
  axes?: [number, number],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeReal-valued input array (at least 2-D).
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 FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array. The last transform axis has length s[1]//2 + 1.
import * as np from 'numpy-ts';

const a = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]);
const F = np.fft.rfft2(a);
// Last axis: length 4//2 + 1 = 3

irfft2

Compute the inverse of rfft2.
function irfft2(
  a: ArrayLike,
  s?: [number, number],
  axes?: [number, number],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array (complex, from rfft2).
s[number, number]inferredShape of the real-valued output along the transform axes.
axes[number, number][-2, -1]Axes over which to compute the inverse FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Real-valued float64 array.

rfftn

Compute the N-dimensional FFT of a real-valued array. Applies fft along all axes except the last, then rfft along the last axis.
function rfftn(
  a: ArrayLike,
  s?: number[],
  axes?: number[],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeReal-valued input 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. The last transform axis has length s[-1]//2 + 1.

irfftn

Compute the inverse of rfftn.
function irfftn(
  a: ArrayLike,
  s?: number[],
  axes?: number[],
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array (complex, from rfftn).
snumber[]inferredShape of the real-valued output along the transform axes.
axesnumber[]all axesAxes over which to compute the inverse FFT.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Real-valued float64 array.

hfft

Compute the FFT of a signal with Hermitian symmetry (i.e., the spectrum is real-valued). This is the inverse of ihfft.
function hfft(
  a: ArrayLike,
  n?: number,
  axis?: number,
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeInput array with Hermitian symmetry.
nnumber(a.shape[axis] - 1) * 2Length of the output.
axisnumber-1Axis along which to compute.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Real-valued float64 array of length n.
import * as np from 'numpy-ts';

// Signal with Hermitian symmetry
const a = np.array([1, 2, 3, 2]);
const spectrum = np.fft.hfft(a);

ihfft

Compute the inverse of hfft. Takes a real-valued signal and returns the Hermitian-symmetric spectrum.
function ihfft(
  a: ArrayLike,
  n?: number,
  axis?: number,
  norm?: 'backward' | 'ortho' | 'forward'
): NDArray
NameTypeDefaultDescription
aArrayLikeReal-valued input array.
nnumbera.shape[axis]Length of the input to use.
axisnumber-1Axis along which to compute.
norm'backward' | 'ortho' | 'forward''backward'Normalization mode.
Returns: NDArray — Complex128 array of length n//2 + 1.