IB DP Physics · Unit 4 Waves · cables.gl Lab

Sound as Sums:
Additive Synthesis & Fourier Thinking

90 min (double period) 🎓 DP1 / DP2 🧪 Browser-only — no install 🔗 cables.gl

01 — OVERVIEWLesson at a Glance

Students have already worked with the mathematics of a single sinusoidal wave: amplitude, frequency, wavelength, and phase. This lesson extends that foundation by asking: what happens when you add multiple sine waves together? The answer — Fourier's great insight — is that virtually any periodic sound is the sum of sine waves at harmonically related frequencies, each with its own amplitude and phase.

Rather than learning this abstractly, students will build it in cables.gl — a free, browser-based visual patching environment inspired by Max/MSP and VCV Rack, using the Web Audio API under the hood. They will watch an oscilloscope and spectrum analyzer respond in real time as they add, scale, and tune oscillators, making the math audible and visible simultaneously.

IB Connections

Topic 4 (Waves): superposition, standing waves, timbre as harmonic content
Topic 11 (AHL Waves): Fourier analysis, diffraction, resolution
Internal Assessment bridge: students running Fourier projects can use this as a listening validation of their mathematical models

02 — INQUIRYEssential Questions

CONCEPTUAL
Why does a violin playing A4 (440 Hz) sound different from a flute playing A4?
Both oscillate at 440 Hz as their fundamental. The spectrum analyzer will show you the answer immediately.
MATHEMATICAL
How does the Fourier series formula relate to what you're building in the patch?
Each oscillator node in cables.gl maps directly to one term in the series: frequency nf₀, amplitude aₙ.
EXPERIMENTAL
Can you "sculpt" a waveform on the oscilloscope by choosing harmonic amplitudes?
Square waves require all odd harmonics at 1/n amplitude. Can students discover this by ear and eye before seeing the formula?
EXTENSION
What physical properties of an instrument determine its harmonic spectrum?
Boundary conditions on strings/tubes constrain which harmonics are present — connecting acoustics to standing wave theory.

03 — TOOLcables.gl Primer for Students

cables.gl is a node-based (visual programming) environment that runs entirely in the browser. You connect ops (operators / nodes) with wires to build signal chains — exactly like the patching paradigm behind Max/MSP, Pure Data, or VCV Rack, but with zero installation. Everything runs via the Web Audio API.

🔐
Account setup (teacher prep): Students need a free cables.gl account to save patches. Alternatively, the teacher can share a read-only clone link of a starter patch — students clone it to their own account before editing. This is the recommended classroom workflow.

Key Concepts in cables.gl

TermMeaningAnalogy
Op A single node/module that does one job A hardware synthesizer module
Port An input or output connection point on an op A jack socket on the module
Wire / Cable The connection between two ports The patch cable
Patch The entire network of connected ops The complete synthesizer setup
Trigger An event signal (bang) rather than a continuous value A gate / trigger pulse in modular

Essential Audio Ops for This Lesson

Ops.WebAudio.Oscillator Ops.WebAudio.AudioMath_Add Ops.WebAudio.Gain Ops.WebAudio.AudioAnalyzer_v2 Ops.WebAudio.Output_v2 Ops.WebAudio.AudioMath_Multiply Ops.Gl.MainLoop Ops.Array.ArrayToTexture Ops.Gl.Meshes.Mesh_BarChart

Add any op by double-clicking the canvas and typing its name in the search box. You only need to type the short name (e.g. "Oscillator", "AudioAnalyzer", "Output").

04 — SEQUENCE90-Minute Lesson Flow

00:00 – 10:00 · HOOK
What is a timbre? The same pitch, different instruments
Play three recordings (prepared in advance): violin A4, flute A4, clarinet A4. Ask students: same note — what's different? Show a spectrogram image side-by-side. Briefly explain that every periodic sound is a sum of pure sine tones (Fourier's theorem). Today they will hear this with their own patch.
10:00 – 20:00 · DIRECT INSTRUCTION
The Fourier series formula (brief but precise)
Write the formula on the board, connecting each symbol to a cables.gl object they are about to use.
20:00 – 50:00 · GUIDED BUILD
Build the additive synth patch step by step
Students follow the build guide (see Section 5). Teacher circulates and models on projected screen. Oscilloscope and spectrum analyzer appear live.
50:00 – 75:00 · OPEN INQUIRY
Instrument approximation challenges
Students use the harmonic recipe table (Section 6) to approximate a square wave, a sawtooth, and one of three instrument timbres of their choice. They screenshot their spectrum and oscilloscope for evidence.
75:00 – 90:00 · CLOSE
Share, connect, exit ticket
Pairs share their most interesting spectrum with the class. Exit ticket: "Write one sentence connecting what you built today to the Fourier project / the sine wave math we did last week."

05 — BUILD GUIDEStep-by-Step Patch Instructions

💡
Before you start: Log in to cables.gl, click New Patch, and name it "Additive Synth — [your name]". Allow audio when the browser asks. The fundamental frequency for this build is 220 Hz (A3) — lower frequencies show up more clearly on the oscilloscope.

Phase 1 — Single Oscillator + Output (5 min)

Goal: Get a single pure sine wave playing and visible.

Ops to add:

Oscillator Output_v2
  1. Double-click the canvas → search "Oscillator" → click to place.
  2. In the right sidebar set Frequency to 220 and Type to sine.
  3. Add Output_v2. Connect the Oscillator's audio out port → Output_v2's audio in.
  4. Press the ▶ Play button at the top of the screen. You should hear a pure tone. (Reduce system volume first!)
Oscillator
220Hz · sine
──▶ Output_v2

Phase 2 — Oscilloscope + Spectrum Analyzer (10 min)

Goal: See what you hear — time domain and frequency domain simultaneously.

AudioAnalyzer_v2 MainLoop ArrayToTexture Mesh_BarChart or DrawArrayLine
  1. Add AudioAnalyzer_v2. Connect Oscillator audio out → AudioAnalyzer audio in. Also connect AudioAnalyzer audio out → Output_v2 (so sound still plays).
  2. AudioAnalyzer_v2 exposes two arrays: FFT Array (frequency spectrum) and Waveform Array (oscilloscope).
  3. Add MainLoop. Add Ops.Array.ArrayToTexture. Connect MainLoop trigger → ArrayToTexture trigger. Connect AudioAnalyzer Waveform Array → ArrayToTexture array.
  4. Add Ops.Gl.Meshes.Mesh_BarChart (or DrawArrayLine for a line scope). Connect ArrayToTexture texture out → the chart's texture input. Press Play. You should see the waveform drawn live.
  5. Repeat step 3–4 for the FFT Array output to get the spectrum — place it beside the waveform display.
Signal Flow
Oscillator ──▶ AudioAnalyzer_v2 ──▶ Output_v2
Visualisation
AudioAnalyzer_v2
FFT Array out
──▶ ArrayToTexture ──▶ Mesh_BarChart
(spectrum)
AudioAnalyzer_v2
Waveform Array out
──▶ ArrayToTexture ──▶ DrawArrayLine
(oscilloscope)
MainLoop ──▶ (both ArrayToTexture triggers)

💡 At this stage you'll see a single spike in the spectrum at exactly 220 Hz and a clean sine wave on the oscilloscope. This is a pure tone — one Fourier component.

Phase 3 — Add Harmonics: Additive Synthesis (15 min)

Goal: Add the 2nd, 3rd, and higher harmonics with controllable amplitudes. Watch the oscilloscope change shape as you add each partial.

Oscillator ×4 Gain ×4 AudioMath_Add ×3 Slider (UI)
  1. Duplicate your first Oscillator three times (right-click → clone, or Ctrl+D). Set their frequencies to 440, 660, 880 (2×, 3×, 4× the fundamental — these are harmonics 2–4).
  2. Add a Gain op after each oscillator. Add a Slider UI op connected to each Gain's value port. Set the sliders' range to 0–1. Start them at 0.
  3. Chain the four Gain outputs together using AudioMath_Add ops. The final sum connects to the AudioAnalyzer and then Output_v2.
  4. Slowly bring up slider 2 (440 Hz). Note the oscilloscope change and the new spike appearing in the spectrum. Repeat for each harmonic.
y(t) = A₁·sin(2π·220·t)
+ A₂·sin(2π·440·t)
+ A₃·sin(2π·660·t)
+ A₄·sin(2π·880·t) + …

Each slider directly controls the Aₙ coefficient in the Fourier series for the output waveform. The oscilloscope is drawing the sum y(t) in real time.

Phase 4 — Interactive Amplitude Control (5 min, optional)

Goal: Make it more playable — connect sliders to labels so the interface is clear.

Right-click each Slider op → Label → name them "H1 (fundamental)", "H2 (octave)", "H3 (fifth+octave)", "H4 (2nd octave)". This labelling reinforces what each harmonic is musically as well as mathematically.

Optional: add Ops.WebAudio.BiquadFilter between the sum and the output to see how filtering changes the spectrum — a preview of why string instruments have rounded tones compared to the sharp spectral spikes of an ideal additive synth.

06 — INQUIRYWaveform Challenge Cards

Each pair receives one challenge. Use the harmonic recipes below. Adjust amplitudes until your oscilloscope shape matches the target — then explain in one sentence why that recipe works.

Target waveform Harmonics present Relative amplitudes Aₙ Musical character
Sine H1 only 1, 0, 0, 0… Flute, pure tuning fork
Square Odd harmonics only 1, 0, 1/3, 0, 1/5, 0… Clarinet (cylindrical bore)
Sawtooth All harmonics 1, 1/2, 1/3, 1/4… Violin, brass, rich strings
Triangle Odd harmonics only 1, 0, 1/9, 0, 1/25… Muted, hollow tone
Piano-like All, but high harmonics decay faster 1, 0.7, 0.5, 0.3, 0.15… Inharmonic partials in real piano
Bell / inharmonic Non-integer ratios Try 1× and 2.76× and 5.4× Metallic, bell-like beating
🔬
Physics connection: The square wave recipe (only odd harmonics) is directly explained by standing wave boundary conditions in a cylindrical tube closed at one end — the same physics as a clarinet. Open cylinders (flute) and strings produce all harmonics (sawtooth recipe). Ask students to draw the standing wave diagrams for each case and check whether the harmonic content matches.

07 — MATHEMATICSFourier Series — What the Patch Is Computing

The general Fourier series for a periodic function with period T (fundamental frequency f₀ = 1/T):

f(t) = a₀/2 + Σₙ₌₁^∞ [ aₙ·cos(2πnf₀t) + bₙ·sin(2πnf₀t) ]

For symmetric waveforms (odd functions), the cosine terms vanish and we are left with the sine-only series — exactly what students are building with their oscillator bank:

y(t) = Σₙ₌₁^N Aₙ · sin(2π · n·f₀ · t + φₙ)

where Aₙ = amplitude of harmonic n (your Gain slider), n·f₀ = frequency of harmonic n (your Oscillator frequency setting), and φₙ = phase offset (cables.gl Oscillator has a phase input port for HL extension).

Connecting to IB DP Waves

What you see in the patchIB Physics / Maths connection
Each oscillator spike in the spectrum A single frequency component — Topic 4.1 characteristics of waves
Oscilloscope shape changing as you add harmonics Principle of superposition — Topic 4.3
Square wave ≈ sum of odd harmonics Boundary conditions of standing waves in closed pipes — Topic 4.5
Spectral "envelope" decaying with harmonic number Connects to resolution and Rayleigh criterion concepts — Topic 11.3
Bell inharmonicity (non-integer ratios) Normal modes of two-dimensional surfaces vs. strings — HL extension

08 — DIFFERENTIATIONExtension & Support

⬇ Support

Pre-built starter patch

Share a teacher-created cables.gl patch with two oscillators and analyzers already wired. Students only need to adjust sliders and add more oscillators.

→ Standard

Build from scratch

Students follow Phase 1–4 of the build guide, working towards the waveform challenge cards.

⬆ HL / Fourier IA

Phase manipulation

Add the phase port on each oscillator. How does changing φₙ affect the oscilloscope? (Hint: it doesn't change the spectrum — explore why.)

🔬 IA bridge

Cross-validate with their Fourier IA data

Students with instrument recordings in their IA can read off the harmonic amplitudes from their FFT graph and enter them as Gain values — then listen to whether their model sounds like the instrument.

🎹 Musical extension

Envelope shaping (ADSR)

cables.gl has an ADSR op. Apply it to the Gain of each harmonic to explore how attack/decay shape defines the transient character of an instrument.

💻 Coding extension

Custom op in JavaScript

Advanced students can write a custom cables.gl op that takes a harmonic number array as input and spawns oscillators programmatically — a miniature synthesis engine.

09 — ASSESSMENTEvidence of Learning

Formative (in-class)

  • Observable patch behaviour — teacher circulates and checks that spectrum spikes appear at correct harmonic multiples.
  • Oscilloscope screenshot + annotation — students annotate a screenshot of their square wave attempt labelling each harmonic, its frequency, and the Aₙ value they used.
  • Exit ticket — one sentence connecting today's activity to either (a) the sine wave formula or (b) standing waves / boundary conditions.

Summative bridge (homework / next lesson)

Students choose one real instrument. Using a reference spectrum from an audio analysis tool (or from their IA data), they:

  1. Write the partial Fourier series with their measured Aₙ values.
  2. Reproduce this in cables.gl and export a screenshot showing the synthesized spectrum compared to the original.
  3. Write a paragraph discussing discrepancies — why does the synthesized version not sound exactly like the real instrument? (Expected answer: real instruments have inharmonic partials, noise components, time-varying amplitudes — all deviations from the ideal Fourier series model.)

10 — TEACHER NOTESPrep Checklist & Common Issues

Before the lesson

Common student difficulties

IssueLikely causeFix
No sound Browser blocked audio autoplay Press the ▶ Play button — this triggers a user gesture which unlocks Web Audio
Spectrum shows only one spike even with 4 oscillators Oscillators not connected to the mixer / all Gain values at 0 Trace cables back from Output_v2 to find the break
Oscilloscope shows noise / garbage ArrayToTexture trigger not connected to MainLoop Check the MainLoop → ArrayToTexture trigger wire
Waveform looks "wrong" for square wave Even harmonics accidentally included, or amplitudes not 1/n Good! Ask the student to explain what they're seeing — it's a learning moment
Very loud / clipping Summing 4+ oscillators at gain 1.0 without a master limiter Add a final Gain op set to 0.2 before Output_v2, or remind students to use the OS volume
🎵
From Max/MSP background to cables.gl: The paradigm is identical — you'll feel at home. The key difference is that all UI elements (sliders, buttons) are also ops dragged onto the canvas rather than separate GUI objects. The AudioMath_Add op is the direct equivalent of Max's +~ (signal addition). The AudioAnalyzer_v2 exposes the same data as Max's fftin~ / scope~. For the physical modeling extension (next unit), cables.gl can be extended with custom JavaScript ops — the equivalent of Max's js objects — which enables Karplus-Strong string synthesis or waveguide models without leaving the browser.

11 — RESOURCESLinks & Going Further

ResourcePurpose
cables.gl The main tool — free account, browser-based
cables.gl Audio Docs Official documentation for all WebAudio ops
AudioNodes.com Alternative browser-based modular synth, useful fallback or complement
Chrome Music Lab — Spectrogram Quick live microphone spectrogram — great for 5-min hook activity showing voice harmonics
PhET: Fourier Making Waves Classic IB-friendly Fourier simulation — good pre-lesson homework
3Blue1Brown: But what is the Fourier Transform? Excellent conceptual video for pre-reading or flipped element
Strudel.cc Live-coding audio in the browser — great next step for students interested in algorithmic composition or microtonality