Discrete Fourier Transform (DFT) Calculator
Compute the DFT spectrum of a signal with selectable windows, FFT cross-check and Parseval energy validation. Free, runs in your browser, no signup.
Original vs windowed vs reconstructed
- Original
- Windowed
- Reconstructed
Magnitude spectrum in DFT bins
- Magnitude
Transform integrity metrics
Twiddle-factor preview (first 8×8)
| k | f[k] | |X[k]| | ∠X[k] |
|---|---|---|---|
| 1 | 6.000 Hz | 15.751076 | -1.5708 rad |
| 2 | -6.000 Hz | 15.751076 | 1.5708 rad |
| 3 | -13.000 Hz | 8.666899 | 0.9427 rad |
| 4 | 13.000 Hz | 8.666899 | -0.9427 rad |
| 5 | -5.000 Hz | 8.059690 | -1.5218 rad |
| 6 | 5.000 Hz | 8.059690 | 1.5218 rad |
| 7 | 7.000 Hz | 8.057358 | 1.6199 rad |
| 8 | -7.000 Hz | 8.057358 | -1.6199 rad |
First 12 record points
| n | t | x[n] | w[n] | xw[n] | x̂[n] | e[n] |
|---|---|---|---|---|---|---|
| 0 | 0.00000 | 0.323282 | 0.000000 | 0.000000 | 0.000000 | 1.67e-16 |
| 1 | 0.01563 | 1.075214 | 0.002485 | 0.002671 | 0.002671 | 6.81e-15 |
| 2 | 0.03125 | 0.902287 | 0.009914 | 0.008945 | 0.008945 | 7.28e-15 |
| 3 | 0.04688 | 0.448606 | 0.022214 | 0.009965 | 0.009965 | 1.07e-15 |
| 4 | 0.06250 | 0.419733 | 0.039262 | 0.016479 | 0.016479 | -3.75e-15 |
| 5 | 0.07813 | 0.560429 | 0.060889 | 0.034124 | 0.034124 | -6.83e-15 |
| 6 | 0.09375 | 0.116795 | 0.086881 | 0.010147 | 0.010147 | 1.84e-16 |
| 7 | 0.10938 | -0.906826 | 0.116978 | -0.106079 | -0.106079 | 6.66e-16 |
| 8 | 0.12500 | -1.543229 | 0.150882 | -0.232845 | -0.232845 | 9.99e-16 |
| 9 | 0.14063 | -1.071495 | 0.188255 | -0.201714 | -0.201714 | 1.55e-15 |
| 10 | 0.15625 | 0.021194 | 0.228727 | 0.004848 | 0.004848 | 2.02e-15 |
| 11 | 0.17188 | 0.669594 | 0.271895 | 0.182059 | 0.182059 | 3.16e-15 |
A clear path from inputs to results.
See exactly which frequencies make up a sampled signal. This tool takes a time-domain record — built-in tones, chirps, impulses, or your own pasted samples — applies an optional window, and computes its discrete Fourier transform spectrum, cross-checked against a fast Fourier transform and against Parseval's energy theorem so you can trust every bin.
How to use
- Pick a signal preset (two-tone superposition, chirp, impulse, step, square, Gaussian burst) or choose Custom and paste your own comma- or space-separated real samples.
- Set the sample count N (it snaps to 16, 32, 64, 128, or 256 so the radix-2 FFT cross-check stays exact) and the sample spacing Δt, which fixes the sample rate fs = 1/Δt and the bin spacing fs/N.
- For the tone presets, set the two frequencies, amplitudes, phases, and any DC offset; for chirp set the sweep rate, for the Gaussian set its width.
- Choose a window — rectangular, Hann, Hamming, or Blackman — to trade frequency resolution against spectral leakage.
- Read the magnitude spectrum, the dominant bin, the spectral centroid, and the 90% bandwidth; toggle fftshift to center zero frequency, and watch the Parseval error and FFT-vs-DFT delta confirm the transform is numerically exact.
The formula
Reference: Oppenheim & Schafer, Discrete-Time Signal Processing (DFT, Parseval's relation); Cooley–Tukey radix-2 FFT (Math. Comp. 19, 1965); window definitions from Harris, "On the use of windows", Proc. IEEE 66 (1978).
Worked example
Single 6 Hz tone, 64 samples, rectangular window
- Tone preset with one sine: f1 = 6 Hz, amplitude A1 = 1, phase 0; second tone amplitude 0; DC offset 0; N = 64 samples; sample spacing Δt = 1/64 s (sample rate 64 Hz, record length 1 s); rectangular window.
- 1
The 1-second record holds exactly 6 cycles of the sine, so the tone lands precisely on bin k = 6 because the bin spacing is fs/N = 64/64 = 1 Hz. Evaluating X[k] = Σ x[n] e^(−j2πkn/N) concentrates all the energy into the two conjugate bins k = 6 and k = N−6 = 58. For a real sine of amplitude 1 each of those bins has magnitude A·N/2 = 1 × 64 / 2 = 32, while every other bin is zero apart from floating-point rounding of order 1e−13. Parseval's theorem checks out: the time-domain energy Σ|x[n]|² = 32 equals (1/N)Σ|X[k]|² = (32² + 32²)/64 = 32.
|X[6]| = |X[58]| = 32.0, sitting at ±6 Hz; all other bins ≈ 0. The energy is 32 in both domains (Parseval error ~1e−15), and the FFT validation path matches the direct DFT to better than 1e−12.
Interpreting the result
Each bin k corresponds to frequency k·fs/N up to the Nyquist frequency fs/2; bins above N/2 represent negative frequencies, which is why fftshift centers the display. A real tone always shows as a conjugate pair, and a tone that completes a whole number of cycles in the record falls on a single bin at magnitude A·N/2. When a tone sits between bins, its energy spreads into neighboring bins (spectral leakage) — that is what the Hann, Hamming, and Blackman windows suppress, at the cost of a slightly wider main lobe and lower resolution.
Assumptions & limitations
- The input is treated as a finite, uniformly sampled, real-valued sequence; the transform assumes it repeats periodically, so discontinuities between the last and first sample create leakage.
- Sample count is restricted to 16, 32, 64, 128, or 256 so the radix-2 FFT used for the cross-check is exact; the authoritative result is the direct matrix DFT.
- Frequencies above the Nyquist limit fs/2 alias to lower bins; the tool does not anti-alias the preset generators, so choose Δt small enough for your highest frequency.
- Windowing multiplies the samples before the transform, so reported magnitudes of windowed signals are scaled by the window and are not directly comparable to the un-windowed amplitude A·N/2.
- Reconstruction via the inverse DFT returns the windowed samples, not the original un-windowed signal, when a non-rectangular window is applied.
Frequently asked questions
Why does a single tone show up as two spikes?
A real-valued sine is mathematically a sum of a positive and a negative frequency, e^(+jωt) and e^(−jωt). The DFT of a real signal is therefore conjugate-symmetric, so a 6 Hz tone appears at both +6 Hz (bin 6) and −6 Hz (bin 58 of 64). Each carries magnitude A·N/2, so a unit-amplitude tone over 64 samples gives 32 in each bin.
When should I use a window instead of rectangular?
Use a window whenever your signal does not complete a whole number of cycles in the record — which is almost always true for real measured data. The rectangular window gives the sharpest frequency resolution but leaks energy into nearby bins when a tone falls between bins. Hann and Hamming reduce that leakage; Blackman reduces it further. The trade-off is a wider main lobe, so closely spaced tones become harder to separate.
How do I read the frequency axis?
Bin k maps to frequency k·fs/N, where fs = 1/Δt is the sample rate. The maximum unambiguous frequency is the Nyquist frequency fs/2. With fftshift enabled the axis runs from −fs/2 to +fs/2 with zero frequency (DC) in the middle; with it disabled, bins 0 to N/2 are positive frequencies and the rest are negative frequencies wrapped to the top of the array.
What is the difference between the DFT and the FFT here?
They compute the same thing. The direct DFT evaluates the full matrix sum X[k] = Σ x[n] e^(−j2πkn/N) and is the authoritative result shown. The FFT is a radix-2 Cooley–Tukey algorithm that produces the identical spectrum far faster; the tool runs both and reports their maximum difference, which stays below 1e−12, as an internal correctness check.
What does the Parseval error tell me?
Parseval's theorem says the signal's energy is the same whether measured in time or frequency: Σ|x[n]|² = (1/N)Σ|X[k]|². The tool computes both sides and reports their relative difference. A value near machine precision (below 1e-12) confirms the transform conserved energy and nothing was lost or fabricated numerically.
Methodology last reviewed 2026-10-06. Results are informational and not financial or engineering advice — see our disclaimer.