I've talked here before about how noise and distortion are very similar concepts with very different causes.  Noise is unwanted artifacts independent of the signal often caused by physical processes outside of a device.  Distortion is unwanted artifacts directly correlated with the signal usually caused by components inside of the device.  When taking measurements of these artifacts, what we aim to measure is likewise quite different.  But the methods are surprisingly similar.

A dynamic range (DR) measurement for a device is simply the difference in dB between the device's output level and its noise floor.  To get output level, play a digital full-scale wave, and measure the amplitude.  To get a noise floor reading, play silence and measure the amplitude.  It turns out that for PC devices, there's a hitch, though.  Many audio codecs have muting circuits that shorts the output to a very low level when they detect that they are only outputting silence.  This is very clever, but it means we aren't really getting a true noise floor measurement.  As a result, when taking a DR measurement on a PC, we play a very low-level sine wave while taking the measurement.  About 60dB below full scale (-60dBFS) should do it.  We just need something to stimulate the codec and disengage the mute circuits.

But, you may be thinking, doesn't this mean we can't take a noise floor measurement below our signal?  We should never be able to  take a DR measurement of more than 60dB this way.  You're right, of course, which is why we need to also put the output through a band reject filter which removes all signal components of one particular frequency - in this case, the frequency at which we're playing our sine wave.  What this filter allows us to do is to measure the amplitude of every frequency in the signal except for the frequency we're playing.  That amplitude is, you guessed it, the noise floor.

Measuring distortion is a completely different can of worms.  To get a distortion reading, we want to play a very loud signal (usually a sine wave, but could be multitone - more on that soon) at or near full scale, in order to provoke distortion artifacts.  Originally, almost all of the distortion in audio devices was harmonic, meaning that if we play a sine wave has frequency F, the frequencies of distortion are 2F, 3F, 4F, and so on.  To take a distortion reading, we measure the power of each harmonic, and sum them all up to get a reading.  Our final measurement is the dB difference between this and our output level.  This measurement is known as the Total Harmonic Distortion (THD).

Modern electronic audio, however, can also have distortion artifacts in between the harmonics.  The summation method for THD won't measure these nonlinear distortion artifacts, which usually sound worse than the harmonics.  What we really want to measure is the sum of every tone, harmonic or not, except the fundamental.  To do this, we turn back to our band reject filter to remove the fundamental signal and capture the amplitude of everything else.  Any distortion in the signal will be at a frequency other than the notched out frequency, and will be captured.  Strictly speaking, once we do this, we're also capturing the noise floor in addition to the distortion.  This is usually not a problem since in most real devices, full-scale distortion swamps the noise floor by an order of magnitude.  Still, to be pedantic, what we're measuring here is Total Harmonic Distortion plus Noise, or THD+N.

So our measurement process looks like this:

  1. Play full-scale tone with no filter
  2. Take amplitude measurement.  This is our output level measurement.
  3. Play test tone with bandreject filter tuned to test frequency.
  4. Take amplitude measurement.  This is our floor measurement.
  5. Take the dB difference between the measurements in steps 2 and 4.  This is our final value.

The only difference between DR and THD+N is the test tone used in step 3.  For DR, we want only to stimulate the circuits, so we use a very quiet tone.  For THD+N, we want to provoke distortion, so we use a very loud tone.  I find it interesting that we can get measurements for these two different effects using the same process.  It sure saves on the test coding time, anyway.