ENع
→Convolutional codes, Viterbi and LDPC
الدرس S4 · Special topics

Stronger codes: convolutional codes, Viterbi and LDPC

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

18 دقيقة11 خطوة5 أسئلةAdvanced
عن هذا الدرس

Hamming codes protect short blocks. Stronger codes spread each message bit over many sent bits. Follow one example end to end: a rate-1/2 convolutional encoder turns 1011 into 11 10 00 01 01 11, Gaussian noise flips two bits, and the Viterbi algorithm walks a trellis of four states to recover 1011 exactly. Then meet LDPC codes, the sparse parity checks inside 5G and Wi-Fi 6, and fix a flipped bit by bit flipping. It builds on the lessons on parity and Hamming codes, noise and decisions (AWGN and SNR), and discrete-time convolution; the encoder is literally np.convolve(u, taps) % 2.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل S4 · تفاعلي
01 / 11

A code with memory

A Hamming code guards fixed blocks. A convolutional code works on a stream. The encoder keeps a sliding window of the last K = 3 message bits in a shift register: the new bit u[n] and the two before it.

message   u = 1 0 1 1
window    [u[n], u[n−1], u[n−2]]
          K = 3 bits (the constraint length)

the register starts at 0 0
each tick: the new bit enters on the left,
the oldest bit falls off the right

block codes (Hamming): see "Parity and Hamming codes"
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. A code with memory

    A Hamming code guards fixed blocks. A convolutional code works on a stream. The encoder keeps a sliding window of the last K = 3 message bits in a shift register: the new bit u[n] and the two before it.

    message   u = 1 0 1 1
    window    [u[n], u[n−1], u[n−2]]
              K = 3 bits (the constraint length)
    
    the register starts at 0 0
    each tick: the new bit enters on the left,
    the oldest bit falls off the right
    
    block codes (Hamming): see "Parity and Hamming codes"
  2. Two parity bits per message bit

    Two mod-2 adders read the window (1 ⊕ 1 = 0). c1 = u[n] ⊕ u[n−1] ⊕ u[n−2] and c2 = u[n] ⊕ u[n−2]. The first bit, 1, after two zeros, gives c1 c2 = 1 1. Two code bits per message bit: rate 1/2.

    c1[n] = u[n] ⊕ u[n−1] ⊕ u[n−2]   taps 111 (octal 7)
    c2[n] = u[n] ⊕ u[n−2]            taps 101 (octal 5)
    
    ⊕ = add mod 2: 0⊕0 = 0, 0⊕1 = 1, 1⊕1 = 0
    
    n = 0: window [1, 0, 0]
      c1 = 1 ⊕ 0 ⊕ 0 = 1
      c2 = 1 ⊕ 0     = 1
    
    rate = 1 message bit / 2 code bits = 1/2
  3. Encoding is a convolution

    Two 0s follow 1011 to flush the register. Out come 11 10 00 01 01 11. Each output stream is the message convolved with its taps, mod 2: that is the name. In Python, np.convolve(u, taps) % 2 gives each stream.

    n   window   c1 c2
    0   100      1  1
    1   010      1  0
    2   101      0  0
    3   110      0  1
    4   011      0  1
    5   001      1  1
    
    sent: 11 10 00 01 01 11
    
    >>> c1
    array([1, 1, 0, 0, 0, 1])
    >>> c2
    array([1, 0, 0, 1, 1, 1])
    (Python 3 with numpy; mode "full" adds the tail)
  4. Noise flips two bits

    Each bit is sent as a voltage: 1 → +1 V, 0 → −1 V. The channel adds Gaussian noise (σ = 0.7 V). The receiver decides 1 when r > 0. Samples r[3] and r[8] cross zero, so two bits arrive flipped.

    sent      11 10 00 01 01 11
    volts     1 -> +1 V, 0 -> −1 V
    noise     Gaussian, σ = 0.7 V (seeded)
    
    r[3] = +0.26 V  (sent −1 V) -> 1, wrong
    r[8] = +0.18 V  (sent −1 V) -> 1, wrong
    
    received  11 11 00 01 11 11
    2 of 12 bits flipped
    noise and SNR: see "Noise and decisions"
  5. States and the trellis

    The register's two older bits are the encoder's state: 00, 01, 10 or 11, so 2^(K−1) = 4 states. A trellis shows every state at every time; each bit takes one branch. The message 1011 is one path through it.

    state = u[n−1] u[n−2]   (4 states)
    
    from each state two branches:
      solid  = input bit 0
      dashed = input bit 1
    
    the encoder's path:
    00 → 10 → 01 → 10 → 11 → 01 → 00
    
    the 2 tail zeros end it at 00
  6. Branch metrics: count mismatches

    Each branch has the pair the encoder would send on it. Its branch metric counts the bits that differ from what arrived: the Hamming distance. At n = 1 we received 11, but the true branch 10 → 01 sent 10: metric 1.

    received at n = 1:  11
    
    00→00  sent 00  metric 2
    00→10  sent 11  metric 0
    10→01  sent 10  metric 1
    10→11  sent 01  metric 1
    
    branch metric = Hamming distance
    (number of differing bits)
    the noise flipped bit 3, so the true
    branch costs 1, not 0
  7. Add, compare, select

    A path metric adds up the branch metrics along a path. Two paths enter each state; the decoder keeps the one with the smaller total, the survivor. So only 4 survivors live at any time, not 2ⁿ paths.

    path metric at each state, per time n
    (∞ = not reachable yet)
    
    n=0  00:0 01:∞ 10:∞ 11:∞
    n=1  00:2 01:∞ 10:0 11:∞
    n=2  00:4 01:1 10:2 11:1
    n=3  00:3 01:2 10:1 11:2
    n=4  00:3 01:2 10:3 11:1
    n=5  00:2 01:2 10:3 11:2
    n=6  00:2 01:3 10:2 11:3
    
    add: old path metric + branch metric
    compare: the two paths into a state
    select: keep the smaller
  8. Trace back the survivor

    The tail zeros end the encoder in state 00. Its survivor has path metric 2: the two flips. Followed backwards, its branches give the inputs 1011 (then 0 0): the message, with both errors corrected.

    end state 00, path metric 2
    
    survivor path:
    00 → 10 → 01 → 10 → 11 → 01 → 00
    input bits on it: 1 0 1 1 0 0
    
    decoded  1011
    sent     1011   ✓
    
    free distance of this code: 5
    -> corrects 2 errors that are spread out
  9. Soft decisions keep the voltages

    Deciding 0 or 1 first discards how sure we were: r[3] = +0.26 V is a weak 1, r[0] = +1.47 V a strong one. A soft-decision decoder uses squared distances in volts. It picks the same path here and, on average, errs less.

    hard metric: Hamming distance (bits)
    soft metric: Σ (r − expected volts)²
    
    soft Viterbi, same trellis:
      survivor 00 → 10 → 01 → 10 → 11 → 01 → 00
      decoded  1011
      path metric 4.57 V²
    
    weak samples (near 0 V) now count little
  10. LDPC: many sparse parity checks

    LDPC codes (Gallager, 1960) are block codes built from many parity checks, each on only a few bits. A Tanner graph draws bits as circles and checks as squares. Here 6 bits meet 4 checks; each check's bits must add to 0 mod 2.

    H (rows = checks, columns = bits)
    1 1 0 1 0 0
    0 1 1 0 1 0
    1 0 0 0 1 1
    0 0 1 1 0 1
    
    edge = a 1 in H
    codeword x = 0 0 1 0 1 1
    H·x mod 2 = 0 0 0 0  (all checks pass)
    
    real LDPC codes: thousands of bits,
    only a few 1s per column ("low density")
  11. Bit flipping fixes the error

    Bit 0 arrives flipped, so checks 0 and 2 fail. Flip the bit that sits in the most failed checks: bit 0, in both. Now every check passes. 5G NR data channels and Wi-Fi 6 use LDPC codes.

    received 1 0 1 0 1 1
    checks   1 0 1 0   (1 = fails)
    
    failed checks per bit:
      2 1 0 1 1 1
    bit 0 is in 2 failed checks -> flip it
    
    decoded  0 0 1 0 1 1
    checks   0 0 0 0   ✓
    
    real decoders pass soft beliefs
    (belief propagation)

اختبار يتاح بعد الخطوة الأخيرة.