Radio from scratch · Chapter 17

Pictures over radio

Before you startThis chapter uses:

Since 1957 people have sent pictures over radio voice channels using nothing but sound. The method, slow-scan television (SSTV), is so simple you could decode it with a pencil, a stopwatch and perfect pitch: each pixel's brightness is a tone's pitch. Astronauts on the International Space Station send SSTV pictures to anyone listening on 145.800 MHz, and by the end of this chapter you'll understand every step of the decoder that receives them, which runs on this site.

Painting with pitch

Take one row of a picture. Read it left to right, and for each pixel play a tone: 1500 Hz for black, 2300 Hz for white, anything in between for grays. The whole row becomes a little melody:

A pixel's value is 64 (dark gray). What tone, in Hz, does it become?

1500 + 800 × 64/255 ≈ 1701 Hz.

That's all SSTV is, repeated for every row: about 240 to 500 rows, each taking a tenth of a second to half a second, so a picture takes from 36 seconds to three minutes. Because only the pitch matters, not the loudness, the signal survives fading, just like FM (↩ ch. 9: only the angle matters). In fact, SSTV is usually sent over FM: the radio's FM demodulator gives you the tones, and the SSTV decoder then measures their pitch.

Anatomy of a line

A decoder needs to know where each row starts, so every line begins (or ends) with a sync pulse: a burst of 1200 Hz, lower than any picture tone can be. Color pictures send the line once per color, or as brightness plus color difference. Pick a mode and see one line laid out in time:

The VIS header: which mode is this?

In the previous section you saw that Martin, Scottie, Robot and PD modes all have different line lengths and color layouts: if a receiver starts drawing lines without knowing which format is arriving, the whole picture turns into scrambled stripes. So before the first line of pixels, every transmission sends a short digital "doorbell" that names its mode, the VIS code (vertical interval signaling): a 1900 Hz leader, a 1200 Hz break and start bit, then seven data bits at 30 ms each (1100 Hz = 1, 1300 Hz = 0, least significant bit first), an even-parity bit, and a 1200 Hz stop bit:

The parity bit is a simple check: the number of 1 bits, including parity, must be even. A decoder that hears a header with the wrong parity ignores it, so a burst of noise doesn't start a fake picture.

Robot 36's VIS code is 8: binary 0001000. What's its even-parity bit (0 or 1)?

One 1-bit in the code, so the parity bit is 1, making two: an even count.
Where it breaks

One parity bit catches one wrong bit, not two. If noise flips a single bit of the VIS header, the count of 1s turns odd and the decoder ignores the header. If it flips two, the count is even again: the header passes the check and names the wrong mode, and the decoder draws a picture with the wrong line length. Stronger checks (chapter 22's checksum) use many check bits for exactly this.

How a computer hears pitch

After mixing down by 1900 Hz, how fast (in Hz) does a 1500 Hz black tone's arrow spin? (Negative means backwards.)

1500 − 1900 = −400: it spins backwards at 400 turns a second, and white (2300 Hz) forwards at +400.

A decoder has to measure the tone's frequency many thousands of times a second, accurately enough to tell 1500 Hz from 1503 Hz. Counting zero crossings is too slow and too sensitive to noise. Instead, our decoder reuses two ideas you already know:

  1. Mix the audio down by 1900 Hz, the middle of the SSTV range (↩ ch. 5). A 2300 Hz tone becomes an arrow spinning at +400 turns a second; a 1500 Hz tone, −400; the 1200 Hz sync, −700. The audio is a real signal (one shadow), so mixing makes a mirror copy too; a low-pass filter removes it (↩ ch. 6).
  2. Measure how far the arrow turns between samples: chapter 9's FM demodulator (↩). Turn per sample × samples per second ÷ 2π = how far the tone is from 1900 Hz.

The result is a frequency track: the tone's pitch at every moment. The SSTV decoder draws it under the picture as it decodes; you can see the sync dips and the picture tones go by.

Two clocks again: slanted pictures

The sender's sound card and yours each have their own crystal, and they never agree exactly (↩ ch. 11). If the sender's clock runs 0.2% fast, each of its lines is 0.2% shorter than you expect, and a decoder that just counts time puts every line a little too late: the picture slants. Here the real encoder sends a Robot 36 picture with a clock error, and the real decoder receives it:

A Robot 36 line is 150 ms and there are 240 of them. The sender's clock runs 0.2% fast. How many milliseconds off is the last line, if the decoder just counts time?

Each line is 0.2% shorter: 0.3 ms, and it adds up: 240 × 0.3 = 72 ms by the bottom, about half a line's width of slant.

The cure uses the sync pulses. For each line, the decoder looks for its 1200 Hz pulse near where it expects it and notes where it actually is. Those measured times, plotted against the line number, fall on a straight line whose slope is the true line length. Fit that line (least squares: the line that's closest to all the points at once) and predict each line's start from it, and the picture comes out straight. A wrong clock in your own sound card is corrected the same way, which is why SSTV software rarely needs calibrating any more.

SSTV turns each pixel's brightness into a tone's pitch, line by line. The decoder measures pitch with chapter 9's FM trick and straightens the picture by fitting a line through the sync pulses.

Why does fitting a line fix a slanted picture?
  1. If the sender's clock runs slightly fast, every line is slightly shorter than expected, by the same amount.
  2. So the measured start of line n is a + b · n: a straight line, with b the true line length.
  3. Each measured sync time is also off by some noise.
  4. A straight line fitted through all the sync times averages that noise away: one bad sync barely moves it.
  5. Predicting each line's start from the line, not from its own noisy sync, puts every line in the right place.

Writing it down

f=1500+800×v255 Hzftone=1900+Δθ×fs2π

In code

Show the real code (optional: everything it does is explained above)

The decoder is about 150 lines. Its pitch detector is three blocks from the course, chained:

this.mixer = new Mixer(fs, 1900);                                   // ch. 5: slide 1900 Hz to 0
this.lp = new FirDecimator(firLowpass(1100 / fs, 700 / fs), m, 2); // ch. 6–7: keep ±1100 Hz, thin out
this.fm = new FmDemod();                                            // ch. 9: angle turned per sample
// … then for each sample:
freq.push(1900 + (turn * rate) / (2 * Math.PI));

Finding each line's sync: try positions near the prediction, and keep the one where the last few milliseconds are closest to 1200 Hz and the next ones to 1500 Hz (every sync is followed by a black "porch"):

for (let t = pred - 12 * r; t <= pred + 12 * r; t += r / 4) {
  const score = Math.abs(avg(t - sync, t) - 1200) + Math.abs(avg(t, t + porch) - 1500);
  if (score < bestScore) { bestScore = score; best = t; }
}

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 picture through every mode (encoder → audio → decoder) and compares it pixel by pixel. Its output:

black 1500 Hz, mid-gray 1902 Hz, white 2300 Hz
Robot 36    36.9 s  header says Robot 36    47.6 dB
Martin M1  115.2 s  header says Martin M1   53.7 dB
Scottie S1 110.5 s  header says Scottie S1  55.9 dB
PD90        90.9 s  header says PD90        53.8 dB
PD120      127.0 s  header says PD120       51.9 dB
PD180      188.0 s  header says PD180       53.1 dB
clock +0.3%, noisy: slant correction 34.6 dB, none 8.6 dB
all checks passed

The numbers are PSNR (peak signal-to-noise ratio): how close the decoded picture is to the original, in decibels (↩ ch. 4: decibels). Above about 30 dB the difference is invisible; below about 20 dB it shows. Without slant correction, the drift ruins the picture.

Lab: receive a picture

The SSTV decoder takes pictures from a built-in transmitter (with noise and clock-error knobs), a recording, your microphone, or your dongle on 145.800 MHz when the ISS is sending. ARISS announces events at ariss.org; between events, try the recordings people share online.

Check yourself

What frequency does a mid-gray pixel (value 128) use?

1500 + 800 × 128/255 ≈ 1902 Hz, right in the middle of the 1500–2300 Hz range.

Why is the sync pulse at 1200 Hz, below black?

So no picture content can ever look like a sync: every pixel is 1500 Hz or above.

Your decoded picture leans to the right. What's wrong, and what fixes it?

The sender's and receiver's sample clocks disagree, so each line's timing drifts a little more. Measuring the sync pulses and fitting a line through their times (slant correction) predicts the true line starts.

Why do PD and Robot modes send color at half resolution?

Our eyes resolve detail in brightness much better than in color, so sending color differences at half resolution saves time with little visible loss.

Last updated