Jump to content

Julf's Blog

  • entries
    4
  • comments
    53
  • views
    2015

Not so hip to be square


Julf

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

 

<p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/dc1ca9de7f258a89d3c579f55d29ed05.png.93746a73f3387dae706cd0249e50e77a.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28170" src="https://audiophilestyle.com/uploads/monthly_2013_06/dc1ca9de7f258a89d3c579f55d29ed05.png.93746a73f3387dae706cd0249e50e77a.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

 

 

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):

<p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/square99.png.aa382256a46a72bcbe0b06cf578e9111.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28171" src="https://audiophilestyle.com/uploads/monthly_2013_06/square99.png.aa382256a46a72bcbe0b06cf578e9111.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

 

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:

 

<p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/square19.png.edc3a5207034ec28f7acf150284048b3.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28172" src="https://audiophilestyle.com/uploads/monthly_2013_06/square19.png.edc3a5207034ec28f7acf150284048b3.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

 

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:

<p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/squareripple.png.a6c99d84af93ea432deb799f26656557.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28173" src="https://audiophilestyle.com/uploads/monthly_2013_06/squareripple.png.a6c99d84af93ea432deb799f26656557.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

 

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:

 

<p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/squarephase.png.d87210d4a9656fdcc54d1de3ccc75592.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28174" src="https://audiophilestyle.com/uploads/monthly_2013_06/squarephase.png.d87210d4a9656fdcc54d1de3ccc75592.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

 

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:

 

<p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/square10khz.png.b5395e0e8ae30d3db6cf16fd4e38c1d2.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28175" src="https://audiophilestyle.com/uploads/monthly_2013_06/square10khz.png.b5395e0e8ae30d3db6cf16fd4e38c1d2.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

 

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).<p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/dc1ca9de7f258a89d3c579f55d29ed05.png.e1f5f3413817fed100908876ebefa5ea.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28420" src="https://audiophilestyle.com/uploads/monthly_2013_06/dc1ca9de7f258a89d3c579f55d29ed05.png.e1f5f3413817fed100908876ebefa5ea.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p><p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/square99.png.9cc239cd98736db94d68e6721a03ba7a.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28421" src="https://audiophilestyle.com/uploads/monthly_2013_06/square99.png.9cc239cd98736db94d68e6721a03ba7a.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p><p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/square19.png.6bb0ddd973a9c518a95a425c65deb4ae.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28422" src="https://audiophilestyle.com/uploads/monthly_2013_06/square19.png.6bb0ddd973a9c518a95a425c65deb4ae.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p><p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/squareripple.png.16f2f5b6bad1612d5029fdca269c6c41.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28423" src="https://audiophilestyle.com/uploads/monthly_2013_06/squareripple.png.16f2f5b6bad1612d5029fdca269c6c41.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p><p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/squarephase.png.d2f2d70fcb43123e3eca43ddf6431cb5.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28424" src="https://audiophilestyle.com/uploads/monthly_2013_06/squarephase.png.d2f2d70fcb43123e3eca43ddf6431cb5.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p><p><a href="https://audiophilestyle.com/uploads/monthly_2013_06/square10khz.png.62c572087a38941fa16007f03c97ebac.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28425" src="https://audiophilestyle.com/uploads/monthly_2013_06/square10khz.png.62c572087a38941fa16007f03c97ebac.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

10 Comments


Recommended Comments

Excellent illustration and blog Julf.

 

Recently was investigating the sound of various squarewaves with various harmonic series not very different than what you are getting at here. Surprisingly awful looking squarewaves sound the same just as you show here the result at 10 khz and above aren't going to sound different than the same frequency sinewave at 10 khz and above.

 

Especially nice you used the 20 khz limited result of a squarewave. The "ringing" many attribute to a flaw in the digital system in fact is no different in the analog world if the response is no more than 20 khz.

Link to comment
Excellent illustration and blog Julf.

 

Thanks!

 

Recently was investigating the sound of various squarewaves with various harmonic series not very different than what you are getting at here. Surprisingly awful looking squarewaves sound the same just as you show here the result at 10 khz and above aren't going to sound different than the same frequency sinewave at 10 khz and above.

 

Indeed. In hindsight I should also have added frequency spectrum plots for the square wave and the "distorted" square wave (the one with the phase shift) just to show that the spectrum plots are exactly the same for both (as spectrum plots show magnitude' date=' not phase).

 

Especially nice you used the 20 khz limited result of a squarewave. The "ringing" many attribute to a flaw in the digital system in fact is no different in the analog world if the response is no more than 20 khz.

 

It is important to remember that we don't listen with our eyes (or at least we shouldn't), and what you think is intuitively right might not be how it actually works...

Link to comment
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.

 

I'm not sure what you are getting at. The wikipedia article that accompanies that figure introduces it with

 

Using Fourier expansion with cycle frequency f over time t, we can represent an ideal square wave with a peak to peak amplitude of 2 as an infinite series of the form

 

What am I missing?

Link to comment
Thanks for giving back to the CA community Julf.

 

I've always found him to be one of the most generous contributors here (among many). He gives back far more than he gets I think.

Link to comment
What am I missing?

 

As usual, you are not missing anything. I was just being overly simplistic. You are completely correct, saying this has nothing to do with Fourier analysis is wrong. I should have said it has nothing to do with Fourier transforms, but even that is not quite right...

 

While the composition of a waveforms from sums of sine waves is part of Fourier analysis as a mathematical model, I was just pointing out that in my example none of the Fourier transforms or other more advanced mathematical tools are required - all that is needed is simple addition of sine waves.

 

The reason I wanted to point that out was to avoid any silly references to the totally misinterpreted paper about how "the ear is superior to Fourier analysis" that has been widely circulated on audiophile boards. If I had referred to my graphs being examples of Fourier analysis, I could see somebody commenting "ah, but the ear doesn't work that way, so the conclusions are not correct". Do we really want to try to explain the difference between Fourier analysis and Fourier transforms at that point?

Link to comment

Sorry. Didn't mean to open a can of worms.

 

But for anyone else reading this, the basic difference is this:

 

Any periodic function can be expanded as a (discrete) sum of sin and cos terms.

 

Any (sufficiently non-pathological) function, including non-periodic functions, can be expressed as a continuous sum (an integral transform) over sin and cos terms.

 

For me, the really interesting thing I learned is that the ear is not a phase-sensitive detector. I did not know that, but I guess it makes sense in retrospect. I think what we hear is the intensity, which is the absolute square of the amplitude (and it eliminates the phase, apart from interference effects).

Link to comment

Agree, interference is a different matter (and is not really an issue with integer harmonics anyway).

Link to comment

Thanks to Bill and Julf for talking about phase interference as distinct from what appears above. I was kind of wondering about that.

 

I think the "silly misinterpreted paper" is actually interesting for helping to point out something you mention: Human hearing and scope traces can be surprisingly orthogonal in some respects, so both "Human hearing is superior to Fourier analysis" or "The level at which our design/measurement instruments operate is beyond anything of which the human ear is capable," which I've also seen, are both in various respects faulty formulations. Partly true, both of them, but certainly not the whole of the matter.

Link to comment



×
×
  • Create New...