"""Find each segment boundary in the channel and check if errors reset there.""" from __future__ import annotations import sys from pathlib import Path REPO = Path(__file__).resolve().parents[1] sys.path.insert(0, str(REPO)) from minimateplus.waveform_codec import decode_waveform_v2 from analysis_idf.recon import TARGET, TXT, load_sidecar_samples def main(): buf = TARGET.read_bytes() sc = load_sidecar_samples(TXT) decoded = decode_waveform_v2(buf[0x0f1f:]) GEO_LSB = 0.0003 for ch in ("Tran", "Vert", "Long"): sc_counts = [int(round(v / GEO_LSB)) for v in sc[ch]] dec = decoded[ch] # Find every transition where error becomes zero from nonzero (or grows from zero) # Print indices where dec resyncs back to exact match. n = min(len(sc_counts), len(dec)) events = [] prev_match = True for i in range(n): match = sc_counts[i] == dec[i] if match != prev_match: kind = "RESYNC" if match else "DIVERGE" events.append((i, kind, sc_counts[i], dec[i])) prev_match = match print(f"{ch}: {len(events)} transitions") for i, kind, sc_v, dec_v in events[:20]: print(f" idx {i:4d} {kind:8s} sc={sc_v:6d} dec={dec_v:6d} diff={dec_v-sc_v:+d}") print() if __name__ == "__main__": main()