#!/usr/bin/env python3 """List RF bursts in a raw rtl_sdr u8 IQ capture and the gaps between them. Usage: iq_bursts.py iq.raw [sample_rate] [threshold_db] Purpose: distinguish "transmitter produced no RF" from "RF exists but the decoder cannot decode it". A repeater under test should produce burst PAIRS separated by approximately the configured repeat delay. """ import sys import numpy as np path = sys.argv[1] fs = int(sys.argv[2]) if len(sys.argv) > 2 else 1_600_000 thr_db = float(sys.argv[3]) if len(sys.argv) > 3 else 9.0 WIN = fs // 1000 # 1 ms resolution CHUNK = fs * 2 # 1 s of bytes env = [] with open(path, "rb") as f: while True: raw = f.read(CHUNK) if len(raw) < WIN * 2: break buf = np.frombuffer(raw, dtype=np.uint8).astype(np.float32) - 127.5 iq = buf[0::2] + 1j * buf[1::2] p = np.abs(iq) ** 2 p = p[: (len(p) // WIN) * WIN].reshape(-1, WIN).mean(axis=1) env.append(p) db = 10 * np.log10(np.concatenate(env) + 1e-9) floor = np.median(db) print(f"windows={len(db)} floor={floor:.1f}dB p99={np.percentile(db,99):.1f} max={db.max():.1f}") active = db > floor + thr_db idx = np.where(active)[0] bursts = [] if len(idx): start = prev = idx[0] for i in idx[1:]: if i > prev + 3: # >3 ms silence splits bursts bursts.append((start, prev)) start = i prev = i bursts.append((start, prev)) print(f"bursts (>{thr_db:.0f} dB over floor): {len(bursts)}") prev_end = None pairs = [] for s, e in bursts: gap = (s - prev_end) if prev_end is not None else None dur = e - s + 1 peak = db[s:e + 1].max() - floor gtxt = f"gap={gap:>5} ms" if gap is not None else "gap= - " print(f" t={s/1000:8.3f}s dur={dur:>3} ms peak=+{peak:5.1f} dB {gtxt}") if gap is not None and 10 <= gap <= 300: pairs.append((prev_end, s, gap)) prev_end = e print(f"\nburst pairs with 10-300 ms spacing (repeat candidates): {len(pairs)}") for a, b, g in pairs[:40]: print(f" original ends {a/1000:.3f}s -> next starts {b/1000:.3f}s (gap {g} ms)")