What can a finite sample actually tell you?
Start with three sine-wave components. Change one frequency, the sampling rate, or the number of samples. The plotted dots are the sampled values; the spectrum is recomputed from those values in your browser.
Try first: set f₁ to 3.25 Hz, then compare the bins. Next, lower Fₛ to 32 Hz and watch the 17 Hz component appear at 15 Hz.
Interactive experiment
Signal → spectrum
Bin width Δf Hz
Nyquist limit Hz
Record length T s
All tones are at or below the Nyquist limit.
Largest spectrum bins (frequency · amplitude): 3.00 Hz (1.00) · 9.00 Hz (0.55) · 17.00 Hz (0.30)
Phase advances automatically. The spectrum is recomputed from each displayed finite sample record.
Input tones:f₁ 3.00 Hzf₂ 9.00 Hzf₃ 17.00 Hz
Sampled waveform · first 0.5 s
Single-sided amplitude spectrum
Sampled waveform · first 0.5 s
Single-sided amplitude spectrum
Read the three settings together
- Sample rate, Fₛ: sets the Nyquist limit at Fₛ/2. Frequencies above it fold into the visible band rather than remaining distinguishable.
- Sample count, N: with Fₛ fixed, a larger N means a longer observation window and more closely spaced frequency bins.
- Bin width, Δf: equals Fₛ/N, or 1/T where T is the record duration. A tone that falls between bins spreads energy across neighboring bins; that spread is spectral leakage.
Three controlled checks
- Leakage: keep Fₛ = 64 Hz and N = 128, so Δf = 0.5 Hz. Set f₁ = 3.25 Hz. It lies halfway between bins, so its energy no longer sits in one bar.
- Aliasing: set Fₛ = 32 Hz. The Nyquist limit becomes 16 Hz. The 17 Hz input is represented at 15 Hz because the sampled points cannot distinguish those two tones.
- Resolution: restore Fₛ = 64 Hz and compare N = 64 with N = 256. The bin width changes from 1 Hz to 0.25 Hz, while the observation window grows from 1 second to 4 seconds.
What the spectrum is computing
The discrete Fourier transform maps N samples to N frequency coefficients. The FFT is an algorithm for computing that same transform efficiently; this lab uses a radix-2 butterfly implementation, not a different transform.
X[k] = Σₙ₌₀ᴺ⁻¹ x[n] · e⁻²πikn/N
For a real-valued signal, the chart shows the nonnegative-frequency half and uses single-sided amplitude normalization. Interior bins use 2|X[k]|/N; DC and the Nyquist endpoint are not doubled. Those amplitudes match the input for bin-centered tones. Between bins, the displayed bars are the actual finite-window result, not an interpolated estimate.
const binWidth = sampleRate / samples.length;
const amplitude = (k === 0 || k === N / 2)
? Math.abs(X[k]) / N
: 2 * Math.abs(X[k]) / N;The radix-2 algorithm requires a power-of-two sample count and reduces the transform work from O(N²) direct summation to O(N log₂N) butterfly stages.
Scope and limitations
The signal is a deterministic sum of three pure tones with fixed amplitudes. The experiment adds no noise, DC offset, or window function; it uses the finite record as-is. That makes bin width, leakage, and aliasing easier to isolate, but it is not a complete measurement instrument. Real acquisition also depends on sensor response, clock accuracy, noise, window choice, and calibration.