liveBook · Manning

Discrete Fourier transform

As explained in Building Quantum Software with Python

The discrete Fourier transform is a mathematical operation that converts a finite sequence of discrete signal samples into its frequency components.

The discrete Fourier transform (DFT) converts finite samples of a signal, such as a sound wave, into numerical frequency components. Its inverse reconstructs the signal from those components, supporting digital audio encoding and analysis. section 7.0

The DFT compares a discrete signal with sinusoidal Fourier bases of different frequencies. Each output is a complex number whose magnitude and phase describe that frequency component; together, the outputs decompose the signal into frequency bins. section 7.3.1

A direct Python implementation follows the correlation-based definition:

  • Build Fourier bases from complex rotations, using a sequence length N and frequency index l. section 7.3.1
  • Compute each coefficient as the inner product between the samples and its corresponding basis. section 7.3.1
  • Apply the same calculation across all frequency indices to produce the complete DFT sequence. section 7.3.1
  • Check the result with NumPy's FFT, a high-performance classical algorithm for computing the DFT. section 7.3.1

Recovering frequencies from sampled data

For N = 8, sample a cosine wave with frequency 1.7, normalize the samples, and correlate them with eight Fourier bases. The resulting complex sequence contains conjugate-symmetric components, with large values near the signal's dominant frequency. NumPy's FFT produces the same values as the explicit inner-product implementation. section 7.3.1

N = 4
omega = cis(2*pi/N)

F_0 = [omega**(0*k) for k in range(N)]
F_1 = [omega**(1*k) for k in range(N)]
F_2 = [omega**(2*k) for k in range(N)]
F_3 = [omega**(3*k) for k in range(N)]

Inspect the explicit Python construction of four Fourier bases for N = 4 before calculating signal correlations. section 7.3.1

How Building Quantum Software with Python covers it

How deep it goes
Defines Fourier bases, complex coefficients, inner-product computation, inverse-sign convention, and a NumPy verification, without deriving FFT internals.
Examples
Uses sampled sound, an N = 4 basis construction, an eight-sample cosine wave, explicit Python correlations, and NumPy FFT output.
What it assumes
Starts from discrete signal samples and introduces complex Fourier bases and inner products while assuming familiarity with basic Python operations.
What you can do after
Apply it via Python inner products or NumPy FFT to decompose finite sampled signals into complex frequency components.
How it connects
Links Fourier bases, inverse Fourier transform, fast Fourier transform, quantum Fourier transform, quantum parallelism, and interference.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.