Radio from scratch · Chapter 20
How analog TV worked
Chapter 17's slow-scan TV takes two minutes per picture. Broadcast television sent thirty a second, in color, from the 1950s until 2009, when full-power US stations switched to digital (the last low-power analog ones went dark in July 2021). There's nothing left on the air to receive, so this chapter builds both ends: a transmitter that turns any picture into the exact signal a 1980s TV expected, and a receiver that decodes it again, live, in your browser.
Honest constraints first: an analog TV channel is 6 MHz wide, and the RTL-SDR captures at most about 3. You'll see below exactly what that costs.
The question to keep in mind: how do you fit a color picture into a signal that black-and-white TVs, built years earlier, still understand?
A spot that never stops moving
A picture tube has one electron beam making one bright spot. The spot sweeps left to right across a line, snaps back, drops a little, and sweeps the next line: a raster. Its brightness follows the signal's voltage moment by moment. Done fast enough, your eye blends the spot's trail into a whole picture.
NTSC (the analog TV standard of North America, named after the committee that wrote it) draws 525 lines per frame, about 480 of them visible. Thirty frames a second would flicker, so each frame is sent as two fields: first the odd lines, then the even ones (tick "interlaced"). The screen is repainted 60 times a second for the bandwidth of 30: a clever trade from 1941.
525 lines per frame, 29.97 frames per second. How many lines does a TV draw each second?
One line of composite video
The signal for one line is a voltage over 63.6 µs. It's called composite video because brightness, color and sync all travel in this one signal. It starts with a sync pulse, a dip below black ("blacker than black") that tells the receiver "start a new line now". Then a short pause with a burst of fast wiggles (the color burst, section 4), then 52.6 µs of picture: higher voltage, brighter spot. Levels are measured in IRE units (a scale where black to white spans about 100; IRE is the engineers' institute that set it): sync −40, blanking 0, black 7.5, white 100. Pick a row of the test card:
Why is the sync pulse below black, instead of being some special pattern inside the picture's range?
- So it's louder than the picture
- So nothing in any picture can ever look like a sync: a simple voltage threshold separates them
- So the screen is darker
Where each field begins
Line syncs say "new line". To say "new field, back to the top", the signal dips to sync level for most of every half line, six times in a row: the vertical sync. Field 1's starts exactly on a line; field 2's starts half a line later. That half line is the whole trick of interlace: everything in field 2 lands half a line lower, between field 1's lines.
A real receiver doesn't trust each sync pulse on its own: noise can fake or hide one. It runs a flywheel: it expects the next sync one line later, and only nudges its timing a little toward each pulse it sees. Our decoder does the same, so snowy pictures still have straight edges (try the noise knob in the lab).
Color as a spinning arrow
Color had to be added in 1953 without breaking 20 million black-and-white sets. The solution: keep the brightness signal (Y) exactly as it was, and add the color as a faint, fast wiggle on top, at 3.579545 MHz, the color subcarrier. Old sets show the wiggle as fine dots too small to notice; color sets decode it.
The wiggle is chapter 1's spinning arrow. Its length is how strong the color is (saturation) and its angle is which color (hue), measured on two axes: blue minus brightness (B−Y) and red minus brightness (R−Y). Drag the arrow:
An angle needs a reference. That's the color burst: nine cycles of the subcarrier at the start of every line, always at the same angle (180°). The TV locks onto it and measures every color against it. (Phase errors on long cable runs turned faces green, so NTSC sets had a "tint" knob, and engineers joked the name stood for "Never Twice the Same Color".)
The subcarrier is 455/2 times the line rate: 227.5 cycles per line. Why half a cycle extra?
Separating brightness and color: the comb
Brightness and color are added together in one signal. How does the receiver pull them apart? Because the color wiggle flips each line and the picture usually doesn't change much from one line to the next, two neighboring lines added together cancel the color and keep the brightness; subtracted, they cancel the brightness and keep the color. It's called a comb filter, because its frequency response is a row of teeth, one every 15.7 kHz (the line rate). A picture that changes little from line to line puts the brightness's energy at whole-number multiples of the line rate, its harmonics (like chapter 10's overtones); the color, flipped on every line, sits exactly halfway between them. The comb's teeth land on one set and its gaps on the other.
Analog TV is a spot sweeping lines, its brightness following the voltage. Sync pulses below black mark each line and field, and color rides on top as a faint spinning arrow that black-and-white sets ignore.
Why do two neighboring lines separate brightness from color?
- Line n carries brightness Y plus color C riding on the subcarrier.
- The subcarrier has 227.5 cycles per line, so on line n + 1 it's upside down: Y − C, if the picture didn't change.
- Adding the two lines: (Y + C) + (Y − C) = 2Y. Half of it is the brightness.
- Subtracting: (Y + C) − (Y − C) = 2C. Half of it is the color.
- That's the comb filter: one line of memory, one addition, one subtraction.
Where it breaks
It relies on neighboring lines being alike. Where the picture changes from one line to the next, say a horizontal edge from black (7.5 IRE) to white (100 IRE), the difference between the lines isn't color at all, yet half of it, about 46 IRE, comes out as color: shimmering fake color along horizontal edges, a classic NTSC artifact. Better TVs compared three lines, or whole frames, to tell real color from edges.
The color that comes out is still riding on the subcarrier. To read its arrow, multiply by the subcarrier itself, sine and cosine (chapter 5's mixing, bringing 3.58 MHz down to 0 Hz), and average over one cycle (chapter 6). Sampling at exactly four times the subcarrier makes this neat: the sine is just 0, 1, 0, −1, repeating.
On the air, and what a dongle can catch
Up to here we've built and decoded the signal on a studio wire, where brightness and color reach up to 4.2 MHz. Putting that onto the airwaves hits a problem: ordinary AM (chapter 10) creates two mirror-image sidebands, which would make the picture alone 8.4 MHz wide — wider than the 6 MHz channel regulators allotted for picture and sound combined! So TV transmitters used AM with most of the lower sideband shaved off to save space (vestigial sideband), and placed the FM sound carrier 4.5 MHz above the picture carrier. Slide our dongle's narrower capture window across that 6 MHz channel to see what fits:
With a 2.4 MHz capture placed to keep as much picture as possible, what does the decoded picture look like?
- Black and white and a bit soft: the color subcarrier (3.58 MHz above the picture carrier) is outside
- Nothing at all
- Full color but blurry
In code
Show the real code (optional: everything it does is explained above)
The encoder and decoder are about 200 lines of code. The decoder's steps, in order:
// 1. sync: smooth, then a threshold halfway between sync (−40) and blanking (0)
if (sm[i] < -20 && sm[i - 1] >= -20) lowStart = fallAt(i); // a falling edge, to a fraction of a sample
// 2. a dip longer than 18 µs is a vertical sync; half a line after the last line sync means field 2
const field = g - prevH < 0.75 * LINE ? 2 : 1;
// 3. the flywheel: expect each line one line later, nudge toward the edge actually seen
err = 0.7 * err + 0.3 * (measured - predicted);
// 4. the burst's angle is the reference for every color on the line
psi = Math.atan2(-qb, -pb);
// 5. comb: the sum of two lines is brightness, the difference is color
Y[j] = (x[k] + x[k - LINE]) / 2; C[j] = (x[k] - x[k - LINE]) / 2;
// 6. demodulate: multiply by the subcarrier, average over a cycle, undo the burst's rotation
U[j] = p * Math.cos(psi) + q * Math.sin(psi); V[j] = -p * Math.sin(psi) + q * Math.cos(psi);
Where this chapter's numbers come from. The numbers this chapter computes come from a short checking script behind this page, which also checks each claim and stops if one is wrong. It sends a test card through channels of different widths and noise and compares what comes out. Its output:
lines per second: 15734.27 (525 lines × 29.970 frames/s)
color subcarrier: 3.579545 MHz = 227.5 × the line rate
sampled at 4 × subcarrier = 14.318 MHz: 910 samples per line, 477750 per frame
the whole 4.2 MHz of video fields 1+2 burst 19.8 IRE color PSNR 25.2 dB (brightness 27.6 dB) sync jitter 0.01 samples
4.2 MHz with noise (snowy) fields 1+2 burst 19.9 IRE color PSNR 21.9 dB (brightness 25.1 dB) sync jitter 0.58 samples
3 MHz (what fits a 3.2 MS/s dongle) fields 1+2 burst 0.3 IRE B&W PSNR 10.9 dB (brightness 27.3 dB) sync jitter 0.01 samples
2 MHz (a 2.4 MS/s dongle) fields 1+2 burst 0.2 IRE B&W PSNR 10.9 dB (brightness 25.5 dB) sync jitter 0.03 samples
a black-and-white transmission: burst 0.1 IRE → color killer on, brightness PSNR 29.5 dB
all checks passed
Without color, the color picture's PSNR drops to 11 dB (all the color is gone), but its brightness is nearly untouched: the same picture a 1950s black-and-white set showed.
Lab: be a TV station
Your picture goes through our NTSC transmitter, a channel (bandwidth and noise), and our receiver, 30 times a second if your computer keeps up. Left: what was sent. Right: what the receiver made of it. Underneath: one line of the received signal, like a studio's waveform monitor.
Nothing from your camera leaves this page. On the air, hams still send analog TV (amateur TV) around 421–440 MHz and 1.2 GHz; it's rare in New York, so this lab doesn't wait for one.
Check yourself
What tells a TV to start a new line, and why can't the picture fake it?
The horizontal sync pulse, a dip to −40 IRE. Picture content never goes below black (7.5 IRE), so a threshold at −20 separates them.
How does a receiver know which field it's drawing?
Field 1's vertical sync starts exactly on a line boundary, field 2's half a line later. Measuring the distance from the last line sync tells them apart.
What do the length and the angle of the color arrow mean?
Length is saturation (how vivid), angle is hue (which color), measured against the color burst sent on every line.
Why does adding two neighboring lines remove the color?
A line holds 227.5 subcarrier cycles, so the color wiggle is inverted on the next line and cancels in the sum, while the brightness, nearly the same on both lines, doubles.
Last updated