ENع
←Line coding
Lesson 53 · Digital communications: bits on a wire

Line coding: NRZ, Manchester and friends

16 min10 steps5 questionsAdvanced
About this lesson

A cable carries voltages, so every bit must become a pulse. Follow the 8 bits 1 0 1 1 1 1 0 0 through four line codes: on-off (unipolar) NRZ, polar NRZ, Manchester and AMI. See why a steady DC part is a problem, why long runs without a level change hide the clock, what Manchester pays in bandwidth for an edge in every bit, and how the receiver turns pulses back into bits. Builds on the Networking lesson on bits on the wire and the Hardware lesson on signal integrity; the spectra use the Fourier transform of a rectangular pulse from the Fourier module and the power spectral density from the multirate and random signals module.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 53 · Interactive
01 / 10

Bits need a shape

A cable carries voltages, not ones and zeros. A line code is the rule that turns each bit into a voltage pulse lasting one bit time, Tb. Here are 8 bits to send: 1 0 1 1 1 1 0 0.

bits to send:  1 0 1 1 1 1 0 0

bit time    Tb  (seconds per bit)
bit rate    R = 1 / Tb  (bits per second)

line code = the rule
  bit  ->  voltage for one Tb

levels are drawn in units of A,
the pulse height in volts
Loading figure…
or ← →
Read the lesson step by step
  1. Bits need a shape

    A cable carries voltages, not ones and zeros. A line code is the rule that turns each bit into a voltage pulse lasting one bit time, Tb. Here are 8 bits to send: 1 0 1 1 1 1 0 0.

    bits to send:  1 0 1 1 1 1 0 0
    
    bit time    Tb  (seconds per bit)
    bit rate    R = 1 / Tb  (bits per second)
    
    line code = the rule
      bit  ->  voltage for one Tb
    
    levels are drawn in units of A,
    the pulse height in volts
  2. On-off: unipolar NRZ

    The simplest rule: a 1 is +A volts, a 0 is 0 volts, held for the whole bit. NRZ means non-return-to-zero: the level does not drop back to 0 in mid-bit. The encoder sends one pulse per bit.

    unipolar NRZ (on-off keying)
      1 -> +A   for the whole bit
      0 ->  0
    
    1 0 1 1 1 1 0 0
    +A 0 +A +A +A +A 0 0
    
    average level here: 0.625 A
    (random bits: A/2)
  3. Polar NRZ: +A and −A

    Polar NRZ sends a 1 as +A and a 0 as −A. The gap between the two levels doubles, so noise must be twice as big to flip a bit. With equally many 1s and 0s it averages to zero.

    polar NRZ
      1 -> +A
      0 -> −A
    
    1 0 1 1 1 1 0 0
    +A −A +A +A +A +A −A −A
    
    gap between levels: 2A  (on-off: A)
    average here: (5 − 3)/8 = 0.25 A
    (5 ones at +A, 3 zeros at −A)
    random bits: 0
  4. The DC problem

    Many cables pass through a transformer or capacitor that blocks DC, a steady voltage. On-off NRZ has a steady part of A/2 (here 0.625 A), and polar NRZ's spectrum peaks at 0 Hz. Blocked, that part is lost and the baseline drifts.

    DC = the average level (0 Hz)
    
    unipolar, these 8 bits: 0.625 A
    unipolar, random bits:  A/2
      -> a spectral line at f = 0
    polar NRZ: S(0) is its biggest value
    
    spectrum (random bits, x = f·Tb):
      polar     sinc²(x)
      unipolar  ¼·sinc²(x) + DC line
    
    a series capacitor or a transformer
    passes changes, not a steady level
  5. Long runs hide the clock

    There is no clock wire. The receiver keeps time by watching the level change. Bits 3 to 6 are all 1, so polar NRZ stays flat for 4 bit times. A slightly fast or slow receiver clock can count 3 or 5 ones.

    clock recovery: the receiver lines up
    its bit timing on the level changes
    (transitions) it sees
    
    1 0 1 1 1 1 0 0
        ^^^^^^^
        four 1s: no change for 4·Tb
    
    longer runs -> more drift -> a bit
    slip: a bit counted twice or missed
    fixes: Manchester, AMI + substitution,
    bit stuffing, 8b/10b
  6. Manchester: an edge in every bit

    Manchester splits each bit in two halves. In the IEEE 802.3 rule a 1 goes low then high, a 0 high then low. Every bit has an edge in its middle, so the clock never starves, and every bit averages to zero.

    Manchester (IEEE 802.3 convention)
      1 -> −A then +A  (rising edge)
      0 -> +A then −A  (falling edge)
    
    edge at the middle of every bit
    longest flat stretch: 1·Tb
    
    each bit averages to 0: no DC,
    whatever the data
    (G. E. Thomas used the opposite rule)
  7. The price: twice the bandwidth

    Half-bit pulses change twice as fast, so Manchester needs more bandwidth. Its spectrum's main hump (lobe) ends at the first null, a frequency with zero power: 2R, against R for polar NRZ. 10BASE-T Ethernet sends 10 Mbit/s in Manchester: that null is at 20 MHz.

    power spectrum, random bits
    (x = f·Tb = f / R)
    lobe = a hump of the spectrum
    null = a frequency with zero power
    
    polar NRZ   sinc²(x)
                first null at f = R
    Manchester  sinc²(x/2)·sin²(πx/2)
                zero at f = 0
                first null at f = 2R
    
    10BASE-T: R = 10 Mbit/s
      polar NRZ would null at 10 MHz
      Manchester nulls at   20 MHz
  8. AMI: alternate the ones

    AMI sends a 0 as 0 volts and each 1 with the opposite sign to the last 1. The pulses cancel in pairs, so no DC builds up, and its main hump still ends at R. Two same-sign 1s in a row reveal an error.

    AMI (alternate mark inversion)
      0 -> 0
      1 -> +A, −A, +A, ... in turn
    
    1 0 1 1 1 1 0 0
    +A 0 −A +A −A +A 0 0
    
    spectrum: sinc²(x)·sin²(πx)
      zero at f = 0, first null at f = R
    bipolar violation = an error
    long 0 runs: no edges, so T1 / E1
    lines substitute them (B8ZS, HDB3)
  9. Getting the bits back

    The receiver locks its clock to the mid-bit edges, then measures each half of every bit. Second half higher than the first: a 1. Lower: a 0. The 8 bits come back as 1 0 1 1 1 1 0 0.

    Manchester decision, bit by bit
      measure at 1/4 and 3/4 of the bit
      second > first  ->  1
      second < first  ->  0
    
    received: 1 0 1 1 1 1 0 0
    sent:     1 0 1 1 1 1 0 0
    
    NRZ instead: one measure at mid-bit,
    compared with a threshold
    (polar: 0, on-off: A/2)
  10. Line coding in Python

    In Python with numpy: 2*b − 1 maps bits to ±1 (polar NRZ). np.repeat doubles each value into two halves, and multiplying by the pattern −1, +1 flips the first half. That is Manchester, 16 half-bits.

    import numpy as np
    b = np.array([1,0,1,1,1,1,0,0])
    nrz = 2*b - 1
    half = np.tile([-1, 1], 8)
    man = np.repeat(nrz, 2) * half
    
    >>> nrz
    array([ 1, -1,  1,  1,  1,  1, -1, -1])
    >>> man
    array([-1,  1,  1, -1, -1,  1, -1,  1, -1,  1, -1,  1,  1, -1,  1, -1])
    >>> (man[1::2] > man[0::2]).astype(int)
    array([1, 0, 1, 1, 1, 1, 0, 0])
    
    (Python 3 with numpy)

Quiz Unlocks after the last step.