Not so hip to be square
by, 06-09-2013 at 10:57 AM (1227 Views)
There seems to be a fair bit of confusion about trying to reproduce square waves using bandwidth-limited systems (and face it, all audio systems are bandwidth-limited), so I decided to try to write up some basic things that hopefully will help clear some of the confusion.
As we know, a square wave is the sum of all odd harmonics, according to the formula
By the way, that formula has nothing to do with Fourier analysis - it is just the sum of a bunch of sine waves, so the only operation we use is addition.
To perfectly reproduce the square wave, infinite bandwidth is required, so we will never get a perfect square wave.
Here is a square wave built up from harmonics 1-99 (So if the fundamental was at 1 KHz, this square wave would require a system capable of reproducing 100 KHz):
Not too shabby, right?
OK, what happens when we lower the bandwidth? Here is the same wave, but with an upper limit of 20 KHz, so only the harmonics 1-19 are included:
As we can see, we now have a ripple caused by the harmonics above the 19th missing from the supposedly infinite sum. Some people might think it is ringing caused by the DAC filter, but note that so far we haven't applied any filter. The ripple is totally natural consequence of the fact that the higher harmonics that would "smooth out" the square wave are missing (and note that the ripple frequency is at 21 times the fundamental, so above the 20 KHz human hearing range). This actually has nothing to do with digital - we could use a bank of analog sine wave generators feeding an analog mixer, and use a tape deck as our bandwidth-limited channel.
Here is the same approximate square wave again, but showing the missing harmonics - exactly the difference between the approximation and the ideal square wave:
Now, does this have anything to do with how it sounds? No, not really. The "squareness" of the square wave is purely a visual thing - and our ears don't care about visual squareness. To illustrate this, let's shift the phase of the harmonics by 180 degrees (180 degrees of harmonic 3 corresponds to 60 degrees of the fundamental), a change that is pretty much inaudible to the ear:
Pretty nasty-looking, huh? It is the same square wave, but with a bit of frequency-dependent phase shift (as generated by any filter or speaker).
It is pretty clear that the "squareness" of a square wave on a 'scope display has very little to do with how it actually sounds.
So, how does the original square wave look when we shift the frequency up to 10 KHz but keep the high frequency cut-off at 20 KHz, just as would happen with any system (not just digital) that has an upper frequency limit below 30 KHz?
Here is the result:
So we have a sine wave. Not very surprising, considering we removed anything from 30 KHz and up - so all harmonics got removed, leaving only the fundamental?
The crucial question remains - how does it sound? Funny enough, just like the unlimited square wave, as our ears can't hear even the 3rd harmonic at 30 KHz anyway. To our ears, there is no difference between a 10 KHz sine wave, and a 10 KHz square wave.
So, considering how common square waves are in digital systems, it is a bit ironic that they are so useless in evaluating systems with a HF cutoff (both analog and digital).