Ah, the Square Wave. You know it, you love it. So simple, yet so complex. Almost every oscillator in electronic music offers a Square Wave output. It's the waveform you turn to for all odd harmonics and no even harmonics. It has a distinctly hollow sound; the sound of a clarinet or a closed-end organ pipe.

Some would argue that the Square Wave does not exist in nature. My fuzzbox might disagree. But nonetheless, it is difficult to find mechanisms in nature that approach the instantaneous transitions of a perfect Square Wave, or to find mechanisms that have a Square Wave as their core operation.

The square wave is easy to make, electrically. It just slams between two values. It's binary. And that has some implementation advantages. Inexpensive digital circuitry can be used to create the waveforms. And a single Exclusive-OR gate will perform Ring Modulation on Square Waves, as implemented on the ARP Odyssey.

Toggle flip flops naturally produce square waves an octave below their input frequency. Of course. And we use those in many ways in electronic music:

- suboctave outputs for oscillators
- frequency multpliers in phase locked loops
- octaves from a Top Octave Generator for organ tone generation
- building faux sawtooth waveforms by summing multiple square wave octaves
- similarly building waveforms with Walsh Functions

And the specialized Buchla 144 Dual Square Wave Oscillator even goes to the trouble of having the core VCO drive a toggle flip flop to guarantee that there is no second harmonic.

The square wave has the lowest Peak to RMS voltage ratio possible, as the peak level of the square wave is the RMS level. Nonlinearities do not affect the mighty square wave.

The binary nature of the square wave is also problematic in that it covers up organic subtleties. Examples would include Phase Modulation and Frequency Modulation. There is a threshold of sensitivity below which modulation has no effect on a square wave. The highest threshold is at the center of the flat area and the lowest threshold is at the transitions. Once that line is crossed, the square wave reacts suddenly.

So here is a plot of the classic square wave.

The equation is:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{sin}3\omega t+\frac{1}{5}\mathrm{sin}5\omega t+\frac{1}{7}\mathrm{sin}7\omega t\dots $$

Where $\omega $ is the frequency in Radians/Second.

(This and the other plots were drawn in Apple's Grapher application from hundreds of sines and cosines. There are some visible artifacts. To make the presentation clearer, the $x$ axis in the plots is scaled to be the same as the $t$ value in the equations with $\omega =1.0$.)

The contribution of each harmonic is inversely proportional to its frequency in what is called a Harmonic Series. Since only odd harmonics are present, this specific situation is called an Odd Harmonic Series.

We can show how the square wave is built up from component Sine Waves at odd harmonics:

The zero-crossing transitions at 0 and 180 degrees are all lined up, so the sum of an infinite number of slopes creates instantaneous transitions. And in the flat sections, the ripples of each successive odd harmonic show up in alternate polarities and quickly converge to a constant level of $\frac{\pi}{4}$. This is related to the Leibniz Forumla for π.

So the first question is, what happens if we sum Cosine Waves instead of Sine Waves. The result is completely different:

$$y=\mathrm{cos}\omega t+\frac{1}{3}\mathrm{cos}3\omega t+\frac{1}{5}\mathrm{cos}5\omega t+\frac{1}{7}\mathrm{cos}7\omega t\dots $$

Isn't it amazing what a phase shift can do? This waveform shares none of the graphical aspects of the original Square Wave. The binary nature has completely vanished. In fact it's the opposite, with points instead of flats. Yet the harmonic power spectrum is identical; there is exactly the same amount of each harmonic as the original Square Wave.

I've heard this called a Hilbert Wave. A Hilbert Transform rotates the phases of a given signal 90 degrees, and the classic example of its effect is to plug in a Square Wave.

Here is the build-up of that from component Cosine Waves:

And sure enough, the humps of all the component waves are now adding up to create peaks, and in between the ripples of the component waves cancel out to a smooth slope.

The peaks of the Hilbert Wave are theoretically infinite, but the Harmonic Series goes up so, so, slowly that the first 500 harmonics bring it up to only 3.75 (with respect to the 1.0 fundamental). So in practice, it's a far cry from infinity.

So we've tried summing sines and summing cosines. How about rotating between $\mathrm{sin}$, $\mathrm{cos}$, $\mathrm{-sin}$, and $\mathrm{-cos}$ over every four harmonics? What would that look like? Here:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{cos}3\omega t-\frac{1}{5}\mathrm{sin}5\omega t-\frac{1}{7}\mathrm{cos}7\omega t\dots $$

That wave is graphically somewhere in between the two previous waveforms, which is interesting because the Square Wave and Hilbert Wave are so different.

And left-right symmetry is gone, the longer near-vertical transistion is on the trailing edge, so one can discern positive vs. negative frequency.

And by playing with the phases it is possible to morph from Square Wave to Hilbert Wave like this:

(This is with the phase of the fundamental held constant at 0 degrees.)

Here's another variation; instead of rotating between the four quadrature phases, how about just alternating between sines and cosines? Here:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{cos}3\omega t+\frac{1}{5}\mathrm{sin}5\omega t+\frac{1}{7}\mathrm{cos}7\omega t\dots $$

Weirder still, pairs of sines alternating with pairs of cosines:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{sin}3\omega t+\frac{1}{5}\mathrm{cos}5\omega t+\frac{1}{7}\mathrm{cos}7\omega t\dots $$

Here are all sines, but invert the polarity of the last of each group of four harmonics:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{sin}3\omega t+\frac{1}{5}\mathrm{sin}5\omega t-\frac{1}{7}\mathrm{cos}7\omega t\dots $$

All sines, but invert the polarity of the third of each group of four harmonics:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{sin}3\omega t-\frac{1}{5}\mathrm{sin}5\omega t+\frac{1}{7}\mathrm{cos}7\omega t\dots $$

All sines, but invert the polarity of the second of each group of four harmonics:

$$y=\mathrm{sin}\omega t-\frac{1}{3}\mathrm{sin}3\omega t+\frac{1}{5}\mathrm{sin}5\omega t+\frac{1}{7}\mathrm{cos}7\omega t\dots $$

And all sines, but invert the polarity of the second, third and fourth of each group of four harmonics, effectively inverting the polarity of the first:

$$y=\mathrm{sin}\omega t-\frac{1}{3}\mathrm{sin}3\omega t-\frac{1}{5}\mathrm{sin}5\omega t-\frac{1}{7}\mathrm{cos}7\omega t\dots $$

Now, if we group the harmonics into threes instead of fours, we can replace the middle of each trio of harmonics with a Cosine:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{cos}3\omega t+\frac{1}{5}\mathrm{sin}5\omega t\dots $$

Or replace the third of each trio of harmonics with a Cosine:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{sin}3\omega t+\frac{1}{5}\mathrm{cos}5\omega t\dots $$

Again, all of these have the same power spectrum as the classic Square Wave.

Well, those are all graphically pretty far removed from Square Waves. Is it even possible for polarity or phase variations that are recognizably related to Square Waves? Yes, if one inverts the polarity of symmetrically located coefficents within equal groups of harmonics.

For example, if you take the Square Wave spectrum and invert the phase of the middle two of every group of four harmonics, you get this:

$$y=\mathrm{sin}\omega t-\frac{1}{3}\mathrm{sin}3\omega t-\frac{1}{5}\mathrm{sin}5\omega t+\frac{1}{7}\mathrm{sin}7\omega t\dots $$

That's very much like a Square Wave. Let's call this a Tri State Square Wave.

A variation of this, inverting the last two of each set of four harmonics, generates what I would have to call a Tri State Hilbert Wave:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{sin}3\omega t-\frac{1}{5}\mathrm{sin}5\omega t-\frac{1}{7}\mathrm{sin}7\omega t\dots $$

But back to the squares...

In a similar way, if we invert the middle of each group of three harmonics, we get a stairstep version of a Square Wave:

$$y=\mathrm{sin}\omega t-\frac{1}{3}\mathrm{sin}3\omega t+\frac{1}{5}\mathrm{sin}5\omega t\dots $$

Similarly, we can do groups of five harmonics at a time and invert the middle one:

$$y=\mathrm{sin}\omega t+\frac{1}{3}\mathrm{sin}3\omega t-\frac{1}{5}\mathrm{sin}5\omega t+\frac{1}{7}\mathrm{sin}7\omega t+\frac{1}{9}\mathrm{sin}9\omega t\dots $$

Or invert the two near-middle harmonics in each group of five:

$$y=\mathrm{sin}\omega t-\frac{1}{3}\mathrm{sin}3\omega t+\frac{1}{5}\mathrm{sin}5\omega t-\frac{1}{7}\mathrm{sin}7\omega t+\frac{1}{9}\mathrm{sin}9\omega t\dots $$

Or invert the three middle harmonics in each group of five:

$$y=\mathrm{sin}\omega t-\frac{1}{3}\mathrm{sin}3\omega t-\frac{1}{5}\mathrm{sin}5\omega t-\frac{1}{7}\mathrm{sin}7\omega t+\frac{1}{9}\mathrm{sin}9\omega t\dots $$

And finally, here is a waveform with the spectrum of a Square Wave, but the phases are random:

All of the waveforms presented here have the identical power spectrum, the same contribution of each harmonic. Only the phases or polarities have changed. Will they sound identical? Yes, at least to a first approximation.

The ear is not very sensitive to phase, but there are experimental situations where it can be. Nonlinearities will affect the waveforms in different ways, and there are nonlearities all around; in circuitry, in speakers or headphones, in the air, and in our ears. And in any kind of real world application, a lot happens after the waveform is first created.

I just think it's interesting, that's all.

Donald Tillman: Synth-DIY -- Buchla 144 Dual Square Wave Oscillator

Series Math Study: A Brief Note on Nth Partial Sum of Harmonic Series

Bernard Hutchings, Jr.: Experimental Electronic Music Devices Employing Walsh Functions

Wikipedia: Apple Grapher

Wikipedia: Harmonic Series

Wikipedia: Hilbert Transform

November 4, 2013: Fixed a unit, added the random phase wave.

Email: don -at- till.com

Web page: till.com