♪Music, Built

Act IX · Electric Sound

Part 48 of 68

Digital Audio

Foundationsstarts at this level36 min of film13 chaptersprerequisites: Part 2, Part 3, Part 4, Part 30, Part 47

How can a list of numbers hold a sound exactly, and how many numbers, how precise, are enough?

44,100 samples a second came from video: three samples a line, 245 lines, 60 fields (or 294 and 50). Behind the accident is the sampling theorem, built here as a sum of sincs through a signal's samples (the error falls from 0.25 with 4 samples per point to 4 in 100,000 with 128) and proved by spectral copies. Aliasing folds 5 and 7 kHz to 3 and 1 kHz at 8 kHz sampling, and an ear question turns a sweep round; the stair-step is a picture of a hold whose images (33 dB down near 44 kHz) a filter removes, and the steps are heard before it does. Quantization measures 6.02 N + 1.76 dB within 0.1 dB from 5 bits up; an ear question hears 4 bits with and without dither. Dither's moments are measured: none (error tied to the input), RPDF (mean freed), TPDF (mean and variance freed, a quarter of a step squared); a sine 0.4 of a step high vanishes without dither and survives with it. Noise shaping cuts the error below 4 kHz from -26 to -44 dB while the total rises; a one-bit delta-sigma modulator gains 9 and 15 dB per octave of oversampling for first and second order (75 dB at 64 times). Jitter costs -20 log10(2 pi f sigma), measured to 0.1 dB, and periodic jitter makes sidebands at -70 dB. Resampling, an ear question at 16 kHz, and the high-resolution debate (Meyer and Moran; Reiss) close it.

What you need. Part 2 for waves; Part 3 for spectra and the Fourier transform; Part 4 for hearing's range and threshold; Part 30 for sound as numbers; Part 47 for blind testing. Fourier series, convolution, probability.

Ideas, mathematics and history
the sampling theorem, aliasing, quantization noise, dither, noise shaping, delta-sigma, why 44,100
What we build, compute and hear
converters simulated; the Tune at one bit, sounding fine

What you will be able to do

Foundations

  • Hear aliasing turn a sweep round, and hear the stair-step's images before a reconstruction filter.
  • Tell a 4-bit Tune with dither from one without, and a 16 kHz rate from 48 kHz.
  • Hear one bit at three speeds, and flat and shaped noise as residues.

Full course

  • Reconstruct a band-limited signal from its samples by sinc interpolation and measure the truncation error.
  • Measure SNR against 6.02 N + 1.76 dB, and the error's mean and variance under no, RPDF and TPDF dither.
  • Build error-feedback noise shaping and a delta-sigma modulator, and measure their in-band SNR.

Research

  • Find how far below Nyquist music can be sampled, by sparsity and l1 recovery, before listeners notice.

Practice

  • Choose word lengths, dither and shaping for recording, mastering and delivery; test formats blind and level-matched.

Contents

Each chapter has a home level. Choose a track to see what to read and watch: Foundations 19 min · Full course 34 min · Research 36 min · Practice 34 min.

  1. 0One bit or sixteen?Foundations2 min
  2. 1Why 44,100?Foundations2 min
  3. 2The sampling theoremFoundations3 min
  4. 3AliasingFoundations3 min
  5. 4The stair-step mythFoundations3 min
  6. 5QuantizationPractice4 min
  7. 6DitherPractice4 min
  8. 7Noise shapingPractice2 min
  9. 8One bitPractice3 min
  10. 9Jitter and clocksPractice2 min
  11. 10Resampling and the high-resolution debateFoundations3 min
  12. 11Frontier: converter limits, and sampling below NyquistResearch2 min
  13. Variation 48, recap and problemsAll tracks2 min

Also on this page: Lecture · Key results · Try it · Lab · Problems · Notes and sources · Build the film.

Lecture

The text of each chapter is the film's narration, as it is spoken, so you can read along or revise without the film. The pictures are in the film. A dashed box stands for a number the film computes when it is rendered (hover over it to see what is computed); the README's figures for each chapter, where it lists them, follow the chapter's text.

One bit or sixteen?Foundations2 min

The first digital recorders stored audio on video cassettes. Before we get there, listen. The Tune, twice. One version was stored as sixteen-bit numbers, forty-eight thousand of them a second. The other was stored as single bits, ones and zeros, three million a second. Which is the one-bit version?

The one-bit version was the first. Judge this demonstration cautiously: the video's lossy soundtrack is not a controlled audibility test. Measure the difference from the original instead. The music sits at decibels. The one-bit version's error is at , the sixteen-bit version's at . The measured error levels are low for this signal; audibility also depends on spectrum, playback level, equipment and listener. A stream of yes-or-no answers, three million a second, can carry high-fidelity audio under suitable modulator and filtering conditions. This part shows why.

Every sound in this series has been a list of numbers, forty-eight thousand a second. How can a list of numbers hold a smooth wave, and everything between the samples? How many numbers a second do we need, and how precise must each one be? What goes wrong, how do we hear it, and how is it hidden? And how can one bit do the work of sixteen?

Here is the plan. Why forty-four thousand one hundred samples a second. The sampling theorem, proved and heard. Aliasing, and the myth of the stair-step. Quantization, six decibels a bit, and dither. Noise shaping, and one-bit conversion. And jitter, resampling, and the high-resolution debate.

1Why 44,100?Foundations2 min

Where did the CD's sample rate come from?

In the 1970s, nothing affordable could store a million numbers a second, except a video recorder. A PCM adaptor turned audio samples into a black-and-white television picture: white dots for ones, black for zeros. Sony's PCM-1600, from 1978, recorded on U-matic video cassettes, and compact discs were mastered from such tapes for years. The sample rate had to fit the picture: a whole number of samples on each line, the same in every field. So the compact disc's sample rate is an accident of television.

Here is the arithmetic. American and Japanese television, NTSC in black and white: sixty fields a second, two hundred and forty-five usable lines in each, three samples on every line: forty-four thousand one hundred samples a second. European television, PAL: fifty fields, two hundred and ninety-four lines, three samples: forty-four thousand one hundred again. One rate worked on both systems, and the compact disc kept it. Colour NTSC runs a thousandth slower, which is why some early recordings ran at instead.

In 1982 Sony and Philips launched the compact disc: forty-four thousand one hundred samples a second, sixteen bits each, two channels. That is 1,411,200 bits every second, about six hundred million bytes an hour. Video and studios settled on forty-eight thousand, which fits film and video frame rates more easily. This series works at forty-eight thousand throughout. But why should forty-odd thousand numbers a second be enough?

Why that number, and not much less? Young ears hear up to about twenty thousand hertz, as Part 4 showed, and the sampling theorem needs a rate above twice the highest frequency. Forty thousand would be the bare minimum, with a perfect filter that cannot be built. The extra four thousand one hundred leave room for a real filter to roll off between twenty thousand and twenty-two thousand and fifty. A lower rate would have made the filter impossible, and a higher one would not have fitted on the tape. Chapter two shows why twice is enough.

2The sampling theoremFoundations3 min

How can samples hold everything between them?

Here is the theorem. If a signal contains no frequency at or above some limit B, then samples taken two B times a second determine it completely. Not approximately: exactly, at every instant between the samples too. Half the sample rate is called the Nyquist frequency; the signal must stay below it. It sounds impossible: infinitely many curves pass through any set of dots. But an infinite, exact sample sequence uniquely determines the strictly band-limited signal under the theorem's assumptions; a finite set of displayed points alone does not.

Here is how the one curve is built. Take the samples of a signal that stays below the Nyquist frequency. At each sample, place a sinc function: sine of pi u over pi u, scaled by the sample's value. Each sinc is one at its own sample and exactly zero at every other sample. Add them all up. The sum passes through every sample, because only one sinc is non-zero there, and between the samples it is the original signal, with an error of here, and that only because we used thirty-three samples instead of infinitely many.

Why does it work? Think in frequencies, as Part 3 taught. The signal's spectrum has nothing above B. Sampling multiplies the signal by a train of spikes, and the spectrum of the samples is the signal's spectrum copied again and again, once every f s. If f s is more than twice B, the copies do not touch. Then keep only the middle copy with an ideal low-pass filter, and you have the original spectrum, so the original signal. The ideal low-pass filter's response to a single spike is exactly the sinc, which is why the sum of sincs works.

A real converter cannot add up infinitely many sincs: it uses a window of nearby samples. How much does that cost? With samples, the largest error is , a quarter of the signal. With , . With , . With , about four in a hundred thousand. Every doubling buys accuracy, and a real interpolation filter uses enough to put the error below the noise. The theorem is exact; its engineering is a trade-off you can measure.

The theorem has many fathers. Edmund Whittaker found the series of sincs in 1915, as pure mathematics. Harry Nyquist showed in 1928 that a channel of bandwidth B carries at most two B independent pulses a second. Vladimir Kotelnikov in 1933 and Claude Shannon in 1949 stated it for communication, with proof. The same idea runs through every digital camera, telephone and scanner. Its fine print is the rest of this part: the signal must really contain nothing above the Nyquist frequency.

3AliasingFoundations3 min

What happens to a frequency the samples cannot hold?

What if the signal does contain something above the Nyquist frequency? Here is a wave of seven cycles a second, sampled eight times a second, so its Nyquist frequency is four. The samples land as if on a wave of one cycle a second, running backwards. After sampling, the two are the same list of numbers: the fast wave has taken the slow one's identity. That is aliasing, and it is the wagon wheel in old films that turns slowly backwards when it is really spinning fast forwards.

Every frequency going in has a frequency it comes out as. Sample at eight thousand a second. Up to four thousand, the Nyquist frequency, everything comes out as it went in. Above it, the frequency folds back down, reaches zero at eight thousand, and climbs again: a zigzag, like paper folded at every multiple of four thousand. Three thousand stays three thousand. Five thousand comes out as three thousand. Seven thousand comes out as one thousand.

Hear it. Each tone first as it is, then after sampling at eight thousand a second with no filter, and rebuilding.

Now a question. A sine sweeping up from two hundred to twelve thousand hertz, sampled at eight thousand a second, twice: once with a filter in front of the sampler, and once without. In which does the pitch turn round?

The first. Without a filter, the sweep climbs to four thousand, then folds back down to zero at eight thousand, and climbs again: the pitch turns round twice. With the filter, the sweep simply fades out at the Nyquist frequency. Nothing above it reaches the sampler, so nothing can fold.

So every converter puts a low-pass filter in front of the sampler: the anti-aliasing filter. At forty-four thousand one hundred it must pass everything up to twenty thousand hertz and stop everything above twenty-two thousand and fifty: a steep cliff. Early CD players and recorders used steep analogue filters, with ringing and phase shift near the top. Modern converters sample far faster, filter digitally, and then reduce the rate, as chapter eight shows. And aliasing is not only a converter's problem: any processing that creates new high frequencies, distortion for one, can fold them back down.

4The stair-step mythFoundations3 min

Does digital audio come out in steps?

Advertisements for high-resolution audio often draw digital sound as a staircase, each sample held flat until the next, with more samples making smaller steps. That is not what comes out of a converter. The samples are points, and what comes out is the one smooth curve through them that contains no frequency above the Nyquist frequency, the curve of the last chapter. The stair-step is a picture of a device, not of the sound.

There is a grain of truth in it. A simple converter does hold each value for one sample period: a zero-order hold. But the steps are made of high frequencies: copies of the music around 44.1, 88.2 and 132.3 kilohertz. A low-pass reconstruction filter after the converter removes those copies, and the steps go with them. What is left is the smooth curve, with a small dip at the top of the band to correct. The stairs never reach the loudspeaker.

Measure the staircase. A one-kilohertz tone held at forty-four point one kilohertz. The tone itself comes out at full strength. Its copies, the images, sit either side of every multiple of the sample rate: around forty-four kilohertz they are about decibels down, around eighty-eight about . They are the steps. The hold also tilts the band itself: at twenty kilohertz it loses decibels, which a converter's filter corrects.

What would the stairs sound like if they did reach the loudspeaker? Here is the Tune sampled at eight kilohertz, where the effect is easy to hear: first played as held steps with no filter, then as the smooth curve. The steps add a metallic shimmer: the images, every copy of the music above four kilohertz.

How do modern converters really do it? They first raise the rate digitally, four, eight or sixty-four times, with an accurate interpolation filter, so the images move far above hearing and a gentle analogue filter can remove them. The droop is corrected in the digital filter. The result is the theorem's smooth curve, to within the converter's noise. More samples a second would not make the curve smoother; they would only widen the band.

5QuantizationPractice4 min

How precise must each sample be?

The second half of digital audio is precision. A sample can only be one of a fixed set of levels: with N bits, two to the N of them. Here are three bits, eight levels: each input is rounded to the nearest, a staircase of output against input. The difference, the quantization error, is a sawtooth that stays within half a step when rounding without overload or clipping. Sixteen bits give 65,536 levels; the steps are tiny, but they are there.

How much does each bit buy? If the error is spread evenly across a step of size delta, its average power is delta squared over twelve. A full-scale sine with N bits has amplitude two to the N minus one steps, so its power is two to the two N, times delta squared, over eight. Their ratio is three halves times two to the two N, which in decibels is six point oh two N plus one point seven six. Each bit halves the step and buys six decibels: sixteen bits give about ninety-eight, twenty-four about a hundred and forty-six. The assumption that the error is even and random is the one dither will make true.

Check it. Quantize a full-scale sine at every word length from two bits to sixteen and measure the error. At eight bits the rule says decibels and we measure ; at sixteen, against . Only at the very shortest words does it fail: at two bits we measure against , because there the error is nothing like random: it is the sine's own shape, squared off.

How much is enough? Sixteen bits put the noise about ninety-eight decibels below the loudest possible sample. If the loudest peak plays at a hundred and ten decibels of sound pressure, the floor sits near twelve: below the noise of a quiet room. So at home, sixteen bits are enough for almost any music, if the level is set well. Studios record at twenty-four bits, not to hear a hundred and forty-six decibels, but to leave room for levels set too low or too high. And the converter's own noise, about twenty bits' worth, is the real floor of a twenty-four-bit recording.

Now listen to four bits, sixteen levels, where the error is loud. The Tune twice: once rounded plainly, once with a little random noise added before rounding. Which had the noise added?

The second. The first is rough and gritty, and the grit follows the music: it is distortion, the error locked to the signal. The second hisses, a steady noise like tape, and the piano sounds clean through it. Measured, the second is worse: decibels of signal to error against . Dither trades signal-correlated distortion for added noise; preference in this sketch has not been measured. Chapter six explains why.

6DitherPractice4 min

How can adding noise make a signal cleaner?

Why did the noisier version sound better? Plain rounding makes the error a fixed function of the signal: it repeats whenever the signal repeats. A repeating error is distortion: new tones, locked to the music, which the ear picks out. Dither means adding a little random noise before rounding, so that chosen error moments no longer depend on the signal, provided the quantizer does not overload. We trade a pattern for a hiss, and the ear forgives a steady hiss far more readily. And the right dither does it exactly, not approximately.

Here is the whole story in six small graphs. Across each, the input's position within one step; above, the error's average, and below, how much it spreads, averaged over thousands of dither draws. With no dither, the average error is a sawtooth: it depends entirely on the input, and it does not spread at all. With rectangular dither one step wide, the average error becomes zero for every input: no more distortion. But its spread still depends on the input, so the noise rises and falls with the music, a modulation the ear can hear. With triangular dither two steps wide, both are flat: the average is zero and the spread is a quarter of a step squared everywhere, measured. The mean and variance are now independent of input under this ideal, non-overloading model; this does not make every feature of the error distribution independent.

Dither does something stranger still. Take a one-kilohertz sine only 0.4 of a step high, at eight bits. Without dither, every sample rounds to zero: the tone vanishes completely. With dither, the samples flicker between levels, and on average they follow the sine: its spectrum shows the tone standing clear of the noise. Listen: silence, then the tone inside a hiss.

Music is full of quiet: every note fades. Take a piano note at eight bits and look at its tail, magnified. Without dither, the tail turns into a few steps. With dither, it rides in noise. Near the threshold, such differences may not survive this video's own compression, so you will hear only the errors, the difference from the original note, raised by decibels: first without dither, then with.

Without dither the error is a ghost of the note itself, gritty, and it chatters as the note dies away. With dither it is a smooth hiss that does not care what the piano is doing.

The theory was settled in 1992 by Stanley Lipshitz, Robert Wannamaker and John Vanderkooy. Rectangular dither one step wide makes the error's average independent of the signal. Triangular dither, two steps wide, makes both its average and its power independent, and it is the least dither that does both. The price is three times the noise power of plain rounding, about 4.8 decibels. Dither is normally applied at final fixed-point requantization when needed to decorrelate quantization artifacts; existing noise and the processing chain affect that choice.

7Noise shapingPractice2 min

Can the noise be moved where we cannot hear it?

Dither leaves us with a steady hiss. Can it be made quieter? The noise cannot be removed, but it can be moved. Remember each sample's rounding error, and subtract it from the next sample before rounding that one. Then the error reaches the output as each error minus the one before: filtered by one minus z to the minus one, a high-pass filter. Do it twice over and the filter is steeper. The noise's total power grows, but it leaves the low frequencies, where the ear is most sensitive. C. Chapin Cutler's patent of 1954 first described feeding the error back this way.

Here are the error spectra of the Tune at eight bits. Plain dither: flat, the same at every frequency. First-order shaping tilts it up. Second order tilts it further. In numbers, the total error power rises from to decibels, but below four kilohertz, the shaded band where the ear is keenest, it falls from to . The noise is louder, and quieter where it matters.

Hear the two errors on their own, raised by decibels: first the flat one, then the shaped. Listen to where the hiss sits.

The flat error is a full, broad hiss. The shaped one is thinner and higher, a fizz near the top of hearing, where our ears are much less sensitive.

In 1989 Michael Gerzon and Peter Craven worked out how to shape the noise to follow the threshold of hearing. Commercial mastering dithers do exactly this when twenty-four-bit masters become sixteen-bit CDs. The noise you perceive drops, though the measured total rises. The cost: reserve strong final noise shaping for delivery when possible; repeated quantization and later processing can accumulate or expose shaped noise, rather than being mathematically forbidden. Pushed to the extreme, with many times the sample rate, shaping makes one bit enough. That is chapter eight.

8One bitPractice3 min

How can a stream of yes-or-no answers carry music?

The hook's one-bit version came from a delta-sigma modulator, and it is simple. Keep a running total of the input minus the output, and output plus one if the total is positive, minus one if not. Each output is crude, but its running average follows the input, because every error is corrected at the next step. It is noise shaping, with one bit: the error is pushed up in frequency. Run it sixty-four times faster than forty-eight kilohertz, and almost all the noise lies far above hearing, where a filter can remove it. Hiroshi Inose, Yasuhiko Yasuda and Jun Murakami named it delta-sigma modulation in 1962.

Watch it work on one slow cycle of a sine. Six hundred output bits. Where the input is high, the bits are mostly plus one; where it is low, mostly minus one; near zero, they alternate. Average the bits over a short window, as a low-pass filter does, and the average traces the input. The information is in the density of the ones.

How good is one bit? Measure the noise below twenty kilohertz for a sine, at rates from eight to a hundred and twenty-eight times forty-eight kilohertz. With one integrator, each doubling of the rate buys about decibels: theory says nine. With two integrators, about : theory says fifteen. At sixty-four times, the second-order modulator reaches decibels, and real converters use five or more integrators and a few bits to go far beyond.

Hear why speed matters. The same one-bit modulator running at forty-eight kilohertz, at eight times that, and at sixty-four times, each filtered back to forty-eight kilohertz.

At the audio rate itself, one bit is a harsh buzz with the tune buried in it: the noise has nowhere to go. At eight times, the tune is clear in a hiss, decibels below it. At sixty-four times, decibels: the noise has been pushed almost entirely above hearing and filtered away.

This is not a curiosity. Delta-sigma architectures are common in audio converters, including many phones and studio devices; other architectures remain in use: it samples millions of times a second with a few bits, then filters and decimates to forty-eight kilohertz and twenty-four bits. The Super Audio CD, in 1999, stored the one-bit stream itself, Direct Stream Digital, at 2,822,400 bits a second for each channel, sixty-four times the CD rate. Its noise rises steeply above twenty kilohertz and must be filtered on playback. The hook's first version was such a stream, filtered back to forty-eight kilohertz.

9Jitter and clocksPractice2 min

What if the samples are taken at slightly the wrong times?

The theorem assumes samples taken at exactly equal times. A real clock wobbles: that is jitter. A sample taken a little late reads the wave a little further along. Where the wave is steep, the error is large; where it is flat, small. So the error is the slope times the timing error, and for a sine of frequency f, with random timing errors of size sigma, the signal-to-noise ratio is minus twenty log ten of two pi f sigma: high frequencies, being steepest, suffer most.

Check the formula on a ten-kilohertz sine. With a hundred picoseconds of jitter, the formula predicts decibels and we measure . One nanosecond: . Ten: . A hundred: . To keep a ten-kilohertz tone as clean as sixteen bits allow, the clock must hold its timing to about two hundred picoseconds, a hundred-thousandth of a sample.

Random jitter adds noise. Jitter with a rhythm of its own does something else. Here is a ten-kilohertz sine sampled by a perfect clock: one line. Now let the clock wobble by ten nanoseconds, a thousand times a second. Two new tones appear, at nine and eleven kilohertz: sidebands. Theory puts them at twenty log ten of pi f a, decibels below the tone; we measure . Faint, but they are tones, not noise, and they move with the music.

Where does jitter matter? Only at the moments of conversion: in the analogue-to-digital and the digital-to-analogue converter. Data copied between devices is not changed by jitter on the way, provided every bit arrives. Real jitter is not always random: a periodic wobble makes sidebands, faint tones either side of every tone. Good converters recover a clean clock, often with a phase-locked loop, before converting. It is an engineering problem, largely solved; the formula says where to look when it is not.

10Resampling and the high-resolution debateFoundations3 min

How many samples a second does music need?

Music recorded at one rate often has to be delivered at another. Forty-eight thousand to forty-four thousand one hundred is the ratio to : every input samples become . Each new sample is read off the band-limited curve of chapter two, at its own instant. Going down, the curve must first lose everything above the new Nyquist frequency, or it will fold. Dropping samples without that filter is chapter three's aliasing, done in software. A good resampler is an accurate interpolation filter: many taps, and a steep, clean cutoff.

A question. A groove, twice. Once sampled at sixteen thousand a second, once at forty-eight thousand. Which was sixteen thousand?

The first. At sixteen thousand a second nothing above eight kilohertz survives: the cymbals lose their sizzle and the piano its edge. The spectra show it: the first stops dead at eight kilohertz; the second carries on to the top. Sixteen kilohertz supports wideband speech; traditional narrowband telephony commonly uses eight kilohertz sampling. The real question is whether anything is lost between forty-four thousand one hundred and more.

That is the high-resolution debate. Formats at ninety-six or a hundred and ninety-two kilohertz and twenty-four bits are sold as better than forty-four point one and sixteen. Is anything audible gained? In 2007 E. Brad Meyer and David Moran inserted a sixteen-bit, forty-four point one kilohertz loop into high-resolution playback, and in hundreds of double-blind trials aggregate performance did not reliably exceed chance under those study conditions. In 2016 Joshua Reiss pooled eighteen studies and over twelve thousand five hundred trials, and found a small but significant ability to tell, larger with training: trained listeners were right about sixty per cent of the time, where guessing gives fifty.

How should such a claim be tested? Blind: the listener must not know which is which; the ABX test plays A, B and an unknown X, and asks whether X is A or B. Level-matched: a difference of a fraction of a decibel is heard as better, not as louder. With enough trials: twelve right out of sixteen happens by guessing only 3.8 per cent of the time. And with the same music, from the same master, through the same chain apart from the one change. Most informal comparisons fail all four.

What should we conclude? For delivery, forty-four point one or forty-eight kilohertz at sixteen bits, properly dithered, is at or near the limit of what people hear. Where differences are found, filters and playback chains, rather than missing samples, may be the cause. For production, twenty-four bits give headroom, and higher rates give room for processing that creates high frequencies. The arguments are about margins, not about stair-steps. How such claims should be tested comes back in Part 67.

11Frontier: converter limits, and sampling below NyquistResearch2 min

What limits a converter, and must we always sample at twice the band?

Two frontiers. First, what limits a converter? A twenty-four-bit word could hold a hundred and forty-six decibels, but no converter reaches it: the thermal noise of its own resistors sets the floor. The best converters reach a dynamic range of roughly a hundred and twenty to a hundred and thirty decibels: about twenty usable bits. Jitter, the modulator's stability and the reference voltage's noise set the rest. Such converter noise is often below room and microphone noise in ordinary recording, while audibility depends on gain and listening conditions. The open problems are cost, power and size: converters in earbuds and hearing aids.

Second, must we always sample at twice the band? The theorem asks that much of any band-limited signal, but a signal with few degrees of freedom may need far fewer samples. In 2002 Martin Vetterli, Pina Marziliano and Thierry Blu showed that a few spikes can be recovered exactly from a few samples. In 2006 Emmanuel Candès, Justin Romberg and Terence Tao, and David Donoho, founded compressed sensing: a sufficiently sparse signal can be recovered from suitable measurements under incoherence or related recovery conditions, often by l-one optimization. Music is not sparse in time, but it is often nearly sparse in frequency, and that is where the theorem's fine print can be renegotiated.

A research problem to end on. Take a recording's short frames, and measure how sparse each is in a good basis. Acquire suitable nonuniform or compressed measurements below the conventional full-band sample count, accounting for analog front-end and reconstruction assumptions, and recover them by minimising an l-one norm. Measure the error against the number of samples, frame by frame, for many kinds of music. The question: how far below the Nyquist rate can music be sampled before listeners notice? An answer would turn the theorem's worst case into music's typical case.

Variation 48, recap and problemsAll tracks2 min

Every part ends by doing something to the Tune with what it built. Here, its first phrase at sixteen, eight, four and one bit. At sixteen and eight bits you hear only the error, raised by sixty and by twenty-four decibels, without dither and then with it; at four bits and one, the Tune itself; and last, one bit again, as a delta-sigma stream at sixty-four times the rate.

Row forty-eight of the ledger. With dither, the signal stands decibels above the error at sixteen bits, at eight, and at four. One bit, sixty-four times faster, gets back to .

What did we find? A band-limited signal is fixed exactly by samples taken at more than twice its top frequency. Anything above half the rate folds back down, so filter first. Converters output the smooth curve, not stairs. Each bit buys about six decibels, and triangular dither makes the error plain noise. Noise shaping moves the noise out of the ear's way, and with enough speed one bit suffices. Jitter costs most at high frequencies, and high sample rates buy margins, and little more.

Five problems. One to compute, one to prove, one for your ears, one to build, and a research problem, marked with a star. Solutions are in this part's notes. Pause here.

Where does this come back? In filters, delay and reverb, where the numbers are processed. In dynamics and distortion, where aliasing returns. In synthesis, which needs oscillators that do not alias. In mastering, with dither and true peaks. And in compression for the ear, which hides noise again, far more boldly.

And in practice. Recording engineers record at twenty-four bits and leave headroom, since the floor is far below. Mastering engineers dither once, at the last step to sixteen bits. Plug-in designers oversample anything that makes new high frequencies. And listeners compare formats blind, and at matched levels.

The books and papers this part follows. The full list, with notes, is in the README.

Where it goes next. Filters, delay and reverb in Part 49; aliasing from distortion in Part 50; alias-free oscillators in Part 51; dither and true peaks in Part 57; perceptual coding in Part 58.

Key results

The part's results in one place, for revision.

Sampling theorem\(\displaystyle x(t) = \textstyle\sum_n x[n]\,\mathrm{sinc}(f_s t - n), \quad\allowbreak f_s > 2B\)
Aliasing\(\displaystyle f \mapsto |f - f_s \,\mathrm{round}(f/f_s)|\)
Quantization\(\displaystyle \mathrm{SNR} = 6.02\,N + 1.76 \text{ dB}\)
TPDF dither\(\displaystyle \mathrm{E}[e \mid x] = 0,\ \mathrm{Var}[e \mid x] = \Delta^2/4\)
Jitter\(\displaystyle \mathrm{SNR} = -20\log_{10}(2\pi f \sigma_t)\)

Try it

Lab 48 · Digital audio, computed

Sample and fold a tone, quantize the Tune to any word length with and without dither, shape the noise, and build a one-bit converter.

Figure produced by Lab 48: Digital audio, computed
Produced by the lab below, seed 0, in 0.8 s.
python -m videos.music.labs 48 needs numpy, scipy, matplotlib · download lab48.py · source on GitHub
a 7000 Hz tone sampled at 8000 Hz is heard at                                      1000 Hz
the Tune at 6 bits, tpdf dither: signal to error                                   21.9 dB (rule for a full-scale sine: 37.9)
error mean across one step: largest |mean|, spread of variance (steps)             0.02, 0.02
error below 4 kHz, flat / second-order shaped (mean dB per band)                   -36.2 / -64.9
one bit, order 2, 32 times 48 kHz: SNR below 20 kHz                                58.8 dB
ear problem: the last three are each 4 bits with or without dither (listen first)  4 bits, dithered, 4 bits, no dither, 4 bits, dithered

Each bit buys about 6 dB; triangular dither makes the error plain noise at the cost of 4.8 dB; shaping moves that noise up out of the ear's way; and one bit suffices if the rate is high enough.
The code (71 lines; it asserts its own result)
"""Lab 48: digital audio, computed: aliasing, quantization at any word length, dither, noise shaping and a one-bit
modulator."""

import numpy as np

from videos.coursekit import labs
from explainer.music.monochord import SR, Clip, concat
from explainer.music.monochord import digital as D
from videos.music.music48 import compute as C

TITLE = "Digital audio, computed"
GOAL = ("Sample and fold a tone, quantize the Tune to any word length with and without dither, shape the noise, and "
        "build a one-bit converter.")
TASKS = [
    "Change TONE and RATE. Predict the frequency you will hear before you run it, then check against alias().",
    "Change BITS (2 to 16) and DITHER ('none', 'rpdf', 'tpdf'). When does dither stop being worth its extra noise?",
    "Change ORDER (1 or 2) and OSR. How many decibels does each doubling of OSR buy?",
]
TONE, RATE = 7000.0, 8000
BITS, DITHER = 6, "tpdf"
ORDER, OSR = 2, 32


def run(seed=0):
    rng = np.random.default_rng(seed)
    lab = labs.Lab()
    lab.row(f"a {TONE:.0f} Hz tone sampled at {RATE} Hz is heard at", f"{D.alias(TONE, RATE):.0f} Hz")
    x = C.tune_signal((0,), peak=0.9)
    q = D.quantize(x, BITS, DITHER, rng)
    lab.row(f"the Tune at {BITS} bits, {DITHER} dither: signal to error", f"{D.snr_db(x, q):.1f} dB (rule for a full-scale sine: {D.theory_snr(BITS):.1f})")
    m = D.error_moments(BITS, DITHER, 11, 2000, seed)
    lab.row("error mean across one step: largest |mean|, spread of variance (steps)", f"{max(abs(v) for v in m['mean']):.2f}, {max(m['var']) - min(m['var']):.2f}")
    sh = D.shaped(x, BITS, 2, DITHER, rng)
    f, P0 = D.noise_spectrum(q - x, SR)
    _, P2 = D.noise_spectrum(sh - x, SR)
    lo = f < 4000
    lab.row("error below 4 kHz, flat / second-order shaped (mean dB per band)", f"{np.mean(P0[lo]):.1f} / {np.mean(P2[lo]):.1f}")
    fs = 48000 * OSR
    t = np.arange(int(0.1 * fs)) / fs
    snr = D.band_snr_db(D.delta_sigma(0.5 * np.sin(2 * np.pi * 1000 * t), ORDER), 1000, fs, 20000)
    lab.row(f"one bit, order {ORDER}, {OSR} times 48 kHz: SNR below 20 kHz", f"{snr:.1f} dB")
    assert snr > 0

    # sound: the Tune at BITS with and without dither; ear problem: three versions in random order
    plain = D.quantize(x, BITS, "none")
    clips, answers = [Clip(plain, SR), Clip(q, SR)], []
    for i in range(3):
        if rng.random() < 0.5:
            clips.append(Clip(D.quantize(x, 4, "none"), SR))
            answers.append("4 bits, no dither")
        else:
            clips.append(Clip(D.quantize(x, 4, "tpdf", rng), SR))
            answers.append("4 bits, dithered")
    lab.audio = concat(clips, gap=0.8)
    lab.row("ear problem: the last three are each 4 bits with or without dither (listen first)", ", ".join(answers))

    fig, (ax1, ax2) = labs.figure(2)
    k = slice(20000, 20400)
    ax1.plot(x[k], color="C7", label="the Tune")
    ax1.plot(q[k], color=labs.GOLD, label=f"{BITS} bits, {DITHER}")
    ax1.set_xlabel("sample")
    ax1.legend(fontsize=7)
    ax2.plot(f, P0, color="C0", label="flat")
    ax2.plot(f, P2, color="C3", label="shaped")
    ax2.set_xlabel("Hz")
    ax2.set_ylabel("error, dB")
    ax2.legend(fontsize=7)
    lab.fig = fig
    lab.note = ("Each bit buys about 6 dB; triangular dither makes the error plain noise at the cost of 4.8 dB; shaping "
                "moves that noise up out of the ear's way; and one bit suffices if the rate is high enough.")
    return lab

Now change it

  1. Change TONE and RATE. Predict the frequency you will hear before you run it, then check against alias().
  2. Change BITS (2 to 16) and DITHER ('none', 'rpdf', 'tpdf'). When does dither stop being worth its extra noise?
  3. Change ORDER (1 or 2) and OSR. How many decibels does each doubling of OSR buy?

Problems, with solutions

Try each problem before opening its solution.

  1. Compute. A 30 kHz tone is sampled at 44.1 kHz with no filter. At what frequency is it heard?

    Solution

    Fold it: 44.1 − 30 = 14.1 kHz. (30 kHz lies between the Nyquist frequency, 22.05 kHz, and the rate, so it folds once.)

  2. Prove. Prove that triangular dither of two steps makes the error's mean and variance independent of the input.

    Solution

    Take the step as 1. With dither d added before rounding, the total error is ε = Q(x + d) − x. Lipshitz, Wannamaker and Vanderkooy show that the m-th moment of ε is independent of x exactly when the dither's characteristic function φ(w) and its first m − 1 derivatives vanish at every w = 2πk, k ≠ 0. One uniform dither on [−½, ½] has φ(w) = sin(w/2)/(w/2), which vanishes at those points but whose derivative does not: the mean is freed, the variance is not. The sum of two independent uniforms has φ(w) = (sin(w/2)/(w/2))², which vanishes there to second order: the first two moments are freed. Then E[ε] = E[d] = 0, and E[ε²] = 1/12 (the rounding, now uniform and independent of the signal) + 1/6 (the dither's own variance) = 1/4 of a step squared, as chapter 6 measured.

  3. Ear. The lab plays the Tune at 4 bits, with and without dither, in random order; say which is which.

    Solution

    The lab prints them. Without dither the error follows the music: a gritty, buzzing distortion that changes with every note. With dither it is a steady hiss, and the piano sounds clean inside it.

  4. Build. Write a third-order delta-sigma modulator and measure its gain per octave of oversampling.

    Where to look. Add a third integrator to delta_sigma (s3 += s2 − y) and measure band_snr_db at 16, 32 and 64 times. Theory gives 21 dB an octave, (2L + 1) × 3 for order L; a naive third-order loop with a one-bit quantizer is unstable, so scale the input down or weight the integrators (the CIFB structure in Schreier and Temes).

  5. ★ How far below Nyquist can music be sampled before listeners notice?

    Where the frontier is. Measure how sparse short frames of music are in good bases (MDCT, wavelets, learned dictionaries); sample at random below the Nyquist rate and recover by ℓ1 minimisation; then run blind, level-matched listening tests across sample counts and kinds of music.

Notes and sources

Sources

  • K. C. Pohlmann, Principles of Digital Audio (6th ed., 2010); J. Watkinson, The Art of Digital Audio (3rd ed., 2001); the PCM adaptor's history (Sony PCM-1600, 1978; PCM-1610 and 1630 for CD mastering).
  • E. T. Whittaker (1915); H. Nyquist, "Certain topics in telegraph transmission theory" (1928); V. A. Kotelnikov (1933); C. E. Shannon, "Communication in the presence of noise", Proc. IRE (1949); J. O. Smith, Mathematics of the Discrete Fourier Transform (2007).
  • S. P. Lipshitz, R. A. Wannamaker and J. Vanderkooy, "Quantization and dither: a theoretical survey", JAES (1992); R. A. Wannamaker, "The theory of dithered quantization" (thesis, 2003); C. C. Cutler, US patent 2,927,962 (1960, filed 1954); M. A. Gerzon and P. G. Craven, "Optimal noise shaping and dither of digital signals", AES (1989).
  • H. Inose, Y. Yasuda and J. Murakami, "A telemetering system by code modulation: delta-sigma modulation" (1962); R. Schreier and G. C. Temes, Understanding Delta-Sigma Data Converters (2005); Sony and Philips, the Super Audio CD (1999).
  • J. Dunn, "Jitter theory", Audio Precision technical notes; B. Brannon, "Sampled systems and the effects of clock phase noise and jitter", Analog Devices AN-756.
  • E. B. Meyer and D. R. Moran, "Audibility of a CD-standard A/D/A loop inserted into high-resolution audio playback", JAES (2007); J. D. Reiss, "A meta-analysis of high resolution audio perceptual evaluation", JAES (2016).
  • M. Vetterli, P. Marziliano and T. Blu, "Sampling signals with finite rate of innovation", IEEE Trans. Signal Processing (2002); E. J. Candès, J. Romberg and T. Tao (2006); D. L. Donoho, "Compressed sensing" (2006).
  • A. V. Oppenheim and R. W. Schafer, Discrete-Time Signal Processing (3rd ed., 2010): sampling, aliasing and reconstruction, the engineering textbook behind this part.
About this partfrom its README

Part 48 of a sixty-eight-part course in music (see the series plan and the syllabus), the first part of Act IX, Electric Sound. Why 44,100 samples a second? Because the first digital recorders stored audio on video cassettes: three samples a line, 245 lines, 60 fields. Behind the accident is a theorem that sounds impossible: a smooth wave can be recovered exactly from its samples. This part builds the theorem as a sum of sincs, folds frequencies, takes the stair-step apart, measures six decibels a bit, dither, noise shaping and jitter, and listens to one-bit audio. The tools are Monochord's (explainer/music/monochord/digital.py); every converter is simulated. Differences near the threshold of hearing are played as residues (the difference from the original, amplified by a stated gain), since this video's own soundtrack is lossy (SYLLABUS §3).

  • One bit or sixteen? An ear question (the Tune stored as 16-bit samples and as one bit at 3.072 MHz: which is which?); the errors measured (the music at −20 dB, the one-bit version's error at −83, the 16-bit version's at −96); the questions; the plan.
  • 1. Why 44,100? Audio on videotape (the PCM adaptor; Sony's PCM-1600); the arithmetic (3 × 245 × 60 = 3 × 294 × 50 = 44,100; colour NTSC's 44,056); the compact disc (1,411,200 bits a second); why that high and no higher.
  • 2. The sampling theorem. The statement; one sinc for every sample, their sum the signal (error 0.007 with 33 samples); why it works (spectral copies and the ideal low-pass); a real filter's finitely many samples (largest error 0.25 with 4, 0.06 with 16, 0.0006 with 64, 0.00004 with 128); Whittaker, Nyquist, Kotelnikov, Shannon.
  • 3. Aliasing. A fast wave and a slow one through the same samples; folding at 8 kHz sampling; three tones heard (3, 5 and 7 kHz come out as 3, 3 and 1); an ear question (a sweep sampled with and without a filter: in which does the pitch turn round?); the anti-aliasing filter.
  • 4. The stair-step myth. The picture in every advertisement, and the smooth curve; where the stairs go; a 1 kHz tone through a zero-order hold at 44.1 kHz (images 33 dB down near 44 kHz, 39 near 88; droop of 3.2 dB at 20 kHz); the stairs heard, before and after the filter; how converters really do it.
  • 5. Quantization. Rounding to the nearest level; six decibels a bit, derived; the rule against the measurement (49.9 dB measured at 8 bits, 98.1 at 16; only at 2 bits does it fail, 8.9 against 13.8); where the floor sits; an ear question (the Tune at 4 bits, with and without dither: which had the noise added?).
  • 6. Dither. Noise as a cure; the error's average and spread for every input, under no, rectangular and triangular dither (TPDF: mean zero, variance a quarter of a step squared everywhere); a tone 0.4 of a step high, silent without dither and alive with it, heard; a piano note fading at 8 bits, its errors heard (+30 dB); the theory (Lipshitz, Wannamaker and Vanderkooy).
  • 7. Noise shaping. Error feedback (Cutler); the Tune's error spectra flat and shaped (below 4 kHz −26, −36, −44 dB; total −18, −15, −10); the two errors heard (+24 dB); shaping to the ear (Gerzon and Craven).
  • 8. One bit. A delta-sigma modulator (Inose, Yasuda and Murakami); 600 bits of a slow sine; one bit measured (9 dB and 15 dB per doubling of the rate for first and second order; 75 dB at 64 times); one bit at three speeds, heard (0, 17 and 62 dB); one bit in practice (DSD at 2,822,400 bits a second).
  • 9. Jitter and clocks. A sample taken late; a 10 kHz sine with 0.1, 1, 10 and 100 ns of jitter (104, 84, 64 and 44 dB, each within 0.1 dB of −20 log₁₀ 2πfσ); periodic jitter's sidebands (−70.1 dB measured and predicted); jitter in practice.
  • 10. Resampling and the high-resolution debate. Changing the rate (147 : 160); an ear question (a groove at 16 kHz and 48 kHz); Meyer and Moran (2007); Reiss (2016); testing it properly (blind, level-matched, enough trials: 12 of 16 by chance 3.8 per cent of the time); what to conclude.
  • 11. Frontier: converter limits, and sampling below Nyquist. What limits a converter (thermal noise; roughly 120 to 130 dB, about 20 usable bits); finite rate of innovation and compressed sensing; ★ research problem: how far below Nyquist can music be sampled before listeners notice?
  • Variation 48, recap and problems. The Tune's first phrase: the errors at 16 and 8 bits (+60 and +24 dB), without and with dither; the Tune at 4 bits both ways, at 1 bit, and as a one-bit stream at 64 times the rate; the ledger (76 dB at 16 bits, 28 at 8, 4 at 4; one bit at 64 times 62 dB); what we found; five problems; where it comes back; in practice; references; Part 49.
What is computed and built

python -m videos.music.music48.compute (about a minute) fills .cache/music48/.

Item What it computes Checked against
hook, speeds, deltasigma one-bit delta-sigma at 64 times, decimated; three speeds; SNR against oversampling 9 and 15 dB an octave (tests)
rate44 the video arithmetic 44,100 both ways (tests)
sampling, stairstep, stairs sinc reconstruction and its truncation; the hold's images and droop sinc(f/fs); error falls with taps (tests)
tones, alias, rate folding at 8 kHz; a sweep with and without a filter; a groove at 16 kHz the folding formula (tests)
quant, moments, lowsine, fade SNR by word length; dither's moments; a sub-step sine; a fading note 6.02 N + 1.76; LWV's moments (tests)
shaping error spectra for orders 0, 1, 2 noise moved up (tests)
jitter, sidebands random and periodic jitter −20 log₁₀ 2πfσ; 20 log₁₀ πfa (tests)

Monochord's tools are held in tests/music/test_digital.py; this part's claims and clips in tests/music/test_music48.py.

Sounds. Part 7's piano and Part 40's drums (physical models), sine tones, and the converters of this part. Residues are labelled with their gain on screen.

What the models are, and are not. The converters are ideal apart from the one effect under study: no analogue noise, no filter ripple. The decimation filter for one-bit audio is an exact frequency-domain low-pass, as no real converter's is. The modulators are first and second order; real converters use higher orders and a few bits. The SNR figures for the Tune are against the Tune itself, at the level it was converted, not against full scale.

Notes

Sampling uniqueness assumes an infinite exact sample sequence and strict band limitation, not a finite displayed dot set. Quantization half-step bounds exclude clipping; the 6.02N+1.76 dB rule assumes a full-scale sine and suitable error statistics. Dither makes specified error moments independent under its assumptions, not every possible statistic or overload behavior. Noise shaping and oversampling involve stability, filtering and later-processing trade-offs. This lossy video is not a controlled format-audibility test. Compressed sensing requires sparsity and suitable measurements; it does not repeal the general sampling theorem.

Companion material in this repository

The syllabus's plan for this partfrom SYLLABUS.md, the plan of record
  1. Hook: an ear question (16 bits or one bit at 3 MHz?); the errors measured; the questions; the plan.
  2. Why 44,100? Audio on videotape; the arithmetic; the compact disc; why that high and no higher.
  3. The sampling theorem: the statement; one sinc per sample; why it works; finite filters; many fathers.
  4. Aliasing: a fast wave through slow samples; folding; three tones heard; an ear question (a sweep turns round); the anti-aliasing filter.
  5. The stair-step myth: the advertisement and the curve; where the stairs go; images and droop; the stairs heard; real converters.
  6. Quantization: rounding; six decibels a bit; the rule measured; where the floor sits; an ear question (4 bits, dithered or not?).
  7. Dither: noise as a cure; the error's moments under three dithers; a sub-step tone heard; a fading note's errors heard; the theory.
  8. Noise shaping: error feedback; three spectra; the errors heard; shaping to the ear.
  9. One bit: the modulator; a bitstream drawn; one bit measured; three speeds heard; one bit in practice.
  10. Jitter and clocks: a late sample; the formula checked; periodic jitter's sidebands; jitter in practice.
  11. Resampling and the high-resolution debate: changing the rate; an ear question (16 or 48 kHz?); the studies; testing properly; conclusions.
  12. Frontier: converter limits; sampling below Nyquist; the research problem.
  13. Variation 48: the Tune at 16, 8, 4 and 1 bit. Outro: problems, payoffs.

Covers: the sampling theorem; aliasing; reconstruction and the stair-step myth; quantization noise and the six decibels per bit; dither; noise shaping; delta-sigma conversion; jitter; resampling; the high-resolution debate. Built and computed: monochord/digital.py: Whittaker–Shannon reconstruction with its truncation error (0.25 with 4 samples per point, 0.00004 with 128); folding; the zero-order hold's images (33 dB down near 44 kHz) and droop (3.2 dB at 20 kHz); quantization measured against 6.02 N + 1.76 dB (within 0.1 dB from 5 bits); the error's mean and variance under no, RPDF and TPDF dither; error-feedback noise shaping (below 4 kHz −26 to −44 dB); one-bit delta-sigma modulators (9 and 15 dB per octave of oversampling; 75 dB at 64 times); jitter (−20 log₁₀ 2πfσ, to 0.1 dB) and its sidebands; band-limited resampling. Variation 48: the Tune at 16, 8, 4 and 1 bit, with and without dither (shown as residues; §3): 77, 29 and 5 dB; one bit at 64 times the rate, 62 dB. Frontier: converter limits; sampling beyond Nyquist (open: how far below Nyquist music can be sampled before listeners notice). Reading: Pohlmann; Lipshitz, Wannamaker & Vanderkooy (1992); Smith, Mathematics of the DFT.

Build the film

python -m videos.music.music48.compute        # the part's numbers, into .cache/music48
python tools/build.py music48                  # render and assemble the film
EXPLAINER_TTS=silent python tools/qa_scene.py music48 Hook   # one chapter, silent, with a contact sheet

Scenes: videos/music/music48. Setup: see the course page. Source of these notes: the README and the scenes' narration.

Build it
python -m videos.music.music48.compute                          # numbers and sounds (about a minute)
EXPLAINER_TTS=silent python tools/build.py music48 -q l --fps 15   # a silent-narration preview, with the sounds
python tools/qa_sound.py music48 --sync                         # the sound gates
python tools/dead_air.py renders/music48_480p.mp4 --sound music48  # no empty screen; no sound over a still one
python tools/lecture_length.py music48                          # 30 to 60 minutes, listening included
python tools/build.py music48                                   # 1080p30, narrated
python -m pytest -q tests/music                                 # Monochord against its references; this part's claims and clips
python -m videos.music.labs 48                                  # the lab (writes a figure and a short WAV)