Decoder: streaming APT.Decoder (coherent PLL or envelope demod, sync A+B tracking loop with coasting and timing-jump re-lock), telemetry analysis, Q-gated impulse (FM click) repair. GUI with fast / realtime decode, Listen, live input, telemetry table, markers. Encoder: APT.Encoder with test impairments (noise, clicks, clock offset, fading, line-timing jump); encoder dialog that feeds the decoder. Tools: offline decode/encode, quality survey, stub-DOM GUI smoke test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NOAA APT decoder and encoder
Browser decoder and encoder for NOAA APT (2400 Hz AM subcarrier, 4160 words/s, 2 lines/s). No build step.
python3 -m http.server -d ~/dev/noaa-apt-2026 8000 # then open http://localhost:8000/
Opening index.html directly works for files. Live input needs the page to be
served, because browsers only allow microphone access from a secure page.
Files
| File | What |
|---|---|
apt.js |
Format constants, streaming APT.Decoder, APT.AnalyzeTelemetry, APT.RepairRow. No DOM; also loads in node. |
encoder.js |
APT.BuildLine, APT.TelemetryWedges, streaming APT.Encoder with test impairments, APT.EncodeAll. |
wav.js |
WAV reader/writer. Reads files at their native rate, unlike decodeAudioData, which resamples. |
app.js, encoder-ui.js, index.html, style.css |
GUI (decoder, encoder dialog) |
tools/decode.js |
node tools/decode.js in.wav out.pgm [lines.txt] [--envelope] [--repair[=strong]] |
tools/encode.js |
node tools/encode.js out.wav [--pgm img.pgm] [--lines N] [--rate R] [--snr dB] [--ppm N] [--jump LINE] |
tools/survey.js |
reference-free quality figures (lock %, sync, noise) for a set of WAVs |
tools/gui-smoke.js |
runs the GUI scripts on a stub DOM: encoder dialog, fast decode, repair toggles |
GUI
- Fast decode: decodes the whole file as fast as possible.
- Realtime: decodes at playback speed (1x/2x/4x/8x). Listen plays the audio. Pause with space; click the progress bar to start from that point.
- Live input: decodes a sound-card input, such as an SDR on a virtual cable. Listen monitors the input.
- Levels:
- Telemetry (default): per-frame wedge 8 = white, wedge 9 = black, interpolated between frames. Follows gain changes during a pass.
- Auto: image percentiles.
- Sync: sync pulse plateaus.
- Telemetry table: each 128-line frame with the AVHRR channel IDs from wedge 16. A change is shown in amber.
- Markers: click the image to mark a line. Each marker lists its line, time and input sample number.
- Demod: coherent (default) or envelope. Takes effect on the next decode.
- Repair: off / normal (default) / strong impulse repair, see below. Applied at display time; the decoded data are kept, so switching it off shows the raw decode. show tints repaired pixels red (never saved).
- Encoder…: see below.
Encoder
Encoder… opens a dialog. Sources:
- test pattern (checkerboard ramp in A, sine pattern in B);
- one image per channel (B empty = same as A; optional invert for IR style), scaled to 909 px wide, one line per row;
- a decoded full-line APT image (2080 wide, e.g. a reference PNG or Save PNG with Full line): either every word as is, or only the two images with fresh sync and telemetry.
Lines get sync A/B, minute markers (every 120 lines: 2 black, 2 white), and the 16-wedge telemetry: ramp 1/8..8/8, zero, PRTs, patch, back scan, wedge 16 = channel ID. Each word sets the amplitude of a 2400 Hz carrier phase-locked to the word clock (255 = full, 0 = 13%), band-limited to 2.4 kHz.
Impairments for testing: noise (SNR over the full band), FM clicks per second, sample-clock offset, fading, and the July 2019 line-timing jump (line N cut off after 1040 words).
Encode & decode loads the signal as the decoder input and fast-decodes it; Encode & decode realtime decodes it at playback speed with Listen; Download WAV saves 16-bit PCM.
Decoder
I/Q mix at 2400 Hz, Blackman FIR lowpass at 2150 Hz, then coherent detection (a 2 Hz PLL on the carrier; the pixel is the in-phase part) or envelope detection, then a linear resample to 8320 Hz (2 samples/word). Coherent mode also outputs the quadrature part per word (line.quad), which holds only noise.
Line timing:
- Locked: sync A and sync B correlated together within +-16 samples of the prediction.
- A second-order tracking loop places each line: small deviations move the line a quarter of the way (more while acquiring), weighted by sync confidence; a clearly better position (dropped samples, a jump) is taken at once. The loop also tracks the line length, so the sound-card clock offset (ppm) does not skew the image.
- Expected sync missing: wide search over the whole line, re-locking at once on a clear sync A (corr > 0.75) or sync A+B (> 0.6). This handles the satellite jumping its line timing, even at 0 dB SNR.
- Weak sync: coasts on the predicted timing for up to 120 lines (1 min) before falling back to an unlocked search across the whole line, confirmed on the next line.
Recovery of noisy recordings
Nothing here smooths the image. Every change was checked against ground truth: a clean real pass, re-encoded with known noise/clicks, decoded and compared.
-
Line placement (sync A+B, tracking loop): line-start jitter at 0 dB SNR went from 1.2 words (worst 8) to 0.04 words (worst 0.1); at -3 dB the worst is 0.2 words. Only where lines go changes, not the pixels.
-
Coherent detection: no Rician bias (envelope detection lifts dark pixels into a noise floor at low SNR). Same as envelope above ~12 dB SNR, 3 dB lower error at 0 dB. On the noisy reference passes the space-view noise relative to image range drops by 25-30%.
-
Impulse (click) repair: the noisy passes have FM threshold clicks, i.e. impulsive noise: 5-8% of quadrature samples beyond 4 sigma, against 0.006% for Gaussian noise. They show as black/white specks.
APT.RepairRowis a switching filter: a pixel is replaced by the median of its 8 neighbours only if it is off that median by > 4x the row noise and > 3x the neighbours' spread, and the quadrature channel spikes there. The image is all in-phase, so real detail never triggers it. Every other pixel is left as decoded. On ground truth:test signal RMS error raw repaired pixels changed changes that moved closer to truth clean 4.49 4.49 0 - 20 dB SNR 9.99 10.01 0.003% - 20 dB + 40 clicks/s 15.85 11.20 1.05% 99% 9 dB + 150 clicks/s 40.10 38.60 0.35% 99.9% Strong (K 3.5, Q 2.5, spread 2.5) takes more clicks at 98-99% precision. On real passes it repairs ~0.8-1.5% of pixels, mostly in bursts and at the noisy ends of the pass; mid-pass on a clean recording ~0.01%. Even the cleanest reference pass (202007151233) has a click burst at line ~838, about 100 clicks/s.
-
Telemetry: wedge values are medians across the wedge columns, so clicks do not bias the calibration.
Not done, on purpose: narrower filters, median or denoise filters, line averaging. They remove noise only by removing detail. Lines that are pure noise stay noise; nothing is invented.
Checked against the 253 WAV/PNG pairs in ~/Downloads/apt/{audio,raw}: line counts match the reference decoder within +-2 lines, except where the reference stopped early or cropped. The two all-noise recordings stay unlocked.
201907201213: where the malfunction starts
NOAA-15 AVHRR, July 2019.
full .wav |
_glitch.wav |
|
|---|---|---|
_glitch.wav starts at |
line 563, ~281.4 s | 0 |
| malfunction onset | line 655, 327.85 s (sample ~3,614,600 @ 11025) | line 92, 46.44 s |
_glitch.wav is the same audio as the full recording from 281.4 s onward: every decoded line matches, corr > 0.99. So the full file is good up to 327.85 s.
What happens at the onset:
- The satellite's line timing jumps by 1039 words, about half a line. Line 655 has sync A at word 0 and again at word 1040.
- A decoder that keeps its old timing, like the one behind the reference PNG, shows channels A and B swapped from there on. This decoder re-locks on the next line.
- The telemetry frame keeps its 128-line period. Wedge 16 changes from A=ch2/B=ch4 to A=ch4/B=ch2, and the A image ends partway across the line.
- The diagonal streaks follow, which looks like scan-motor jitter.