"""Find body byte ranges that look like absolute int8 sample data (smooth waveform).""" import sys sys.path.insert(0, ".") from analysis.load_bundle import load_bundle def looks_like_smooth_int8(buf): """Convert bytes to int8 and check if successive deltas are small (waveform-like).""" if len(buf) < 8: return 0.0 vals = [b if b < 128 else b - 256 for b in buf] diffs = [abs(vals[i+1] - vals[i]) for i in range(len(vals)-1)] avg_diff = sum(diffs) / len(diffs) return avg_diff def main(): for name in ("event-a", "event-c"): b = load_bundle(name) body = b.body # Scan with sliding window of 64 bytes; find segments where the bytes look like a smooth wave win = 64 scores = [] for i in range(len(body) - win): scores.append((i, looks_like_smooth_int8(body[i:i+win]))) # Lowest avg_diff means smoothest scores.sort(key=lambda x: x[1]) print(f"\n=== {name} (body={len(body)}) — smoothest 10 windows ===") for off, s in scores[:10]: print(f" +{off:>5} avg_diff={s:.2f} bytes={body[off:off+24].hex(' ')}") if __name__ == "__main__": main()