Hexadecimal is a true answer to "what did that say" and not a useful one. This is the work of turning the rest of what a receiver hears into something a person can read, and most of it is pictures. PICTURES Three of the things on the air are images rather than sounds, and all three arrive as the audio a scan already records: SSTV 14.230 and 144.5 MHz Martin M1/M2, Scottie S1/S2/DX, Robot 36/72 APT 137-138 MHz the NOAA weather satellites HF fax 2-20 MHz, sideband the marine weather charts Each is written from its published specification, and the generators used to test them are written from the same specification without reference to the decoders -- so a picture that comes back matching the one that went in is evidence about the format. Every SSTV mode reproduces its published line time exactly, which is worth failing a test over: a line a few milliseconds long walks the picture off the screen inside ten lines. Against synthetic transmissions at 30 dB SNR, SSTV is 96-98% of pixels exact, APT correlates at 0.97 and fax at 0.998; all three still read at 6-12 dB. None of the three is guessed at, and that is what makes it safe to try them on every recording. SSTV needs its VIS header, APT needs both line syncs at the right distance from each other, fax needs the phasing signal. No false pictures in 295 attempts over noise, tones, speech and swept whistles. Two things had to be got right beyond the arithmetic. A band-pass does not switch between two tones, it slides between them, so every edge is measured at the midpoint of the slide rather than at the first sample past a threshold -- the earlier version was reading the coarse search stride back as the edge and shifting Martin M1 sideways by a whole colour bar. And a picture now keeps its capture whatever the content check made of it: a satellite is a steady tone with a wobble on it and SSTV is a whistle, so both were being discarded as "no signal content" having already been recognised. PNG is written here rather than pulled in from Pillow. A scanner that cannot start because an imaging library is missing is worse than one that cannot draw. saunterbrowse marks a picture in the list, gives its path in full -- wrapped rather than cut off, because half a path opens nothing -- and moves or deletes the PNGs with the recording. o prints the picture's path, not the audio's. GRIB is not a modulation and is not pretended to be one. It is the format weather models are published in and it travels by satellite link and by e-mail; where a decoded byte stream begins with its magic number it is named, and that is all. AIRCRAFT `bandsaunter adsb` parks the receiver on 1090 MHz and reads Mode S extended squitter: address, callsign, altitude, position, speed. A command of its own because a megabit a second will not go through a channel twelve and a half kilohertz wide. Every frame carries a 24-bit checksum so there is no threshold anywhere in it -- with one trap, which is that a frame of all zeros satisfies that checksum and silence is exactly that. Positions round trip exactly through compact position reporting, and a pair straddling a longitude-zone boundary is refused rather than resolved against two grids. METERS AND SENSORS Itron ERT utility meters on 900 MHz and AcuRite weather sensors on 433 MHz are named rather than reported as hex, and neither is believed without its own checksum -- BCH(255,239) for the meter, a checksum and four parity bits for the sensor. Both are implemented from published descriptions and checked against frames built from the same descriptions, which proves the framing and the arithmetic and is not the same as having held a meter. HEX INTO WORDS Everything else that decodes to bits now gets its fields named where the shape is standard, its text read out where there is text, and its bytes laid out in groups with the printable characters beside them. The text search is where the care went, because printability is not evidence. Forty framings of each packet, and seven-bit values printable three in four, meant a bar set on printability called 64% of random payloads text. Real text is nearly all one case where random letters are half and half, two fifths vowels where random is a fifth, and mostly alphanumeric where random draws punctuation one time in four. Together: under 0.5%, measured in the suite. CALLSIGNS The licensed address is recorded in full -- the street, not merely the town -- and goes into the KML with everything else. US amateur records are public by law and carry it; holding it and not saying so is worse than either showing it or not asking, and --no-lookup asks for none of it. Also here: Morse is decoded again from the whole recording where the capture was made in cw mode. The first pass works from the classifier's buffer, which holds a few seconds -- enough to say "this is Morse", not enough to catch a callsign whole between two word gaps, so a beacon repeating every eight seconds through an eight-second window was never identified. And classify._psk_order took the logarithm of zero on a silent block. 1318 tests, up from 1161. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016PsWPTweCT6pwxKngvVxcg
198 lines
8.3 KiB
Python
198 lines
8.3 KiB
Python
"""Generate SSTV, APT and HF fax audio, so the decoders can be tested.
|
|
|
|
Written from the mode specifications rather than from the decoders, so that a
|
|
decoder agreeing with one of these is evidence rather than a tautology.
|
|
"""
|
|
import numpy as np
|
|
|
|
from bandsaunter.sstv import (BIT_ONE_HZ, BIT_ZERO_HZ, BLACK_HZ, BREAK_HZ,
|
|
LEADER_HZ, SYNC_HZ, WHITE_HZ, SSTVMode)
|
|
|
|
|
|
def fm(segments, rate: float) -> np.ndarray:
|
|
"""Turn ``(hertz, seconds)`` pairs into one continuous-phase tone."""
|
|
phase = 0.0
|
|
out = []
|
|
for hz, seconds in segments:
|
|
n = max(1, int(round(seconds * rate)))
|
|
freq = np.full(n, float(hz)) if np.isscalar(hz) else np.asarray(hz)
|
|
if freq.size != n:
|
|
freq = np.interp(np.linspace(0, 1, n),
|
|
np.linspace(0, 1, freq.size), freq)
|
|
step = 2.0 * np.pi * freq / rate
|
|
angles = phase + np.cumsum(step)
|
|
phase = float(angles[-1] % (2.0 * np.pi))
|
|
out.append(np.sin(angles))
|
|
return np.concatenate(out) if out else np.zeros(0)
|
|
|
|
|
|
def _levels(row: np.ndarray) -> np.ndarray:
|
|
"""A row of 0-255 as the frequencies that carry it."""
|
|
return BLACK_HZ + np.asarray(row, dtype=np.float64) / 255.0 * (
|
|
WHITE_HZ - BLACK_HZ)
|
|
|
|
|
|
def vis_header(code: int) -> list:
|
|
bits = [(code >> i) & 1 for i in range(7)]
|
|
bits.append(sum(bits) % 2) # even parity
|
|
out = [(LEADER_HZ, 0.300), (BREAK_HZ, 0.010), (LEADER_HZ, 0.300),
|
|
(SYNC_HZ, 0.030)]
|
|
out += [(BIT_ONE_HZ if b else BIT_ZERO_HZ, 0.030) for b in bits]
|
|
out.append((SYNC_HZ, 0.030)) # stop bit
|
|
return out
|
|
|
|
|
|
def sstv_audio(mode: SSTVMode, image: np.ndarray, rate: float = 16000.0,
|
|
lines: int | None = None, lead: float = 0.2,
|
|
snr_db: float = 40.0, seed: int = 0) -> np.ndarray:
|
|
"""A whole SSTV transmission: header, then the picture, line by line.
|
|
|
|
Built from the mode's own segment list, so that a decoder agreeing with
|
|
this is agreeing about the published line structure rather than about a
|
|
second copy of the same guess.
|
|
"""
|
|
rng = np.random.default_rng(seed)
|
|
height = lines if lines is not None else min(mode.height, image.shape[0])
|
|
segments = [(0.0, lead)] + vis_header(mode.vis)
|
|
if not mode.sync_first:
|
|
# Scottie sends one sync pulse before the first line, because its
|
|
# per-line pulse comes two thirds of the way through.
|
|
segments.append((SYNC_HZ, mode.sync))
|
|
for y in range(height):
|
|
row = image[y % image.shape[0]].astype(np.float64)
|
|
red, green, blue = row[:, 0], row[:, 1], row[:, 2]
|
|
luma = 0.299 * red + 0.587 * green + 0.114 * blue
|
|
chroma_u = 0.564 * (blue - luma) + 128.0
|
|
chroma_v = 0.713 * (red - luma) + 128.0
|
|
scans = {"R": red, "G": green, "B": blue, "Y": luma,
|
|
"U": chroma_u, "V": chroma_v,
|
|
"C": chroma_v if y % 2 == 0 else chroma_u}
|
|
for what, seconds in mode.segments():
|
|
if seconds <= 0:
|
|
continue
|
|
if what == "sync":
|
|
segments.append((SYNC_HZ, seconds))
|
|
elif len(what) == 1:
|
|
segments.append((_levels(scans[what]), seconds))
|
|
else:
|
|
segments.append((BLACK_HZ, seconds))
|
|
audio = fm(segments, rate)
|
|
if snr_db < 60:
|
|
noise = np.sqrt(np.mean(audio ** 2) / (10 ** (snr_db / 10.0)))
|
|
audio = audio + noise * rng.standard_normal(audio.size)
|
|
return audio
|
|
|
|
|
|
def colour_card(width: int = 320, height: int = 256) -> np.ndarray:
|
|
"""A picture with structure a decoder can be checked against.
|
|
|
|
Colour bars across the top, a grey wedge down the middle and a border, so
|
|
that a picture decoded with the colours swapped, the lines out of order or
|
|
the geometry wrong looks wrong in a way a test can measure.
|
|
"""
|
|
image = np.zeros((height, width, 3), dtype=np.uint8)
|
|
bars = [(255, 255, 255), (255, 255, 0), (0, 255, 255), (0, 255, 0),
|
|
(255, 0, 255), (255, 0, 0), (0, 0, 255), (0, 0, 0)]
|
|
band = height // 2
|
|
for i, colour in enumerate(bars):
|
|
lo = i * width // len(bars)
|
|
hi = (i + 1) * width // len(bars)
|
|
image[:band, lo:hi] = colour
|
|
wedge = np.linspace(0, 255, width).astype(np.uint8)
|
|
image[band:, :] = wedge[None, :, None]
|
|
image[:, :2] = 255
|
|
image[:, -2:] = 255
|
|
return image
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# APT
|
|
# ---------------------------------------------------------------------------
|
|
|
|
APT_SYNC_A = "0" + "1100" * 7 + "0" * 8 # 1040 Hz square, 39 words
|
|
APT_SYNC_B = "0" + "11100" * 7 + "0" * 3
|
|
|
|
|
|
def apt_audio(image: np.ndarray, rate: float = 16000.0,
|
|
snr_db: float = 40.0, seed: int = 0,
|
|
subcarrier: float = 2400.0) -> np.ndarray:
|
|
"""A NOAA APT transmission: two lines a second, 2080 words each.
|
|
|
|
``image`` is greyscale and becomes channel A; channel B is the same
|
|
picture inverted, which is what a real pass looks like when one channel is
|
|
visible and the other infrared.
|
|
"""
|
|
rng = np.random.default_rng(seed)
|
|
words_per_line = 2080
|
|
lines = image.shape[0]
|
|
frame = np.zeros((lines, words_per_line), dtype=np.float64)
|
|
for y in range(lines):
|
|
row = np.interp(np.linspace(0, 1, 909),
|
|
np.linspace(0, 1, image.shape[1]),
|
|
image[y].astype(np.float64))
|
|
line = np.zeros(words_per_line)
|
|
line[0:39] = np.array([255.0 if c == "1" else 11.0
|
|
for c in APT_SYNC_A.ljust(39, "0")])
|
|
line[39:86] = 11.0 # space A
|
|
line[86:995] = row
|
|
line[995:1040] = 128.0 # telemetry A
|
|
line[1040:1079] = np.array([255.0 if c == "1" else 11.0
|
|
for c in APT_SYNC_B.ljust(39, "0")])
|
|
line[1079:1126] = 11.0
|
|
line[1126:2035] = 255.0 - row
|
|
line[2035:2080] = 128.0
|
|
frame[y] = line
|
|
|
|
words = frame.reshape(-1)
|
|
word_rate = 4160.0
|
|
n = int(round(words.size / word_rate * rate))
|
|
envelope = np.interp(np.linspace(0, 1, n), np.linspace(0, 1, words.size),
|
|
words) / 255.0
|
|
t = np.arange(n) / rate
|
|
audio = (0.1 + 0.9 * envelope) * np.sin(2 * np.pi * subcarrier * t)
|
|
if snr_db < 60:
|
|
noise = np.sqrt(np.mean(audio ** 2) / (10 ** (snr_db / 10.0)))
|
|
audio = audio + noise * rng.standard_normal(audio.size)
|
|
return audio
|
|
|
|
|
|
def grey_card(width: int = 909, height: int = 40) -> np.ndarray:
|
|
"""A greyscale picture with a hard edge and a ramp, for APT and fax."""
|
|
image = np.zeros((height, width), dtype=np.uint8)
|
|
image[:, :] = np.linspace(0, 255, width).astype(np.uint8)[None, :]
|
|
image[height // 3:2 * height // 3, width // 4:width // 2] = 255
|
|
image[:, ::128] = 0
|
|
return image
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# HF fax
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def fax_audio(image: np.ndarray, rate: float = 16000.0, lpm: float = 120.0,
|
|
ioc: int = 576, black: float = 1500.0, white: float = 2300.0,
|
|
start_seconds: float = 5.0, phasing_lines: int = 20,
|
|
snr_db: float = 40.0, seed: int = 0) -> np.ndarray:
|
|
"""A weather fax transmission: start tone, phasing, then the chart."""
|
|
rng = np.random.default_rng(seed)
|
|
pixels = int(round(np.pi * ioc))
|
|
line_seconds = 60.0 / lpm
|
|
segments = [(black, 0.5)]
|
|
# The start tone: 300 Hz for 120 lpm, sent as black/white alternation.
|
|
tone_period = 1.0 / 300.0
|
|
for _ in range(int(start_seconds / tone_period)):
|
|
segments += [(white, tone_period / 2), (black, tone_period / 2)]
|
|
# Phasing: a white pulse at the start of each line, black for the rest.
|
|
for _ in range(phasing_lines):
|
|
segments += [(white, line_seconds * 0.05),
|
|
(black, line_seconds * 0.95)]
|
|
for y in range(image.shape[0]):
|
|
row = np.interp(np.linspace(0, 1, pixels),
|
|
np.linspace(0, 1, image.shape[1]),
|
|
image[y].astype(np.float64))
|
|
segments.append((black + row / 255.0 * (white - black), line_seconds))
|
|
audio = fm(segments, rate)
|
|
if snr_db < 60:
|
|
noise = np.sqrt(np.mean(audio ** 2) / (10 ** (snr_db / 10.0)))
|
|
audio = audio + noise * rng.standard_normal(audio.size)
|
|
return audio
|