Learn AI.
Understand Neural Networks · ORIGINAL LEARN AI LESSON

Turn sound into features.

Connect samples, local frequency measurements and a spectrogram, then expose aliasing and window tradeoffs.

By the end: Explain sample-rate ambiguity, compute a simple spectral interpretation and compare time/frequency detail without relying on hearing.

01 · TRY

Start with something concrete.

A digital recording stores measurements at separated times. Can those measurements distinguish every possible continuous wave? Compare a 6,000 Hz cosine with 2,000 Hz at 8,000 samples per second, then change the sample rate.

Try the interactive model ↓
02 · PREDICT
Before you experiment

A 6,000 Hz cosine is sampled at 8,000 samples per second. Does a spectral peak near 2,000 Hz prove the source was 2,000 Hz?

A 6,000 Hz cosine is sampled at 8,000 samples per second. Does a spectral peak near 2,000 Hz prove the source was 2,000 Hz?
03 · EXPERIMENT

Change one thing. Watch what follows.

  1. Inspect the default 1,000 Hz tone. Compare its waveform, amplitude and peak bin.
  2. Apply 6,000 Hz at 8 kHz, then 2,000 Hz at 8 kHz. Compare their sampled spectra. Change to 16 kHz and inspect the distinction.
  3. Choose a 500-to-3,000 Hz chirp and compute its spectrogram. Select early and late frames and compare peaks.
  4. Keep the signal fixed and compare 64- and 256-sample windows. Report duration, hop and bin spacing.
  5. Try a 650 Hz off-bin tone with rectangular and Hann windows. Inspect leakage rather than assuming a single perfect bin.
  6. Export a report with a supported sampling/window choice. Playback is optional; all evidence is visible numerically.

Loading this browser experiment…

04 · UNDERSTAND

A waveform is a sequence of measurements

Sound varies over time. A digital signal records a value at each sample time. Sample rate, measured in samples per second, tells you how close those measurements are. Frequency, measured in hertz (Hz), counts cycles per second; it is not the number of stored values.

The lab generates dimensionless amplitude-0.5 cosine waves, not microphone pressure measurements. At 8,000 samples per second, samples are 1/8,000 second apart: 0.125 ms. A 1,000 Hz tone completes one cycle in 1 ms, so this setting stores eight samples per cycle. The generated duration is always 128 ms: 1,024 samples at 8 kHz or 2,048 at 16 kHz.

A chirp changes frequency over time. Our chirp increases or decreases linearly between the selected endpoints. To generate it correctly, we accumulate the changing frequency into phase. Simply multiplying the instantaneous frequency by time would produce the wrong sweep rate.

Sampling can make different waves indistinguishable

At 8,000 samples per second, 6,000 Hz and 2,000 Hz cosines with this phase produce the same stored values. The high frequency has aliased to a lower one. A frequency analyzer cannot tell which continuous source produced identical samples.

The Nyquist frequency is half the sample rate: 4,000 Hz at 8 kHz. For an appropriately band-limited signal, sampling faster than twice its highest frequency avoids this ambiguity. Actual acquisition also needs a suitable anti-alias filter before sampling. Our deliberately unfiltered generator lets you observe the failure; it is not an audio-capture pipeline.

Changing to 16 kHz raises Nyquist to 8,000 Hz, allowing these 2,000 and 6,000 Hz examples to differ. Increasing only the analysis-window length cannot recover a distinction already lost during sampling. Listening to the sampled preview cannot recover it either.

Ask which frequencies are present in a short interval

A window selects a short run of samples. A rectangular window keeps them unchanged. A Hann window smoothly reduces their contribution near the edges. The discrete Fourier transform, or DFT, compares the windowed samples with cosine and sine patterns at a set of frequencies called bins.

fk=kfsN,Δf=fsNf_k=k\frac{f_s}{N},\qquad \Delta f=\frac{f_s}{N}

Here fₛ is sample rate in samples/second, N is window length in samples, k is the bin number beginning at zero, fₖ is that bin’s frequency in Hz, and Δf is spacing between bins. Our real-valued signal uses bins from zero through Nyquist. At 8 kHz with N = 128, bins are 62.5 Hz apart. The 1,000 Hz tone lands exactly at bin 16.

Practice: double the window to 256 samples at the same rate. Bin spacing becomes 8,000/256 = 31.25 Hz, while the window covers 32 ms, twice as long as the 128-sample window. Finer bin spacing is not unlimited frequency resolution: the window shape and signal also matter.

Multiply, add, and normalize

For each bin, multiply windowed samples by the matching cosine pattern and sum them to form the real part. Multiply by the negative sine pattern and sum to form the imaginary part. Those two numbers keep phase information that a magnitude-only picture discards. Their combined magnitude is the square root of real² + imaginary².

The lab divides this magnitude by the sum of the window weights. Interior bins are doubled to account for the omitted negative-frequency partner. The zero-frequency (DC) and Nyquist bins are not doubled. This produces the displayed one-sided amplitude spectrum; it is not a power-density or loudness measurement.

For the default bin-centered tone, amplitude is approximately 0.5 at 1,000 Hz. An off-bin tone such as 650 Hz spreads across neighboring bins: spectral leakage. The Hann taper reduces distant leakage for this example but broadens its central peak. It does not discover a uniquely correct source frequency in every case. The strongest bin is an estimate on this frequency grid.

Optional calculation convention

The periodic Hann weights are w[n] = 0.5 − 0.5 cos(2πn/N), for sample index n from 0 to N−1. The first weight is zero; the final weight is near zero, not exactly zero. Each DFT frame uses these N weights, no extra zero padding and no subtraction of a fitted mean. These details matter when reproducing the numerical values in another library.

Slide the window to build a spectrogram

A spectrogram places frequency measurements beside one another over time. This lab moves each window by half its length, so adjacent frames overlap. They are correlated measurements, not independent new observations. Each plotted column is positioned at the center of its frame; its display band is one hop wide. No frames are invented beyond the recorded boundaries.

Compare early and late frames of a 500-to-3,000 Hz chirp. The strongest bin should move upward, subject to the window width and bin spacing. Longer windows include more cycles but also mix changes across a longer interval. Shorter windows localize change better while providing coarser frequency detail. State both quantities when choosing a representation.

The plots use fixed amplitude ranges rather than stretching each frame to appear equally strong. Every selected frame has a numerical spectrum, and the spectrogram has a numerical peak timeline. Optional playback uses reduced gain and short edge fades; those playback-only changes do not alter the analyzed samples.

For a guided report, explain an alias pair and a window tradeoff. For implementation, reproduce selected complex bins, amplitude scaling and frame times. For a decision brief, specify the signal frequencies and timing detail a system must capture, then justify a sampling and analysis choice. Generated tones are useful controlled cases, not evidence of performance on speech, music or real recordings.

05 · APPLY
Check your understanding

Increasing window length gives finer frequency-bin spacing. What tradeoff should you report?

Increasing window length gives finer frequency-bin spacing. What tradeoff should you report?
06 · CONTINUE

Take this idea with you.

Samples constrain what you can know. Windowed spectra reveal local frequency structure while trading time detail for frequency detail.

My work
Learn AI · Understand by doing.Loading local progress…Copyright (c) 2026 Mobi Weave, Inc. All rights reserved