RFFTFREQ

This function returns the discrete frequency-bin centers corresponding to the output of a one-sided real FFT. It provides the nonnegative frequency axis used to interpret amplitudes from real-input transforms.

For transform length n and sample spacing d, the bins are:

f_k = \frac{k}{d n}, \quad k = 0, 1, \dots, \left\lfloor\frac{n}{2}\right\rfloor

Excel Usage

=RFFTFREQ(n, d)
  • n (int, required): Window length.
  • d (float, optional, default: 1): Sample spacing (inverse of sampling rate).

Returns (list[list]): A single-row 2D array of nonnegative sample frequencies.

Example 1: Frequency bins for even length

Inputs:

n
8

Excel formula:

=RFFTFREQ(8)

Expected output:

Result
0 0.125 0.25 0.375 0.5
Example 2: Frequency bins for odd length

Inputs:

n
7

Excel formula:

=RFFTFREQ(7)

Expected output:

Result
0 0.142857 0.285714 0.428571
Example 3: Frequency bins with custom sample spacing

Inputs:

n d
8 0.1

Excel formula:

=RFFTFREQ(8, 0.1)

Expected output:

Result
0 1.25 2.5 3.75 5
Example 4: Frequency bins for longer transform

Inputs:

n d
16 0.5

Excel formula:

=RFFTFREQ(16, 0.5)

Expected output:

Result
0 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1

Python Code

Show Code
from numpy.fft import rfftfreq as numpy_rfftfreq

def rfftfreq(n, d=1):
    """
    Return sample frequencies for one-sided real FFT bins.

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

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

    Args:
        n (int): Window length.
        d (float, optional): Sample spacing (inverse of sampling rate). Default is 1.

    Returns:
        list[list]: A single-row 2D array of nonnegative sample frequencies.
    """
    try:
        n_val = int(n)
        d_val = float(d)

        if n_val <= 0:
            return "Error: n must be a positive integer"
        if d_val <= 0:
            return "Error: d must be positive"

        freqs = numpy_rfftfreq(n_val, d=d_val)
        return [freqs.tolist()]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Window length.
Sample spacing (inverse of sampling rate).