rfftfreq
→Tensorrfftfreq(n: int, d: float = 1.0, dtype: DTypeLike = None, device: DeviceLike = None)Frequency bin centres for the output of rfft / rfftn.
Returns a 1-D tensor of length
containing the non-negative discrete frequencies corresponding to
the output bins of a length-n real DFT. Because rfft
exploits conjugate symmetry and returns only the unique half of the
spectrum, all returned frequencies are non-negative:
Parameters
nintrfft output. Must be positive.dfloat= 1.01.0
(cycles per sample). Pass d = 1/fs to get frequencies in Hz.dtypeDTypeLike= NonedeviceDeviceLike= NoneReturns
Tensor1-D float tensor of shape containing the non-negative frequency bin centres, in ascending order from 0 to the Nyquist frequency .
Notes
Non-negative only — unlike fftfreq, rfftfreq returns
only non-negative frequencies. The last bin is the Nyquist frequency
. This is because for a real input
the negative-frequency bins are redundant (they are the complex
conjugates of the positive-frequency bins).
Bin count — for even , there are bins (including DC and Nyquist); for odd , there are bins (including DC but no exact Nyquist bin).
Monotone ordering — the output is always in ascending order,
making it directly usable as an -axis for power spectra.
No fftshift is needed.
Examples
Frequencies for a length-8 real DFT:
>>> lucid.fft.rfftfreq(8)
# [0., 0.125, 0.25, 0.375, 0.5] — shape (5,)
Frequencies in Hz at 44100 Hz sample rate:
>>> fs = 44100.0
>>> freqs = lucid.fft.rfftfreq(2048, d=1.0/fs)
>>> freqs.shape
(1025,)
>>> # freqs[-1] ≈ 22050.0 Hz (Nyquist)
Pair with rfft output:
>>> x = lucid.randn(1024)
>>> X = lucid.fft.rfft(x)
>>> freqs = lucid.fft.rfftfreq(1024)
>>> # len(freqs) == X.shape[-1] == 513