RFFT

The real FFT computes the discrete Fourier transform (DFT) of a real-valued signal and returns only the nonnegative-frequency terms. This reduces redundant output compared with the full complex FFT because negative-frequency components are implied by conjugate symmetry.

For a real sequence x_n of length N, the transform is:

X_k = \sum_{n=0}^{N-1} x_n e^{-i 2\pi kn/N}, \quad k = 0, \dots, \lfloor N/2 \rfloor

Excel Usage

=RFFT(a, n, axis, norm)
  • a (list[list], required): Real-valued signal samples (Excel range).
  • n (int, optional, default: null): Length of the transformed axis of the output.
  • axis (int, optional, default: -1): Axis over which to compute the transform.
  • norm (str, optional, default: null): Normalization mode.

Returns (list[list]): A 2D array where the first row is the real part and the second row is the imaginary part of the one-sided FFT output.

Example 1: One-sided FFT of simple real signal

Inputs:

a
0 1 0 -1

Excel formula:

=RFFT({0,1,0,-1})

Expected output:

Result
0 0 0
0 -2 0
Example 2: One-sided FFT with explicit transform length

Inputs:

a n
1 2 3 8

Excel formula:

=RFFT({1,2,3}, 8)

Expected output:

Result
6 2.41421 -2 -0.414214 2
0 -4.41421 -2 1.58579 0
Example 3: One-sided FFT with orthonormal scaling

Inputs:

a norm
2 0 -2 0 ortho

Excel formula:

=RFFT({2,0,-2,0}, "ortho")

Expected output:

Result
0 2 0
0 0 0
Example 4: One-sided FFT for single scalar input

Inputs:

a
5

Excel formula:

=RFFT(5)

Expected output:

Result
5
0

Python Code

Show Code
import numpy as np
from numpy.fft import rfft as numpy_rfft

def rfft(a, n=None, axis=-1, norm=None):
    """
    Compute the one-dimensional discrete Fourier transform for real input.

    See: https://numpy.org/doc/stable/reference/generated/numpy.fft.rfft.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        a (list[list]): Real-valued signal samples (Excel range).
        n (int, optional): Length of the transformed axis of the output. Default is None.
        axis (int, optional): Axis over which to compute the transform. Default is -1.
        norm (str, optional): Normalization mode. Valid options: Backward, Ortho, Forward. Default is None.

    Returns:
        list[list]: A 2D array where the first row is the real part and the second row is the imaginary part of the one-sided FFT output.
    """
    try:
        def to_ndarray(v):
            if isinstance(v, list):
                if all(isinstance(row, list) for row in v):
                    return np.array([[float(x) for x in row] for row in v], dtype=float)
                return np.array([float(x) for x in v], dtype=float)
            return np.array([float(v)], dtype=float)

        a_arr = to_ndarray(a)
        n_val = int(n) if n is not None else None
        axis_val = int(axis)
        norm_val = norm if norm is not None and str(norm) != "" else None

        result = numpy_rfft(a_arr, n=n_val, axis=axis_val, norm=norm_val)
        flat_result = np.ravel(result)

        return [flat_result.real.tolist(), flat_result.imag.tolist()]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Real-valued signal samples (Excel range).
Length of the transformed axis of the output.
Axis over which to compute the transform.
Normalization mode.