Frequency-spectrum analysis
Analyze real sensor, audio, or sampled measurement data in the frequency domain.
SciPy · Function
Computes the one-dimensional discrete Fourier transform of real-valued input using an efficient FFT algorithm. It returns the nonredundant complex spectrum along the selected axis.
rfft computes the one-dimensional, n-point discrete Fourier transform of real-valued input using an efficient FFT algorithm. It transforms the selected axis, optionally truncating or zero-padding it to n, and returns only the nonredundant frequency components.
scipy.fft.rfft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, *, plan=None)| Name | Type | Description |
|---|---|---|
x | array_like | Input array. |
n | int, optional | Number of points along the transformation axis to use. If omitted, the axis length is used; smaller values crop and larger values zero-pad. |
axis | int, optional | Axis over which to compute the FFT. Defaults to the last axis. |
norm | {"backward", "ortho", "forward"}, optional | Normalization mode: "backward", "ortho", or "forward". Defaults to "backward". |
overwrite_x | bool, optional | Whether to allow overwriting the input array when possible. |
workers | int, optional | Maximum number of workers to use for parallel computation. |
plan | object, optional | Reserved for a future FFT plan argument; currently not used. |
complex ndarray: the transformed, truncated or zero-padded input along the selected axis; for even n its transformed-axis length is n/2 + 1, and for odd n it is (n + 1)/2.
import numpy as np
from scipy.fft import rfft
samples = np.array([0.0, 1.0, 0.0, -1.0])
spectrum = rfft(samples)
print(spectrum)
print(spectrum.shape) # (3,)Transforms a real four-sample signal and prints its one-sided complex spectrum.
Analyze real sensor, audio, or sampled measurement data in the frequency domain.
Transform multidimensional real arrays along a selected dimension.
Control transform length for consistent FFT sizes or zero-padding.
rfft computes the one-dimensional discrete Fourier transform for real-valued input with an FFT algorithm. It avoids returning the redundant negative-frequency half that is implied by a real input.
Follow-up: How does the output size change with n? For even n it is n/2 + 1; for odd n it is (n + 1)/2.
n specifies how many points along the chosen transformation axis are used. A smaller n crops the input, while a larger n pads it with zeros; if omitted, the axis length is used.
Follow-up: Which axis is transformed by default? The last axis, because axis defaults to -1.
norm controls normalization and accepts backward, ortho, or forward. The default is backward, so callers should choose explicitly when interoperability requires a particular scaling convention.
Follow-up: What does the function return? A complex ndarray containing the transformed, possibly cropped or zero-padded input along the selected axis.
scipy.fft.fftscipy.fft.irfftscipy.fft.rfftfreqscipy.fft.fftnscipy.fft.rfftn