⏹️

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

Logarithmic from 20 Hz to 5 kHz so the slider is uniform across decades.
50% = symmetric square (odd harmonics only). Anything below or above adds even harmonics and shifts the DC offset.
Quick presets
Start low — narrow pulses concentrate energy into many harmonics and sound bright at the same setting as a sine.
Idle — press Play.

PWM modulation

Pulse width
25.0 %
Log 0.1 – 5 Hz. Slow sweeps (0.3 Hz) give the classic “analog synth” PWM motion.
Sine LFO swings the pulse width by ± this much around the base value. Result is always clamped to 1 – 99 %.

Spectral character

Waveform
On : Off ratio
= D : (1 − D)
DC offset
= 2D − 1
Strongest harmonic
excluding DC
THD
|H₂..H₂₀| RMS / |H₁|
Odd harmonics
H3, H5, H7… of total
Even harmonics
H2, H4, H6… of total
Harmonic amplitude rule
|Hn| = (4 / πn) · |sin(πnD)|
Spectral nulls land at every integer multiple of 1/D. At D = 0.25 → nulls at H4, H8, H12.
Band-limited waveform (3 cycles, gold dash = DC offset)
Harmonic spectrum — H1 through H20 (dB relative to H1)

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?
Mathematically they're the same Fourier series; a 50% pulse is a square. This tool focuses on the asymmetric region — narrow pulses, the spectral nulls that move with D, and the automatic PWM LFO that sweeps duty continuously. Use the Square generator when you want a clean 50% reference; use this one to explore how the spectrum changes when you push D toward the extremes or modulate it over time.
What does the PWM sweep actually do to the audio?
The LFO drives the pulse-width parameter through D(t) = D₀ + depth·sin(2π·rate·t). On every animation frame we rebuild the 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?
Because the waveform is rebuilt at the browser's animation-frame rate (60 fps in most cases). At 5 Hz LFO we get ~12 wavetable refreshes per modulation cycle, which sounds smooth. Pushing to audio-rate FM-style modulation (50 Hz+) would require an AudioWorklet instead of PeriodicWave — that's a different tool.
Why is the audible loudness about the same at 50% and 10% duty?
We build the 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.
Where do the spectral nulls move when I change duty?
Nulls land at every integer multiple of 1/D. D = 0.5 → all even n; D = 0.33 → H3, H6, H9, …; D = 0.25 → H4, H8, H12; D = 0.10 → H10, H20. For non-simple fractions the “null position” lands at a non-integer harmonic that doesn't actually exist, so the spectrum fills in densely and no harmonic is exactly zero.
What's the “DC offset” readout for if the audio is zero-mean?
It's the time-average of the mathematical waveform — the value a DC-coupled measuring instrument would see if you fed it a real pulse with the same duty. The audio path discards DC (Web Audio spec, and most amplifiers are AC-coupled anyway), but the readout is the right reference if you're designing a real circuit, simulating a class-D PWM stage, or driving a lab DUT.
Why does the waveform look round at the corners?
Band-limited reconstruction: we sum only the first 40 harmonics (or fewer near the Nyquist edge), so transitions take a finite time and exhibit the classic Gibbs ringing overshoot. This is exactly what your speaker plays. Drawing infinitely-vertical edges would misrepresent the audio.
Is high-volume pulse-wave playback safe for speakers and ears?
Narrow pulses pack more energy into more harmonics than a sine of the same peak voltage. Start at the default 10% volume and increase gradually. Avoid extended high-volume listening — ear fatigue arrives much faster than with sine tones. For speakers the real risk is at amplifier clipping; below that level, pulses are no worse than any other complex signal.