In the last posting, I talked about the effects of a bandpass filter on the probability density function (PDF) of an audio signal. This left the open issue of other filter types. So, below is the continuation of the discussion…
I made noise signals (length 2^16 samples, fs=2^16) with different PDFs, and filtered them as if I were building a three-way loudspeaker with a 4th order Linkwitz-Riley crossover (without including the compensation for the natural responses of the drivers). The crossover frequencies were 200 Hz and 2 kHz (which are just representative, arbitrary values).
So, the filter magnitude responses looked like Figure 1.
The resulting effects on the probability distribution functions are shown below. (Check the last posting for plots of the PDFs of the full-band signals – however note that I made new noise signals, so the magnitude responses won’t match directly.)
The magnitude responses shown in the plots below have been 1/3-octave smoothed – otherwise they look really noisy.
This posting has a Part 1 that you’ll find here and a Part 2 that you’ll find here.
In a previous posting, I showed some plots that displayed the probability density functions (or PDF) of a number of commercial audio recordings. (If you are new to the concept of a probability density function, then you might want to at least have a look at that posting before reading further…)
I’ve been doing a little more work on this subject, with some possible implications on how to interpret those plots. Or, perhaps more specifically, with some possible implications on possible conclusions to be drawn from those plots.
To start, let’s create some noise with a desired PDF, without imposing any frequency limitations on the signal.
To do this, I’ve ported equations from “Computer Music: Synthesis, Composition, and Performance” by Charles Dodge and Thomas A. Jerse, Schirmer Books, New York (1985) to Matlab. That code is shown below in italics, in case you might want to use it. (No promises are made regarding the code quality… However, I will say that I’ve written the code to be easily understandable, rather than efficient – so don’t make fun of me.) I’ve made the length of the noise samples 2^16 because I like that number. (Actually, it’s for other reasons involving plotting the results of an FFT, and my own laziness regarding frequency scaling – but that’s my business.)
Uniform (aka Rectangular) Distribution
uniform = rand(2^16, 1);
Of course, as you can see in the plots in Figure 1, the signal is not “perfectly” rectangular, nor is it “perfectly” flat. This is because it’s noise. If I ran exactly the same code again, the result would be different, but also neither perfectly rectangular nor flat. Of course, if I ran the code repeatedly, and averaged the results, the average would become “better” and “better”.
n = 100; % number of random number vectors used to create final vector (more is better)
xnover = n/2;
sc = 1/sqrt(n/12);
total = sum(rand(2^16, n), 2);
gaussian = sigma * sc * (total – xnover) + xmu;
Of course, if you are using Matlab, there is an easier way to get a noise signal with a Gaussian PDF, and that is to use the randn() function.
The effects of band-passing the signals
What happens to the probability distribution of the signals if we band-limit them? For example, let’s take the signals that were plotted above, and put them through two sets of two second-order Butterworth filters in series, one set producing a high-pass filter at 200 Hz and the other resulting in a low-pass filter at 2 kHz .(This is the same as if we were making a mid-range signal in a 4th-order Linkwitz-Riley crossover, assuming that our midrange drivers had flat magnitude responses far beyond our crossover frequencies, and therefore required no correction in the crossover…)
What happens to our PDF’s as a result of the band limiting? Let’s see…
So, what we can see in Figures 7 through 12 (inclusive) is that, regardless of the original PDF of the signal, if you band-limit it, the result has a Gaussian distribution.
And yes, I tried other bandwidths and filter slopes. The result, generally speaking, is the same.
One part of this effect is a little obvious. The high-pass filter (in this case, at 200 Hz) removes the DC component, which makes all of the PDF’s symmetrical around the 0 line.
However, the “punch line” is that, regardless of the distribution of the signal coming into your system (and that can be quite different from song to song as I showed in this posting) the PDF of the signal after band-limiting (say, being sent to your loudspeaker drivers) will be Gaussian-ish.
And, before you ask, “what if you had only put in a high-pass or a low-pass filter?” – that answer is coming in a later posting…
This posting has a Part 1 that you’ll find here, and a Part 3 that you’ll find here.
If you have a bunch of audio devices in a chain (say, a CD player connected to a preamplifier connected to a power amplifier connected to a loudspeaker) then one of the simplest things that you can do to improve or optimise your audio quality is to look after the gain of the signal through the system. It’s also free – and getting a lot for free is always a good thing…
Let’s start by taking a simple view of one device – a piece of audio gear. It doesn’t matter what the gear is – it could be an MP3 player, it could be a giant mixing console. What we’ll do is just look at the output of this device as it tries to play an audio signal with a varying level.
Let’s use a very simple example of a sine wave as our audio signal; we’ll look at the output of the Audio Device as we increase the level of our sine wave from very quiet to very loud.
This screen shot shown in Figure 2, by itself, is not that interesting. Let’s zoom in to the three points on the plot to see what’s going on.
Figure 3 shows a zoomed-in view of point “A” in Figure 2. Notice that you cannot see a sine wave in that signal – it’s just noise. This is the noise that is naturally generated by the device for some reason. This may be natural noise in the analogue chain – caused by thermal movement of electrons in resistors, amplified by the device itself. It may be intentional noise like dither which is added to the signal to randomise errors in a digital audio chain. Or, it may be something else entirely…
But be careful not to jump to conclusions… Just because you can’t see a sine wave there doesn’t mean that you won’t be able to hear it. As the level of the sine wave is increased, we’ll be able to hear it along with the noise before we’ll be able to see it on the screen.
In this case, we have a very low “signal-to-noise ratio”. In other words, the level of the signal (the sine wave) divided by (because it’s a ratio) the level of the noise gives us a low number. Or, in normal English – the sine wave is “drowned out” by the noise.
Figure 4 shows a nice, clean-looking sine wave coming out of our audio device. It’s what’s going on at point “B” in Figure 2. We’ve zoomed in so much that you can’t see the increase in level over time – but trust me, it’s happening there.
The noise is still there, “riding the wave” of the sine tone. In fact, if we were to zoom in on the sine wave in that figure, we’d see the same kind of noise that we saw in Figure 3 – like little ripples on big ocean waves. Now, however, the sine wave is much louder than the noise – so we have a reasonably high “signal-to-noise ratio”. In other words, the level of the signal (the sine wave) divided by (because it’s a ratio) the level of the noise gives us a high number. Or, in normal English – the sine wave “drowns out” the noise.
Figure 5 shows what’s happening at point “C” in Figure 2. Notice that this doesn’t really look like a sine wave any more – the top and bottom has been chopped off or “clipped”. This has happened because we are trying to make our audio device have an output level that is beyond its abilities. As the sine wave increases, the audio device follows along, until its output can go no higher, so it stops and holds that output level until the sine wave comes back down.
At the point, the noise is still very much lower in level than the signal – but we have caused a problem – the input is a sine wave, but the output is not. In other words, we have distorted the shape of the audio signal.
Note that distortion of an audio signal can take an infinite number of forms. The example here is symmetrical clipping of the signal – which is what many people mean when they say “distorted” – but don’t be fooled… “Distortion” means a whole lot more than this.
So, there’s a moral to the story-thus-far: every audio device has an upper and lower limit for audio level. (Yes, even a wire has a lower limit set by thermal noise in the electrons it contains and an upper limit set by the amount of current it will pass through before melting.) That range of dynamics or dynamic range is (hopefully) big – in other words, the noise floor (the quietest sound) should be MUCH MUCH quieter than a just-clipped signal (the loudest sound). Because this difference is so big, we’ll measure it in decibels (for kind of the same reason it doesn’t make sense to measure the speed of a car in millimetres per year, or the area of Canada in square micrometres.)
We can also represent these two numbers (the level of the noise floor and the level of a just-clipped signal) as two values relative to each other. Let’s say, for the purposes of keeping the numbers pretty, that we have an audio device that just so happens to have a level of noise floor that it 100 dB below the level of a signal that just starts to clip at its output.
Figure 6 shows one way to represent this. The red vertical rectangle on the left shows the range of audio levels that is possible to achieve with “Device #1”. It has a noise floor of 10 µV and will clip at 1 V – therefore it has a total dynamic range of 100 dB. Since, in this example, Device #1 is the only device in our audio system, the dynamic range of the entire system is also 100 dB (shown as the ride rectangle on the right) – since the entire system consists of just one device.
What happens if we add another device in our chain? Let’s say, for example, that we put a second device in the system after Device #1. Let’s also say that Device #2 can play louder signals than Device #1 – and it has a lower noise floor, as is shown in Figure 7.
There are three things to notice in Figure 7:
Device #2 can play louder than Device #1
Device #2 has a lower noise floor than Device #1
Therefore Device #2 has a wider dynamic range than Device #1
The dynamic range of the total system is set by Device #1, since it is not limited by Device #2.
However, we should be careful here. The fact that Device #2 has a wider dynamic range than Device #1 does not automatically mean that the total system has a dynamic range that is defined by the “weakest link” (Device #1). Look at Figure 8, for example.
In Figure 8, we have not changed the devices – Device #2 still has a 120 dB dynamic range – but the Total System has a dynamic range that is reduced to 90 dB because of the alignment of levels in the system. Now, the noise floor of the system comes from Device #2 because we have not been careful about setting up the alignment of the levels of the devices.
Another way to think of this is that Device #2 is set up with the expectation that it will go much louder – but it doesn’t because of the limitations of Device #1. Because of that incorrect setup, the noise that you hear at the output of the system comes from Device #2.
An example of a system like the one shown in Figure 8 is when you connect a low-end audio device’s output (say, the headphone jack of your computer or phone) to a better device that is built to handle a much higher input level. The possible result is that the “headroom” (the amount by which the better device can handle higher level signals) is wasted (since the lower-quality device doesn’t deliver those high levels) and the total system has a degraded dynamic range.
So, the moral of the story here so far is that you should always try to ensure that your system’s dynamic range is not limited by the way it’s connected.
For example, if you have a system that has an adjustable input sensitivity, you should set it so that the input is not expecting more level than the device that’s feeding it can deliver. If your output device can only deliver 2 V RMS maximum, it my not be helpful for the thing it’s connected to to be “expecting” to see 4 V coming from it. If this is the way things are setup, then you might be “throwing away” 6 dB of dynamic range (because 4 V is 6 dB louder than 2 V).
Generally, there are two good “rules of thumb” that can help you here.
The first one is to try to align all your maximum levels as much as possible. So, as in the last example above, if your source device has a maximum output of 2.0 V RMS, set the input sensitivity of your next device to “expect” 2.0 V RMS maximum. This will make the tops of the red rectangles all align, and the dynamic range will be defined by the worst link in the chain instead of the way the devices are connected.
The second rule of thumb is to put as much gain as possible at the beginning of the chain. This is particularly true if you’re working in a recording studio. This is because every piece of gear contributes noise to the audio signal. If you put all the gain at the end of the chain, then you are making the signal louder, but you’re also making all of the noise from all of the gear “upstream” louder as well. If you put all the gain at the beginning of the chain, then you might wind up in a situation where you have to turn DOWN the signal through the chain, those reducing your signal to the correct level, and bringing the noise floor down with it. (Two obvious examples of this are using lots of gain at your mic preamp in a recording studio, or getting a RIAA preamp with a healthy output level for your turntable…) Another good example of this is the case where you have a headphone output from your phone connected to the aux input of a small stereo system. You want to turn up the phone as much as possible, and turn down the stereo volume. If you do the opposite, you’ll be using the stereo system to turn up the noise output of your phone.
One last thing: connecting devices digitally will probably help with your dynamic range, however, this is not necessarily always true. You certainly cannot make an automatic conclusion that a digital connection is better in all respects than an analogue one – or vice versa. For example, in some cases, the errors in a sampling rate converter at a digital input stage may result in a higher level of “noise” floor than the analogue noise caused by an analogue-to-digital converter on the same device. Or, it might be that these two inputs have the same measurable noise floor, but those two noises have very different characteristics. Typically analogue noise is program independent – meaning it’s unrelated to the signal – whereas poorly-implemented digital transmission and processing typically results in program-dependent errors. These can be interpreted by the listener as being part of the signal (more like distortion artefacts than noise) and therefore will be different for different signals. To make things even more confusing, different digital inputs on the same device (e.g. Optical, S/P-DIF, and HDMI) may (or may not) behave differently – so any decisions you make about one of them may (or may not) be applicable to the others…
Let’s talk about the subject of noise. To begin with, we have to agree on a definition, which might become the biggest part of the problem. For normal people, going about their daily lives, “noise” is a word that usually means “unwanted sound”, as the Grinch explained, just before hitching up his dog to a sleigh:
However, “noise” means something else to an audio professional, who is consequently not “normal” and does not have a life – daily or otherwise.
When an audio professional says “noise”, they mean something very specific – “noise” is an audio signal that is random. For example, if the noise signal is digital, there would be no way to predict the value of the next sample – even if you know everything about all previous samples.
So, “noise”, according to the professionals, is a signal made of a random sequence. However, we can be a little more specific than this. For example, in order to make the noise plotted in Figure 2, above, I asked Matlab to generate 64 random numbers between -1 and 1 using the code
So, although this will generate random numbers for me (we’ll assume for the purposes of this discussion that Matlab is able to generate truly random numbers… actually they’re “pseudorandom” – but let’s pretend for today…), there are some restrictions on those values. No matter how many random values I ask for using this code, I will never get a value greater than 1 or less than -1.
However, if I used a slightly different Matlab function – “randn” instead of “rand”, using the following code
I would get 64 random numbers, but they are not restricted as my previous bunch were, as you can seen in Figure 2a, below.
Again, it’s impossible to guess what the next value will be, but now you can see that it might be greater than 1 or less than -1 – but it will more likely to be closer to 0 than to be a “big” number.
So, Figures 2 and 2a show two different types of noise. Both are random numbers, but the distribution of the numbers in those two sequences are different.
To be more specific:
Let’s use the “rand(1,1000000)*2-1” function to make a sequence of 1,000,000 samples. We know that this will produce values ranging from -1 to 1. So, we’ll divide this range into 100 steps (-1.00 to -0.98, -0.98 to -0.96, -0.96 to -0.94, … and so on up to 0.98 to 1.00 – I know, I know, there’s some overlap here, but I didn’t want to use a bunch of less than or equal to symbols… The concept is the important point here… Back off!). For each of those divisions, we’ll count how many of the 1,000,000 samples fall inside that smaller range, and we’ll plot it. This is shown in Figure 3a.
As you can see in Figure 3a, there are about 10,000 samples in each “bin”. This means that about 10,000 samples have a value that fall within each of the smaller slices of the total range. Also, if I added up the values of all 100 of those numbers plotted in 3a, I would get 1,000,000, since that’s the total number of values that we analysed.
If I do the same thing to the numbers coming out of the other function: “randn(1,1000000)” it would look very different. As we already saw, the numbers can be outside the range of -1 to 1, and they’re more likely to be around 0 than to be far away from it. This can be seen in Figure 3b.
Just to clean up a loose end – there are official terms to describe these differences. The noise plotted in Figure 2 has what is called a “rectangular distribution” because a plot of the distribution of the values in it (if we measure enough sample values) eventually looks like a rectangle (a blue rectangle, in the case of Figure 3a). The noise plotted in Figure 2a has a “normal distribution”, as can be seen in the bell-like shape of the plot in Figure 3b. There are many other types of distributions (for example, rolling 2 dice will give you random numbers with a “triangular distribution”), but we’ll leave it at 2 for now.
So, we’ve seen that we can have at least two different “types” of random number sets – but let’s do a little more digging.
Here’s where things get a little interesting. If I take the 1,000,000 samples that I used to make the plot in Figure 3a and I pretend it’s an audio signal, and then calculate the frequency content (or spectrum) of the signal, it would look like the green plot in Figure 4a, below. If I did a frequency analysis of the signal used to make the plot in Figure 3b, it would look like the red plot.
What’s interesting about this is that, basically speaking, the two signals, although they’re very different, have basically the same spectra – meaning they have the same frequency content, and therefore they’ll sound the same. This is really evident if I smooth these two plots using, for example, a 1/3 octave smoothing function, as is shown below in Figure 4b.
As you can see there, the very fine peaks and dips in the response shown in Figure 4a, when averaged, smooth to the flat response shown in Figure 4b.
Now we have to clear up a couple of issues…
The first is that, as you can see in the plot above, the spectrum of both random signals (both noise generators) is flat. However, due to the way that I did the math to calculate this, this means that we have an equal amount of energy in equal-sized frequency ranges throughout the entire frequency range of the signal. So, for example, we have as much energy from 20-30 Hz as we do from 1000-1010 Hz as we do from 10,000 – 10,010 Hz. In other words, we have equal energy per Hz. This might be a little counter-intuitive, since we’re looking at a semilogarithmic plot (notice the scale of the x-axis) but trust me, it’s true. This means that, in both cases, we have what is known as a “white noise” signal – which is a colourful way of saying “noise with an equal amount of energy per Hz”.
The second thing is that I just lied to you. In order to get the pretty plots in Figures 4a and 4b, I had to take long signals and analyse how much energy we got, over a long period of time. If I had taken a shorter slice of time (say, 100 samples long) then the spectra plots would not have looked as pretty – or as flat. For example, if I just take the first 100 samples of both of those noise generator outputs, and calculate the spectra in those, I get the plots in Figure 4c, below.
Notice that these plots do not look nearly as flat – even though I’ve smoothed them with a 1/3 octave smoothing filter again. Why is this?
Well, the problem is probability. Since the two signals are random, there is no guarantee that all frequencies will be contained in them for any one little slice of time. However, there is an equal probability of getting energy at all frequencies over time. So, in a really strange universe, you might get all frequencies below 1000 Hz for one second, and then all frequencies above 1000 Hz for the next second – over two seconds, you get all frequencies, but at any one moment, you don’t.
What this means is that “white noise” doesn’t necessarily contain energy at all frequencies equally – unless you wait for a long time. If you listen for long enough, all frequencies will be represented, but the shorter the measurement, the less “flat” your response.
Just for the purposes of comparison, let’s also find out what the distribution of values is for a sine wave – since this might be interesting later… This is shown in Figure 5, below.
It may be interesting to note that “normal” sounds like music and speech have distributions that look much more like Figure 3b than like Figure 5, as is shown in the examples in Figures 6, 7, and 8. This is why you shouldn’t necessarily use a sine wave to measure a piece of audio equipment and draw a conclusion about how music will sound…
If I play the first kind of white noise (the one shown in Figure 2) and measure how loud it is with a sound pressure level meter, I’ll get a number – probably higher than 0 dB SPL (or else I can’t hear it) and hopefully lower than 120 dB SPL (or else I’ll probably be in pain…). Let’s say that we turn up the volume until the meter says 70 dB SPL – which is loud enough to be useful, but not loud enough to be uncomfortable.
Then, I switch to playing the other kind of white noise (the one shown in Figure 2a) and turn up the volume until it also measures 70 dB SPL on the same meter.
Then, I switch to playing a sine wave at 1 kHz and turn up the volume until it also reads 70 dB SPL.
If I were to compare what is coming into the loudspeaker for each of those three signals, after they have been calibrated to have the same output level, they would look like the three signals in Figure 9.
These will all sound roughly the same level, but as you can see in the plot in Figure 9, they do not have the same PEAK level – they have the same average level – averaged over time…
However, if we were to do a frequency-dependent analysis of these three signals, one of these things would not look like the others… Check out Figure 4a, which I’ve copied below…
Notice that, in a frequency-dependent analysis, the sine wave (the black line sticking up around 1000 Hz) looks much louder (35 dB louder is a lot!) than the green plot and the red plot (our two types of white noise). So, even though all three of these signals sound and measure to have roughly the same level, the distribution of energy in frequency is very different.
Another way to think about this is to say that each of the three signals has the same energy – but the sine wave has all of it at only one frequency all the time – so there’re more energy right there. The noise signals have the energy at that frequency only some of the time (as was explained above…).
ANOTHER way to think about this is to put a glass of water in the bottom of an empty bathtub. If the depth of the water in the glass is 10 cm – and you pour it out into the tub, the depth of the water will be less, since it’s distributed over a larger area.
As you can see in the title of this posting, this is “Part 1″… All of this was to set up for Part 2, which will (hopefully) come next week. As a preview: the topic will be the use (and mis-use) of weighting functions (like “A-weighting”) when doing measurements…