---
title: Oversampling and noise shaping
heading: Spreading quantization noise by oversampling, pushing it out of band with feedback, the SNR of shaped converters, and decimating back to the signal rate
eyebrow: S7 · Lesson 8 · Oversampling and noise shaping
xp: 50
---

::: hook
A one-bit converter, a comparator, is about the crudest quantizer imaginable, yet the converters in nearly every phone and audio interface are built around one. The trick is to sample far faster than the Nyquist rate and use feedback so the quantization error is mostly at high frequencies, where a digital filter can then remove it. S2 built the analog loop; this lesson does the signal-processing accounting: how much of the noise lands in the band of interest, how that depends on the oversampling ratio and the shaping order, and why each doubling of the clock buys more than six decibels once the noise is shaped.
:::

::: play
- The quantization noise spectrum after shaping of order p, $|1 - e^{-j\omega}|^{2p}$ in dB, against frequency from 0 to π (the oversampled Nyquist frequency), with the signal band ending at π/M.
- With p = 0 the noise is flat; plain oversampling only spreads it thinner. With shaping the noise is driven down near zero frequency and up near π.
- The readout gives the in-band noise relative to unshaped, unoversampled quantization: $\frac{\pi^{2p}}{(2p + 1)M^{2p+1}}$ in dB.
:::
:::

```sim plot
view: graph
x: w = 0..3.1416
y: N = -80..20 dB
slider: p = 0..3 = 1 step 1
slider: M = 4..256 = 64 log
plot: 20*p*log(abs(2*sin(w/2)) + 1e-9) | samples: 800 | label: noise shaping |1 − e^{−jω}|^{2p}, dB
plot: 0 | dashed | color: ch3 | label: unshaped
marker: w = pi/M | label: band edge π/M
readout: in-band noise change, dB = 10*log(pi^(2*p)/((2*p + 1)*M^(2*p + 1)))
```

::: predict
## A converter is oversampled by 64. How much does its in-band SNR improve with no noise shaping, and with first-order shaping?

- [ ] 18 dB both ways
- [x] About 18 dB, and about 49 dB
- [ ] About 36 dB, and about 54 dB
- [ ] Nothing without shaping

::: reveal
Plain oversampling spreads the same noise power over 64 times the bandwidth, so the in-band fraction falls by 10 log 64 = 18.1 dB. First-order shaping also lowers the noise density near DC, and the in-band noise falls by $10\log\frac{3M^3}{\pi^2}$ = 54.2 − 5.2 = 49.0 dB. Every doubling of M then gains 9 dB with first-order shaping, against 3 dB without.
:::
:::

::: nameit
## Oversampling alone

Quantization noise of power $\sigma_e^2 = \Delta^2/12$ is spread evenly from 0 to π. Sampling M times faster than needed and lowpass-filtering to π/M keeps only 1/M of it:

$$\text{SNR} = 6.02B + 1.76 + 10\log M \text{ dB}$$

3 dB, half a bit, per doubling of M.

## Noise shaping

Feeding the quantization error back through a filter gives an output $Y = X + (1 - z^{-1})^pE$: the signal passes unchanged while the noise is filtered by the noise transfer function $(1 - z^{-1})^p$, whose magnitude $|2\sin(\omega/2)|^p$ is small near ω = 0. The in-band noise power is

$$\sigma_e^2\frac{\pi^{2p}}{(2p + 1)M^{2p + 1}}$$

so the SNR becomes

$$6.02B + 1.76 - 10\log\frac{\pi^{2p}}{2p + 1} + (2p + 1)\,10\log M$$

- first order: $-5.17 + 30\log M$, 9 dB per octave of oversampling;
- second order: $-12.90 + 50\log M$, 15 dB per octave.

Orders above two need careful loop design to stay stable with a coarse quantizer.

## Decimation

The shaped noise above π/M must be removed before the rate is reduced: a cascade of decimating filters (often a CIC stage, then FIR halfband stages) lowers the rate by M while keeping only the band of interest. The output then carries the high-resolution samples at the signal rate. The effective number of bits is $(\text{SNR} - 1.76)/6.02$.
:::

::: example
## A 1-bit quantizer runs at 64 times oversampling. What SNR does it give with no shaping, first-order and second-order shaping?

::: solution
1. **No shaping.**
   $$\begin{aligned} \text{SNR} &= 6.02 + 1.76 + 18.06 \\ &= 25.8\ \text{dB} \end{aligned}$$
2. **First order.**
   $$\begin{aligned} \text{SNR} &= 6.02 + 1.76 \\ &\quad - 5.17 + 54.19 \\ &= 56.8\ \text{dB} \end{aligned}$$
3. **Second order.**
   $$\begin{aligned} \text{SNR} &= 7.78 - 12.90 + 90.31 \\ &= 85.2\ \text{dB} \end{aligned}$$
   That's equivalent to 13.9 bits from a one-bit quantizer.

**Answer:** 25.8 dB with no shaping, 56.8 dB with first-order shaping and 85.2 dB with second-order shaping.
:::
:::

::: example
## The first-order design needs 65 dB. How much faster must it run?

::: solution
1. **Gain per doubling.** Each doubling of the oversampling ratio gains 9.03 dB with first-order shaping.
2. **Try M = 128.**
   $$\begin{aligned} \text{SNR} &= 56.8 + 9.0 \\ &= 65.8\ \text{dB} \end{aligned}$$
   That's enough.
3. **Compare second order.** The second-order design would need only M = 64, which is why second-order and higher loops are the norm.

**Answer:** twice as fast, M = 128, which gives 65.8 dB.
:::
:::

::: example
## A 16-bit audio DAC runs at 4× oversampling with second-order noise shaping. What in-band SNR can it reach? What would a 1-bit, third-order modulator at 64× reach?

::: solution
1. **16 bits, 4×, second order.**
   $$\begin{aligned} \text{SNR} &= 96.32 + 1.76 - 12.90 \\ &\quad + 50\log_{10}4 \\ &= 115.3\ \text{dB} \end{aligned}$$
   against 98.1 dB without oversampling.
2. **One bit, 64×, third order.**
   $$\begin{aligned} \text{SNR} &= 6.02 + 1.76 \\ &\quad - 10\log_{10}(\pi^6/7) \\ &\quad + 70\log_{10}64 \\ &= 6.02 + 1.76 \\ &\quad - 21.38 + 126.43 \\ &= 112.8\ \text{dB} \end{aligned}$$
3. **Compare.** The one-bit design matches the 16-bit one by trading word length for speed, but a third-order loop with a one-bit quantizer needs careful design to stay stable.

**Answer:** the 16-bit DAC reaches 115.3 dB, and the 1-bit third-order modulator at 64× reaches 112.8 dB.
:::
:::

::: check
given: B = 1 | 4 | 12; M = 8 | 64 | 256
answer: 6.02*B + 1.76 + 10*log(M)
unit: dB
tolerance: 0.05

## A {B}-bit quantizer is oversampled by {M} with no noise shaping. What's the in-band SNR?

::: right
Right. 6.02B + 1.76 + 10 log M = {answer} dB.
:::

::: misses
- [6.02*B + 1.76 + 30*log(M)] That's the first-order shaped growth; without shaping it's 10 log M.
- [any] Not yet. Oversampling alone gains 10 log M.
:::
:::

::: check
given: B = 1 | 2 | 4; M = 16 | 64 | 128
answer: 6.02*B + 1.76 - 10*log(pi^2/3) + 30*log(M)
unit: dB
tolerance: 0.05

## The same quantizer ({B} bits, oversampled ×{M}) is put in a first-order noise-shaping loop. What's the in-band SNR?

::: right
Right. $6.02B + 1.76 - 5.17 + 30\log M$ = {answer} dB.
:::

::: misses
- [6.02*B + 1.76 + 30*log(M)] Include the $-10\log(\pi^2/3)$ term.
- [any] Not yet. In-band noise $\sigma_e^2\pi^2/(3M^3)$.
:::
:::

::: check
given: B = 1 | 2 | 3; M = 32 | 64 | 128
answer: 6.02*B + 1.76 - 10*log(pi^4/5) + 50*log(M)
unit: dB
tolerance: 0.05

## With second-order shaping instead, what's the in-band SNR?

::: right
Right. $6.02B + 1.76 - 12.90 + 50\log M$ = {answer} dB.
:::

::: misses
- [6.02*B + 1.76 + 50*log(M)] Include the $-10\log(\pi^4/5)$ term.
- [any] Not yet. In-band noise $\sigma_e^2\pi^4/(5M^5)$.
:::
:::

::: check
given: p = 0 | 1 | 2 | 3
answer: 10*log(2^(2*p + 1))
unit: dB
tolerance: 0.05

## By how much does each doubling of the oversampling ratio improve the SNR with order-{p} noise shaping?

::: right
Right. $(2p + 1) \times 3.01$ = {answer} dB.
:::

::: misses
- [6.02*p] Count the extra 3 dB from spreading the noise: $(2p + 1)\,10\log 2$.
- [any] Not yet. The in-band noise falls as $M^{-(2p+1)}$.
:::
:::

::: check
given: S = 60 | 85 | 110
answer: (S - 1.76)/6.02
tolerance: 0.5%

## A converter achieves {S} dB SNR. What's its effective number of bits?

::: right
Right. (SNR − 1.76)/6.02 = {answer} bits.
:::

::: misses
- [S/6.02] Subtract the 1.76 dB first.
- [any] Not yet. Invert SNR = 6.02B + 1.76.
:::
:::

::: check
given: p = 1 | 2; w = 0.01 | 0.05 | 0.3
answer: 20*p*log(2*sin(w/2))
unit: dB
tolerance: 0.05

## By how much does order-{p} shaping change the noise density at ω = {w} rad?

::: right
Right. $|2\sin(\omega/2)|^{2p}$ in dB: {answer} dB.
:::

::: misses
- [10*p*log(2*sin(w/2))] The power response is the magnitude squared: 20p log.
- [any] Not yet. The NTF is $(1 - z^{-1})^p$.
:::
:::

::: check
kind: parts
given: B = 1 | 4 | 16; M = 4 | 16 | 64; p = 1 | 2 | 3

## A {B}-bit quantizer is oversampled by {M} with order-{p} noise shaping.

::: part
answer: 6.02*B + 1.76 - 10*log(pi^(2*p)/(2*p + 1)) + (2*p + 1)*10*log(M)
unit: dB
tolerance: 0.5%

### What in-band SNR does it give?

::: misses
- [6.02*B + 1.76 + 10*log(M)] That's without shaping.
- [any] $6.02B + 1.76 - 10\log\frac{\pi^{2p}}{2p + 1} + (2p + 1)10\log M$.
:::
:::

::: part
answer: (6.02*B + 1.76 - 10*log(pi^(2*p)/(2*p + 1)) + (2*p + 1)*10*log(M) - 1.76)/6.02
unit: bits
tolerance: 0.5%

### How many effective bits is that?

::: misses
- [any] (SNR − 1.76)/6.02.
:::
:::
:::

::: check
kind: derivation
vars: B = 1..24, M = 2..256, p = 1..4

## A B-bit quantizer is oversampled by M with order-p shaping.

::: step
answer: 6.02*B + 1.76 + 10*log(M)

### What is the SNR with oversampling alone?
:::

::: step
answer: 6.02*B + 1.76 - 10*log(pi^(2*p)/(2*p + 1)) + (2*p + 1)*10*log(M)

### What is it with the shaping?
:::

::: step
answer: (2*p + 1)*3.0103

### How many decibels does each doubling of M add with shaping?
:::

::: right
Right. Shaping turns the 3 dB per octave of plain oversampling into 6p + 3.
:::
:::

::: explain
## How can a one-bit quantizer produce a 14-bit-accurate signal?

::: model
A one-bit quantizer's error is huge on every sample, but the error is only a problem if it lands in the frequency band that's kept. Running the converter many times faster than the signal needs spreads the error over a much wider band, and wrapping the quantizer in a feedback loop that integrates the error shapes it further: the loop keeps the running average of the output close to the input, so the error is pushed toward high frequencies, where it changes rapidly from sample to sample. A digital lowpass filter then removes nearly all of that high-frequency error and lowers the sample rate, and the averaged output carries many more bits of accuracy than any single sample did. The resolution comes from time and averaging rather than from fine voltage steps.
:::
:::

::: practice

::: check
given: B = 1 | 8; M = 32 | 128
answer: 6.02*B + 1.76 + 10*log(M)
unit: dB
tolerance: 0.05

## Unshaped SNR: {B} bits, ×{M}?

::: misses
- [any] $6.02B + 1.76 + 10\log M$.
:::
:::

::: check
given: B = 1 | 3; M = 32 | 256
answer: 6.02*B + 1.76 - 10*log(pi^2/3) + 30*log(M)
unit: dB
tolerance: 0.05

## First-order shaped SNR: {B} bits, ×{M}?

::: misses
- [any] $6.02B + 1.76 - 5.17 + 30\log M$.
:::
:::

::: check
given: S = 62 | 70 | 80 | 86 | 96 | 104
answer: (S - 1.76)/6.02
tolerance: 0.5%

## ENOB at {S} dB?

::: misses
- [any] (SNR − 1.76)/6.02.
:::
:::
:::
