A robot vibration logger can save the nonnegative frequencies from a real-valued accelerometer trace. A later tool may use that spectrum to reconstruct a block of samples or compare its frequency bins with a reference. The number of stored bins does not uniquely identify the length of the original transform. An even block and an odd block can have the same spectrum shape, and the last bin has a different meaning in each case.

The real FFT saves the zero-frequency coefficient and the positive-frequency coefficients because the omitted negative-frequency coefficients are their complex conjugates. With four samples the stored coefficients are indexed zero through two. With five samples the indices are also zero through two. Both files can therefore contain three complex values. Which time grid produced them depends on whether the forward transform used four or five points.

Check two short synthetic blocks

The fixture places a single unit impulse at the second sample in each block. This makes it easy to test both waveform length and timing. The numbers are synthetic and do not describe a fault measurement or a robot operating condition.

import numpy as np

from scipy.fft import rfft

odd = np.array([0.0, 1.0, 0.0, 0.0, 0.0])

even = np.array([0.0, 1.0, 0.0, 0.0])

odd_bins = np.fft.rfft(odd)

even_bins = np.fft.rfft(even)

assert odd_bins.shape == even_bins.shape == (3,)

assert np.allclose(odd_bins, rfft(odd))

assert np.allclose(even_bins, rfft(even))

default_inverse = np.fft.irfft(odd_bins)

odd_inverse = np.fft.irfft(odd_bins, n=5)

even_inverse = np.fft.irfft(even_bins, n=4)

assert default_inverse.shape == (4,)

assert np.allclose(odd_inverse, odd)

assert np.allclose(even_inverse, even)

This ran with NumPy 2.5.2 and SciPy 1.18.1. The default inverse of the odd spectrum produced four samples, approximately 0.2023, 0.9278, minus 0.1068, and minus 0.0233. Supplying five as the inverse length recovered the original impulse within numerical precision. Both implementations of the forward transform agreed for these two blocks. Confirming the output length explicitly is useful because a comparison of rounded values or a plot that normalizes its horizontal span can obscure the mismatch.

Why the final coefficient changes

For a real signal of even length, the final stored bin sits at half the sample rate, called the Nyquist frequency. Its positive- and negative-frequency representations coincide on the sampled grid. The corresponding coefficient is real. In the four-sample impulse example, that last coefficient is minus one with zero imaginary part.

A five-sample transform has no stored bin exactly at half the sample rate. Its highest positive bin sits at two fifths of the sample rate and has a separate conjugate partner. In the same impulse example that coefficient is approximately minus 0.8090 minus 0.5878 times the imaginary unit. NumPy's default inverse assumes the even length derived from the bin count, so it treats the final coefficient as a real Nyquist term. In a separate check, removing the last imaginary component manually gave the same four-sample default inverse. The even inverse is therefore an interpretation of the spectrum on a different grid rather than a truncation of the recovered five-sample waveform.

Retain the transform contract in a log

A spectrum intended for reuse can store the transform length, the sample interval or sample rate, and the normalization convention alongside the complex values. With the length and sample rate, a reader can recover bin spacing in hertz. With the normalization convention, it can use the matching inverse scaling. A channel or array with more than one dimension also needs the axis along which the transform was run. Store those fields as part of the same record as the spectrum to keep them aligned if a capture is split into multiple files.

The stored transform length can differ from the number of captured samples. A pipeline that pads a short block with zeros before the FFT needs both lengths if a consumer must recover the padded array and then locate the original interval. A pipeline that crops the input before transforming can preserve the starting sample offset and the chosen view length. An inverse reconstructs the data represented by the transformed block, so windowing or replacing coefficients changes what that inverse can recover.

Validate what the file promises

For a full nonnegative spectrum, confirm that the bin count equals the integer half of the transform length plus one. A file that stores only magnitudes or a selected band lacks some of the data needed for the round trip demonstrated here. Distinguish complete complex spectra from display summaries in the record format. A legacy spectrum whose transform length is absent can be flagged as ambiguous if the acquisition details cannot settle the length.

Add an odd block with a nonzero imaginary part in its final bin and an even block with an ordinary Nyquist coefficient to a file round-trip test. Save them through the same writer used in the logger, read them back, and check shape before comparing every sample. Include a case where the forward transform length differs from the raw capture length so the test can detect a reader that retrieves the wrong field. Include the sample rate in the expected record and assert that the reconstructed time grid has the original spacing. This catches an independently corrupted rate field even when the FFT round trip succeeds. Keep any synthetic test run in separate records from hardware observations.

The AI-generated concept image shows a vibration sensor on a robot joint beside a diagnostic screen. The displayed waveform and bars illustrate the topic. The quantities in the text come from the synthetic impulse fixture.

Sources checked November 28, 2026. NumPy irfft documentation at https://numpy.org/doc/stable/reference/generated/numpy.fft.irfft.html and SciPy rfft documentation at https://docs.scipy.org/doc/scipy/reference/generated/scipy.fft.rfft.html.