# Python model of the 16 nm DMPPM resonant HBC transceiver (Li et al., CICC 2026)

There are two models of the same link, plus a loop that feeds results from the block-level
model back into the system model.

```
hbc/
  params.py          every parameter, tagged [paper] / [derived] / [assumed] / [calibrated]
  dmppm.py           protocol: bits <-> Gray symbols <-> pulse intervals (shared by both models)
  system_model.py    (1) INDEPENDENT SYSTEM MODEL - equations + symbol-level Monte Carlo
  blocks/
    dtc.py           TX delay-line DTC: 1 ns grid, static INL, jitter
    resonant_tx.py   switched RLC circuit (pass-gate, L, C_load, C_lx, RC damper, tuning bank
                     with ESR, reset switch), exact matrix-exponential solve, C_TUNE calibration
    channel.py       EQS body channel: path loss vs distance (Fig. 10), band limits, multipath,
                     per-pulse amplitude variation, 60 Hz mains
    rx_afe.py        819 kHz input HPF, noise/offset, S0/S1/S2 amps, coarse comparator,
                     RC one-shot power gating, HPF differentiator, LPF, fine comparator
                     (zero-crossing mode, or fixed-threshold mode for comparison)
    tdc.py           two ping-pong GRO TDCs: quantisation, sqrt(T) jitter, gain mismatch
  integrated.py      (2) BLOCKS CHAINED INTO THE SYSTEM - waveform-level, end to end, incl. TDMA
  proposed.py        the proposed design: ZCS tank, slot grid + preamble TDC calibration, dead-time
                     amplifier gating, antiphase drive, RS(63,51) with erasures, V_TH servo + baseline
                     restore, single timestamp counter, thin-film coil; system and block level
  calibrate.py       back-annotation: block-level results -> system-model parameters
run_all.py           runs everything, writes results/F*.png and results/summary.md
tests/               pytest: protocol round trip, RLC loss = pi/(2Q), energy conservation, ...
```

## Proposed design

```python
from hbc.proposed import ProposedParams, apply_proposed, ProposedSystemModel, ProposedIntegrated
q = apply_proposed(SystemParams(), ProposedParams(zcs=True, gate_amps=True, coding=True))
ProposedSystemModel(q).summary()["sensitivity_dbm"]
ProposedIntegrated(q).run(2000, rx_vpp=0.03)["ber"]      # information BER after RS decoding
```

## How the two models differ

| | (1) System model | (2) Integrated block model |
|---|---|---|
| TX | `E = pi R C^1.5 V^2 / 4 sqrt(L)` + parasitic + gate + detune | circuit simulation of the switched RLC, energy integrated from supply current |
| Channel | straight-line fit in dB vs distance | piecewise dB interpolation + filters, echo, mains, per-pulse fading |
| RX timing | `sigma_t = penalty * sigma_v / (A w0/2)` | actual filter chain, noise, power-gated comparator, zero-crossing interpolation |
| Detection | Q-function miss, Rice false-alarm rate | coarse comparator + non-retriggerable one-shot on simulated noise |
| BER | closed form (+ fast symbol-level MC) | bits in, bits out, scored against the truth |
| Power | sum of the paper's numbers | measured from block activity (pulses fired, S3 duty, TDC run time) |

## Usage

```bash
pip install numpy scipy matplotlib pytest
python run_all.py --quick      # ~1.5 min  (full: ~2.5 min)
python -m pytest -q tests
```

```python
from hbc.params import SystemParams
from hbc.system_model import SystemModel
from hbc.integrated import IntegratedSystem

p = SystemParams()
SystemModel(p).link(rx_vpp=0.035).ber            # analytic
IntegratedSystem(p).run(4000, rx_vpp=0.035)["ber"]  # block-level, waveform simulation
IntegratedSystem(p).run(4000, d_cm=150)            # with channel model
```

## What the integration showed (things the simple system model misses)

1. **Baseline wander from the AC-coupled input.** The 819 kHz input HPF removes the DC of the
   pulse train, so the baseline sits about 8% of A below zero. Between pulses this keeps noise
   away from the coarse threshold, so false alarms are far fewer than Rice predicts. Without it,
   the paper-only system model floors at BER ~1e-3 (F6, dotted). It is now back-annotated
   (`baseline_wander=True`) as a time-resolved baseline b(t) that recovers with
   tau = R_in*C_in ~ 194 ns. Using the average alone missed the false pulses that cluster late
   in long intervals.
2. **Timing penalty.** The simulated differentiator chain does about 1.9 dB *better* than the
   naive noise-bandwidth reference. The paper's "3 dB" is relative to a different reference, so
   it's fitted rather than assumed.
3. **Resonance calibration.** With C_lx and the damper loading the tank, the best C_TUNE code is
   about 4-6, while the ideal-LC system model says about 16 (F2).
4. **Deterministic timing errors.** Rounding to the 1 ns DTC grid (±1 ns triangular) and the
   ±0.1% gain mismatch between the two TDCs (±0.4 ns over 400 ns) eat into the ±3.125 ns half-slot.
   They cause a BER floor near 1e-4 even at large signal (F10). Fixes: put the slots on the DTC
   grid, or calibrate the TDC gains.
5. **1 b/pulse sensitivity.** The block model gets −57.6 dBm and the system model −55.5 dBm,
   against −61 in the paper. The system model counts a single look at the pulse peak, but the
   comparator gets many chances while the pulse is above threshold. The 3 dB gap to the paper
   comes from sizing the coarse threshold for < 1e-3 false alarms/symbol at the noise level
   fitted for 6 b/pulse.
6. **Headline 2.2 pJ/b.** Both models land at about 4.3 pJ/b TX+RX (0.9-1.0 TX, 3.4 RX), which
   matches the paper's own 12.75 uW + 48 uW at 15 Mb/s. The paper doesn't define its 2.2 pJ/b.

The paper doesn't give the TDC LSB, amplifier noise, R_on, ESR and electrode R. Those values are
assumed and tagged in `params.py`. They were picked to reproduce the paper's measured TX power
breakdown (Fig. 13) and its 6 b/pulse sensitivity.
