Skip to content

Quantization and Noise Shaping

Copy this iframe to your website:

1
<iframe src="https://dmccreary.github.io/signal-processing/sims/quantization-and-noise-shaping/main.html" width="100%" height="632px" scrolling="no"></iframe>

Run MicroSim in Fullscreen

Description

This MicroSim quantizes a full-scale waveform with a uniform mid-rise quantizer and shows the result in the time domain and in the frequency domain. With \(b\) bits and a full-scale range \(V = 2\) (from \(-1\) to \(+1\)) there are \(2^b\) levels, a step size of

\[\Delta = \frac{V}{2^b}\]

and an error \(e[n] = x_q[n] - x[n]\) that is never larger than \(\Delta/2\). Everything on the screen is computed from the actual samples: the error spectrum comes from a radix-2 FFT and the signal-to-quantization-noise ratio (SQNR) is measured from it.

Five controls change the experiment:

  • Signal selects a sinusoid, a triangle wave or a three-harmonic waveform with a 547 Hz fundamental.
  • Oversampling sets the sampling rate to 1, 2, 4, 8 or 16 times 40 kHz.
  • Bit depth b sets the number of bits from 1 to 16.
  • Noise shaping switches an error-feedback loop between off, 1st order and 2nd order.
  • Show low-pass filtered output adds the signal and the error left after an ideal 20 kHz low-pass filter.

The banner compares the SQNR measured in the 0 to 20 kHz signal band with the white-noise model, and the two numbers under the spectrum give the noise in the signal band and the total noise. This simulation supports the section on quantization in Chapter 5: Sampling and Quantization.

The Four Plots

From top to bottom:

  1. Original signal \(x(t)\): the chosen waveform, four milliseconds of it.
  2. Quantized signal \(x_q[n]\), drawn as a staircase. The horizontal lines are the quantization levels (drawn up to 32 levels).
  3. Quantization error \(e[n]\), in units of the step size \(\Delta\).
  4. Spectrum of the error from 0 to \(f_s/2\), computed from the samples with an FFT. The shaded band from 0 to 20 kHz is the signal band. The dashed curve is the white-noise model described below.

Mathematical Concepts

The white-noise model. If the error behaves like noise that is uniformly distributed over \([-\Delta/2, \Delta/2]\), its power is \(\sigma_e^2 = \Delta^2/12\) and it is spread evenly from 0 to \(f_s/2\). For a full-scale sinusoid this gives

\[\text{SQNR} \approx 6.02\,b + 1.76\ \text{dB}\]

The banner shows this prediction next to the value measured from the actual samples. The two agree well for many bits and drift apart for few bits, where the error of a simple waveform is not noise-like at all: it is a distortion locked to the signal.

Oversampling. Sampling at \(f_s = \text{OSR} \times 40\) kHz leaves the total error power unchanged but spreads it over a band that is OSR times wider. A digital low-pass filter that keeps only 0 to 20 kHz then removes all but \(1/\text{OSR}\) of it, a gain of 3 dB (half a bit) for every doubling of the sampling rate.

Noise shaping. A noise shaper feeds the previous quantization errors back to the quantizer input, so that the error appears at the output multiplied by a high-pass noise transfer function:

Modulator order Noise transfer function Total noise power In-band gain per doubling of OSR
Off \(1\) \(\Delta^2/12\) 3 dB
1st order \(1 - z^{-1}\) \(2 \times \Delta^2/12\) about 9 dB
2nd order \((1 - z^{-1})^2\) \(6 \times \Delta^2/12\) about 15 dB

Noise shaping does not reduce the total noise. It increases it, and moves almost all of it above the signal band where the low-pass filter removes it. The two numbers under the spectrum (noise in the signal band and total noise) show this directly. Tick Show low-pass filtered output to see the filtered signal (green) and the error that is left.

With noise shaping the quantizer input can exceed full scale by up to \(\Delta/2\) (first order) or \(3\Delta/2\) (second order). The shaped quantizer is therefore given a few extra levels above and below full scale, drawn dashed; the caption reports how many levels are in use. Practical delta-sigma converters instead keep the input a little below full scale.

How to Use

  1. Leave oversampling at 1× and noise shaping off. Move the Bit depth slider and watch the staircase, the error and the SQNR.
  2. Choose an Oversampling ratio. The spectrum axis stretches to the new \(f_s/2\) while the shaded signal band stays at 20 kHz.
  3. Switch Noise shaping to 1st or 2nd order and compare the two noise figures under the spectrum.
  4. Tick Show low-pass filtered output to see what a decimation filter recovers.

Lesson Plan

Learning Objectives

By the end of this activity, students will be able to:

  1. Explain why quantization is irreversible and why the error is bounded by half a step.
  2. Predict the SQNR of a full-scale sinusoid from the bit depth.
  3. Describe the quantization error in time and in frequency, and say when the white-noise model fails.
  4. Explain how oversampling and noise shaping raise the SQNR in the signal band without lowering the total noise.
  5. Evaluate when noise shaping helps and when it makes the in-band SQNR worse.

Target Audience

Undergraduate students in signals and systems or digital signal processing. Plan 20-25 minutes for the activities.

Prerequisites

  • Sampling and the Nyquist frequency
  • Decibels and signal power
  • The idea of a frequency spectrum

Activities

Activity 1: Six decibels per bit (5 min). Choose Sinusoid, 1× oversampling, noise shaping off. Set the bit depth to 2, 4, 8 and 16. The step size reads 0.5, 0.125, 0.00781 and \(3.05\times10^{-5}\), and the measured SQNR is 12.8, 25.3, 49.6 and 97.5 dB (the rule \(6.02\,b + 1.76\) gives 13.8, 25.8, 49.9 and 98.1 dB). From 8 to 16 bits the SQNR rises by 47.9 dB, which is 6.0 dB per bit. The error plot always spans \(\pm\Delta/2\).

Activity 2: When the white-noise model fails (10 min). Keep Sinusoid and noise shaping off, set the bit depth to 4 and raise oversampling from 1× to 16×. The model promises a gain of 12 dB (25.8 to 37.9 dB), but the measured SQNR rises only from 25.3 to 28.5 dB and the total noise stays at -25.3 dBFS. Look at the error plot: it is a repeating sawtooth pattern locked to the signal, not noise, so much of its power falls inside the signal band. Now set the bit depth to 12: the measured value is 84.1 dB against 86.0 dB for the model, much closer, because the error has become noise-like.

Activity 3: Noise shaping needs oversampling (10 min). Set 4 bits, 16×, and step the noise shaping through Off, 1st order and 2nd order. The in-band SQNR is 28.5, 56.1 and 73.3 dB, while the total noise rises from -25.3 to -22.7 and -18.1 dBFS: the noise is moved out of the band, not removed. Now set oversampling to 1× and repeat: the SQNR falls to 25.3, 22.5 and 18.3 dB, because the signal band covers the whole spectrum and there is no empty band to push the noise into.

Activity 4: Few bits, high rate (5-10 min). Set 2 bits, 16×, 2nd-order noise shaping and tick the filtered output. The staircase uses 8 levels (4 plus headroom levels) and looks nothing like the input, yet the green filtered signal follows the input closely and the measured SQNR is 60.1 dB. A plain quantizer needs about 10 bits for this: 9 bits measure 55.6 dB and 10 bits measure 62.2 dB. Discussion: a delta-sigma audio converter uses a quantizer with very few bits at a sampling rate of several megahertz. Which part of the system turns that coarse stream into 16 or more useful bits? The digital low-pass (decimation) filter, which removes the shaped noise above the signal band and reduces the sampling rate.

Assessment

  1. A converter has 12 bits and a full-scale range of \(V = 2\). What are the step size and the predicted SQNR for a full-scale sinusoid? Answer: \(\Delta = 2/4096 = 4.88\times10^{-4}\) and SQNR \(\approx 6.02 \times 12 + 1.76 = 74.0\) dB. The simulation measures 74.8 dB.
  2. At 8 bits and 1× oversampling the sinusoid gives 49.6 dB but the triangle wave gives 47.7 dB. Why, when the step size is the same? Answer: the noise power is about the same (\(\Delta^2/12\)), but the triangle wave has less signal power (0.34 against 0.5), so the ratio is smaller.
  3. At 4 bits and 16× oversampling with noise shaping off, the model predicts 37.9 dB but the measured SQNR is 28.5 dB. Why is the model wrong here? Answer: the white-noise model assumes the error is spread evenly over 0 to \(f_s/2\). At 4 bits the error is a distortion locked to the signal, so a large part of its power lies inside the 20 kHz band and the filter removes little of it.
  4. At 4 bits and 16×, 2nd-order shaping raises the SQNR from 28.5 to 73.3 dB. Did the quantization noise decrease? Answer: no. The total noise rose from -25.3 to -18.1 dBFS (about 7 dB, a factor of about 5). The noise in the signal band fell because the shaping moved it above 20 kHz.
  5. At 4 bits and 1× oversampling, why does 2nd-order shaping lower the SQNR from 25.3 to 18.3 dB? Answer: at 1× the signal band is the whole spectrum up to \(f_s/2\). The noise transfer function has a gain above 1 for \(f > f_s/6\), so the noise is amplified in the band and there is no empty band to move it into.

Common Misconceptions

"Quantization error is always white noise that is unrelated to the signal." For few bits the error is a distortion that follows the signal. At 4 bits the error plot is a repeating sawtooth and the measured SQNR is 28.5 dB at 16×, 9.4 dB below the white-noise model. The model works well only when the bit depth is large enough.

"Noise shaping removes quantization noise." It moves noise. The total-noise figure under the spectrum goes up with shaping (from -25.3 to -18.1 dBFS at 4 bits) while the noise in the signal band goes down.

"Oversampling adds resolution without any filtering." The total noise does not depend on the oversampling ratio. The gain appears only when a low-pass filter discards the part of the noise above the signal band; tick the filtered output to see it.

References

  1. Quantization (signal processing) - Wikipedia - uniform quantization, step size and the error model
  2. Noise shaping - Wikipedia - error feedback and the noise transfer function
  3. Delta-sigma modulation - Wikipedia - oversampling converters that combine a coarse quantizer with noise shaping
  4. Oversampling - Wikipedia - why a higher sampling rate lowers the in-band quantization noise
  5. The Scientist and Engineer's Guide to Digital Signal Processing - Steven W. Smith - free online textbook; Chapter 3 (ADC and DAC) covers quantization and oversampling
  6. Chapter 5: Sampling and Quantization - this textbook - where the MicroSim is used

Print references: Bennett, W. R. (1948), "Spectra of quantized signals", Bell System Technical Journal 27(3), 446-472. Oppenheim, A. V., and Schafer, R. W. (2010), Discrete-Time Signal Processing, 3rd ed., Pearson, Chapter 4.