Chapter 17 of 22 Part IV: Information Processing

The Fingerprint of Sound

Each project below is tailored to a specific algorithm and scientific question from Chapter 17, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.

Project 1 of 3 · v1-c17-p01 Applied · ~30 min

Fourier Frequency Decomposition of Mixed Waves

Lab activity: 1. Look inside a mixed sound · Related code: block-01.js, block-04.js · Pioneer: View profile

Real-World Problem: A microphone records a single combined air-pressure curve even when an entire orchestra plays simultaneously.
Scientific Question: How does the Discrete Fourier Transform (DFT) recover the exact frequencies hidden inside a summed waveform?

Objective: Synthesize a sum of two sine waves (e.g., 440 Hz + 660 Hz), compute DFT magnitudes, and identify the exact spectral peaks.

Hypothesis to Test: Correlating a mixed signal against reference sine/cosine waves yields strong peaks ONLY at the constituent frequencies.

Step-by-Step Implementation

  1. Generate N evenly spaced time samples of two summed sine waves.
  2. Compute real and imaginary DFT components for frequency bins k = 0 .. N/2.
  3. Compute magnitude sqrt(re^2 + im^2) / (N/2) and locate the top two peaks.
  4. Reduce f_s below 2 × 880 Hz (e.g., 1200 Hz) to observe aliasing fold 880 Hz down to 320 Hz!
Concrete Input: N = 256 samples at f_s = 4096 Hz of sin(2π·440t) + 0.5·sin(2π·880t).
Expected Output: DFT peaks cleanly at bin ~27.5 (440 Hz, amp 1.0) and bin ~55 (880 Hz, amp 0.5); all other bins near 0.

Test Cases: f_s=4096, f=440 -> peak at 440 Hz; f_s=1200, f=880 -> aliased peak at 320 Hz.

Boundary Condition: Frequencies not aligned with integer bin k*(f_s/N) exhibit spectral leakage unless windowed.

Common Mistake to Avoid: Forgetting that DFT output is symmetric above N/2 (the Nyquist frequency f_s/2).

Interpreting Results: Joseph Fourier's decomposition turns complex time waveforms into readable frequency recipes.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 17 before testing the boundary case: Frequencies not aligned with integer bin k*(f_s/N) exhibit spectral leakage unless windowed.

Extension Challenge: Apply a Hann window before the DFT and observe how spectral leakage around non-integer bins shrinks.

Reflection Question: Why does CD audio sample at 44,100 Hz instead of exactly 40,000 Hz?

Project 2 of 3 · v1-c17-p02 Applied · ~30 min

Acoustic Peak-Pair Song Fingerprint Matcher

Lab activity: 2. Find the mystery tune · Related code: block-02.js, block-05.js · Pioneer: View profile

Real-World Problem: Music-ID apps recognize a 5-second clip played in a noisy restaurant out of millions of tracks.
Scientific Question: Why do pairs of strong spectrogram peaks (f1, f2, Δt) survive background chatter far better than raw waveforms?

Objective: Extract top spectral peak pairs from synthetic melodies, add random noise, and match the mystery clip to a tiny catalog.

Hypothesis to Test: Even with background noise added, the strongest frequency peaks and their time offsets still align cleanly for the true song.

Step-by-Step Implementation

  1. Compute short-time spectral peaks across 4 time frames for each synthetic tune.
  2. Create compact landmark hashes (freq1, freq2, deltaTime) for each tune.
  3. Add synthetic noise to one query clip and count matching hashes per catalog track.
  4. Verify time-offset coherence (matches occur at a consistent offset in the true song).
Concrete Input: 3 synthetic 4-note melodies; add noise to Melody #2 and query its peak-pair hashes.
Expected Output: Melody #2 achieves highest aligned time-offset match count -> identified correctly.

Test Cases: Clean query -> 100% match; Moderate noise -> true track still #1; Silent clip -> no match.

Boundary Condition: Very heavy noise that drowns out spectral peaks causes missed matches.

Common Mistake to Avoid: Matching raw time-domain amplitude samples directly (a 1-millisecond shift destroys raw correlation).

Interpreting Results: Constellation peak-pair hashing makes acoustic search both shift-invariant and noise-tolerant.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 17 before testing the boundary case: Very heavy noise that drowns out spectral peaks causes missed matches.

Extension Challenge: Shift the query clip by +2 time frames and verify the matcher still identifies the song.

Reflection Question: Why does fingerprinting store compact spectral landmarks instead of uploading full audio recordings?

Project 3 of 3 · v1-c17-p03 Foundational · ~20 min

Active Noise Cancellation Phase-Inversion Lab

Lab activity: 3. Fight noise with an opposite wave · Related code: block-03.js, block-04.js, block-05.js · Pioneer: View profile

Real-World Problem: Airplane cabins and trains produce steady low-frequency hum that foam earpads alone struggle to block.
Scientific Question: How accurately must an anti-noise wave match amplitude and 180° phase to cancel an incoming wave?

Objective: Superpose a noise sine wave with a phase-adjustable anti-noise wave and measure residual RMS amplitude across 0°–360°.

Hypothesis to Test: At 180° phase shift with equal amplitude, residual RMS drops to 0; at 0° phase shift, amplitude doubles (+6 dB).

Step-by-Step Implementation

  1. Generate 100 samples of noise(t) = sin(2πft) and anti(t) = A * sin(2πft + phi).
  2. Sum combined(t) = noise(t) + anti(t) and compute RMS amplitude.
  3. Sweep phi from 0° to 360° and verify minimum at 180°.
  4. Test a 15° phase delay to see why active cancellation works best on steady low frequencies rather than sudden high-pitched voices.
Concrete Input: 100 Hz noise wave (amp 1.0) + anti-noise at phase 0°, 90°, 180°, and 195°.
Expected Output: 180° -> residual RMS = 0.00; 195° -> residual ≈ 0.26; 0° -> residual = 2.00 (constructive reinforcement!).

Test Cases: phi = Math.PI, A = 1 -> RMS < 1e-12; phi = 0, A = 1 -> RMS doubled.

Boundary Condition: At high frequencies (shorter wavelengths), tiny microsecond latency creates huge phase errors.

Common Mistake to Avoid: Thinking noise-canceling headphones "absorb" sound rather than adding an inverted wave.

Interpreting Results: Wave superposition explains both constructive amplification and destructive noise cancellation.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 17 before testing the boundary case: At high frequencies (shorter wavelengths), tiny microsecond latency creates huge phase errors.

Extension Challenge: Add a 1 ms processing delay and calculate the highest frequency that still achieves >50% cancellation.

Reflection Question: Why do modern headphones combine passive foam (for high frequencies) with active cancellation (for low hum)?