---
title: Mutual information and channel capacity
heading: How much a channel's output says about its input, mutual information, the capacity of the binary symmetric and erasure channels, hard-decision demodulation, and the channel coding theorem
eyebrow: S8 · Lesson 31 · Mutual information and channel capacity
xp: 50
---

::: hook
Lesson 21 gave the capacity of the continuous Gaussian channel. Many channels are better seen as discrete: a demodulator that outputs hard 0/1 decisions turns the analog channel into a binary one that occasionally flips bits; a packet network either delivers a symbol or loses it. Shannon's framework handles all of them the same way. The mutual information between input and output measures how much each channel use actually conveys, its maximum over input distributions is the capacity, and the channel coding theorem promises that any rate below it can be sent with as few errors as desired.
:::

::: play
- The capacity of a binary symmetric channel that flips each bit with probability p, $C = 1 - H(p)$, and of a binary erasure channel that loses each bit with probability ε, $C = 1 - \varepsilon$, in bits per channel use.
- A BSC that flips 11% of its bits can still carry half a bit per use, error-free in principle, with a good enough code.
- An erasure is less harmful than a flip: the receiver knows which bits it lost. At p = ε = 0.11 the erasure channel carries 0.89 bits per use against the BSC's 0.5.
:::
:::

```sim plot
view: graph
x: p = 0.001..0.5
y: C = 0..1.05
plot: 1 + p*log(p)/log(2) + (1 - p)*log(1 - p)/log(2) | samples: 600 | label: binary symmetric channel, 1 − H(p)
plot: 1 - p | samples: 200 | dashed | color: ch2 | label: binary erasure channel, 1 − ε
```

::: predict
## BPSK at Es/N0 = 0 dB is demodulated with hard decisions. How many bits can each symbol carry, at most?

- [ ] 1
- [x] About 0.60
- [ ] About 0.92
- [ ] 0, since the SNR is 0 dB

::: reveal
Hard decisions turn the channel into a BSC with crossover $p = Q(\sqrt{2E_s/N_0}) = Q(1.414)$ = 0.079, whose capacity is $1 - H(0.079)$ = 0.60 bits per symbol. Keeping soft information, the demodulator's real-valued outputs, would allow about 0.72; throwing it away costs about 2 dB at low rates, which is why modern decoders use soft decisions.
:::
:::

::: nameit
## Mutual information

For input X and output Y,

$$I(X;Y) = H(Y) - H(Y|X) = H(X) - H(X|Y)$$

the reduction in uncertainty about one from observing the other. It depends on the channel and on the input distribution.

## Capacity

$$C = \max_{p(x)}I(X;Y)\text{ bits per channel use}$$

times the symbol rate for bits per second.

- **Binary symmetric channel** (each bit flipped with probability p): with uniform input, $C = 1 - H(p)$. Zero at p = ½.
- **Binary erasure channel** (each bit lost, and known to be lost, with probability ε): $C = 1 - \varepsilon$.
- With a non-uniform input $P(X = 1) = q$ on a BSC, $I = H\big(q(1 - p) + (1 - q)p\big) - H(p)$, less than capacity.

## Hard decisions

A binary modulation with hard decisions becomes a BSC with p equal to the demodulator's bit error probability, for BPSK $Q(\sqrt{2E_s/N_0})$. Hard decisions lose about 2 dB against soft decisions at low SNR.

## The channel coding theorem

For any rate R < C there are codes whose error probability goes to zero as the block length grows; for R > C the error probability can't. Coding theory (lessons 34 to 36) is the search for codes that get close to C with practical decoders.
:::

::: example
## A BSC flips 11% of its bits. What's its capacity, and what rate could a code run at?

::: solution
1. **Capacity.**
   $$\begin{aligned} C &= 1 - H(0.11) \\ &= 1 - 0.4999 \\ &= 0.500\ \text{bits per use} \end{aligned}$$
2. **Code rate.** A rate-1/2 code is right at the limit; a practical code at this crossover would run at about rate 0.4 to leave a margin.

**Answer:** the capacity is 0.500 bits per use, and a practical code would run at about rate 0.4.
:::
:::

::: example
## On a BSC with p = 0.1, what mutual information does an input with P(1) = 0.3 achieve, compared with capacity?

::: solution
1. **Output probability.**
   $$\begin{aligned} P(Y = 1) &= 0.3(0.9) + 0.7(0.1) \\ &= 0.34 \end{aligned}$$
2. **Output entropy.**
   $$\begin{aligned} H(Y) &= H(0.34) \\ &= 0.925 \end{aligned}$$
3. **Mutual information.** With $H(Y|X) = H(0.1) = 0.469$:
   $$\begin{aligned} I &= 0.925 - 0.469 \\ &= 0.456\ \text{bits} \end{aligned}$$
4. **Capacity.** With a uniform input,
   $$\begin{aligned} C &= 1 - 0.469 \\ &= 0.531\ \text{bits} \end{aligned}$$
   The biased input wastes 0.075 bits per use.

**Answer:** the input achieves 0.456 bits per use, against a capacity of 0.531.
:::
:::

::: example
## A rate-½ code runs over BPSK at Eb/N0 = 4 dB with hard decisions. Is reliable communication possible?

::: solution
1. **Energy per coded bit.** Each coded bit has $E_s = E_b/2$:
   $$\begin{aligned} E_s/N_0 &= 1\ \text{dB} \\ &= 1.26 \end{aligned}$$
2. **Crossover probability.** Hard decisions flip a bit with probability
   $$\begin{aligned} p &= Q(\sqrt{2 \times 1.26}) \\ &= 0.056 \end{aligned}$$
3. **Capacity of that BSC.**
   $$\begin{aligned} C &= 1 - H(0.056) \\ &= 0.69\ \text{bit per use} \end{aligned}$$
4. **Compare the rate.** Rate ½ is below that, so yes, though a code working with hard decisions at 0.69 capacity is demanding; soft decisions would leave more room.

**Answer:** yes: hard decisions leave a channel of capacity 0.69 bit per use, above the code's rate of ½.
:::
:::

::: check
given: p = 0.01 | 0.05 | 0.11 | 0.2
answer: 1 + (p*log(p) + (1 - p)*log(1 - p))/log(2)
tolerance: 0.5%

## A binary symmetric channel flips bits with probability {p}. What's its capacity, in bits per use?

::: right
Right. $1 - H(p)$ = {answer}.
:::

::: misses
- [1 - p] That's the erasure channel; flips are harder to deal with.
- [any] Not yet. $C = 1 - H(p)$.
:::
:::

::: check
given: e = 0.05 | 0.2 | 0.5
answer: 1 - e
tolerance: 0.5%

## A binary erasure channel loses {e} of its bits (and flags them). What's its capacity?

::: right
Right. $1 - \varepsilon$ = {answer} bits per use.
:::

::: misses
- [1 + (e*log(e) + (1 - e)*log(1 - e))/log(2)] That's the BSC formula; an erasure is known, so it only costs the lost fraction.
- [any] Not yet. Only the erased fraction is lost.
:::
:::

::: check
given: E = -3 | 0 | 3 | 6
answer: 1 + (Q(sqrt(2*10^(E/10)))*log(Q(sqrt(2*10^(E/10)))) + (1 - Q(sqrt(2*10^(E/10))))*log(1 - Q(sqrt(2*10^(E/10)))))/log(2)
tolerance: 0.5%

## BPSK at Es/N0 = {E} dB is demodulated with hard decisions. What's the resulting channel's capacity, in bits per symbol?

::: right
Right. A BSC with $p = Q(\sqrt{2E_s/N_0})$: {answer}.
:::

::: misses
- [any] Not yet. Find p, then $1 - H(p)$.
:::
:::

::: check
given: p = 0.02 | 0.1; R = 1 | 10 | 100
answer: R*(1 + (p*log(p) + (1 - p)*log(1 - p))/log(2))
unit: Mb/s
tolerance: 0.5%

## A BSC with p = {p} is used {R} million times a second. What's its capacity in bits per second?

::: right
Right. $R_s(1 - H(p))$ = {answer} Mb/s.
:::

::: misses
- [R*(1 - p)] Use 1 − H(p), not 1 − p, for flipped bits.
- [any] Not yet. Capacity per use times uses per second.
:::
:::

::: check
given: q = 0.2 | 0.3 | 0.4; p = 0.05 | 0.1
answer: -((q*(1 - p) + (1 - q)*p)*log(q*(1 - p) + (1 - q)*p) + (1 - (q*(1 - p) + (1 - q)*p))*log(1 - (q*(1 - p) + (1 - q)*p)))/log(2) + (p*log(p) + (1 - p)*log(1 - p))/log(2)
tolerance: 0.5%

## A BSC with p = {p} is driven with P(X = 1) = {q}. What's the mutual information between input and output?

::: right
Right. $H(Y) - H(p)$ = {answer} bits.
:::

::: misses
- [1 + (p*log(p) + (1 - p)*log(1 - p))/log(2)] That's capacity, reached only with a uniform input.
- [any] Not yet. P(Y = 1) = q(1 − p) + (1 − q)p, then H(Y) − H(Y|X).
:::
:::

::: check
given: p = 0.03 | 0.08 | 0.15
answer: 1 + (p*log(p) + (1 - p)*log(1 - p))/log(2)
tolerance: 0.5%

## What's the highest code rate that can work reliably on a BSC with p = {p}?

::: right
Right. Any rate below C = {answer} can be made reliable.
:::

::: misses
- [1 - 2*p] Rates follow from capacity, $1 - H(p)$.
- [any] Not yet. The coding theorem's limit is C.
:::
:::

::: check
kind: parts
given: E = -2 | 1 | 4 | 7

## BPSK at Es/N0 = {E} dB is demodulated with hard decisions.

::: part
answer: Q(sqrt(2*10^(E/10)))
tolerance: 1%

### What crossover probability does the resulting BSC have?

::: misses
- [any] $Q(\sqrt{2E_s/N_0})$.
:::
:::

::: part
answer: 1 + Q(sqrt(2*10^(E/10)))*log(Q(sqrt(2*10^(E/10))))/log(2) + (1 - Q(sqrt(2*10^(E/10))))*log(1 - Q(sqrt(2*10^(E/10))))/log(2)
unit: bits
tolerance: 0.5%

### What is its capacity per use?

::: misses
- [any] $1 - H(p)$.
:::
:::
:::

::: check
kind: derivation
vars: p = 0.001..0.499, e = 0..1

## A BSC flips bits with probability p; a BEC erases them with probability e.

::: step
answer: 1 + p*log(p)/log(2) + (1 - p)*log(1 - p)/log(2)

### What is the BSC's capacity?
:::

::: step
answer: 1 - e

### What is the BEC's?
:::

::: right
Right. Knowing which bits were lost is worth a great deal: a 10% erasure channel keeps 0.9 bit, a 10% BSC only 0.53.
:::
:::

::: explain
## Why does an erasure cost less capacity than a bit flip of the same probability?

::: model
When a bit is erased, the receiver knows exactly which position it lost and that the other bits are correct, so the only missing information is the erased bits themselves: the channel delivers a fraction 1 − ε of the input intact. When bits are flipped, the receiver doesn't know which ones are wrong. To correct them, a code must spend extra redundancy identifying the error positions as well as their values, and that identification costs H(p) bits per use, more than p for any p below one half. The uncertainty about where the errors are is the expensive part, which is why demodulators that can flag unreliable symbols as erasures, or better still pass soft values, help decoders so much.
:::
:::

::: practice

::: check
given: p = 0.01 | 0.02 | 0.05 | 0.1 | 0.15 | 0.25
answer: 1 + (p*log(p) + (1 - p)*log(1 - p))/log(2)
tolerance: 0.5%

## BSC capacity at p = {p}?

::: misses
- [any] $1 - H(p)$.
:::
:::

::: check
given: e = 0.05 | 0.1 | 0.2 | 0.25 | 0.35 | 0.5
answer: 1 - e
tolerance: 0.5%

## BEC capacity at ε = {e}?

::: misses
- [any] $1 - \varepsilon$.
:::
:::

::: check
given: E = -3 | -1 | 0 | 2 | 4 | 6
answer: 1 + (Q(sqrt(2*10^(E/10)))*log(Q(sqrt(2*10^(E/10)))) + (1 - Q(sqrt(2*10^(E/10))))*log(1 - Q(sqrt(2*10^(E/10)))))/log(2)
tolerance: 0.5%

## Hard-decision BPSK capacity at Es/N0 {E} dB?

::: misses
- [any] $1 - H(Q(\sqrt{2E_s/N_0}))$.
:::
:::
:::
