﻿# CuPy real FFT round trips: retain the original length, axis and normalization

Preserve the original signal length and explicit transform conventions when using CuPy rfft and irfft, especially for odd lengths and batched signals.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-cupy-real-fft-length-normalization-contract/
Language: en

## Treat spectral metadata as part of the signal

An audio-feature pipeline stores a real-input Fourier spectrum and later reconstructs a waveform. The complex coefficient array is not the complete reconstruction contract. The [CuPy rfft reference](https://docs.cupy.dev/en/stable/reference/generated/cupy.fft.rfft.html) defines the transformed axis, requested transform length and normalization. Preserve these choices alongside the coefficients. A downstream consumer that guesses from the array shape can produce a plausible waveform with a different intended sample count or scaling convention.

## Keep the original length for odd signals

The [CuPy irfft reference](https://docs.cupy.dev/en/stable/reference/generated/cupy.fft.irfft.html) describes an even-length default inferred from the spectrum when an output length is omitted. A half-spectrum can correspond to different original length parities. Pass the intended reconstruction length explicitly when exact coverage matters. Do not silently trim the source signal to make a round-trip test pass: that changes the represented interval and can move the relationship between the waveform and its time-based labels.

## Understand why the final coefficient is ambiguous

The [NumPy inverse real-FFT notes](https://numpy.org/doc/stable/reference/generated/numpy.fft.irfft.html) explain the dependence of Hermitian interpretation on original length. This gives a mathematical reason to preserve metadata instead of treating a shape mismatch as a library inconvenience. An odd-length signal and an even-length signal can assign different meaning to the final stored frequency component. A correct consumer must know which interpretation the producer intended before reconstructing or editing the spectrum.

## Specify axes and normalization at both ends

A batch axis, channel axis and time axis are different dimensions. Record which one the transform uses, and apply the same intended forward/inverse normalization pair. A tensor layout refactor can preserve the array rank while changing the meaning of a default last-axis transform. Include an input with distinguishable channel and time structure so the test reveals the wrong axis rather than passing because all dimensions happened to contain similar values or symmetric patterns.

## Validate the interval as well as numerical error

Compare reconstructed values within an appropriate tolerance, confirm output shape and check alignment with the original time interval. The guides on [audio resampling and time labels](/journal/data-guide-audio-resample-time-labels/) and [tensor layout contracts](/journal/learn-tensor-memory-descriptor/) provide related context. A successful inverse operation does not prove that the consumer recovered the producer's intended signal. Store the transform contract with the spectral artifact so a later model or preprocessing revision can reproduce the same interpretation.
