Skip to main content

FFT Module Overview

The numpy.fft module provides functions for computing the Discrete Fourier Transform (DFT) and its inverse using the Fast Fourier Transform (FFT) algorithm.

What is FFT?

Fourier analysis is a method for expressing a function as a sum of periodic components, and for recovering the function from those components. The DFT has become essential in numerical computing because of the FFT algorithm, which computes it efficiently.

Module Organization

The FFT module is organized into several categories:

Standard FFTs

1D, 2D, and N-dimensional complex FFTs

Real FFTs

Optimized transforms for real-valued input

Hermitian FFTs

Transforms for Hermitian-symmetric data

Helper Functions

Frequency bins and spectrum shifting utilities

Mathematical Definition

The DFT is defined as: Ak=m=0n1amexp{2πimkn}k=0,,n1A_k = \sum_{m=0}^{n-1} a_m \exp\left\{-2\pi i\frac{mk}{n}\right\} \qquad k = 0,\ldots,n-1 The inverse DFT is: am=1nk=0n1Akexp{2πimkn}m=0,,n1a_m = \frac{1}{n}\sum_{k=0}^{n-1}A_k\exp\left\{2\pi i\frac{mk}{n}\right\} \qquad m = 0,\ldots,n-1

Normalization Modes

All FFT functions accept a norm parameter with three options:
  • "backward" (default): Forward transform unscaled, inverse scaled by 1/n
  • "ortho": Both transforms scaled by 1/√n (unitary transforms)
  • "forward": Forward transform scaled by 1/n, inverse unscaled

Quick Example

import numpy as np

# Create a simple signal
t = np.linspace(0, 1, 500)
signal = np.sin(2 * np.pi * 50 * t) + 0.5 * np.sin(2 * np.pi * 120 * t)

# Compute FFT
fft_result = np.fft.fft(signal)
freqs = np.fft.fftfreq(len(signal), t[1] - t[0])

# Get power spectrum
power = np.abs(fft_result) ** 2

print(f"Peak frequencies: {freqs[np.argsort(power)[-3:]]}")

Type Promotion

numpy.fft promotes float32 and complex64 arrays to float64 and complex128 respectively. For an FFT implementation that preserves input precision, see scipy.fftpack.

Common Use Cases

Signal Processing

Analyze frequency content of time-domain signals (audio, sensor data)

Image Processing

Apply frequency-domain filters, compression (JPEG uses DCT, similar to FFT)

Fast Convolution

Multiply in frequency domain instead of convolving in time domain

Differential Equations

Solve PDEs using spectral methods
  • SciPy FFT: The scipy.fft module is a more comprehensive superset of numpy.fft
  • Performance: FFT is most efficient when the array size is a power of 2
  • References: Based on Cooley-Tukey algorithm (1965)

See Also

Build docs developers (and LLMs) love