Pulse Wave Generator
Free, browser-only pulse wave generator with adjustable pulse width (1 – 99 %), an automatic PWM sweep LFO (0.1 – 5 Hz), live band-limited waveform, and a H1 – H20 harmonic bar chart. Built on Web Audio's PeriodicWave for alias-free synthesis from 20 Hz to 5 kHz.
Source
PWM modulation
Spectral character
Pulse Waves, PWM & the Spectrum
A pulse wave is a two-level signal that sits at +1 for a fraction D of each period and at −1 for the remaining (1 − D). The symmetric case D = 0.5 is the familiar square wave; any other duty produces a richer, asymmetric pulse whose spectrum contains both odd and even harmonics, with carefully-placed spectral nulls. Sliding D back and forth in real time — pulse-width modulation, or PWM — is one of the most recognizable sounds in analog synthesis.
The amplitude rule
For a bipolar pulse of duty D, the n-th harmonic's magnitude is |Hn| = (4 / πn) · |sin(πnD)|. Three immediate consequences:
- The fundamental (n=1) peaks at 4/π ≈ 1.273 when D = 0.5 and falls off as D approaches the edges.
- At D = 0.5 the sine factor is zero for every even n → only odd harmonics (the classical square).
- For any D, harmonics at integer multiples of 1/D are zero. D = 0.25 → nulls at H4, H8, H12; D = 0.10 → nulls at H10, H20.
The DC offset
If high = +1 and low = −1, the time-average is DC = 2D − 1. A 10% pulse sits at −0.8 V average; a 90% pulse at +0.8 V. The dashed gold line on the waveform plot shows this offset visually. Web Audio's PeriodicWave always discards the DC component — the audio you hear is zero-mean — but the offset still matters when you reason about a real pulse driving DC-coupled hardware.
PWM — why the sweep sounds “fat”
When the pulse width is automatically modulated by a slow LFO, the harmonic spectrum is no longer static: each harmonic's amplitude breathes in and out as the duty cycle moves. Because different harmonics are modulated by different amounts (the sin(πnD) term varies more for higher n than for the fundamental), a single pulse oscillator under PWM sounds like two or three slightly-detuned oscillators — the source of the “super-saw” / “Juno” / “chorus-bass” effect on the Minimoog, Prophet-5, Roland Juno-60 and countless modern softsynths.
Band-limited synthesis
An ideal pulse has infinite bandwidth; any sampled audio system has a Nyquist limit (24 kHz at a 48 kHz context). This tool synthesises only the harmonics that fit below Nyquist (capped at 40), so the visible waveform shows realistic Gibbs ringing at each edge. That ringing is audible and intentional — not a rendering glitch.
Frequently Asked Questions
What's the difference between this and the Square Wave Generator?
What does the PWM sweep actually do to the audio?
PeriodicWave with the new D, and the oscillator picks up the new harmonic mix on its next cycle. The audible result: the timbre breathes between “hollow square” (near 50%) and “thin nasal pulse” (near 1% / 99%) at the LFO rate.Why does the PWM rate cap at 5 Hz?
AudioWorklet instead of PeriodicWave — that's a different tool.Why is the audible loudness about the same at 50% and 10% duty?
PeriodicWave with disableNormalization: false, so Web Audio rescales each shape's peak to ±1 before playback. Without that normalisation, a 5% pulse would be ~10× quieter than a 50% square at the same peak voltage. The chart still shows you the true relative harmonic levels.