Learn

Learning preferences

Make learning more comfortable. Changes apply immediately.

Enlarges page content, including diagrams and their labels. You can also use your browser’s zoom.

Choose the colours that are easiest for you to distinguish. Applies to lesson diagrams and lab plots. Labels, shapes, hatching and line patterns also distinguish meanings. Source photographs and raw image brightness stay unchanged; mask-only views are available for image overlays.

ExampleComparisonSample link

Saved in this browser on this device. Preferences are separate from progress backups.

Lesson 7 of 13 in this unit

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.

Start with the exampleJump to the experimentRead the explanation
Prerequisites and path options

Why learn this? Understand what a sound representation preserves so you can detect losses caused by sampling and compression.

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.

Loading this browser experiment…

04 · UNDERSTAND
READ & CONNECT

Understand what changed.

Back to the experiment

A shorter explanation, with the original worked examples available below. Both explain the same experiment and its limits.

Same learning goal in both modes: Explain sample-rate ambiguity, compute a simple spectral interpretation and compare time/frequency detail without relying on hearing.

The idea in everyday terms

A digital sound signal is a sequence of samples. Sample rate tells you how often values are recorded; frequency tells you how quickly a wave repeats. These are different quantities. Too few samples can make different waves look identical.

What to watch in the experiment

Inspect the sampled wave and frequency view together. Compare windows that preserve short-time changes with windows that distinguish nearby frequencies more clearly. A frequency-bin value describes the chosen window and calculation, not the entire sound forever.

What this does not establish

The lab generates teaching waves rather than microphone recordings. Sampling can lose information that later analysis cannot recover, and a clean spectrum is not evidence of speech or real-world sound recognition.

Open the full worked examples, calculations and limitations

This is the same reference used in Technical mode. Expand it whenever you need the exact numbers, assumptions or further explanation.

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 Learning
Explore related topics and the topic map

How this topic connects

Explore this topic on the interactive map

Use these connections to review a foundation or choose where to go next. You can open any topic without completing the others.

What it builds on

  • Vectors and weighted sums

    Treat a list of numbers as one representation and trace weighted sums. These operations connect the lesson’s inputs to its outputs.

  • Reading graphs

    Read axes, coordinates and scales so you can connect a plotted change with the numerical evidence in this lesson.

You are hereTurn sound into features

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

What it enables

  • Order changes meaning Explore a related application

    After turning sound into a sequence of frame features, explore why the order of a sequence can change a model’s interpretation.