---
title: Finite word-length effects
heading: Fixed-point numbers, the additive model of roundoff noise, noise gain through a filter, scaling against overflow, and zero-input limit cycles
eyebrow: S7 · Lesson 18 · Finite word-length effects
xp: 50
---

::: hook
A filter designed in floating point runs on a processor with 16 or 24 bits, and every multiplication has to be rounded back to that width. Each rounding injects a tiny error that the filter then processes like signal: a recursive filter with poles near the unit circle amplifies it, sometimes by tens of decibels. Overflow is worse, since a sum that wraps around turns a small signal into a full-scale one. And with no input at all, rounding can keep a recursive filter humming forever in a limit cycle. This lesson puts numbers on all three so a design can be checked before it's coded.
:::

::: play
- The **noise gain** $\sum h^2[n]$ of a two-pole resonator $1/(1 - 2r\cos\theta\,z^{-1} + r^2z^{-2})$, in dB, against the pole angle θ: how much the filter amplifies roundoff noise injected at its input.
- Poles near the unit circle (r → 1) raise it sharply; so do poles near θ = 0 or π, where the two poles crowd together.
- A narrowband lowpass with r = 0.99 and θ = 0.3 multiplies the roundoff noise power by 290, nearly 25 dB.
:::
:::

```sim plot
view: graph
x: t = 0.05..3.09
y: G = 0..60 dB
slider: r = 0.5..0.995 = 0.95
plot: 10*log((1 + r^2)/((1 - r^2)*((1 + r^2)^2 - 4*r^2*cos(t)^2))) | samples: 600 | label: noise gain, dB
```

::: predict
## A first-order recursive filter y[n] = 0.99y[n − 1] + x[n] runs in 16-bit fixed point with rounding after the multiply. Roughly how much louder is the roundoff noise at its output than the noise of one rounding?

- [ ] The same
- [ ] Twice as large
- [x] About 50 times the power, 17 dB
- [ ] 100 times the power

::: reveal
The rounding error enters at the filter's input node, so it's shaped by the whole impulse response $0.99^n$, and its variance is multiplied by $\sum 0.99^{2n} = 1/(1 - 0.9801)$ = 50.3, or 17.0 dB. The narrower the filter, the closer its pole to the unit circle and the larger this noise gain.
:::
:::

::: nameit
## Fixed point and rounding

A (B + 1)-bit two's-complement fraction covers [−1, 1) in steps of $\Delta = 2^{-B}$. Rounding a product to that grid adds an error e[n] modeled as white noise, uniform on $[-\Delta/2, \Delta/2]$:

$$\sigma_e^2 = \frac{\Delta^2}{12} = \frac{2^{-2B}}{12}$$

which for B = 15 is −101.1 dB relative to 1.

## Noise through a filter

A noise source injected at a node whose path to the output has impulse response g[n] produces output noise power

$$\sigma_f^2 = \sigma_e^2\sum_n g^2[n]$$

For a first-order pole a, $\sum g^2 = \frac{1}{1 - a^2}$. For the resonator above, $\frac{1 + r^2}{(1 - r^2)\left[(1 + r^2)^2 - 4r^2\cos^2\theta\right]}$. Every multiplier rounded separately adds its own source; in direct form I they all enter at one node.

## Overflow and scaling

To guarantee no overflow with |x[n]| ≤ 1, scale the input by $1/\sum|h[n]|$ (the L1 norm, safe but pessimistic); for sinusoidal inputs, $1/\max|H(e^{j\omega})|$ suffices. Scaling down raises the relative noise, so it trades overflow against SNR. **Saturation** arithmetic clips instead of wrapping and prevents the large-scale **overflow oscillations** that wrap-around can sustain.

## Limit cycles

With rounding, a first-order filter $y[n] = Q(ay[n - 1])$ can get stuck at a nonzero value with no input: any |y| inside the **dead band**

$$|y| \le \frac{\Delta/2}{1 - |a|}$$

rounds back to itself (a > 0) or alternates in sign (a < 0). For a = 0.9 that's up to 5 LSBs of steady output from a filter that should have decayed to zero.
:::

::: example
## A 16-bit (B = 15) filter with a pole at 0.99 has one rounding point at its input. What's the output noise, in dB relative to full scale, and in LSBs rms?

::: solution
1. **Rounding noise.**
   $$\sigma_e^2 = \frac{2^{-30}}{12}$$
   which is −101.1 dB.
2. **Noise gain.**
   $$\begin{aligned} G &= \frac{1}{1 - 0.9801} \\ &= 50.3 \end{aligned}$$
   which is +17.0 dB.
3. **Output noise.**
   $$-101.1 + 17.0 = -84.1\ \text{dB}$$
   re 1.
4. **In LSBs.**
   $$\begin{aligned} \sigma &= \sqrt{50.3/12} \\ &= 2.05\ \text{LSB rms} \end{aligned}$$
   so the bottom bit of the output is pure noise.

**Answer:** −84.1 dB relative to full scale, or 2.05 LSB rms.
:::
:::

::: example
## The same filter must never overflow for inputs bounded by 1. How much must the input be scaled, and what does that do to the SNR?

::: solution
1. **Worst-case gain.**
   $$\begin{aligned} \sum|h[n]| &= \sum 0.99^n \\ &= 100 \end{aligned}$$
2. **Scale the input.** The input must be multiplied by 0.01, a 40 dB reduction in signal while the roundoff noise stays put: the SNR drops by 40 dB.
3. **Sinusoidal inputs.** For sinusoidal inputs the peak gain $|H(1)|$ = 100 gives the same factor here; for wideband filters the two scalings differ.

**Answer:** the input must be scaled by 0.01, which costs 40 dB of SNR.
:::
:::

::: example
## A resonator with poles at $0.95e^{\pm j\pi/3}$ rounds once at its input. What is its noise gain, and its output noise in LSBs rms?

::: solution
1. **Noise-gain formula.**
   $$G = \frac{1 + r^2}{(1 - r^2)[(1 + r^2)^2 - 4r^2\cos^2\theta]}$$
2. **Put in r = 0.95 and θ = π/3.**
   $$\begin{aligned} G &= \frac{1.9025}{0.0975 \times (3.6195 - 0.9025)} \\ &= 7.18 \end{aligned}$$
   or 8.6 dB.
3. **Output noise.** Rounding noise of 1/12 LSB² becomes
   $$\begin{aligned} \sigma^2 &= \frac{7.18}{12}\ \text{LSB}^2 \\ &= 0.60\ \text{LSB}^2 \end{aligned}$$
   which is 0.77 LSB rms.
4. **Closer poles.** Moving the poles closer to the circle raises the gain roughly as $1/(1 - r)$, so narrow resonators need more bits.

**Answer:** a noise gain of 7.18 (8.6 dB), giving 0.77 LSB rms at the output.
:::
:::

::: check
given: B = 7 | 11 | 15 | 23
answer: 10*log(2^(-2*B)/12)
unit: dB
tolerance: 0.05

## Products are rounded to B = {B} fractional bits. What's the roundoff noise power in dB relative to 1?

::: right
Right. $10\log(2^{-2B}/12)$ = {answer} dB.
:::

::: misses
- [10*log(2^(-2*B))] Include the 1/12 of a uniform distribution's variance.
- [any] Not yet. $\sigma_e^2 = \Delta^2/12$ with $\Delta = 2^{-B}$.
:::
:::

::: check
given: a = 0.5 | 0.9 | 0.98 | -0.95
answer: 10*log(1/(1 - a^2))
unit: dB
tolerance: 0.05

## Roundoff noise enters a first-order recursive filter with its pole at {a}. By how much is it amplified?

::: right
Right. $\sum a^{2n} = 1/(1 - a^2)$: {answer} dB.
:::

::: misses
- [20*log(1/(1 - abs(a)))] That's the peak gain for a signal; noise power gain sums the squared impulse response.
- [any] Not yet. Noise gain = $\sum h^2[n]$.
:::
:::

::: check
given: r = 0.9 | 0.97; t = 0.4 | 1.5 | 2.8
answer: 10*log((1 + r^2)/((1 - r^2)*((1 + r^2)^2 - 4*r^2*cos(t)^2)))
unit: dB
tolerance: 0.05

## What's the noise gain of the resonator with poles at {r}e^{±j{t}}?

::: right
Right. {answer} dB.
:::

::: misses
- [any] Not yet. $\frac{1 + r^2}{(1 - r^2)[(1 + r^2)^2 - 4r^2\cos^2\theta]}$.
:::
:::

::: check
given: a = 0.8 | 0.95 | 0.99
answer: sqrt(1/(12*(1 - a^2)))
tolerance: 0.5%

## A filter with pole {a} rounds once at its input. What's the output roundoff noise in LSBs rms?

::: right
Right. $\sqrt{\frac{1}{12}\cdot\frac{1}{1 - a^2}}$ = {answer} LSB.
:::

::: misses
- [sqrt(1/12)] That's one rounding's noise; it's amplified by the filter.
- [any] Not yet. One LSB of step has variance 1/12, times the noise gain.
:::
:::

::: check
given: a = 0.6 | 0.9 | -0.95
answer: 1 - abs(a)
tolerance: 0.5%

## To make overflow impossible for any input bounded by 1, by what factor must the input of the filter with pole {a} be scaled?

::: right
Right. $1/\sum|h| = 1 - |a|$ = {answer}.
:::

::: misses
- [sqrt(1 - a^2)] That's an energy (L2) scaling, which doesn't guarantee no overflow.
- [any] Not yet. Divide by the L1 norm of h.
:::
:::

::: check
given: a = 0.75 | 0.9 | 0.95
answer: 0.5/(1 - a)
tolerance: 0.5%

## A first-order filter with pole {a} rounds after the multiply. How large (in LSBs) can a zero-input limit cycle be?

::: right
Right. Up to $\frac{1/2}{1 - |a|}$ = {answer} LSB.
:::

::: misses
- [0.5] The dead band is wider than half an LSB by the factor 1/(1 − |a|).
- [any] Not yet. Solve $|Q(ay)| = |y|$ for the largest y.
:::
:::

::: check
kind: parts
given: B = 7 | 15 | 23; a = 0.5 | 0.9 | 0.99

## A filter with a pole at {a} rounds once at its input, with B = {B} fractional bits.

::: part
answer: 10*log(2^(-2*B)/12/(1 - a^2))
unit: dB
tolerance: 0.5%

### What is the output noise power relative to full scale?

::: misses
- [10*log(2^(-2*B)/12)] Include the noise gain $1/(1 - a^2)$.
- [any] $10\log_{10}\left(\frac{2^{-2B}}{12}\cdot\frac{1}{1 - a^2}\right)$.
:::
:::

::: part
answer: 0.5/(1 - a)
unit: LSB
tolerance: 0.5%

### How large can a zero-input limit cycle be?

::: misses
- [any] $(\Delta/2)/(1 - |a|)$.
:::
:::
:::

::: check
kind: derivation
vars: B = 4..31, a = -0.99..0.99

## A first-order filter with pole a rounds to B fractional bits once per sample.

::: step
answer: 2^(-2*B)/12

### What is the rounding noise power?
:::

::: step
answer: 2^(-2*B)/12/(1 - a^2)

### What output noise power results?
:::

::: step
answer: 1 - abs(a)

### By what factor must inputs bounded by 1 be scaled so the output can never overflow?
:::

::: right
Right. A pole near the circle raises both the noise gain and the required scaling: narrowband filters need extra bits twice over.
:::
:::

::: explain
## Why does rounding make a recursive filter able to oscillate forever with no input, when the ideal filter decays to zero?

::: model
In exact arithmetic a stable recursive filter shrinks its stored value by the factor |a| each step, so with no input it decays toward zero. With rounding, each new value is snapped to the nearest representable level. Once the value is small, multiplying by a reduces it by less than half a step, and rounding snaps it straight back to where it was, so it never gets smaller. The filter sits at a constant nonzero output, or, with a negative coefficient, flips sign every sample. The range of values where this happens is the dead band, wider for poles closer to the unit circle. Larger word lengths shrink it in absolute terms, and techniques like magnitude truncation or dithering eliminate it.
:::
:::

::: practice

::: check
given: B = 8 | 9 | 10 | 12 | 13 | 16
answer: 10*log(2^(-2*B)/12)
unit: dB
tolerance: 0.05

## Roundoff noise for B = {B}, in dB?

::: misses
- [any] $10\log(2^{-2B}/12)$.
:::
:::

::: check
given: a = 0.5 | 0.7 | 0.9 | 0.95 | 0.99 | 0.995
answer: 10*log(1/(1 - a^2))
unit: dB
tolerance: 0.05

## Noise gain of a pole at {a}?

::: misses
- [any] $1/(1 - a^2)$.
:::
:::

::: check
given: a = 0.75 | 0.8 | 0.9 | 0.95 | 0.98 | 0.99
answer: 0.5/(1 - a)
tolerance: 0.5%

## Dead-band limit for a pole at {a}, in LSBs?

::: misses
- [any] $0.5/(1 - |a|)$.
:::
:::
:::
