Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

fft.rfft

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.

How it works

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.

Syntax

scipy.fft.rfft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, *, plan=None)

Parameters

NameTypeDescription
xarray_likeInput array.
nint, optionalNumber of points along the transformation axis to use. If omitted, the axis length is used; smaller values crop and larger values zero-pad.
axisint, optionalAxis over which to compute the FFT. Defaults to the last axis.
norm{"backward", "ortho", "forward"}, optionalNormalization mode: "backward", "ortho", or "forward". Defaults to "backward".
overwrite_xbool, optionalWhether to allow overwriting the input array when possible.
workersint, optionalMaximum number of workers to use for parallel computation.
planobject, optionalReserved for a future FFT plan argument; currently not used.

Returns

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.

Key points

  • Use rfft to transform a real-valued one-dimensional signal into its frequency-domain representation.
  • The implementation uses the Fast Fourier Transform for efficient computation.
  • n determines how many samples along the transformation axis participate in the calculation.
  • axis selects the dimension to transform, allowing multidimensional arrays to be processed along a chosen axis.
  • When axis is omitted, the final array dimension is transformed.
  • norm chooses the transform's normalization mode from backward, ortho, or forward.
  • The result is a complex array representing the transformed input after any length adjustment.

Common mistakes

  • Choosing n larger than the input length zero-pads the transformed axis; choosing a smaller n truncates it.
  • The output length depends on n: it is n/2 + 1 for even n and (n + 1)/2 for odd n.

Example: Compute a real-input FFT

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.

When to use it

Frequency-spectrum analysis

Analyze real sensor, audio, or sampled measurement data in the frequency domain.

Axis-specific transforms

Transform multidimensional real arrays along a selected dimension.

Length normalization

Control transform length for consistent FFT sizes or zero-padding.

Interview questions

QWhat does scipy.fft.rfft compute?

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.

QWhat do n and axis control?

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.

QHow is normalization selected, and what is returned?

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.fft
  • scipy.fft.irfft
  • scipy.fft.rfftfreq
  • scipy.fft.fftn
  • scipy.fft.rfftn

Source: rfft — SciPy v1.17.0 Manual. Checked 2026-10-15.