---
title: ARQ and link throughput
heading: Frame errors, stop-and-wait, go-back-N and selective repeat, window sizes, frame length and hybrid ARQ
eyebrow: S8 · Lesson 40 · ARQ and link throughput
xp: 50
---

::: hook
Forward error correction leaves some residual errors, and most data must arrive perfectly. Links therefore add a cyclic redundancy check to every frame and ask for a retransmission when it fails: automatic repeat request. How much of the raw bit rate survives depends on the frame error rate, on how long the link takes to say "resend" compared with how long a frame takes to send, and on how many frames may be in flight at once. On a satellite hop, a naive protocol can waste 99.8% of the channel.
:::

::: play
- The curve is a link's efficiency against frame length when each frame carries a fixed H-bit header and bits err independently with probability p: $(1 - H/L)(1 - p)^L$.
- Short frames waste the header; long frames are too often lost. The best length is near $\sqrt{H/p}$ for small p.
- With a 48-bit header at p = 10⁻⁵, the best frames are about 2200 bits long and 95.7% efficient.
:::

```sim plot
view: graph
x: L = 100..100000 log
y: e = 0..100 %
slider: p = -7..-3 = -5
plot: 100*(1 - 48/L)*(1 - 10^p)^L | label: efficiency (H = 48 bits, p = 10^p)
```

::: predict
## A geostationary satellite link runs at 10 Mb/s with 1500-byte frames and a one-way delay of 250 ms. With stop-and-wait ARQ and no errors, what fraction of the channel carries data?

- [ ] About 50%
- [ ] About 10%
- [x] About 0.24%
- [ ] All of it

::: reveal
A frame takes 1.2 ms to send but 500 ms to be acknowledged, so a = 250/1.2 = 208 and the efficiency is 1/(1 + 2a) = 0.24%. Keeping the channel full needs 1 + 2a = 418 frames in flight: a sliding window that large, or a protocol designed for long delays.
:::
:::

::: nameit
## Frame errors

A frame of L bits with independent bit errors of probability p fails with probability $P = 1 - (1 - p)^L$. A CRC detects almost all of these (a 32-bit CRC misses about one in $2^{32}$ corrupted frames).

## Protocols

With a = $t_\text{prop}/t_\text{frame}$ (propagation delay over transmission time), ignoring acknowledgment and processing times:
- **Stop-and-wait**: send, wait for the acknowledgment, repeat: $\eta = \frac{1 - P}{1 + 2a}$.
- **Go-back-N** with window W ≥ 1 + 2a: on an error, resend that frame and all after it: $\eta = \frac{1 - P}{1 + 2aP}$.
- **Selective repeat** with W ≥ 1 + 2a: resend only the bad frames: $\eta = 1 - P$, but the receiver must buffer out-of-order frames.

A window smaller than 1 + 2a caps the efficiency at about W/(1 + 2a) even without errors.

## Frame length

With an H-bit header, the useful fraction is $(1 - H/L)(1 - p)^L$, maximized at
$$L^* = \frac{H + \sqrt{H^2 - 4H/\ln(1 - p)}}{2} \approx \sqrt{H/p}$$

## Hybrid ARQ

Instead of discarding a failed frame, **hybrid ARQ** keeps it: **chase combining** adds the retransmission's soft values, doubling the SNR (3 dB) with each copy; **incremental redundancy** sends extra parity bits instead, lowering the code rate step by step. Cellular systems (LTE, 5G) and Wi-Fi rely on it.
:::

::: example
## A terrestrial link has a = 0.5 and 12 000-bit frames with bit error probability 10⁻⁵. Compare the three protocols.

::: solution
1. **Frame error probability.**
   $$\begin{aligned} P &= 1 - (1 - 10^{-5})^{12\,000} \\ &= 0.113 \end{aligned}$$
2. **Stop-and-wait.**
   $$\frac{0.887}{2} = 44.3\%$$
3. **Go-back-N.**
   $$\frac{0.887}{1 + 0.113} = 79.7\%$$
4. **Selective repeat.**
   $$1 - P = 88.7\%$$
5. **What sets the loss.** Even with a short delay, waiting for each acknowledgment halves the throughput; once frames flow continuously, the error rate sets the remaining loss.

**Answer:** 44.3% for stop-and-wait, 79.7% for go-back-N and 88.7% for selective repeat.
:::
:::

::: example
## Frames carry a 48-bit header and see bit errors with probability 10⁻⁵. What frame length is best, and how much is lost with 1000- or 10 000-bit frames?

::: solution
1. **Best length.**
   $$\begin{aligned} L^* &= \frac{48 + \sqrt{48^2 + 4 \times 48/10^{-5}}}{2} \\ &\approx 2215\ \text{bits} \end{aligned}$$
2. **Efficiency there.**
   $$\begin{aligned} \eta &= \left(1 - \frac{48}{2215}\right)(1 - 10^{-5})^{2215} \\ &= 95.7\% \end{aligned}$$
3. **1000-bit frames.** The header costs more: 94.3%.
4. **10 000-bit frames.** Too many frames fail: 90.0%.
5. **A broad optimum.** The optimum is broad, so protocols pick a convenient size near it.

**Answer:** about 2215 bits, for 95.7%; 1000-bit frames give 94.3% and 10 000-bit frames 90.0%.
:::
:::

::: example
## A hybrid-ARQ receiver chase-combines up to four copies of a frame. How much SNR does each extra copy add?

::: solution
1. **Combining k copies.** The k copies' signal amplitudes add coherently, k² times the power, while their independent noise adds only k times the noise power, so the SNR grows k-fold.
2. **Two, three and four copies.**
   $$\begin{aligned} 10\log 2 &= 3.0\ \text{dB} \\ 10\log 3 &= 4.8\ \text{dB} \\ 10\log 4 &= 6.0\ \text{dB} \end{aligned}$$
3. **In practice.** A frame that failed at 2 dB below the decoder's threshold usually succeeds on the first retransmission.

**Answer:** the SNR grows k-fold: 3.0 dB with two copies, 4.8 dB with three and 6.0 dB with four.
:::
:::

::: check
kind: parts
given: p = 1e-6 | 1e-5 | 1e-4; L = 1000 | 12000

## Frames of {L} bits see independent bit errors with probability {p}.

::: part
answer: 1 - (1 - p)^L
tolerance: 1%

### What is the frame error probability?

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

::: part
answer: (1 - p)^L*100
unit: %
tolerance: 0.5%

### What fraction of frames gets through first time?

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

::: check
kind: parts
given: R = 1 | 10 | 100; B = 1500 | 9000; d = 0.25 | 5 | 250

## A {R} Mb/s link sends {B}-byte frames over a one-way propagation delay of {d} ms.

::: part
answer: d*1e-3/(B*8/(R*1e6))
tolerance: 0.5%

### What is a?

::: misses
- [any] Propagation delay over frame time.
:::
:::

::: part
answer: 1 + 2*d*1e-3/(B*8/(R*1e6))
unit: frames
tolerance: 0.5%

### How many frames must be in flight to keep the channel full?

::: misses
- [any] 1 + 2a.
:::
:::
:::

::: check
kind: parts
given: P = 0.01 | 0.1 | 0.3; a = 0.5 | 5 | 50

## A link has frame error probability {P} and a = {a}, with windows large enough for go-back-N and selective repeat.

::: part
answer: (1 - P)/(1 + 2*a)*100
unit: %
tolerance: 0.5%

### What efficiency does stop-and-wait give?

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

::: part
answer: (1 - P)/(1 + 2*a*P)*100
unit: %
tolerance: 0.5%

### And go-back-N?

::: misses
- [(1 - P)*100] That's selective repeat.
- [any] $(1 - P)/(1 + 2aP)$.
:::
:::
:::

::: check
kind: parts
given: H = 32 | 48 | 160; p = 1e-6 | 1e-5 | 1e-4

## Frames carry an {H}-bit header; bits err with probability {p}.

::: part
answer: (H + sqrt(H^2 - 4*H/ln(1 - p)))/2
unit: bits
tolerance: 0.5%

### What frame length is best?

::: misses
- [any] $L^* = \frac{H + \sqrt{H^2 - 4H/\ln(1 - p)}}{2}$.
:::
:::

::: part
answer: (1 - H/((H + sqrt(H^2 - 4*H/ln(1 - p)))/2))*(1 - p)^((H + sqrt(H^2 - 4*H/ln(1 - p)))/2)*100
unit: %
tolerance: 0.5%

### What efficiency does it reach?

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

::: check
kind: parts
given: k = 2 | 3 | 4 | 8; S = -2 | 1

## A hybrid-ARQ receiver chase-combines {k} copies, each received at {S} dB SNR.

::: part
answer: S + 10*log(k)
unit: dB
tolerance: 0.5%

### What SNR does the combination reach?

::: misses
- [S + 20*log(k)] Combining k noisy copies multiplies SNR by k, not k².
- [any] $S + 10\log_{10}k$.
:::
:::
:::

::: check
kind: parts
given: W = 8 | 64 | 1024; a = 10 | 200

## A sliding-window protocol has a window of {W} frames on a link with a = {a}, and no errors.

::: part
answer: W/(1 + 2*a)*100*step(1 + 2*a - W) + 100*step(W - 1 - 2*a)
unit: %
tolerance: 0.5%

### What efficiency can it reach?

::: misses
- [any] W/(1 + 2a), capped at 100%.
:::
:::
:::

::: check
kind: choice

## Why does selective repeat beat go-back-N on a long-delay link with occasional errors?

- [ ] It uses a shorter CRC
- [x] When a frame fails, go-back-N resends it and every frame sent after it, about 2a extra frames per error; selective repeat resends only the bad frame, at the cost of the receiver buffering frames that arrive out of order
- [ ] It doesn't need acknowledgments
- [ ] It sends frames more slowly

::: misses
- [1] Both use the same error detection.
- [3] Both need acknowledgments, selective ones in fact.
- [4] Both keep the channel full when their windows are large enough.
:::
:::

::: check
kind: derivation
vars: p = 1e-8..1e-3, L = 100..100000, a = 0.01..1000, H = 8..400

## Frames of L bits (H of them header) see bit errors with probability p; a = propagation over frame time.

::: step
answer: 1 - (1 - p)^L

### What is the frame error probability P?
:::

::: step
answer: (1 - p)^L/(1 + 2*a*(1 - (1 - p)^L))

### What is go-back-N's efficiency (ignoring the header)?
:::

::: step
answer: (1 - H/L)*(1 - p)^L

### What useful fraction does selective repeat leave after the header?
:::

::: right
Right. Errors, delay and headers each take their own bite, and they multiply.
:::
:::

::: check
kind: python

## Write `efficiency(protocol, P, a)` for 'sw', 'gbn' and 'sr', and `best_frame(H, p)`: the integer frame length maximizing $(1 - H/L)(1 - p)^L$, checking the integers around the closed form.

```python starter
def efficiency(protocol, P, a):
    return 1.0

def best_frame(H, p):
    return H + 1
```

```python solution
import math

def efficiency(protocol, P, a):
    if protocol == 'sw':
        return (1 - P) / (1 + 2 * a)
    if protocol == 'gbn':
        return (1 - P) / (1 + 2 * a * P)
    return 1 - P

def best_frame(H, p):
    f = lambda L: (1 - H / L) * (1 - p) ** L
    L0 = (H + math.sqrt(H * H - 4 * H / math.log(1 - p))) / 2
    return max((int(L0) + d for d in (-2, -1, 0, 1, 2)), key=f)
```

```python tests
P = 1 - (1 - 1e-5) ** 12000
assert abs(efficiency('sw', P, 0.5) - 0.4435) < 1e-4 and abs(efficiency('gbn', P, 0.5) - 0.7968) < 1e-4 and abs(efficiency('sr', P, 0.5) - 0.8869) < 1e-4, "The worked example: 44.3%, 79.7%, 88.7%."
L = best_frame(48, 1e-5)
assert abs(L - 2215) <= 1, "Best frame for a 48-bit header at 10⁻⁵: about 2215 bits."
f = lambda L: (1 - 48 / L) * (1 - 1e-5) ** L
assert f(L) >= f(L - 50) and f(L) >= f(L + 50), "It's a maximum."
```

::: right
Right. The closed form comes from setting the derivative of the log efficiency to zero.
:::
:::

::: explain
## Why does stop-and-wait ARQ perform so badly on a satellite link, and what fixes it?

::: model
With stop-and-wait, the sender transmits one frame and then sits idle until its acknowledgment comes back, a full round trip later. On a geostationary satellite the round trip is about half a second, while a frame at megabits per second takes only a millisecond or so to send, so the channel is busy for a tiny fraction of the time. The fix is to keep sending while waiting: a sliding window lets many frames be in flight, and with a window of at least one plus twice the ratio of delay to frame time, the channel stays full. Errors are then handled by resending only the affected frames, which keeps efficiency close to the fraction of frames that arrive intact.
:::
:::

::: practice
::: check
given: p = 1e-5 | 1e-4; L = 4000 | 16000
answer: 1 - (1 - p)^L
tolerance: 1%

## Frame error probability for {L} bits at p = {p}?

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

::: check
given: P = 0.05 | 0.2; a = 1 | 20
answer: (1 - P)/(1 + 2*a*P)*100
unit: %
tolerance: 0.5%

## Go-back-N efficiency at P = {P}, a = {a}?

::: misses
- [any] $(1 - P)/(1 + 2aP)$.
:::
:::

::: check
given: H = 40 | 100; p = 1e-6 | 1e-4
answer: (H + sqrt(H^2 - 4*H/ln(1 - p)))/2
unit: bits
tolerance: 0.5%

## Best frame length, {H}-bit header, p = {p}?

::: misses
- [any] $(H + \sqrt{H^2 - 4H/\ln(1 - p)})/2$.
:::
:::
:::
