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.

Step 1 of 5: Input state

The state you chose, before any gate.

Basis stateSizeChancePhase (turns)
|000⟩0.0000.0%–
|001⟩0.0000.0%–
|010⟩0.0000.0%–
|011⟩1.000100.0%0.000
|100⟩0.0000.0%–
|101⟩0.0000.0%–
|110⟩0.0000.0%–
|111⟩0.0000.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

  1. 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.
  2. 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.
  3. Phase estimation tab: press Snap φ to a t-bit fraction. The best outcome jumps to 100 percent.
  4. Move φ slightly off the grid and watch the chance split between two neighbours. Compare it with the two bounds printed beside it.
  5. Use the counting-qubit calculator: ask for 8 bits with a 1 percent failure chance and note how the largest power of U grows.
  6. 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.

QFT of a basis state |j⟩ on 3 qubits. Every output has chance 1/8; the phase of |k⟩ is j·k/8 of a turn (mod 1).
jk = 000k = 001k = 010k = 011k = 100k = 101k = 110k = 111
00.0000.0000.0000.0000.0000.0000.0000.000
10.0000.1250.2500.3750.5000.6250.7500.875
20.0000.2500.5000.7500.0000.2500.5000.750
30.0000.3750.7500.1250.5000.8750.2500.625
The rotation R_k used in the QFT circuit: a phase of 2π/2^k on the state where both qubits are 1.
GateAngleDegreesCommon name
R22π / 490.00°S gate (controlled)
R32π / 845.00°T gate (controlled)
R42π / 1622.50°none
R52π / 3211.25°none
R62π / 645.63°none
R82π / 2561.406°none
R102π / 10240.352°none
True phase φ = 0.3 turns (not a binary fraction). More counting qubits, finer grid. Computed by the lab’s simulator formulas.
Counting qubits tGrid spacing 1/2^tBest outcomeChance of bestChance within one step
20.250001/4 = 0.2500088.2%94.5%
30.125002/8 = 0.2500057.8%83.7%
40.062505/16 = 0.3125087.6%93.1%
50.0312510/32 = 0.3125057.3%82.8%
60.0156319/64 = 0.2968887.5%93.0%
80.0039177/256 = 0.3007887.5%93.0%
100.00098307/1024 = 0.2998087.5%93.0%
Counting qubits t from the textbook rule t = n + ⌈log₂(2 + 1/(2ε))⌉, for n bits of accuracy and failure chance ε. The rule is a sufficient count, so a smaller t may often work.
Bits nε = 25%ε = 10%ε = 1%
46710
8101114
12141518
16181922
Register of 6 qubits (N = 64), denominator bound 30. Chance that one measurement plus continued fractions returns the full period r. Exact sum over the output distribution.
Period rDivides 64?Chance of the full periodφ(r)/r, this page’s own arithmetic
2yes50.0%50.0%
4yes50.0%50.0%
8yes50.0%50.0%
3no56.1%not exact
5no58.3%not exact
6no0.0%not exact
10no0.0%not exact
Exact gate counts of the QFT circuit against the order-of-growth size of a classical FFT on N = 2^n numbers.
Qubits nHadamardsControlled phasesSwapsTotal gatesClassical FFT, about n·2^n
44621264
88284402,048
161612081441,048,576
323249616544137,438,953,472
6464201632211264 × 2^64
Approximate QFT on 8 qubits. Fidelity is the average over 6 random input states in this page’s own simulation, a sample and not a bound.
Keep rotations up toControlled phases keptShare of the full 28Average fidelity
R2725%20.25%
R31346%71.09%
R41864%93.87%
R52279%98.95%
R62589%99.86%
R828100%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

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.