1+ #!/usr/bin/env python3
2+ """
3+ EyeAnalyzer Demo Script
4+
5+ This script demonstrates how to use the EyeAnalyzer module.
6+ It generates synthetic eye diagram data and performs analysis.
7+ """
8+
9+ import numpy as np
10+ import sys
11+ import os
12+
13+ # Add current directory to path
14+ sys .path .insert (0 , os .path .dirname (os .path .abspath (__file__ )))
15+
16+ from eye_analyzer import EyeAnalyzer
17+
18+ def generate_test_data (ui = 2.5e-11 , num_ui = 10000 , noise_level = 0.01 ):
19+ """
20+ Generate synthetic eye diagram data.
21+
22+ Args:
23+ ui: Unit interval in seconds
24+ num_ui: Number of UI to generate
25+ noise_level: Noise standard deviation in volts
26+
27+ Returns:
28+ Tuple of (time_array, value_array)
29+ """
30+ # Generate time array
31+ time_array = np .arange (num_ui ) * ui
32+
33+ # Generate PRBS-like binary signal
34+ np .random .seed (42 )
35+ value_array = np .random .choice ([0.4 , - 0.4 ], size = num_ui )
36+
37+ # Add noise
38+ value_array += np .random .normal (0 , noise_level , size = num_ui )
39+
40+ return time_array , value_array
41+
42+ def main ():
43+ """Main demo function."""
44+ print ("=" * 60 )
45+ print ("EyeAnalyzer Demo" )
46+ print ("=" * 60 )
47+
48+ # Parameters
49+ ui = 2.5e-11 # 10Gbps
50+ num_ui = 10000
51+ noise_level = 0.01
52+
53+ print (f"\n Generating test data:" )
54+ print (f" UI: { ui :.2e} s (10 Gbps)" )
55+ print (f" Number of UI: { num_ui } " )
56+ print (f" Noise level: { noise_level } V" )
57+
58+ # Generate test data
59+ time_array , value_array = generate_test_data (ui , num_ui , noise_level )
60+
61+ print (f"\n Data statistics:" )
62+ print (f" Time range: { time_array [0 ]:.2e} to { time_array [- 1 ]:.2e} s" )
63+ print (f" Value range: { value_array .min ():.3f} to { value_array .max ():.3f} V" )
64+ print (f" Value mean: { value_array .mean ():.3f} V" )
65+ print (f" Value std: { value_array .std ():.3f} V" )
66+
67+ # Create analyzer
68+ print (f"\n Initializing EyeAnalyzer..." )
69+ analyzer = EyeAnalyzer (ui = ui , ui_bins = 128 , amp_bins = 128 )
70+
71+ # Perform analysis
72+ print (f"\n Analyzing eye diagram..." )
73+ metrics = analyzer .analyze (time_array , value_array )
74+
75+ # Save results
76+ output_dir = 'demo_results'
77+ print (f"\n Saving results to '{ output_dir } /'..." )
78+ analyzer .save_results (metrics , output_dir )
79+
80+ # Print summary
81+ print ("\n " + "=" * 60 )
82+ print ("Analysis Complete!" )
83+ print ("=" * 60 )
84+ print (f"\n Eye Metrics:" )
85+ print (f" Eye Height: { metrics ['eye_height' ]* 1000 :.2f} mV" )
86+ print (f" Eye Width: { metrics ['eye_width' ]:.3f} UI" )
87+ print (f"\n Output Files:" )
88+ print (f" 📄 { os .path .join (output_dir , 'eye_metrics.json' )} " )
89+ print (f" 🖼️ { os .path .join (output_dir , 'eye_diagram.png' )} " )
90+ print ("=" * 60 )
91+
92+ if __name__ == "__main__" :
93+ main ()
0 commit comments