import json
import math
from pathlib import Path

d = json.loads(Path('starter.json').read_text())
wu = d['unity_hz']
phase_lag = sum(math.degrees(math.atan(wu / pole)) for pole in d['poles_hz'])
margin = 180 - phase_lag
assert margin >= d['phase_margin_min_deg']
assert 70 < margin < 80
print(f"PASS compensation phase_margin_deg={margin:.2f} threshold={d['phase_margin_min_deg']} model=two_pole")
