|q⟩ Bad Qubits

intermediate · Programming · The Quantum Fourier Transform

The Discrete Fourier Transform

The Quantum Fourier Transform (QFT) is at the heart of some of the most important quantum algorithms — Shor's factoring algorithm and quantum phase estimation among them. Before building the quantum version, it is worth recalling what the classical Discrete Fourier Transform (DFT) does, because the QFT computes exactly the same mathematical function, just on quantum amplitudes rather than on a list of numbers.

Signals and frequency content

Suppose you record a sound for one second and sample it NN times, obtaining a list of real (or complex) numbers

x0,x1,,xN1.x_0,\, x_1,\, \dots,\, x_{N-1}.

Each xjx_j is the amplitude of the signal at time tj=j/Nt_j = j/N. The signal might contain several pure tones mixed together, and you want to find out which frequencies are present and how strongly. That is exactly what the DFT does.

The DFT formula

The DFT maps the time-domain vector x=(x0,,xN1)\mathbf{x} = (x_0, \dots, x_{N-1}) to a frequency-domain vector y=(y0,,yN1)\mathbf{y} = (y_0, \dots, y_{N-1}) by

yk=1Nj=0N1xjωNjk,k=0,1,,N1,y_k = \frac{1}{\sqrt{N}} \sum_{j=0}^{N-1} x_j \, \omega_N^{jk}, \qquad k = 0, 1, \dots, N-1,

where ωN=e2πi/N\omega_N = e^{2\pi i / N} is the primitive NN-th root of unity. The coefficient yky_k measures how much the signal oscillates at frequency kk cycles per sample window.

The DFT as a matrix

Because the DFT is a linear map, it can be written as matrix multiplication y=FNx\mathbf{y} = F_N \mathbf{x}, where the (k,j)(k,j) entry of the N×NN \times N DFT matrix FNF_N is

(FN)kj=1NωNjk.(F_N)_{kj} = \frac{1}{\sqrt{N}} \omega_N^{jk}.

For N=4N = 4 the matrix is

F4=12(11111i1i11111i1i).F_4 = \frac{1}{2} \begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & i & -1 & -i \\ 1 & -1 & 1 & -1 \\ 1 & -i & -1 & i \end{pmatrix}.

The rows are sampled complex exponentials at frequencies k=0,1,2,3k = 0, 1, 2, 3. You can verify directly that F4F4=IF_4 F_4^\dagger = I, confirming that F4F_4 is unitary.

The inverse DFT

Because FNF_N is unitary, its inverse is simply its conjugate transpose: FN1=FNF_N^{-1} = F_N^\dagger. Explicitly,

xj=1Nk=0N1ykωNjk.x_j = \frac{1}{\sqrt{N}} \sum_{k=0}^{N-1} y_k \, \omega_N^{-jk}.

The inverse DFT converts frequency-domain data back to the time domain, and its formula differs from the forward DFT only by the sign of the exponent.

Naive complexity and the FFT

Computing all NN outputs of the DFT naively requires NN multiplications and additions for each of the NN outputs, giving O(N2)O(N^2) operations. For N=2nN = 2^n, the Fast Fourier Transform (FFT) exploits the recursive structure of ωN\omega_N to reduce this to O(NlogN)=O(n2n)O(N \log N) = O(n \cdot 2^n) operations — a dramatic improvement that made signal processing practical.

Despite the FFT's speed, factoring an nn-bit number still requires classical steps exponential in nn. The QFT will allow quantum computers to evaluate the transform in only O(n2)O(n^2) gate operations on nn qubits — an exponential improvement over even the FFT when measured per input qubit — and that efficiency is the key ingredient in Shor's algorithm.

What comes next

In the following lessons we will:

  1. Define the QFT as a unitary transformation on the standard nn-qubit basis states.
  2. Show that it equals the DFT acting on the vector of computational-basis amplitudes.
  3. Build the QFT circuit gate by gate from Hadamards and controlled phase rotations.
  4. Apply the QFT to quantum phase estimation, which underlies Shor's factoring algorithm.

Keeping the DFT formula yk=1NjxjωNjky_k = \frac{1}{\sqrt{N}} \sum_j x_j \omega_N^{jk} in mind will make every subsequent step feel like a natural generalization.

Sign in on the full site to ask questions and join the discussion.