Browser RF packet: format and reference receiver
================================================

This is the format used by the article's "Transmit repeatedly" button. It is
separate from the native 6,500-symbol/s CLI and the blind-reader photo packet.

Run the measured example (Python 3.10+ and NumPy required):

    uv run --with numpy decode.py sample-phone-spectrogram.npz

The output must contain the UTF-8 message "I hope this works baby ABC" and
"crc_ok": true. The sample is a real, reduced RSP1B spectrogram from an iPhone
browser transmission. It is cropped to 1.9906–2.0394 MHz to omit unrelated RF.
It is not raw IQ or a synthetic signal. The decoder is not given the message
or the emitting line's frequency.

To decode your own 20-second raw capture, record signed, little-endian,
interleaved int16 I,Q at exactly 2,000,000 complex samples/s. For example,
with the SDR tuned to 1,400,000 Hz:

    uv run --with numpy decode.py capture.iq --center-hz 1400000

The receiver searches usable frequencies in that passband for the public
preamble. The carrier is an incidental RF line from the device and can differ
between a Mac and an iPhone. A strong signal and good near-field placement are
needed; a CRC-valid result is the criterion for a complete decoded packet.

Wire format
-----------

* On/off keying at 32 milliseconds per physical chip (31.25 chips/s).
  0 = idle; 1 = four WebAssembly Workers repeatedly touch memory.
  Each Worker allocates 16 MiB once before transmission. Memory is not
  allocated anew for each chip.
* A 750 ms idle lead precedes each packet. The UI also waits 250 ms after a
  complete packet before starting another 750 ms lead, so repeated packets
  have about one second of idle time between them.
* The 32 uncoded preamble chips are:

      00000000111111110000111100001111

* The logical data bytes are: one unsigned 8-bit UTF-8 byte count (1–34),
  that many UTF-8 bytes, and a 16-bit CRC-16/CCITT-FALSE of the count byte
  followed by the payload. CRC parameters: polynomial 0x1021, initial
  register 0xFFFF, no reflection, final XOR 0. Bits and CRC transmit MSB first.
* Zero-pad the logical bits to an 11-bit boundary. Encode each 11-bit group
  using systematic Hamming(15,11), even parity at one-based bit positions
  1, 2, 4, and 8; data bits occupy the other positions in ascending order.
* Keep the first 15-bit codeword in place, so the length byte is readable
  before the full frame size is known. For the remaining R codewords, emit
  columns c = 0..14; within each column emit rows (n+c) mod R for n = 0..R-1.
  One resulting coded bit is one physical 32 ms chip.

The receiver matches the preamble over time and frequency, estimates 0/1
levels from that preamble, decodes the first Hamming word to obtain length,
reads the matching number of coded chips, reverses the diagonal interleaver,
decodes Hamming words, checks CRC, and then decodes strict UTF-8. A local
frequency-tracking fallback handles a line that moves between FFT bins.

The maximum 34-byte message uses 437 chips, or 13.984 seconds of symbols;
the 750 ms lead keeps one packet inside the browser's 15-second Worker limit.

Files
-----

decode.py                    Command-line receiver for .npz or raw .iq input
analysis.py                  IQ-to-spectrogram reduction and preamble search
ook_fast32.py                Hamming/interleaver/CRC packet decoder
sample-phone-spectrogram.npz Measured, frequency-cropped phone capture

The sample spectrogram has 10.24 ms time bins and grouped 1.953 kHz
frequency bins. The original uncropped reduced capture's SHA-256 is recorded
in sample-provenance.json. No raw IQ was saved for this phone packet.
