View RSS Feed

Julf

Not so hip to be square

Rate this Entry
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

[ATTACH=CONFIG]5912[/ATTACH]


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):
[ATTACH=CONFIG]5913[/ATTACH]

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:

[ATTACH=CONFIG]5914[/ATTACH]

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:
[ATTACH=CONFIG]5915[/ATTACH]

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:

[ATTACH=CONFIG]5916[/ATTACH]

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:

[ATTACH=CONFIG]5917[/ATTACH]

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).
Attached Thumbnails Attached Thumbnails blogs/julf/attachments/5912-not-so-hip-be-square-dc1ca9de7f258a89d3c579f55d29ed05.png   blogs/julf/attachments/5913-not-so-hip-be-square-square99.png   blogs/julf/attachments/5914-not-so-hip-be-square-square19.png  

blogs/julf/attachments/5915-not-so-hip-be-square-squareripple.png   blogs/julf/attachments/5916-not-so-hip-be-square-squarephase.png   blogs/julf/attachments/5917-not-so-hip-be-square-square10khz.png  

Categories
Personal Blogs

Comments

  1. The Computer Audiophile's Avatar
    Thanks for giving back to the CA community Julf.
  2. esldude's Avatar
    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.
  3. Julf's Avatar
    [QUOTE=The Computer Audiophile;bt1618]Thanks for giving back to the CA community Julf.[/QUOTE]

    My pleasure, Chris!
  4. Julf's Avatar
    [QUOTE=esldude;bt1619]Excellent illustration and blog Julf. [/QUOTE]

    Thanks!

    [quote]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. [/quote]

    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, not phase).

    [quote]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.[/quote]

    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...
  5. wgscott's Avatar
    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?
  6. wgscott's Avatar
    Quote Originally Posted by The Computer Audiophile
    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.
  7. Julf's Avatar
    [QUOTE=wgscott;bt1622]What am I missing?[/QUOTE]

    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?
  8. wgscott's Avatar
    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).
  9. Julf's Avatar
    Agree, interference is a different matter (and is not really an issue with integer harmonics anyway).
  10. Jud's Avatar
    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.