Skip to content

Make the SSTV decoder work on real off-air audio - #480

Merged
smittix merged 2 commits into
mainfrom
fix/sstv-decoder
Nov 13, 2026
Merged

smittix merged 2 commits into
mainfrom
fix/sstv-decoder

Conversation

@smittix

@smittix smittix commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Problem

Live HF SSTV tests (Scottie 2 and Martin 1 transmissions on 2026-11-13) detected the incoming transmission but decoded an all-white speckled image. The ISS SSTV mode shares the same pipeline and was equally affected.

Root causes

  1. VIS code read as 8 data bits instead of 7 + parity. The detector swallowed the parity bit as data, read the stop bit as parity, and consumed 30 ms of image audio as the "stop bit". Every image started one VIS bit late (a constant 64–75 px shift), and detection itself only succeeded through the single-bit error-correction fallback — gated on an effectively random decode of the 1200 Hz stop tone. The test helper encoded the same wrong format, so the suite was self-consistently green.
  2. No bandpass before the instantaneous-frequency demodulator. rtl_fm's SSB output is noisy across its full bandwidth (24 kHz at 48 kS/s). The Hilbert/instantaneous-frequency demodulator reads wideband noise as a very high frequency, clipping pixels to white — while the narrowband Goertzel VIS detector still hears the tones fine. That asymmetry is exactly "detected the transmission, image is white mush".
  3. Scottie's one-off 9 ms starting sync was never consumed, and Scottie lines never re-sync, so its images carried a second permanent shift.
  4. Sync search picked the window with maximum 1200 Hz energy, which lands anywhere on the pulse's plateau (±½ window). It now locates the pulse's trailing edge, which also survives the VIS stop-bit tail (also 1200 Hz) merging into the first sync. Channel segments are demodulated with guard samples so FFT edge artifacts no longer blow out the first/last pixel of fast modes.

Fixes

  • 7-bit VIS parsing (vis.py), matching MMSSTV/QSSTV/phone apps.
  • Linear-phase FIR bandpass 400–3000 Hz, group-delay compensated, applied in both the live rtl_fm pipeline and decode_file (dsp.py, sstv_decoder.py), plus clamping of per-sample frequency to the SSTV tone range.
  • Scottie starting-sync consumption with sync-end search on line 0 (image_decoder.py).
  • Trailing-edge sync locator (vectorized via goertzel_batch) and guard-sample channel demodulation (image_decoder.py).

Validation

New end-to-end harness encodes spec-timed transmissions (leader + VIS + image) and decodes them through the full pipeline:

Condition Before After
Clean, 6 modes (Martin 1/2, Scottie 1/2, Robot 36/72) MAE ≈ 115–122 (noise level) MAE 3.3–12.4
Wideband noise ≈ 4.5 dB broadband SNR white mess MAE 12–33, recognizable image, no white bias
SSB mistuning ±120–150 Hz — MAE 2.5–3.6
Vertical stripe position, per channel shifted 64–75 px within 2 px

The e2e encoder plus regression tests for VIS handover timing, stripe alignment (Martin 2, Scottie 2) and noise bleaching (Robot 36) are added to tests/test_sstv_decoder.py. All 111 SSTV tests pass; ruff and black clean.

🤖 Generated with Claude Code

smittix and others added 2 commits November 13, 2026 18:55
Live HF tests decoded the VIS header but produced an all-white speckled
image. Four defects, verified by encoding spec-timed transmissions
(leader + VIS + image, as MMSSTV/QSSTV and phone apps send them) and
decoding them through the full pipeline:

- The VIS reader took 7-bit codes as 8 data bits, so it swallowed the
  parity bit, read the stop bit as parity, and handed the image decoder
  its audio one bit (30 ms) late. Every mode decoded shifted by 64-75
  pixels, and detection itself only worked when the error-correction
  fallback happened to flip the phantom eighth bit.
- No bandpass before the instantaneous-frequency pixel demodulator.
  rtl_fm's SSB output carries noise across its whole bandwidth, and the
  demodulator reads that as a very high frequency, bleaching the image
  white even when the narrowband Goertzel VIS detector hears the signal
  clearly. Audio now passes a linear-phase FIR bandpass (400-3000 Hz,
  group delay compensated) in both the live and file pipelines, and
  per-sample frequencies are clamped to the SSTV tone range.
- Scottie's one-off 9 ms starting sync was never consumed, shifting
  Scottie images by a further constant amount; Scottie lines never
  re-sync, so the error could never heal.
- Sync search took 'window with the most 1200 Hz energy', which lands
  anywhere on the pulse's energy plateau. It now finds the trailing
  edge of the pulse, which also survives the stop-bit tail merging into
  the first sync. Channel demodulation gets guard samples around each
  segment so FFT edge artifacts stop blowing out the first and last
  pixel of fast modes.

A synthetic end-to-end matrix (Martin 1/2, Scottie 1/2, Robot 36/72;
clean, noisy, and ±150 Hz mistuned) now decodes with mean pixel error
3-13 on clean audio where it previously scored ~120 (noise-level), and
stays recognizable below 5 dB broadband SNR. The e2e encoder and the
regression tests for the handover, stripe alignment and noise bleaching
are in tests/test_sstv_decoder.py.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@smittix
smittix merged commit bbad2d9 into main Nov 13, 2026
7 checks passed
@smittix
smittix deleted the fix/sstv-decoder branch November 13, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant