Friday, 18 July 2014

Impulse Response

If you choose to embark upon an entrepreneurial career, you will often find yourself putting together financial spreadsheets to model your business. Investors in particular love to pore over scenarios of how your business might develop, and having a good financial model is an invaluable tool to have at your disposal. Of course, if you’re smart, you’ll want to thoroughly test your spreadsheet to make sure that your financial logic contains no embarrassing errors. One of the techniques for doing that is to enter an arbitrary billion dollars into one of the input cells, and see where else in your spreadsheet unexpected extra billions show up. It is very easy to spot billions of dollars when they start to appear in places they don’t belong. You might say that what you are doing is measuring the “impulse response” of your spreadsheet.

Digital filters are no different. Data goes in one place, and results come out someplace else. In this case, both the inputs and outputs are streams of numbers. Conceptually, digital filters are quite simple things. You take the input value, and add to it bits of the previous input values together with bits of the previous output values. That’s really all there is to it. The filter design tells you how many of the previous input and output values go into the mix, and precisely what fraction of each to use. Some filters only rely on the previous input values, and don’t use the previous output values. Filters that do use the previous output values have an interesting property - each output value contains a little bit of each and every previous input value.

What are the implications when a bit of one input value ends up in each and every one of the subsequent output values? A very easy analysis would be to take a signal comprising digital silence - in effect nothing but zeros - and modify it so that one data point (and only one data point) is at a maximum value. We call this waveform an “Impulse”. We put this data stream through our digital filter and see what comes out the other end. What happens is that the output comprises a stream of zeros up until the time the impulse reaches the input of the filter. After that, the output will comprise a sequence of non-zero values - in effect a series of echoes of the original impulse. This artificial construct - how the residue of one single impulse value in a sea of zeros appears in the output data stream - is called the “impulse response” of the filter. If the filter uses only previous input values and no previous output values, then the echoes will fall to zero as soon as we reach the point where the impulse is no longer one of the previous values that goes into the mix. Such filters are called “Finite Impulse Response” (FIR) filters. If, however, the filter uses previous output values, then the echoes of the impulse will remain within the output signal forever, or at least until such time as its magnitude becomes too small to register. These filters are called “Infinite Impulse Response” (IIR) filters.

An impulse response looks like a waveform. You can easily plot it out. It looks like a waveform precisely because it is a waveform, and you can do anything with it that you can do with any other waveform. Impulse responses have many interesting properties, most of which are beyond the scope of this post. But, as an example, if we take its Fourier transform, the result is the transfer function of the filter, which is to say its frequency and phase responses. This is why the key aspects of a filter’s performance are intimately inter-related. Once you define a filter’s frequency response (for example by defining the characteristics of a low-pass filter) and phase response (for example by specifying linear phase or minimum phase), you will have set in stone its impulse response. In other words, the impulse response (IR) is the direct consequence of the choices you have made in terms of frequency response (FR) and phase response (PR). What it boils down to, is that when it comes to filter design, you only get to specify any two of its IR, PR and FR, and the third will be determined for you.

Tuesday, 15 July 2014

The Most Beautiful Piece of Music Ever Written

They say beauty is in the eye of the beholder. What is beautiful to one person, may not be beautiful to another. However, a significant element of that is cultural. The things we have grown up being told are beautiful are usually the things we hold to be beautiful for the rest of our lives. But those standards evolve over time and place. The ideal classical female figure is apparently somewhat chunky to the modern sensibility, just as today’s anorexic teenaged supermodels would appear emaciated to Da Vinci, Michelangelo, and the Ancient Greeks (although maybe not to Botticelli, whose aesthetic appears to have been somewhat more ‘modern’ with his tall, willowy, long-limbed blondes).

Faces are somewhat different. There is plenty of evidence that the most attractive facial features have remained more or less constant over the ages, with many common traits that can be discerned across both ethnic and cultural boundaries. Symmetry, for example, is a notable common factor. Men and women around the globe tend to find symmetric facial features to be superficially more attractive in the opposite sex.

What about music? Can music be said to be fundamentally beautiful? For sure, there is some music which is very clearly the opposite of beautiful, and people from different cultures can be found to agree on that. After all, there is no requirement for music to be beautiful in order to be good. Music tends to benefit greatly from the creation and resolution of tension, dissonance, and rhythmic discord. But some music is undeniably beautiful, like Schubert’s “Ave Maria”. Who would disagree with that? How about the Ode to Joy from Beethoven’s 9th symphony. Is that beautiful? How about NWA’s “Straight Outta Compton”? The fact that you can discern meaning and feel a powerful connection with a piece of music is not the same thing as finding it beautiful.

What is it about music that makes it beautiful to our ears? Three things tend to stand out. The first is that beauty pretty much always requires a major key. The sort of beauty that makes you smile is inevitably in a major key. The second is that beautiful music tends to have slow tempi and simple rhythmic structures. This is wonderfully expressed by the title of a great Alison Moyet song “I Go Weak In The Presence Of Beauty”. That’s what beauty does. It doesn’t enervate you. It makes you go weak at the knees. The third attribute is that beautiful melodies tend to have arching spans. Most well-known tunes follow a path of adjacent notes up and down the musical scale. The theme from Beethoven’s Ode To Joy that I mentioned earlier follows this path. It may be stirring music, but it is not particularly beautiful. Beautiful music tends to have themes which feature prominent jumps from one note to another some distance away. These jumps - usually jumps up in pitch rather than down - are usually themselves the focal points of the music’s inherent beauty.

There is one piece of music that to my ears epitomizes beauty in music. I first heard it in 1972 when the choir I was in performed a version of it. I think no less of it today than I did then. It is one of my “desert island” pieces. It is, I humbly assert, the most beautiful piece of music ever written. I think it would be terribly sad to go through life without ever hearing it.

“Serenade To Music” was written by the English Composer Ralph Vaughan Williams in 1938. It is scored for an orchestra, solo violin, and 16 vocal soloists, and is a setting of an extract from Shakespeare’s “The Merchant Of Venice”. The solo vocal parts were specifically written for 16 prominent English singers of the day including Isobel Bailie and Heddle Nash, and each part is annotated by the composer with the initials of the designated singer. A recording exists, made shortly after the work’s premiere, by the same performers. It is more of musical and historical than audiophile significance, but captures a wonderful vignette of the ethereal beauty that was soprano Dame Isobel Baillie in her prime. Sergei Rachmaninoff, himself no stranger to musical beauty, attended the premiere (having performed his 2nd Piano Concerto in the first half of the concert) and was said to have broken down in tears at the beauty of the music.

There are precious few recordings of Serenade To Music, and I can’t think why. It is a bucket list composition. The best is Sir Adrian Boult’s 1969 recording with the London Philharmonic on EMI’s HMV label. This is a terrific performance (Boult was an absolute master of Vaughan Williams) marred only by Shirley Minty’s dreadful - and thankfully brief - contribution which literally makes me cringe for a second until she’s finished. I have this on LP only and I don’t know if it is available anywhere for download. The world still awaits a modern digital recording of this stunning work.

It would be worth a little effort on your part - well OK, maybe quite a lot of effort - to seek it out.

Monday, 14 July 2014

Fazed by Phase

In my discussion on square waves, when I mentioned the properties of its Fourier components, I glibly suggested “We’ll ignore phase”.  In truth, we need to look a little more closely at it.   I’ll start by defining phase.

Imagine in your mind’s eye a graph of a sine wave. If this were to represent a sound wave, the vertical axis would represent the air pressure oscillating up and down, and the horizontal axis would represent the passage of time. If you were to capture that sound wave with a microphone, the voltage waveform that the microphone would create would look just the same. Imagine now that you could actually “see” the sound waves, as though they were waves on the surface of a pond. Imagine yourself standing next to the microphone, observing the sound waves as they travel toward you and the mic. Imagine that you can make out the individual peaks and troughs. You can watch an individual peak approach and impinge on the microphone. At the instant it does so, you observe the output voltage of the microphone. You will see that the output voltage also goes through a peak. You watch as the peak passes by and is replaced by its trailing trough, and you observe the voltage from the microphone simultaneously decay from a peak to a trough. I hope this is all pretty obvious.

Now we are going to add a second microphone. Except that we are going to align this one a short distance behind the first one. Now, by the time the peak of the sound wave impinges on the second microphone, it has already passed the first one. The output voltage from the first microphone has already passed its peak and is on its way down to the trough. But the output voltage of the second microphone is only just reaching its peak. Over a period of time, both microphones capture exactly the same oscillating sine wave, but the output of the second is always delayed slightly compared to the output of the first. This is the Phase of the sine wave in action. The phase represents the time alignment. And, as you can work out for yourself, it is not the absolute phase which is important, but the relative differences between phases.

Interesting things happen when we add two nominally identical sine waves together. Let’s specify two sine waves which have the exact same magnitude and frequency, but differ only in phase. I won’t go into the mathematics of this, but what you get depends strongly on the phase difference. If both phases are identical the two sine waves add up, and the result is a sine wave of exactly twice the magnitude of the original. However, if the two sine waves are time aligned such that the peak of one coincides with the trough of the other, then the end result is that both sine waves cancel each other out and you end up with nothing. These two extreme conditions are often referred to as “in-phase” and “out-of-phase”. However, there are a whole spectrum of phase relationships between these two extremes. As the phase difference gradually varies from “in-phase” to “out-of-phase”, so the magnitude of the resultant signal gradually falls from twice that of the original, down to zero.

Lets now go back to the square-wave example of yesterday’s post. Yesterday’s example was concerned with the summing of individual sine waves (a fundamental and its odd harmonics), and how the more of these odd harmonics you added in, the closer the result approached to a square wave. We also saw that by limiting the number of harmonics, what we got was a close approximation to a square wave, but with some leading and trailing edge overshoot, and a bit of ripple. However, in all of that discussion we took no account of phase. Or, more specifically, we allowed for no phase difference between the different harmonics. What happens if we start to introduce phase differences?

The result is that we no longer get a nice clean square wave. As we mess with the phase relationships we get all sorts of odd-looking waveforms, some of them bearing precious little visual relationship to the original square wave. Yet all of these different waveforms comprise the exact same mixture of frequencies. The obvious question arises - do they sound at all different? In other words, can we hear phase relationships? This is a tricky question.

My own experiments have shown me that I have problems detecting any differences between test tones that I have created artificially, comprising identical assemblies of single frequency components added together with different - and sometime arbitrary - phases. But from a psychoacoustical perspective this is perhaps not surprising. Our brains are not wired to recognize test tones, and cannot therefore create a sonic reference from memory with which to compare them, so it is not surprising that I would find it very difficult to hear differences between them.

The conventional wisdom is that relative phase is inaudible, but this is hard to test with anything other than synthesized test tones. With real music there is no possibility to independently adjust the phase of individual frequency components (for reasons I won’t get into here) so the question of the audibility of relative phase is one which remains either unproven, or proven as to its inaudibility, depending on your perspective.

Saturday, 12 July 2014

The Square Waveform

In digital audio, a simple square wave has some interesting properties. On the face of it, you can actually represent the square wave digitally with no error whatsoever. The quantization error, such as it is, becomes merely a scaling factor. If you adjust the input gain, you can get it so that the quantization error is zero for every single recorded value.

Imagine that - a waveform captured digitally with no loss whatsoever. Even though it is of no practical value (who wants to listen to recorded square waves?) you would imagine that it would be useful for test and measurement purposes if nothing else. And people do imagine that. In fact, it is not unusual to see reproductions of square waves, captured on an oscilloscope, as part of a suite of measurements on a DAC. But in digital audio things are seldom quite what they may logically appear to be. Lets take a closer look at square waves and see what we come up with.

A true and perfect square wave can be analyzed mathematically and broken down into what we call its Fourier components. These are nothing more scary than simple sine waves, each one having its own frequency, phase, and amplitude. The Fourier components (sine waves) which make up a square wave comprise the fundamental frequency plus each of its odd harmonics. The fundamental frequency is simply the frequency of the square wave itself. The odd harmonics are just frequencies which are odd multiples of the fundamental frequency (3x, 5x, 7x, 9x, 11x, etc). The amplitudes of each Fourier component are inversely proportional to the frequency of the harmonic. We’ll ignore phase.

If that sounds complicated, it really isn’t. Start with a sine wave, at the frequency of the square wave which I will refer to as ‘F’. Now add to it a sine wave of its third harmonic, which is three times the fundamental frequency, ‘3F’. This sine wave should have an amplitude 1/3 of the amplitude of the fundamental sine wave. OK? Next we add a sine wave of the fifth harmonic, 5F, with an amplitude 1/5. Then the seventh harmonic (5F) with an amplitude 1/7, the ninth harmonic with amplitude 1/9, and so on, ad infinitum. The more of these harmonics you add into the mix, the closer the result approaches a perfect square wave. A truly perfect square wave comprises an infinite number of these Fourier components. Here is a link to an animated illustration which might help make this clearer.

Some interesting things happen as we add more and more Fourier components to build up our square wave. The ripple on the waveform gets smaller in magnitude, and its frequency gets higher. The ‘spikes’ at the start and end of the flat portions of the waveform decay more rapidly. These things can all be seen clearly on the web page I mentioned. However, one surprising thing is that the ‘spikes’ don’t ever disappear, no matter how many Fourier components you add in. In fact, their magnitude doesn’t even get smaller. As you add Fourier components, the 'spikes' converge to about 9% of the amplitude of the square wave, something referred to as the ‘Gibbs Phenomenon’. The spike itself ends up approximating half a cycle of the highest frequency Fourier component present.

So now lets go back to the idea at the start of this post, that we can easily encode a square wave with absolute precision in a digital audio stream. If this were actually true, it would imply that we are encoding Fourier components comprising an infinite bandwidth of frequencies. But Nyquist-Shannon sampling theory tells us that any frequencies that we attempt to encode which are higher than one half of the sampling rate actually end up encoding ‘alias’ frequencies, which are things that are seriously to be avoided. The square wave that we thought we had encoded perfectly, and with absolute precision, turns out to contain a whole bunch of unwanted garbage! And that, to many people, is bizarrely counter-intuitive.

We’ve gone over this in previous posts, but the bottom line is that any waveform that you wish to capture digitally - square waves included - need to be first passed through a low-pass filter called an ‘anti-aliasing’ filter, which blocks all frequencies above one half of the sampling rate. For the purpose of this post, lets assume that the anti-aliasing filter is ‘perfect’ and does nothing except remove all frequencies above half the sampling frequency. What this filter does to our square wave is, in effect, to strip off the vast majority of the square wave’s Fourier components, leaving only a few behind.

Lets look at what this means in the context of Red Book (44.1kHz sample rate) audio. If the square wave is, for example a 1kHz square wave, then its first ten Fourier components (the 3rd through 21st harmonics) are left intact. However, if the square wave is a 10kHz square wave, not one single odd harmonic component makes it through the filter! This means that if you attempt to record a 10kHz square wave, all you could actually ever capture would be a pure 10Hz sine wave.

What does this mean for DAC reviews where you are presented with a screenshot illustrating the attempted reproduction of a square wave? The bottom line here is that for such a screenshot to make any sense at all, you need to know exactly what a perfectly reproduced square wave ought to look like. For example, it ought to have leading and trailing edge ‘spikes’ which approximate to half cycles of an approximate 20kHz sin wave, and with an amplitude which is about 9% higher than the amplitude of the square wave itself. It needs to have ripple. I could be a lot more specific about those things, but the fine details end up being governed by issues such as the frequency of the square wave, and - far more complex - the characteristics of the anti-aliasing filter used to encode the original signal. Without this information a square-wave screenshot is of limited value. If nothing else, it can provide a level of confidence that the person conducting the test knows what they are talking about. Not to mention avoiding allowing the reader to infer or imply erroneous conclusions of their own.

Friday, 11 July 2014

The Unanswered Question

Back in 1970 or ’71, my mother gave me an LP she thought I might like.  I’m not sure why she did that, since she had no conception of the sort of music I played.  She herself listened to very little other than Austrian popular music from the ‘40s and ‘50s.  Anyway, maybe because they were seriously cheap, she came home with two LPs, one of which was “Classical Heads”, a peculiar album released on the prog rock Charisma label.

Classical Heads was a mild re-working of mostly mainstream classical music, dominated by Berlioz.  The ‘progressive’ element comprised playing with the phasing effects slider here and there, and occasional over-dubbing with spoken word.  It was not a good album at all, but for whatever reason (maybe because I didn’t actually own many other records) I found myself playing it quite a lot.  And I still have it.  It is sitting at my side as I type this.

But Classical Heads did contain one work which lodged in my consciousness, a track titled ‘The Unanswered Question”.  I rather liked it a lot and imagined it might have been the work of a contemporary prog rock band - sort of Moody Blues meets Pink Floyd.  It was ascribed to a certain “Ives” whose name was unfamiliar to me.  In those days, of course, there was no Internet.  In my youthful naïveté I assumed it was some contemporary piece chosen to fill out the album, but regardless, it became the one track that I wanted most to hear when I took the album out to play it.

Many years later I came across the piece again, this time performed more professionally, and learned that “The Unanswered Question” was in fact a major piece written by the American composer Charles Ives, back in 1908.  In fact, it is considered to be in many ways Ives’ most notable work, despite being very short - typically something like seven minutes in duration.  Despite being hardly demanding on the performing requirements, it is a piece that does not command appropriate prominence in the major classical repertoire.  Both performances and recordings are sparse and hard to come by.

I wanted to write an analysis of the piece, but I find that its Wikipedia page does such a good job that I feel it would be pointless for me to elaborate upon it.  But, in brief, it comprises three components: a slow and quiet shimmering string chorale which forms a permanent backdrop and evolves at the pace of a lava lamp; a solo trumpet which poses an atonal question several times; and a discordant wind quartet which attempts unsuccessfully to answer each question, getting progressively more distraught with each failure.  The final question is, as you might imagine, left unanswered.  Read the Wikipedia page I linked to.

It is a haunting piece, short enough not to require you to invest too much of your time in it, accessible enough to hold your attention, intriguing enough to draw you back again for more.

I have two performances on LP and one on CD.  The CD version is by far and away the best.  It is by the Chicago Symphony Orchestra, conducted by Michael Tilson Thomas, on Sony Classical from 1990.  If you look around you can still find it.

I hate to recommend something that can be a swine to find, but sometimes the thrill of the hunt is half the fun!

Thursday, 10 July 2014

OS X 10.9.4

I have been using the latest update to OS X (version 10.9.4) for a few days now on multiple machines and have encountered no problems with BitPerfect. BitPerfect users who wish to apply this update should therefore feel free to do so.

Sunday, 29 June 2014

Art and The Trolls

How many of you have ever been to The Louvre in Paris?  Next question, how many of you have been to Paris but have not visited The Louvre?  In the humble opinion of your author, The Louve is the finest museum and art gallery in the world.  The scale, breadth, and sheer quality of The Louvre is quite breathtaking.  This is not an attraction that you set an afternoon aside to check off your bucket list.  I don’t see how you can do it justice in less than two solid days.

The Louvre is a stunning experience.  The exhibits are laid out with flawless vision, and a quality that places the world’s finest works of art in an appropriate setting, while avoiding the temptation of overblown in-your-face opulence.  It also avoids that sense of tired dowdiness that mars so many of Europe’s oldest and most famous establishments.  It is surprisingly spacious.  Unlike Florence’s Uffizi, it manages to maintain a serene, contemplative, and unhurried ambiance, even during the busiest times.  But that is with one glaring exception.  Everybody who comes to The Louvre comes to see Leonardo Da Vinci’s masterpiece Mona Lisa; sometimes that is the only thing they enter the building to accomplish.  Mona Lisa sits inside a room of its own, maybe 2,000 square feet in all.  It is always packed.  What do you do?  You can elbow your way to the front, arrogantly and unashamedly, and people [insert your preferred stereotype here] do just that.  Or you can just go with the flow, and gradually drift towards the front over a period of maybe 45 minutes.  This is a great way to contemplate the work’s iconically enigmatic message.  The third thing you could do is to check it off your bucket list from the back of the room and head for the exit and a nice tasse of French coffee.

I took the middle approach, allowing me to contemplate La Giaconda from a number of perspectives.  One of the thoughts that occupied my mind was this one.  How do I know I am looking at the real thing?  Was that just a reproduction, with the original sealed deep in a climate-controlled nuclear-bomb-proof vault?  How would I know?  If I was in possession of an accurate replica, which I could hang above my fireplace, would I be able to tell that it wasn’t the original?  We’ll set aside the logical (not to mention legal) difficulties of explaining how it got from the Louvre to my Lounge.

Proving the provenance and authenticity of original art is a thorny problem.  Currently disputed works include those of artists from Caravaggio to Jackson Pollock.  Inevitably, the problem ends up being resolved based on the opinion of a single expert, or panel of experts.  On occasion, even the opinions of those experts is hotly contested.

So if only a tiny panel of experts can tell the real Mona Lisa from a high quality fake, it follows that I can’t.  If I had the money and the desire, I could commission my own Mona Lisa replica, and hang it in my lounge.  It may as well be the real thing, as far as I would be concerned, because I would be quite unable to tell the difference.  Of course, the more of an Art buff I was, and the greater my appreciation and knowledge of fine art, the more accurate the replica would have to be so that I could not tell it apart.  And, of course, the more expensive it would be.

The parallels to high end audio are obvious.  The concept of the “original” Mona Lisa corresponds to the original performance of musicians in a recording studio, and the concept of the “fake” corresponds to the distributed recording.  There are two significant differences.  The first is that in the music sphere there is an intent on the part of the artist to distribute accurate copies of the art to consumers.  The second is that in music we all get to be members of the “select panel of experts” who get to weigh in on the authenticity debate.  Even, unfortunately, the Internet Trolls who believe that their opinions count for more than yours.