QFT and Phase Estimation Lab
Watch the quantum Fourier transform turn a period into a peak, one gate at a time. Then use it to read a hidden phase with counting qubits, see exactly how often the reading lands on the right value, and decode a period from a measurement with continued fractions. Every table is computed live by an exact state-vector simulator in your browser.
Reviewed December 2026. New to this? On the Fourier transform tab pick Evenly spaced states, set the period to 4 and press Next to the end.
The state you chose, before any gate.
| Basis state | Size | Chance | Phase (turns) |
|---|---|---|---|
| |000⟩ | 0.000 | 0.0% | – |
| |001⟩ | 0.000 | 0.0% | – |
| |010⟩ | 0.000 | 0.0% | – |
| |011⟩ | 1.000 | 100.0% | 0.000 |
| |100⟩ | 0.000 | 0.0% | – |
| |101⟩ | 0.000 | 0.0% | – |
| |110⟩ | 0.000 | 0.0% | – |
| |111⟩ | 0.000 | 0.0% | – |
Phase is shown in turns: 0.25 is a quarter turn (90°), 0.5 a half turn. Size is the absolute value of the amplitude.
What to look for
A basis state goes to a flat spread: every output has chance 1/8. The information moved into the phases. Output |k⟩ carries phase j·k/8 of a turn (mod 1) with j = 3, so the phases wind round 3 times across the table.
Largest difference between this circuit and the textbook formula F|j⟩ = N−1/2 Σ e2πijk/N|k⟩: below 1e-12.
Gates for n = 3: 3 Hadamards, 3 controlled phases, 1 swap (7 in all).
A five-minute path
- Fourier transform tab: leave n = 3 and One basis state, then press Next through all five steps. Note that every output has the same chance and the information sits in the phases.
- Switch to Evenly spaced states with period 4 and n = 5. The output collapses to a few peaks. Change the offset and see that the peaks stay put.
- Phase estimation tab: press Snap φ to a t-bit fraction. The best outcome jumps to 100 percent.
- Move φ slightly off the grid and watch the chance split between two neighbours. Compare it with the two bounds printed beside it.
- Use the counting-qubit calculator: ask for 8 bits with a 1 percent failure chance and note how the largest power of U grows.
- Period finding tab: choose r = 6, press Measure 5 times and read each row. Then lower the denominator bound below r and see recovery fail.
What the lab does and does not do
- It simulates the full quantum state with perfect gates. There is no noise and no hardware.
- In phase estimation the target qubit is the exact eigenvector, so the controlled powers of U become phases on the counting qubits. The result is exact, and the lab compares it with the closed-form formula.
- It counts gates, not time. Building U raised to a large power costs gates the lab does not count.
- The Period finding tab starts from the periodic state that Shor’s algorithm prepares. It does not run modular exponentiation.
Reference tables
Computed by the same code as the lab.
| j | k = 000 | k = 001 | k = 010 | k = 011 | k = 100 | k = 101 | k = 110 | k = 111 |
|---|---|---|---|---|---|---|---|---|
| 0 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 |
| 1 | 0.000 | 0.125 | 0.250 | 0.375 | 0.500 | 0.625 | 0.750 | 0.875 |
| 2 | 0.000 | 0.250 | 0.500 | 0.750 | 0.000 | 0.250 | 0.500 | 0.750 |
| 3 | 0.000 | 0.375 | 0.750 | 0.125 | 0.500 | 0.875 | 0.250 | 0.625 |
| Gate | Angle | Degrees | Common name |
|---|---|---|---|
| R2 | 2π / 4 | 90.00° | S gate (controlled) |
| R3 | 2π / 8 | 45.00° | T gate (controlled) |
| R4 | 2π / 16 | 22.50° | none |
| R5 | 2π / 32 | 11.25° | none |
| R6 | 2π / 64 | 5.63° | none |
| R8 | 2π / 256 | 1.406° | none |
| R10 | 2π / 1024 | 0.352° | none |
| Counting qubits t | Grid spacing 1/2^t | Best outcome | Chance of best | Chance within one step |
|---|---|---|---|---|
| 2 | 0.25000 | 1/4 = 0.25000 | 88.2% | 94.5% |
| 3 | 0.12500 | 2/8 = 0.25000 | 57.8% | 83.7% |
| 4 | 0.06250 | 5/16 = 0.31250 | 87.6% | 93.1% |
| 5 | 0.03125 | 10/32 = 0.31250 | 57.3% | 82.8% |
| 6 | 0.01563 | 19/64 = 0.29688 | 87.5% | 93.0% |
| 8 | 0.00391 | 77/256 = 0.30078 | 87.5% | 93.0% |
| 10 | 0.00098 | 307/1024 = 0.29980 | 87.5% | 93.0% |
| Bits n | ε = 25% | ε = 10% | ε = 1% |
|---|---|---|---|
| 4 | 6 | 7 | 10 |
| 8 | 10 | 11 | 14 |
| 12 | 14 | 15 | 18 |
| 16 | 18 | 19 | 22 |
| Period r | Divides 64? | Chance of the full period | φ(r)/r, this page’s own arithmetic |
|---|---|---|---|
| 2 | yes | 50.0% | 50.0% |
| 4 | yes | 50.0% | 50.0% |
| 8 | yes | 50.0% | 50.0% |
| 3 | no | 56.1% | not exact |
| 5 | no | 58.3% | not exact |
| 6 | no | 0.0% | not exact |
| 10 | no | 0.0% | not exact |
| Qubits n | Hadamards | Controlled phases | Swaps | Total gates | Classical FFT, about n·2^n |
|---|---|---|---|---|---|
| 4 | 4 | 6 | 2 | 12 | 64 |
| 8 | 8 | 28 | 4 | 40 | 2,048 |
| 16 | 16 | 120 | 8 | 144 | 1,048,576 |
| 32 | 32 | 496 | 16 | 544 | 137,438,953,472 |
| 64 | 64 | 2016 | 32 | 2112 | 64 × 2^64 |
| Keep rotations up to | Controlled phases kept | Share of the full 28 | Average fidelity |
|---|---|---|---|
| R2 | 7 | 25% | 20.25% |
| R3 | 13 | 46% | 71.09% |
| R4 | 18 | 64% | 93.87% |
| R5 | 22 | 79% | 98.95% |
| R6 | 25 | 89% | 99.86% |
| R8 | 28 | 100% | 100.00% |
Eight guides
What is the quantum Fourier transform?
9 min read
The QFT is the discrete Fourier transform written as a gate sequence on n qubits. It turns a hidden period into a sharp peak, and that is its whole job inside Shor’s algorithm and phase estimation.
Building the QFT circuit, gate by gate
10 min read
A Hadamard and a ladder of controlled phase rotations per qubit, then a row of swaps. This guide derives why that circuit equals the Fourier matrix, with a worked three-qubit example.
The QFT versus the classical FFT: what the speed-up really is
8 min read
n squared gates on n qubits sounds exponentially cheaper than the n times 2^n steps of the fast Fourier transform. The gap is real, but only if you can load the input and live with reading a single sample.
Quantum phase estimation explained
10 min read
Given a unitary U and one of its eigenvectors, phase estimation reads out the eigenvalue as a binary number. This guide builds the circuit, shows why it works and what happens when the phase does not fit the grid.
How many counting qubits does phase estimation need?
8 min read
Accuracy of n bits with failure chance ε costs about n plus a few extra qubits, but the real price is the number of times U must be applied: it doubles with every extra counting qubit.
Period finding: from a QFT peak to the period
10 min read
After the QFT, a measurement lands close to a multiple of N/r. Continued fractions turn that reading into the period r. This is the classical post-processing in Shor’s algorithm, shown with exact numbers.
The approximate QFT: how many rotations can you drop?
8 min read
The smallest controlled rotations in the QFT turn the phase by tiny angles. Dropping them cuts the gate count a lot and costs little accuracy. This guide shows the counts and a measured fidelity table.
Run the QFT and phase estimation in code
8 min read
A short NumPy script that reproduces the lab’s numbers, a Qiskit outline for a real circuit, and the bit-order mistakes that make results look wrong.
Predict, then check
On 3 qubits, the QFT of |5⟩. What phase does output |011⟩ carry?
5 × 3 / 8 = 15/8, which is 7/8 of a turn once whole turns are dropped: 0.875. Every output has chance 12.5 percent.
A state with period 4 on 6 qubits (N = 64). Where are the peaks after the QFT?
At multiples of 64/4 = 16: 0, 16, 32, 48, each with chance 25 percent.
Phase estimation with t = 4 counting qubits and φ = 5/16. What do you read?
φ is exactly a 4-bit fraction, so the reading is 0101 with chance 100 percent.
Phase estimation with t = 3 and φ = 1/3. What is the most likely reading?
011, which is 3/8 = 0.375, with chance 68.8 percent. The true phase 0.333 is not on the 1/8 grid.
How many counting qubits give 6 bits of accuracy with a 5 percent failure chance?
t = 6 + ⌈log₂(2 + 10)⌉ = 6 + 4 = 10. This page’s own arithmetic from the textbook rule.
You measure m = 171 on 8 qubits, expecting a period of at most 15. What does the continued fraction give?
The last convergent of 171/256 with denominator at most 15 is 2/3, so the proposed period is 3.
How many gates does the exact QFT on 10 qubits use?
10 Hadamards, 45 controlled phases and 5 swaps: 60 in all.
Related on QuantumAtlas
- Algorithm page: Quantum Fourier Transform
- Algorithm page: Quantum Phase Estimation
- Algorithm page: Shor’s algorithm
- Shor’s Algorithm Lab
- Lesson: Qiskit quantum Fourier transform
- Lesson: Quantum phase estimation
- Dictionary: quantum Fourier transform
- Circuit Builder: Quantum Fourier Transform
- Oracle Algorithms Lab
- People: Alexei Kitaev
Frequently asked questions
What is the quantum Fourier transform?
The discrete Fourier transform applied to the amplitudes of an n-qubit state. It maps the basis state |j⟩ to an equal-size mix of all basis states with phases e^(2πi·j·k/N), where N = 2^n. It turns a hidden period into a sharp peak.
How many gates does the QFT need?
On n qubits: n Hadamards, n(n−1)/2 controlled phase rotations and ⌊n/2⌋ swaps. That grows like n², while the classical fast Fourier transform on 2^n numbers needs about n·2^n operations.
Does the QFT speed up Fourier analysis of ordinary data?
No. Loading N numbers into amplitudes costs about N operations, and a measurement returns one sample rather than all N outputs. The QFT pays off inside algorithms whose input state is cheap to prepare and where one sample of the output is enough.
What does quantum phase estimation do?
Given a unitary U and an eigenvector of it, it reads the eigenvalue e^(2πiφ) as a binary fraction of φ, using counting qubits, controlled powers of U and an inverse QFT.
What happens when the phase is not a binary fraction?
The reading is random. The best outcome is one of the two grid points next to the true phase and has chance at least 4/π², about 40.5 percent. The chance of being within one grid step is at least 8/π², about 81.1 percent.
How many counting qubits do I need?
For n bits of accuracy with failure chance at most ε, the textbook rule is t = n + ⌈log₂(2 + 1/(2ε))⌉. Each extra qubit doubles the number of times U must be applied.
How does the QFT help find a period?
A state with period r goes to peaks near multiples of N/r. A measurement gives m with m/N close to k/r, and continued fractions turn m/N into the period.
What is the approximate QFT?
A version that drops the smallest controlled rotations. It uses fewer gates and gives a state close to the exact result. The lab measures the fidelity for random states.
Is the simulation exact?
Yes. The lab simulates the full state vector with perfect gates, up to 5 qubits for the transform steps and 8 counting qubits for phase estimation. The random samples use a seeded generator, so they repeat.
Where does this appear in Shor’s algorithm?
The QFT and the continued-fraction step are the period-finding core. See the Shor’s Algorithm Lab for the full factoring chain.
Sources and further reading
- P. Shor, “Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer” (1994, journal version 1997). Uses the quantum Fourier transform to find a period, followed by continued fractions to read it.
- A. Kitaev, “Quantum measurements and the Abelian stabilizer problem” (1995). Phase estimation as a way to measure an eigenvalue of a unitary, in the form that led to the circuit used today.
- R. Cleve, A. Ekert, C. Macchiavello and M. Mosca, “Quantum algorithms revisited” (1998). Presents phase estimation with the counting register and the inverse QFT, the layout this lab follows.
- D. Coppersmith, “An approximate Fourier transform useful in quantum factoring” (1994, IBM research report). Introduces dropping the smallest controlled rotations to cut the gate count.
- J. Cooley and J. Tukey, “An algorithm for the machine calculation of complex Fourier series” (1965). The classical fast Fourier transform that the QFT is compared with.
- M. Nielsen and I. Chuang, Quantum Computation and Quantum Information, chapter 5. The standard textbook treatment of the QFT, phase estimation and order finding, including the counting-qubit rule used here.
References were written from memory of the original works. Check the originals for exact citations.