# Square Wave Variations

J. Donald Tillman
October 29, 2013

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.

## Binary Nature

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.

## Plots

So here is a plot of the classic square wave.

The equation is:

$y= sinωt + 13sin3ωt + 15sin5ωt + 17sin7ωt …$

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$.)

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

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

$y= cosωt + 13cos3ωt + 15cos5ωt + 17cos7ωt …$

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.

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= sinωt + 13cos3ωt - 15sin5ωt - 17cos7ωt …$

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= sinωt + 13cos3ωt + 15sin5ωt + 17cos7ωt …$

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

$y= sinωt + 13sin3ωt + 15cos5ωt + 17cos7ωt …$

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

$y= sinωt + 13sin3ωt + 15sin5ωt - 17cos7ωt …$

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

$y= sinωt + 13sin3ωt - 15sin5ωt + 17cos7ωt …$

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

$y= sinωt - 13sin3ωt + 15sin5ωt + 17cos7ωt …$

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= sinωt - 13sin3ωt - 15sin5ωt - 17cos7ωt …$

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= sinωt + 13cos3ωt + 15sin5ωt …$

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

$y= sinωt + 13sin3ωt + 15cos5ωt …$

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

## Back to Squariness

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= sinωt - 13sin3ωt - 15sin5ωt + 17sin7ωt …$

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= sinωt + 13sin3ωt - 15sin5ωt - 17sin7ωt …$

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= sinωt - 13sin3ωt + 15sin5ωt …$

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

$y= sinωt + 13sin3ωt - 15sin5ωt + 17sin7ωt + 19sin9ωt …$

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

$y= sinωt - 13sin3ωt + 15sin5ωt - 17sin7ωt + 19sin9ωt …$

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

$y= sinωt - 13sin3ωt - 15sin5ωt - 17sin7ωt + 19sin9ωt …$

## And... Random

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

## What Do They Sound Like?

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.

## Conclusion

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