Line coding: NRZ, Manchester and friends
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.
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
Read the lesson step by step
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 voltsOn-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)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: 0The 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 levelLong 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/10bManchester: 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)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 MHzAMI: 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)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)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)
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01In polar NRZ, which levels stand for 1 and 0?
Polar NRZ uses two opposite levels held for the whole bit. +A / 0 is on-off (unipolar) NRZ, the half-bit pair is Manchester, and alternating ±A for 1s is AMI.
02Encode the bits 1 1 0 in Manchester (IEEE 802.3 convention). Which half-bit sequence is sent?
IEEE 802.3: a 1 goes low then high (−A, +A) and a 0 goes high then low (+A, −A). So 1 1 0 is −A +A, −A +A, +A −A.
03Why does a long run of 1s cause trouble for polar NRZ but not for Manchester?
Receivers recover bit timing from level changes. Polar NRZ does not change during a run of equal bits; Manchester has an edge in the middle of every bit, whatever the data.
04A link sends 10 Mbit/s. Where is the first null of the spectrum for polar NRZ and for Manchester?
Polar NRZ's spectrum is sinc²(f·Tb), first zero at f = R = 10 MHz. Manchester's half-bit pulses push its first null to 2R = 20 MHz: about twice the bandwidth.
05An AMI receiver sees the pulses +A, 0, +A. What does it conclude?
In AMI each 1 must have the opposite sign to the previous 1. Two +A pulses with only a 0 between them break that rule, so at least one bit was received wrongly.
Glossary
- Line code
- The rule that turns each bit into a voltage pattern on a wire, chosen for DC balance, clock recovery and bandwidth.
- Bit time Tb, bit rate R
- Tb is how long one bit lasts; the bit rate R = 1/Tb is bits per second.
- NRZ (non-return-to-zero)
- A code that holds one level for the whole bit. Unipolar NRZ uses +A and 0; polar NRZ uses +A and −A.
- DC component
- The average (0 Hz) part of a signal. Transformers and series capacitors block it, so a code with a DC part is distorted.
- Clock recovery
- The receiver finds the bit timing from the transitions (level changes) in the signal itself; long runs without transitions make it drift.
- Manchester code
- Each bit has a transition at its middle: low-to-high for 1 and high-to-low for 0 in IEEE 802.3. No DC, easy clock, about twice the bandwidth of NRZ.
- AMI (alternate mark inversion)
- A bipolar code: 0 is 0 V and successive 1s alternate between +A and −A. No DC; a same-sign pair (bipolar violation) reveals an error.
- Power spectral density (lobe, null)
- How a random signal's power is spread over frequency. A lobe is one hump of it; a null is a frequency where it is zero. For line codes it shows the DC content and the bandwidth needed.
Notes and sources
- Levels are drawn in units of A, the pulse height. The spectra assume long streams of random, equally likely, independent bits with full-width rectangular pulses, normalised by A²·Tb; every curve is computed from the formulas in the model and checked against a DFT of simulated bits.
- Manchester has two opposite conventions. This lesson uses IEEE 802.3 (used by 10BASE-T Ethernet): a 1 is a low-to-high transition, a 0 high-to-low. G. E. Thomas's original rule is the reverse.
- The motion is slowed down a great deal: at 10 Mbit/s one bit lasts 100 ns.
- B. P. Lathi, Modern Digital and Analog Communication Systems, Holt, Rinehart and Winston, 1983 (line coding and the PSD of line codes; Internet Archive record)
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson (Fourier transform of a rectangular pulse)
- MIT OpenCourseWare 6.02 Introduction to EECS II: Digital Communication Systems (Balakrishnan, Verghese, Fall 2012), readings: Bits, Signals, and Packets, ch. 4 Digital Signaling
- MIT OpenCourseWare 6.450 Principles of Digital Communications I (Gallager, Zheng, Fall 2006)
- Line code (Wikipedia): DC through transformers, clock recovered from transitions
- Non-return-to-zero (Wikipedia): unipolar and polar NRZ, long runs and synchronisation
- Manchester code (Wikipedia): IEEE 802.3 and G. E. Thomas conventions, no DC, twice the bandwidth
- Bipolar encoding (Wikipedia): AMI, bipolar violations, B8ZS and HDB3
- Ethernet over twisted pair (Wikipedia): 10BASE-T at 10 Mbit/s uses Manchester code
- NumPy documentation: numpy.repeat
- NumPy documentation: numpy.tile
Quiz Unlocks after the last step.