Algorithmadvanced
Chow-Cioffi-Bingham algorithm
Also called Chow bit loading.
Fast DMT bit loading: compute real rates log2(1 + SNR/(Gamma margin)), round them, adjust the margin until the rounded total meets the target, then fix the last bits and scale the energies.
- Solves
- Bit loading
- Time
- O(N (K + F)) worst
- Space
- O(N) extra
- Where
- F = the number of bits moved by the fix-up; K = the number of margin rounds (at most MaxCount); N = the number of subcarriers
- Model
- Real RAM
- Properties
- deterministicheuristicneeds csitnot optimal
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Peter S. Chow, John M. Cioffi, John A. C. Bingham, 1995
The Chow-Cioffi-Bingham algorithm is a fast heuristic for bit loading in discrete multitone modems. It starts with unit energy on every subcarrier and computes a real rate for each, with the SNR gap and a margin that starts at 0 dB. It rounds the rates, compares their sum with the target, and changes the margin by dB, where is the number of subcarriers in use; this is about 3 dB per missing or extra bit per subcarrier. After a few rounds it fixes the remaining difference one bit at a time, using the rounding errors, and finally gives each used subcarrier the energy its bits need and scales all energies to the budget. Each round costs . The result meets the target exactly and gives every used subcarrier the same margin, but unlike the Hughes-Hartogs and Levin-Campello algorithms it is not optimal in general.
In plain words
A modem must place a fixed number of bits on its tones. The slow, exact method places the bits one at a time.
This method is faster. It first asks: with equal power on every tone and a given safety margin, how many bits could each tone carry? It rounds each answer to a whole number and adds them up. If the sum is too large, it asks for a bigger margin; if too small, a smaller one, and it repeats a few times. Then it fixes the last few bits by hand, picking the tones that were rounded the most. Last, it sets the power of each tone so that all used tones have the same safety margin.
The problem
This is the margin-adaptive form of bit loading: carry exactly bits with the total energy and the largest margin that is common to all used subcarriers. Subcarrier has at unit energy. Under the gap model, bits at the energy have the margin . The largest common margin is , where is the least energy for bits at margin 1, and the optimal algorithms reach it. This algorithm reaches a common margin that is usually close to it.
The algorithm
and are linear factors here; the paper writes the sum of the gap and the margin in dB.
CHOW-CIOFFI-BINGHAM(SNR[1..N], Γ, B_target, P, MaxCount) ▷ SNR_i at unit energy- 1
γ_dB ← 0, count ← 0 - 2
repeat: b_i ← log2(1 + SNR_i / (Γ · 10^(γ_dB/10))), b̂_i ← round(b_i), diff_i ← b_i - b̂_i - 3
B_total ← Σ b̂_i, U ← the number of i with b̂_i > 0 - 4
γ_dB ← γ_dB + 10 log10(2^((B_total - B_target)/U)), count ← count + 1 - 5
until B_total = B_target or count = MaxCount - 6
while B_total ≠ B_target: if B_total > B_target, take a bit from the i with b̂_i > 0 and the smallest diff_i (diff_i ← diff_i + 1); else add a bit to the i with the largest diff_i (diff_i ← diff_i - 1) - 7
e_i ← Γ (2^(b̂_i) - 1) / SNR_i for i = 1 .. N ▷ the energy for b̂_i bits at margin 1 - 8
scale every e_i by P / Σ_j e_j and return (b̂, e)
The test code uses . A channel that loads no bit in the first round is reported as unusable. With a cap , line L2 clips to it, and line L6 adds bits only below it.
Example
Take at unit energy, , , and the budget , one unit per subcarrier.
| round | margin before | real rates | rounded | margin step | |
|---|---|---|---|---|---|
| 1 | 0 dB | 4.392, 3.322, 2.585, 1.322 | (4, 3, 3, 1) | 11 | dB (3 extra bits over 4 carriers) |
| 2 | 2.258 dB | 3.688, 2.667, 1.990, 0.920 | (4, 3, 2, 1) | 10 | dB |
| 3 | 3.763 dB | 3.234, 2.258, 1.633, 0.706 | (3, 2, 2, 1) | 8 | stop |
The loading needs units at margin 1. Line L8 scales by , so the energies are and the common margin is , or 3.12 dB. The optimal loading needs , for a margin of 3.76 dB; the heuristic gives up 0.64 dB here.
With , the fix-up starts from round 1: with . It removes a bit from carrier 3, then from carrier 2 and carrier 4, whose rounding errors are equal, and reaches , which is optimal. More margin rounds are not always better.
Correctness
Claim. If the first round loads at least one bit, the algorithm stops, the output carries exactly bits, the energies add up to , and every used subcarrier has the same margin . This margin is at most the optimal margin , with equality when the rounded loading is optimal.
Key steps. The margin loop has at most rounds. Each fix-up step moves one bit toward the target, and a subcarrier to change always exists, so the fix-up takes exactly steps. Lines L7 and L8 make proportional to the energy that bits need at margin 1, so all used subcarriers get the same factor . Raising the margin by lowers each real rate by at most bits, and by almost exactly on strong subcarriers, which is why the step of line L4 aims at the target. The full proof is in the proofs folder.
Proof: The Chow-Cioffi-Bingham loading meets the bit target and the energy budget with one common marginfull
The algorithm is a heuristic, so its correctness is a statement about what its output satisfies, not about optimality. The input is , the SNR of subcarrier at unit energy, for ; the gap ; the target with (or without a cap); the energy budget ; and . Write for the integer bits, and for the margin as a linear factor ().
Theorem. If the first round loads at least one bit or , the algorithm stops, and its output satisfies
- and ;
- and ;
- every used subcarrier () gets with the same , and every unused subcarrier gets ;
- , where is the least energy that carries bits at margin 1.
Lemma 1 (the margin loop stops). Lines L2 to L5 run at most rounds.
Proof. Each round raises the counter by 1, and line L5 stops the loop when the counter reaches . (The implementation also stops when a later round loads no bit, because then the margin step of line L4 is not defined.)
Lemma 2 (the fix-up stops at the target). Line L6 runs exactly steps, and each step is possible.
Proof. Each step changes by one toward and stops when they are equal. When , some , so a bit can be removed. When , some , so a bit can be added. Removing a bit from keeps , and adding one to keeps . The rounding at line L2 is clipped to as well, since .
This proves property 1.
Lemma 3 (the energies). Let , the energy that carries bits at margin 1, and . If , then , and lines L7 and L8 give .
Proof. If , some , so . Then , and . For a used subcarrier, , the same for every . For an unused one, , so .
This proves properties 2 and 3 with . Under the gap model, the margin on every used subcarrier means that each one reaches the target error rate with the same reserve, which is the aim of the last step of the algorithm. If , all bits are 0 and the energies are 0; the margin is unbounded.
Property 4. The loading carries bits, so its energy at margin 1 is by the definition of . So , the margin of an optimal loading such as that of the Levin-Campello algorithm. Equality can fail: for , , and , the loop stops after three rounds at with , while the optimum has , so the algorithm loses dB of margin.
Lemma 4 (the size of a margin step). For , and ,
with strict inequality on the right when .
Proof. The difference is with . Since , the denominator satisfies . The right inequality gives , so the difference is at least 0. The left inequality gives , so the difference is at most ; when and , the left inequality is strict, and so is the bound.
So when line L4 raises the margin by the factor with , every real rate falls by at most , and the rates of subcarriers with high SNR fall by almost exactly , since the difference tends to as . If all used subcarriers had high SNR and the rounding did not change, the next total would be ; this is the reason for the step. Rounding and subcarriers near zero bits can make the loop overshoot or cycle, which is why it has the cap and the fix-up of line L6. The same bound holds for a lower margin () with the signs reversed.
Complexity
In the real RAM, each round of lines L2 to L4 costs , and there are rounds. Each fix-up step of line L6 scans the subcarriers in ; with the rounding errors sorted once, the fix-up costs instead, because a subcarrier changed once has the largest or smallest error until all others have changed. Lines L7 and L8 cost . So the time is as written, and the space is . The Hughes-Hartogs rule needs , which is much more when each of thousands of tones carries many bits.
Properties
- Exact target, common margin. The output always meets the bit target, and all used subcarriers have the same margin, so under the gap model they have the same error rate.
- Not optimal. The rounding to the nearest integer ignores the costs of the bits. The example loses 0.64 dB against the optimum.
- Usually close. On random channels with many subcarriers and a gap of 9.8 dB, the test code measures a mean loss of under 0.3 dB of margin; this is a measurement, not a bound.
- Few rounds. At high SNR one margin step nearly corrects the total, since each bit per subcarrier costs about 3.01 dB.
- No sort and no heap in the main loop. This made it attractive for the modem hardware of the 1990s.
Variants and improvements
- Rate-adaptive form. Fix the margin, compute the rounded rates once, and scale the energies; the result is the rate that the channel supports at that margin.
- Bisection on the margin. Search the margin by bisection for the value where the rounded total crosses the target, then fix up; this replaces the step of line L4 when the loop does not settle.
- A final optimal pass. Run the swap phase of the Levin-Campello algorithm on the output. Since the output is already close, few swaps are needed, and the result is optimal.
- Fine gains. DSL modems apply a fine gain per tone, a small energy adjustment that equalizes the margins; line L8 is a simple form of it.
When to use it
Use it for a fast first loading of many tones, as in the training phase of a DSL modem, when an exact optimum is not needed or when a repair pass will follow. For an exact result use the Hughes-Hartogs or Levin-Campello algorithm.
Pitfalls
- The margin in dB. The paper writes the denominator as the gap plus the margin in dB, which is a product of linear factors. Adding linear values is a bug.
- Division by zero. If a round loads no bit, and line L4 is undefined. Stop or report the channel as unusable.
- Cycling. The margin step can overshoot, for example when several subcarriers are near a rounding boundary. Keep and the fix-up.
- Rounding of halves. Some languages round halves to even. Pick one rule and use it in both the loop and the fix-up.
- Forgetting the scaling. Without line L8 the total energy can exceed the budget or waste it, and the margins of the subcarriers differ.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/chow-cioffi-bingham-algorithm/. The authors are listed in prov/KRYPZ8.jsonl.
"""Chow-Cioffi-Bingham loading for a multicarrier link (margin-adaptive form).
snr[i] is the SNR of subcarrier i when it gets unit energy. Each round
computes the real rate b[i] = log2(1 + snr[i] / (Gamma * margin)), rounds it
to the nearest integer, and moves the margin by the factor
2 ** ((total - target) / used), so that the next round lands closer to the
target. After at most max_count rounds, the bits are fixed one at a time with
the rounding errors diff[i] = b[i] - round(b[i]): extra bits are taken from
the subcarriers with the smallest diff, and missing bits are added where diff
is largest. Last, each used subcarrier gets the energy its bits need under the
gap model, and all energies are scaled to the budget, which gives every used
subcarrier the same margin.
Each round costs O(N). The fix-up scans all subcarriers once per bit that it
moves.
"""
import heapq
import math
def round_half_up(x: float) -> int:
return math.floor(x + 0.5)
def chow_cioffi_bingham(snr, target_bits, gap=1.0, budget=None, max_count=10, b_max=None):
"""Return (bits, energies, margin, rounds).
budget defaults to N (unit energy per subcarrier, as in the paper's
initialization). margin is the common margin, a linear factor, that the
final energies give on every used subcarrier.
"""
n = len(snr)
if n == 0 or any(not s > 0 for s in snr):
raise ValueError("need at least one subcarrier and positive SNR values")
if target_bits < 0 or (b_max is not None and target_bits > n * b_max):
raise ValueError("the target must lie in [0, N * b_max]")
if max_count < 1:
raise ValueError("max_count must be at least 1")
if budget is None:
budget = float(n)
margin_db, rounds = 0.0, 0 # @line L1
while True:
m = gap * 10 ** (margin_db / 10)
b = [math.log2(1 + s / m) for s in snr] # @line L2
bh = [round_half_up(x) if b_max is None else min(round_half_up(x), b_max) for x in b]
diff = [x - y for x, y in zip(b, bh)]
used = sum(1 for y in bh if y > 0)
total = sum(bh) # @line L3
if total == 0 and target_bits > 0 and rounds == 0:
raise ValueError("the channel carries no bits at this gap")
if used > 0:
margin_db += 10 * math.log10(2 ** ((total - target_bits) / used)) # @line L4
rounds += 1
if total == target_bits or rounds >= max_count or used == 0: # @line L5
break
while total > target_bits: # @line L6
i = min((d, i) for i, d in enumerate(diff) if bh[i] > 0)[1]
bh[i], diff[i], total = bh[i] - 1, diff[i] + 1, total - 1
while total < target_bits:
i = -max((d, -i) for i, d in enumerate(diff) if b_max is None or bh[i] < b_max)[1]
bh[i], diff[i], total = bh[i] + 1, diff[i] - 1, total + 1
need = [gap * (2**y - 1) / s for y, s in zip(bh, snr)] # @line L7
total_need = sum(need)
if total_need == 0:
return bh, [0.0] * n, math.inf, rounds
scale = budget / total_need
return bh, [e * scale for e in need], scale, rounds # @line L8
def loading_power(snr, bits, gap=1.0) -> float:
"""The least energy that carries the bits at margin 1: the sum of Gamma (2**b - 1) / snr."""
return sum(gap * (2**b - 1) / s for b, s in zip(bits, snr))
def optimal_power(snr, target_bits, gap=1.0) -> float:
"""The least energy for target_bits bits, by the greedy rule; the reference optimum."""
bits = [0] * len(snr)
heap = [(gap / s, i) for i, s in enumerate(snr)]
heapq.heapify(heap)
total = 0.0
for _ in range(target_bits):
c, i = heapq.heappop(heap)
total += c
bits[i] += 1
heapq.heappush(heap, (gap * 2 ** bits[i] / snr[i], i))
return total
test_chow_cioffi_bingham_algorithm.py 91 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/chow-cioffi-bingham-algorithm/. The authors are listed in prov/KRYPZ8.jsonl.
import math
import random
import pytest
from chow_cioffi_bingham_algorithm import chow_cioffi_bingham, loading_power, optimal_power
def check_output(snr, target, gap, budget, bits, energy, margin, b_max=None):
assert sum(bits) == target
assert min(bits) >= 0
if b_max is not None:
assert max(bits) <= b_max
assert abs(sum(energy) - budget) < 1e-9 * budget
for b, e, s in zip(bits, energy, snr):
if b == 0:
assert e == 0
else:
assert abs(s * e / (gap * (2**b - 1)) - margin) < 1e-9 * margin
def test_page_example() -> None:
snr = [20, 9, 5, 1.5]
bits, energy, margin, rounds = chow_cioffi_bingham(snr, 8)
assert bits == [3, 2, 2, 1] and rounds == 3
assert abs(loading_power(snr, bits) - 1.95) < 1e-12
assert abs(margin - 4 / 1.95) < 1e-12
assert abs(optimal_power(snr, 8) - 101 / 60) < 1e-12
assert abs(10 * math.log10(1.95 / (101 / 60)) - 0.638) < 1e-3
check_output(snr, 8, 1.0, 4.0, bits, energy, margin)
def test_targets_budget_and_equal_margin() -> None:
rng = random.Random(41)
for _ in range(300):
n = rng.randint(1, 64)
snr = [rng.expovariate(1 / 1000) + 0.5 for _ in range(n)]
gap = 10 ** (rng.uniform(0, 10) / 10)
b_max = rng.choice([None, 15])
target = rng.randint(1, 6 * n)
budget = rng.uniform(1, 100)
bits, energy, margin, rounds = chow_cioffi_bingham(snr, target, gap, budget, b_max=b_max)
assert 1 <= rounds <= 10
check_output(snr, target, gap, budget, bits, energy, margin, b_max)
def test_never_better_than_the_optimum_and_close_on_average() -> None:
rng = random.Random(42)
losses = []
for _ in range(200):
n = rng.randint(16, 64)
snr = [rng.expovariate(1 / 1000) + 0.5 for _ in range(n)]
gap = 10 ** 0.98
target = rng.randint(n, 6 * n)
bits, _, _, _ = chow_cioffi_bingham(snr, target, gap)
ratio = loading_power(snr, bits, gap) / optimal_power(snr, target, gap)
assert ratio >= 1 - 1e-12
losses.append(10 * math.log10(ratio))
assert sum(losses) / len(losses) < 0.3
def test_one_round_when_rounding_hits_the_target() -> None:
snr = [3.0, 15.0, 63.0]
bits, _, margin, rounds = chow_cioffi_bingham(snr, 2 + 4 + 6)
assert bits == [2, 4, 6] and rounds == 1
assert abs(margin - 3 / 3) < 1e-12
def test_fix_up_after_max_count() -> None:
snr = [20, 9, 5, 1.5]
bits, _, _, rounds = chow_cioffi_bingham(snr, 8, max_count=1)
assert rounds == 1 and bits == [4, 2, 2, 0]
assert abs(loading_power(snr, bits) - optimal_power(snr, 8)) < 1e-12
bits, _, _, rounds = chow_cioffi_bingham(snr, 5, max_count=1)
assert rounds == 1 and sum(bits) == 5
def test_bad_input() -> None:
with pytest.raises(ValueError):
chow_cioffi_bingham([], 1)
with pytest.raises(ValueError):
chow_cioffi_bingham([1, 0], 1)
with pytest.raises(ValueError):
chow_cioffi_bingham([1, 2], 31, b_max=15)
with pytest.raises(ValueError):
chow_cioffi_bingham([1e-9], 1, gap=1e9)
bits, energy, margin, _ = chow_cioffi_bingham([5, 7], 0)
assert bits == [0, 0] and energy == [0.0, 0.0] and margin == math.inf
History
Peter Chow, John Cioffi and John Bingham published the algorithm in 1995 in the IEEE Transactions on Communications, in a short paper on a practical loading method for discrete multitone transceivers on spectrally shaped channels such as telephone lines. It came from the work on DMT for ADSL, and it was an alternative to the greedy method of Hughes-Hartogs, whose cost grows with the number of bits. Later work, such as Campello's 1999 paper, gave fast loading methods that are also optimal.
References
- Peter S. Chow, John M. Cioffi and John A. C. Bingham, A practical discrete multitone transceiver loading algorithm for data transmission over spectrally shaped channels, IEEE Transactions on Communications 43(2/3/4), 1995, pages 773 to 775, the loading algorithm: unit energy per carrier at the start, the rounded rates log2(1 + SNR/(Gamma + margin in dB)), the margin iteration and the final energy adjustment
- John A. C. Bingham, Multicarrier modulation for data transmission: an idea whose time has come, IEEE Communications Magazine 28(5), 1990, pages 5 to 14, multicarrier modems that load each subchannel according to its SNR, the setting of the algorithm
- Jorge Campello, Practical bit loading for DMT, IEEE International Conference on Communications (ICC), 1999, pages 801 to 805, optimal discrete loading, against which heuristics such as this one are compared
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag KRYPZ8 Edit this page History Report an error Markdown