Discrete Fourier Transform (DFT)
calculator.
Paste up to 64 evenly spaced readings to see the frequencies they hold.
- Mean, X[0] over N
- 0
- Bin spacing
- 125 Hz
- Nyquist limit
- 500 Hz
The strongest pattern repeats 1 time in the 8 samples, which is 125 Hz. As a wave it has amplitude 1.3066 and phase −67.5° against a cosine. 2 of the 5 bins from 0 to 4 are not 0.
Spectrum
Size of all 8 bins. The tallest bar after bin 0 is k = 1, at 125 Hz. Bin 1: X[1] = 2 − 4.8284j, size 5.2263, phase −67.5°, frequency 125 Hz.
The samples and the waves they hold
The 8 samples, with the smooth curve made by adding the waves of bins 0 to 4; it passes through every sample. The dotted line is bin 1 on its own, a wave of amplitude 1.3066.
Working for bin 1
- 1Count the samples and space the binsN = 8, bin spacing =1,000 Hz8= 125 Hz
- 2Bin 0 is the sum of the samplesX[0] = 0, so the mean is08= 0
- 3Bin 1: multiply by a cosine and a sine of 1 cycle, then addRe X[1] = Σ x[n] cos2π · 1 · n8= 2Im X[1] = −Σ x[n] sin2π · 1 · n8= −4.8284
- 4Its size and angle|X[1]| = √(Re² + Im²) = 5.2263phase = atan2(Im, Re) = −67.5°
- 5As a frequency and a wave heightf = 1 ×125 Hz = 125 Hzamplitude =2 |X[1]|N= 1.3066
- 6Check: the inverse DFT gives the samples back, and the energy matchesLargest gap between x[n] and the inverse: 0Σ x[n]² = 8 and1NΣ |X[k]|² = 8
Every bin
| Hz | Re X[k] | Im X[k] | Phase | Inverse | ||
|---|---|---|---|---|---|---|
| 00 Hz | 0 | 0Im 0x = 1 | 0 | 00° | 0° | 1 |
| 1125 Hz | 125 | 2Im −4.8284x = 1 | −4.8284 | 5.2263−67.5° | −67.5° | 1 |
| 2250 Hz | 250 | 0Im 0x = 1 | 0 | 00° | 0° | 1 |
| 3375 Hz | 375 | 2Im −0.8284x = 1 | −0.8284 | 2.1648−22.5° | −22.5° | 1 |
| 4500 Hz | 500 | 0Im 0x = −1 | 0 | 00° | 0° | −1 |
| 5625 Hz | 625 | 2Im 0.8284x = −1 | 0.8284 | 2.164822.5° | 22.5° | −1 |
| 6750 Hz | 750 | 0Im 0x = −1 | 0 | 00° | 0° | −1 |
| 7875 Hz | 875 | 2Im 4.8284x = −1 | 4.8284 | 5.226367.5° | 67.5° | −1 |
Bins above 4 mirror the ones below for real samples: the same size with the phase sign flipped. The last column is the inverse DFT, which should match your samples.
How it's worked out
The DFT takes N samples and gives back N complex numbers, one per frequency bin. Smith's definition multiplies each sample by a wave that turns k times over the whole window, then adds. Here x[n] is sample n and j is the square root of −1.
In plain terms, the real part of X[k] is the sum of x[n] times a cosine, and the imaginary part is minus the sum of x[n] times a sine. The size of X[k] says how much of that wave is in the samples, and its angle says where the wave starts.
From bin to hertz. Bin k is k times the bin spacing, and the spacing is the sample rate over N. With 8 samples at 1,000 per second the bins sit 125 Hz apart. Leave the rate blank and the tool gives k over N, in cycles per sample.
Back again. The inverse uses the same sum with a plus sign and divides by N. The tool runs it on every result, so you can see your samples come back. It also checks Parseval's theorem: the sum of the squared samples equals the sum of the squared bin sizes over N.
Worked examples
Priya checks a 4 point DFT by hand
Priya has the samples 1, 2, 3 and 4 on a problem set. With N = 4 the wave factors are just 1, −j, −1 and j, so each bin is a short sum.
Bin 0 is the plain sum, 10. Bin 1 is 1 + 2(−j) + 3(−1) + 4(j), which is −2 + 2j. Bin 2 is 1 − 2 + 3 − 4, which is −2. Bin 3 is −2 − 2j, the mirror image of bin 1 with the sign of j flipped.
The inverse returns 1, 2, 3, 4, and both sides of the energy check give 30. With no sample rate, bin 1 is 0.25 cycles per sample.
Marco finds two tones in a vibration reading
Marco samples a motor mount 800 times a second and keeps 16 readings. The bins are 50 Hz apart, and the highest frequency 800 samples a second can show is 400 Hz.
The bins that are not 0 from 0 to 400 Hz are 50 Hz, with height 1 and phase −90°, and 150 Hz, with height 0.5 and phase 0°, and 250 Hz, with height 4.9781 × 10⁻⁸ and phase −124°. The heights match the 1 and 0.5 that built the signal. A phase of −90° marks a sine, and 0° marks a cosine.
Both tones complete a whole number of cycles in the 16 readings, so each one lands in a single bin.
Ana sees a tone fall between two bins
Ana's 8 samples hold a sine that fits 1.5 cycles in the window. At 1,000 samples a second the bins are 125 Hz apart, and the tone sits halfway between bin 1 and bin 2, so no bin matches it.
The strongest bin is 125 Hz, with size 2.8478, and the next is 250 Hz, with size 2.4142. In all, 8 of the 8 bins are not 0. Smith calls this spectral leakage: cutting a wave off part way through spreads it over the whole spectrum.
Reading your result
Wave height. For a real wave, the size of a bin is N times half its height, because the wave is split between bin k and bin N − k. So the height is 2 times |X[k]| over N, except at bin 0 and the Nyquist bin, where it is |X[k]| over N. A sine of height 3 over 8 samples gives |X[1]| = 12, and 2 × 12 over 8 is 3.
The mirror half. For real samples the spectrum is Hermitian: bin N − k has the same size as bin k and the opposite phase. In the square wave, bin 7 is 2 + 4.8284j and bin 1 is 2 − 4.8284j. Only bins 0 to N/2 carry new facts.
| Signal | |X[0]| to |X[7]| |
|---|---|
| Impulse | 1, 1, 1, 1, 1, 1, 1, 1 |
| Constant | 8, 0, 0, 0, 0, 0, 0, 0 |
| Alternating | 0, 0, 0, 0, 8, 0, 0, 0 |
| Square wave | 0, 5.23, 0, 2.16, 0, 2.16, 0, 5.23 |
A single spike spreads evenly over every bin, and a flat signal puts everything in bin 0. The alternating signal is the fastest pattern 8 samples can hold, so it sits at bin 4, the Nyquist bin. The square wave has odd bins only, because its second half is the first half turned upside down.
Common mistakes
- Reading |X[k]| as the wave height. The size grows with N, so divide by N, and double it for every bin except 0 and N/2.
- Counting the mirror bins twice. Bins above N/2 repeat the lower half for real samples. Adding both halves to a list of tones counts each tone twice.
- Mixing up the scaling. This tool puts no factor on the forward sum and 1/N on the inverse. Some books and libraries use 1 over the square root of N both ways, which changes every size by the same factor.
- Expecting one bin per tone. A tone that does not fit a whole number of cycles in the window leaks into the bins around it. Choose a window length that holds whole cycles, or taper the samples first.
Questions people ask
Sources
- J. O. Smith III, Mathematics of the Discrete Fourier Transform, DFT Definition (CCRMA, Stanford)
- J. O. Smith III, Mathematics of the DFT, Inverse DFT
- J. O. Smith III, Spectral Audio Signal Processing, Rayleigh Energy Theorem (Parseval's Theorem)
- J. O. Smith III, Mathematics of the DFT, Symmetry
- J. O. Smith III, Mathematics of the DFT, Frequencies in the Cracks
- J. O. Smith III, Mathematics of the DFT, Why a DFT is usually called an FFT