DevTools Logo

FFT Fourier Decomposition

FFT Fourier Decomposition

Explore signal components with a radix-2 Cooley-Tukey transform in your browser

Runs in your browser
Try an example

Signal

12 lines · 137 chars

Up to 65,536 samples. Everything is computed in this tab.

Spectrum

256 point FFT · 1 Hz per bin

Signal

±1.4140 s1 s

Magnitude spectrum (amplitude)

peak 10 Hz128 Hz (Nyquist)

Phase spectrum (cosine phase, −π to π)

+π0 Hz128 Hz

A sine of phase 0 reads −π/2. Bins with negligible magnitude show 0.

Detected frequency components
FrequencyAmplitudePhase
50.00 Hz1.000-1.571 rad
90.00 Hz0.450-0.971 rad

One-sided amplitudes: 2·|X|/Σwindow, and 1·|X|/Σwindow at 0 Hz and Nyquist. Bin spacing 1 Hz, window: rectangular.

Inverse FFT round-trip error (against the windowed samples): —

Examples

Exact 50 Hz tone

Input
analyzeFourier(generateSyntheticSignal([{ frequency: 50, amplitude: 1, phase: 0 }], 256, 256), 256)
Output
peaks[0] -> { frequency: 50, magnitude: ~1 }

Fifty cycles fit exactly into 256 samples at 256 Hz, so all energy lands on bin 50.

Lossless round-trip

Input
ifft(fft([1.25, -2, 0.5, 3, 4.5, -1, 0, 2]))
Output
the original 8 samples back

Forward then inverse FFT inverts exactly up to floating-point rounding.

About this tool

FFT Fourier Decomposition analyzes signals with analyzeFourier(input, sampleRate): it returns the complex spectrum, per-bin magnitude/phase entries, magnitude-ranked peaks, and the ifft-reconstructed signal. Building blocks fft, ifft (alias inverseFFT), generateSyntheticSignal (alias generateSignal), detectPeaks, and isPowerOfTwo are exported individually.

The transform is an iterative radix-2 Cooley-Tukey FFT: inputs must be a positive power of two (never padded or mutated), bin k sits at k * sampleRate / N, and magnitudes scale by 2/N (1/N at DC and Nyquist). Peak detection keeps local maxima above 1e-10 and sorts them loudest-first.

Everything is deterministic and client-side: the same samples and sample rate always give the same bins and peaks, and round-tripping real data through ifft(fft(x)) recovers the input within floating-point tolerance.

How to use this tool

  1. Prepare power-of-two samples

    Supply 64, 256, 1024, or any 2^n-length array — other lengths throw instead of padding.

  2. Analyze at the true rate

    Pass the real sample rate so bin frequencies (k * rate / N) land on the intended hertz.

  3. Read peaks loudest-first

    Take peaks[0] as the dominant tone with its index, frequency, magnitude, and phase.

  4. Verify with reconstruction

    Compare reconstructed against the input to confirm the spectrum explains the signal.

Use cases

Identifying dominant tones

Decompose a recording into ranked sine components with frequency and phase.

Teaching bin math

Show how the same 50 Hz tone moves bins when the sample rate changes at fixed N.

Validating signal chains

Round-trip samples through fft/ifft to prove the pipeline is lossless.

Common mistakes

Mistake:Passing a non-power-of-two length and expecting zero-padding.

Fix:The FFT throws on lengths like 100 or 3 — resample or truncate to 2^n first (e.g. 128, 256).

Mistake:Reading peak index as hertz.

Fix:Index is the bin number; multiply by sampleRate / N for hertz — bin 25 at 512 Hz/N=256 is still 50 Hz.

Mistake:Expecting DC energy in peaks.

Fix:detectPeaks scans interior bins only, so a flat DC signal reports bin 0 magnitude with an empty peaks list.

Frequently asked questions

What does this tool do?

It analyzes signals with analyzeFourier(input, sampleRate) — complex spectrum, per-bin magnitudes/phases, loudest-first peaks, and the ifft reconstruction — plus fft, ifft (inverseFFT), generateSyntheticSignal (generateSignal), detectPeaks, and isPowerOfTwo.

Why is my 50 Hz tone on the wrong bin?

Bins are k * sampleRate / N: 50 Hz sits on bin 50 at 256 Hz/N=256 but bin 25 at 512 Hz/N=256. Read frequency, not index, and pass the true sample rate.

Is my signal uploaded or stored?

No. Synthesis, FFT butterflies, peak picking, and reconstruction run entirely in your browser.

Why did the FFT throw, or why are there no peaks?

Lengths must be a positive power of two — the FFT throws instead of padding, so resize to 2^n. An empty peaks list with strong bin-0 energy means a DC-only signal, which peak detection intentionally skips.

References & standards