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 N times, obtaining a list of real (or complex) numbers
x0,x1,…,xN−1.
Each xj is the amplitude of the signal at time tj=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,…,xN−1) to a frequency-domain vector y=(y0,…,yN−1) by
yk=N1j=0∑N−1xjωNjk,k=0,1,…,N−1,
where ωN=e2πi/N is the primitive N-th root of unity. The coefficient yk measures how much the signal oscillates at frequency k 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, where the (k,j) entry of the N×NDFT matrixFN is
(FN)kj=N1ωNjk.
For N=4 the matrix is
F4=2111111i−1−i1−11−11−i−1i.
The rows are sampled complex exponentials at frequencies k=0,1,2,3. You can verify directly that F4F4†=I, confirming that F4 is unitary.
The inverse DFT
Because FN is unitary, its inverse is simply its conjugate transpose: FN−1=FN†. Explicitly,
xj=N1k=0∑N−1ykω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 N outputs of the DFT naively requires N multiplications and additions for each of the N outputs, giving O(N2) operations. For N=2n, the Fast Fourier Transform (FFT) exploits the recursive structure of ωN to reduce this to O(NlogN)=O(n⋅2n) operations — a dramatic improvement that made signal processing practical.
Despite the FFT's speed, factoring an n-bit number still requires classical steps exponential in n. The QFT will allow quantum computers to evaluate the transform in only O(n2) gate operations on n 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:
Define the QFT as a unitary transformation on the standard n-qubit basis states.
Show that it equals the DFT acting on the vector of computational-basis amplitudes.
Build the QFT circuit gate by gate from Hadamards and controlled phase rotations.
Apply the QFT to quantum phase estimation, which underlies Shor's factoring algorithm.
Keeping the DFT formula yk=N1∑jxjωNjk 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.