HomeSignals & TelecommunicationsSpectral Analysis

📻 Spectral Analysis

Decompose signals into frequency components using the Fast Fourier Transform. Build signals by summing harmonics, apply windowing functions, and visualise the short-time spectrogram to track frequency changes over time.

Signals & Telecommunications3DEasy60 FPS
spectral-analysis ↗ Open standalone

About Spectral Analysis

The Fast Fourier Transform

The DFT decomposes any discrete signal into N complex sinusoids: X[k] = Σ x[n]·e^(−2πijk/N). The Cooley-Tukey radix-2 FFT computes this in O(N·log₂N) operations instead of O(N²), making real-time spectrum analysis practical. A 1024-point FFT needs only ~10,000 operations instead of one million.

Windowing & Spectral Leakage

A finite signal segment is implicitly multiplied by a rectangular window, whose sharp edges create spectral leakage — energy from one frequency bleeds into neighbours. The Hann window w[n] = 0.5(1−cos(2πn/N)) tapers the edges smoothly, trading frequency resolution for dramatically reduced leakage. Blackman windows suppress leakage further at the cost of wider main lobes.

The Spectrogram (STFT)

The Short-Time Fourier Transform runs an FFT on overlapping windows slid across time: X(m,k) = Σ x[n+m·hop]·w[n]·e^(−2πijk/N). The result is displayed as a 2D heatmap (time × frequency). There is an inherent resolution trade-off: long windows give fine frequency resolution but blur rapid changes; short windows capture transients but smear frequencies.

About this simulation

This tool builds a signal from adjustable harmonics, adds optional noise, and runs it through a radix-2 FFT to show the time waveform, magnitude/phase spectrum and a sliding-window spectrogram side by side. Switching the analysis window (rectangular, Hann, Hamming, Blackman) or the FFT size lets you feel the trade-off between frequency resolution and spectral leakage in real time.

🔬 What it shows

A composite waveform built from your harmonic list is transformed into a frequency-domain spectrum via FFT, plus a spectrogram that tracks how that spectrum evolves over time using the Short-Time Fourier Transform.

🎮 How to use

Add or remove harmonics, drag the FFT Size and Noise Level sliders, toggle "Show Phase Spectrum" or "Power Spectral Density", and pick a window function from the Window dropdown to compare leakage behaviour.

💡 Did you know?

The Cooley-Tukey FFT algorithm computes a 1024-point transform in about 10,000 operations instead of the roughly one million a naive DFT would require — the same trick your phone uses for real-time audio spectrum displays.

Frequently asked questions

What does the FFT Size control actually change?

It sets how many samples are analysed per transform (from 256 up to a few thousand). Larger sizes give finer frequency resolution (smaller Δf) but blur fast time-domain changes, which is why the stat box shows Δf in Hz alongside it.

Why does changing the window function shift the spectrum shape?

Each window tapers the signal edges differently. Rectangular gives the sharpest peaks but the worst leakage; Hann and Hamming smooth the edges for less leakage at the cost of a slightly wider main lobe; Blackman suppresses leakage further but widens peaks even more.

What is the spectrogram showing that the FFT plot doesn't?

The FFT plot is a single snapshot of frequency content. The spectrogram runs the FFT repeatedly on overlapping time slices (the STFT) and stacks the results as a time-versus-frequency heatmap, revealing how the spectrum changes over time.

What does adding noise do to the SNR readout?

The Noise Level slider mixes random samples into the signal before analysis. The Signal-to-Noise Ratio (SNR) stat box reports, in decibels, how much the harmonic content still dominates the noise floor — higher noise levels push this value down.

What is the "Parseval err" statistic checking?

Parseval's theorem states that total signal energy computed in the time domain must equal total energy computed in the frequency domain. This readout is the numerical discrepancy between the two, which should stay near zero and confirms the FFT implementation is energy-consistent.

⚙ Under the hood

FFT, spectrogram, STFT windowing and frequency domain analysis of signals.

FFTspectrogramSTFTwindowingfrequency domain

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)