AI Wiki中文/EN

Fourier transforms

傅里叶变换

Read frequency, phase and normalization through a known spectrum and a real FFT.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

The same signal can be described by its ingredients

A sampled signal may combine a constant offset, a slow oscillation and a faster oscillation. Looking at its values over time mixes those ingredients together. A Fourier representation describes how much of each frequency component is present, including its phase.

This is a change of representation, not a claim that every real process is periodic. It is useful in audio, image filtering, numerical solvers and model diagnostics. The meaning of a frequency bin depends on sampling interval, observation duration and normalization.

Read scalars and vectors and inner products first. Here i²=−1 and exp(iθ)=cosθ+i sinθ; a complex number a+ib stores real part a and imaginary part b. If complex numbers are new, interpret the real and imaginary parts as coefficients of cosine and sine components; phase records their relative alignment.

State which Fourier object you are using

For an absolutely integrable continuous-time function, one common frequency-in-cycles convention is:

f^(ν)=∫−∞∞f(t)e−2πiνt dt.\widehat f(\nu)=\int_{-\infty}^{\infty}f(t)e^{-2\pi i\nu t}\,dt.

Other conventions use angular frequency and different constants. Inversion needs additional conditions or an appropriate generalized interpretation; it is not an unconditional operation on every function. DLMF §1.14 describes Fourier integral transforms and convention-dependent formulas.

A Fourier series describes a periodic function through discrete harmonics. A discrete Fourier transform, or DFT, instead maps a finite sequence of N numbers to N coefficients. We use NumPy’s default forward and inverse conventions:

Xk=∑n=0N−1xne−2πikn/N,xn=1N∑k=0N−1Xke2πikn/N.X_k=\sum_{n=0}^{N-1}x_n e^{-2\pi i kn/N},\qquad x_n=\frac1N\sum_{k=0}^{N-1}X_k e^{2\pi i kn/N}.

The complex exponentials are orthogonal on these sample positions. Summing a nontrivial Nth-root-of-unity progression gives zero; matching frequencies give N. That identity explains both reconstruction and the inverse’s factor 1/N. NumPy 1.26’s FFT documentation states the implemented signs, normalization and output order.

Frequencies, magnitudes and energy

With sample spacing Δt, bin k has frequency k/(NΔt), understood modulo the sample rate 1/Δt. Upper-index bins represent negative frequencies in the usual ordering. For real inputs, positive and negative frequency coefficients are conjugate pairs. An even-length Nyquist bin is its own negative-frequency counterpart.

X₀ is the sum of the samples, so the mean is X₀/N. For a cosine exactly aligned with a nonzero, non-Nyquist bin, its amplitude is 2|X_k|/N. Do not apply that factor blindly to DC or Nyquist. Under this normalization, energy satisfies:

∑n=0N−1∣xn∣2=1N∑k=0N−1∣Xk∣2.\sum_{n=0}^{N-1}|x_n|^2=\frac1N\sum_{k=0}^{N-1}|X_k|^2.

FFT is an algorithm for the DFT

Directly evaluating every coefficient costs O(N²) arithmetic. FFT algorithms exploit structure. For power-of-two lengths, a radix-two split separates even and odd samples into two half-length transforms, then combines them in O(N) work, giving O(N log N). The transform being computed is still the DFT. Production implementations support other lengths and choose suitable factorizations; this chapter calls NumPy’s implementation rather than claiming to implement all FFT variants.

Recover a known spectrum and invert it

Use Python 3.12 and NumPy 1.26.4. The complete program accepts 1–32 finite real or complex samples of magnitude at most one million. It compares an explicit DFT matrix with a real FFT call and then checks inverse reconstruction. The chosen tolerances belong to this bounded small experiment.

import numpy as np


def analyze(values):
    x=np.asarray(values)
    if x.ndim!=1 or not 1 <= len(x) <= 32 or x.dtype.kind not in 'iufc':
        raise ValueError('1 to 32 numeric scalar samples required')
    x=x.astype(np.complex128)
    if not np.all(np.isfinite(x)) or np.any(np.abs(x)>1e6):
        raise ValueError('finite samples with magnitude at most 1e6 required')
    n=len(x);indices=np.arange(n)
    basis=np.exp(-2j*np.pi*np.outer(indices,indices)/n)
    direct=basis@x
    fast=np.fft.fft(x)
    restored=np.fft.ifft(fast)
    np.testing.assert_allclose(direct,fast,atol=1e-7,rtol=1e-12)
    np.testing.assert_allclose(restored,x,atol=1e-7,rtol=1e-12)
    return fast,restored


if __name__ == '__main__':
    n=np.arange(8)
    signal=1+2*np.cos(2*np.pi*n/8)+np.sin(4*np.pi*n/8)
    spectrum,restored=analyze(signal)
    expected=np.array([8,8,-4j,0,0,0,4j,8])
    np.testing.assert_allclose(spectrum,expected,atol=1e-12,rtol=0)
    time_energy=float(np.sum(np.abs(signal)**2))
    spectral_energy=float(np.sum(np.abs(spectrum)**2)/8)
    print('nonzero bins:',[(k,int(round(z.real)),int(round(z.imag)))
                           for k,z in enumerate(spectrum) if abs(z)>1e-10])
    print('time energy:',round(time_energy,10))
    print('spectral energy / N:',round(spectral_energy,10))
    print('inverse reconstruction:',bool(np.allclose(restored,signal,atol=1e-12,rtol=0)))

Output, with displayed coefficient components rounded to integers:

nonzero bins: [(0, 8, 0), (1, 8, 0), (2, 0, -4), (6, 0, 4), (7, 8, 0)]
time energy: 28.0
spectral energy / N: 28.0
inverse reconstruction: True

The signal has DC value 1, cosine amplitude 2 at bin 1, and sine amplitude 1 at bin 2. Its spectrum therefore has X₀=8, X₁=X₇=8, X₂=−4i and X₆=4i. Both energy calculations give 28. The direct reference intentionally stores O(N²) coefficients; it is a verification tool, not a replacement for the FFT.

A clean spectrum can still answer the wrong question

Sampling aliases frequencies separated by an integer multiple of the sample rate. Recovering a continuous signal from samples requires assumptions such as band limitation and appropriate sampling; a DFT cannot recover frequencies already aliased before it runs.

A finite window effectively selects a limited observation. If the signal does not fit whole cycles in that window, energy spreads across bins—spectral leakage. Window functions trade aspects of that leakage against frequency localization and amplitude interpretation. Zero-padding samples the finite-window spectrum more densely; it does not add observation time or new measured information.

Magnitude alone discards phase, so it generally cannot reconstruct the original signal. Also distinguish cyclic convolution of length-N sequences from linear convolution: FFT multiplication needs sufficient padding when the intended operation is linear convolution. Numerical roundoff remains even though the transform is algebraically invertible.

Read the bins under a declared convention

  1. If X₀=8 for N=8, what is the sample mean?

Answer 1: One. DC is the sample sum in the chosen forward normalization.

  1. Why is the sine component’s bin-2 coefficient imaginary and negative?

Answer 2: With a negative forward exponential, sine decomposes into opposite imaginary coefficients at positive and negative frequencies. Unit sine amplitude gives −iN/2 at its positive bin here.

  1. Why does the inverse formula divide by N?

Answer 3: Matching exponential basis vectors have squared norm N. The division compensates for that factor when summing the coefficients back into samples.

  1. Does appending zeros distinguish two unresolved frequencies as if you had observed the signal longer?

Answer 4: No. It increases spectral sampling density but adds no new observations or time span. Resolution remains constrained by the original measurement window and estimation assumptions.

Connect algebra to sampling conditions

DLMF supplies continuous-transform context, while NumPy fixes the finite numerical convention. The known-bin example checks signs, scaling, energy and reconstruction, so agreement with a library is not the only evidence.

A useful project is to change bin-1’s frequency to 1.25 cycles per window, compare the resulting leakage, and repeat with a longer observation. Keep those changes separate from zero-padding. Continue with convolution to connect spectral multiplication with filtering.

Make a prediction, then check

What does zero-padding add to a fixed measured signal?

Choose one answer

Learning objectives

  • Distinguish continuous transform, series, DFT and FFT.
  • Verify scaling, phase, Parseval energy and inverse reconstruction.

Prerequisites & connections

Explore related knowledge →

References

  1. DLMF §1.14 — Integral Transforms
    NIST Digital Library of Mathematical Functions
  2. Discrete Fourier Transform — NumPy 1.26
    NumPy developers

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: primary-source locations, explicit assumptions, derivations, exact/literal and numerical checks, and bilingual review; not independent human or second-agent peer review.

  • Single-agent authored technical review: primary-source locations, explicit domains and assumptions, derivations, literal/exact probability or numerical reference cases, bilingual examples and exercises. Not independent human or second-agent review.
  • Four focused tests passed on CPython3.12.4; NumPy1.26.4 actually executed for the Fourier chapter. Exact rational probability/stencil checks are distinguished from floating-point calculations and observed Monte Carlo output. Both languages render three equations, six anchors and four answers; final repository checks recorded separately.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.