Last active
May 25, 2026 15:18
-
-
Save raytroop/d6f4353a1882e5a1042b0b2e9180f90e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Plot statistical and empirical eye diagrams from the smoke test fixtures.""" | |
| import os | |
| import sys | |
| import matplotlib | |
| # matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| sys.path.insert(0, "/path/to/SerDesSystemCProject") | |
| from eye_analyzer import EyeAnalyzer | |
| UI = 100e-12 | |
| DT = 1e-12 | |
| RNG = np.random.default_rng(42) | |
| def make_pulse_response(ui=UI, dt=DT, n_ui=20, tau_frac=0.3): | |
| sps = int(round(ui / dt)) | |
| t = np.arange(n_ui * sps) * dt | |
| tau = tau_frac * ui | |
| in_sig = (t < ui).astype(float) | |
| # Backward-Euler discretization: y[n] = (1-α)·y[n-1] + α·x[n] | |
| alpha = dt / (tau + dt) | |
| out = np.zeros_like(in_sig) | |
| out[0] = alpha * in_sig[0] | |
| for k in range(1, len(in_sig)): | |
| out[k] = out[k - 1] + alpha * (in_sig[k] - out[k - 1]) | |
| return out | |
| def make_nrz_waveform(ui=UI, dt=DT, n_bits=4000, noise=0.02): | |
| sps = int(round(ui / dt)) | |
| bits = RNG.choice([-0.4, 0.4], size=n_bits) | |
| raw = np.repeat(bits, sps).astype(float) | |
| tau = 0.3 * ui | |
| # Backward-Euler discretization: y[n] = (1-α)·y[n-1] + α·x[n] | |
| alpha = dt / (tau + dt) | |
| sig = np.zeros_like(raw) | |
| sig[0] = alpha * raw[0] | |
| for k in range(1, len(raw)): | |
| sig[k] = sig[k - 1] + alpha * (raw[k] - sig[k - 1]) | |
| sig += RNG.normal(0.0, noise, size=sig.shape) | |
| t = np.arange(len(sig)) * dt | |
| return t, sig | |
| fig, axes = plt.subplots(1, 2, figsize=(14, 6)) | |
| # Statistical mode | |
| pulse = make_pulse_response() | |
| a_stat = EyeAnalyzer(ui=UI, mode="statistical", modulation="nrz") | |
| a_stat.analyze(pulse, noise_sigma=0.005, jitter_rj=0.005, dt=DT) | |
| a_stat.plot_eye(ax=axes[0], title="Statistical eye (NRZ, RC pulse, σ=5mV, RJ=0.005UI)", cmap="hot") | |
| # Empirical mode | |
| t, v = make_nrz_waveform() | |
| a_emp = EyeAnalyzer(ui=UI, mode="empirical", modulation="nrz") | |
| a_emp.analyze((t, v)) | |
| a_emp.plot_eye(ax=axes[1], title="Empirical eye (NRZ, 4000 bits, σ=20mV)", cmap="hot") | |
| plt.tight_layout() | |
| out = "/tmp/eyes_compare.png" | |
| fig.savefig(out, dpi=150) | |
| print(f"wrote {out}") | |
| plt.figure() | |
| plt.plot(t, v) | |
| plt.show() |
raytroop
commented
May 25, 2026
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment