Spectral analysis
Inspecting frequency content in sampled signals.
SciPy · Function
Computes a one-dimensional discrete Fourier transform using the fast Fourier transform algorithm. It transforms the selected axis, optionally changing its length and normalization.
The function transforms one selected axis of an array into its discrete Fourier representation using the FFT algorithm. The optional length can crop or zero-pad that axis, while normalization controls scaling between forward and inverse transforms.
scipy.fft.fft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, *, plan=None)| Name | Type | Description |
|---|---|---|
x | array_like | Input array; it may contain complex values. |
n | int, optional | Output length along the transformed axis; defaults to that axis's input length. |
axis | int, optional | Axis along which to compute the transform; defaults to the last axis. |
norm | {“backward”, “ortho”, “forward”}, optional | Normalization mode: backward, ortho, or forward. |
overwrite_x | bool, optional | Whether the input may be overwritten to reduce memory use. |
workers | int, optional | Number of workers to use for computation. |
plan | object, optional | Reserved parameter for vendor-specific FFT plans; currently unused. |
A complex-valued array containing the one-dimensional discrete Fourier transform, with the transformed axis having length n or its original length when n is omitted.
import numpy as np
from scipy.fft import fft, ifft
x = np.array([1.0, 0.0, -1.0, 0.0])
spectrum = fft(x)
reconstructed = ifft(spectrum)
print(spectrum)
print(np.allclose(reconstructed, x))Computes the spectrum of a short real sequence and verifies that the inverse transform reconstructs the input.
Inspecting frequency content in sampled signals.
Converting convolution or filtering work into the frequency domain.
Transforming each row or column of a multidimensional array.
It computes a one-dimensional discrete Fourier transform with the efficient Fast Fourier Transform algorithm. The transform is applied along the selected axis, which defaults to the last axis.
Follow-up: How can the transform length differ from the input length? Set n explicitly: a smaller value crops the selected axis and a larger value zero-pads it.
n specifies the output length along the transformed axis. Omitting it uses the input length along axis; setting it changes the length by cropping or zero-padding.
Follow-up: Which axis is affected? The axis argument identifies it, and its default value is -1, the last axis.
The default backward mode applies no scaling to the forward transform and uses 1/n scaling on ifft. forward applies 1/n to the forward transform, while ortho scales both directions by 1/sqrt(n).
Follow-up: When is ortho useful? It provides symmetric scaling between the forward and inverse operations.
scipy.fft.ifftscipy.fft.fft2scipy.fft.fftnscipy.fft.rfftscipy.fft.rfftfreq