1313from sigint_examples .plotting import plot_basic_workflow
1414import argparse
1515
16- # Parse command-line arguments
17- parser = argparse .ArgumentParser (description = "Run basic SIGINT workflow" )
18- parser .add_argument (
19- "--show-plots" ,
20- action = "store_true" ,
21- help = "Display plots during execution"
22- )
23- args = parser .parse_args ()
24- SHOW_PLOTS = args .show_plots
16+ def main ():
17+ # Parse command-line arguments
18+ parser = argparse .ArgumentParser (description = "Run basic SIGINT workflow" )
19+ parser .add_argument (
20+ "--show-plots" ,
21+ action = "store_true" ,
22+ help = "Display plots during execution"
23+ )
24+ args = parser .parse_args ()
25+ SHOW_PLOTS = args .show_plots
26+
27+ # -----------------------------
28+ # Parameters
29+ # -----------------------------
30+ fs = 1_000_000 # 1 MHz sampling rate
31+ duration = 0.002 # 2 ms total time
32+ fc = 100_000 # 100 kHz carrier frequency
33+ PRI = 100e-6 # 100 µs pulse repetition interval
34+ pulse_width = 5e-6 # 5 µs pulse width
35+ SNR_dB = 0 # Noise level in dB
36+ seed = 42 # For reproducibility
2537
26- # -----------------------------
27- # Parameters
28- # -----------------------------
29- fs = 1_000_000 # 1 MHz sampling rate
30- duration = 0.002 # 2 ms total time
31- fc = 100_000 # 100 kHz carrier frequency
32- PRI = 100e-6 # 100 µs pulse repetition interval
33- pulse_width = 5e-6 # 5 µs pulse width
34- SNR_dB = 0 # Noise level in dB
35- seed = 42 # For reproducibility
38+ # -----------------------------
39+ # Generate pulse train
40+ # -----------------------------
41+ t , clean_signal , rx_signal = generate_basic_pulse_train (
42+ fs , duration , PRI , pulse_width , fc , SNR_dB , seed = seed
43+ )
3644
37- # -----------------------------
38- # Generate pulse train
39- # -----------------------------
40- t , clean_signal , rx_signal = generate_basic_pulse_train (
41- fs , duration , PRI , pulse_width , fc , SNR_dB , seed = seed
42- )
45+ # -----------------------------
46+ # Processing
47+ # -----------------------------
48+ mf_output = matched_filter ( rx_signal , pulse_width , fs )
49+ auto , lags = autocorrelation ( rx_signal )
50+ PRI_estimate , peak_lags , auto_pos , lags_pos = estimate_PRI_from_autocorr ( auto , lags )
4351
44- # -----------------------------
45- # Processing
46- # -----------------------------
47- mf_output = matched_filter (rx_signal , pulse_width , fs )
48- auto , lags = autocorrelation (rx_signal )
49- PRI_estimate , peak_lags , auto_pos , lags_pos = estimate_PRI_from_autocorr (auto , lags )
52+ # Pulse width estimation using FWHM
53+ center_idx = np .argmax (auto_pos )
54+ half_max = auto_pos [center_idx ] / 2
55+ left_idx = np .where (auto_pos [:center_idx ] <= half_max )[0 ]
56+ left_idx = 0 if len (left_idx ) == 0 else left_idx [- 1 ]
57+ right_idx = np .where (auto_pos [center_idx :] <= half_max )[0 ]
58+ right_idx = len (auto_pos )- 1 if len (right_idx ) == 0 else right_idx [0 ]+ center_idx
59+ pulse_width_estimate = lags_pos [right_idx ] - lags_pos [left_idx ]
5060
51- # Pulse width estimation using FWHM
52- center_idx = np .argmax (auto_pos )
53- half_max = auto_pos [center_idx ] / 2
54- left_idx = np .where (auto_pos [:center_idx ] <= half_max )[0 ]
55- left_idx = 0 if len (left_idx ) == 0 else left_idx [- 1 ]
56- right_idx = np .where (auto_pos [center_idx :] <= half_max )[0 ]
57- right_idx = len (auto_pos )- 1 if len (right_idx ) == 0 else right_idx [0 ]+ center_idx
58- pulse_width_estimate = lags_pos [right_idx ] - lags_pos [left_idx ]
61+ # -----------------------------
62+ # Display results
63+ # -----------------------------
64+ print (f"True PRI: { PRI * 1e6 :.2f} µs" )
65+ print (f"Estimated PRI from autocorrelation: { PRI_estimate * 1e6 :.2f} µs" )
66+ print (f"True pulse width: { pulse_width * 1e6 :.2f} µs" )
67+ print (f"Estimated pulse width (FWHM): { pulse_width_estimate * 1e6 :.2f} µs" )
5968
60- # -----------------------------
61- # Display results
62- # -----------------------------
63- print (f"True PRI: { PRI * 1e6 :.2f} µs" )
64- print (f"Estimated PRI from autocorrelation: { PRI_estimate * 1e6 :.2f} µs" )
65- print (f"True pulse width: { pulse_width * 1e6 :.2f} µs" )
66- print (f"Estimated pulse width (FWHM): { pulse_width_estimate * 1e6 :.2f} µs" )
69+ # -----------------------------
70+ # Plotting
71+ # -----------------------------
72+ if SHOW_PLOTS :
73+ plot_basic_workflow (
74+ t = t ,
75+ rx_signal = rx_signal ,
76+ clean_signal = clean_signal ,
77+ mf_output = mf_output ,
78+ auto = auto ,
79+ lags = lags ,
80+ peak_lags = peak_lags ,
81+ pulse_width_estimates = [pulse_width_estimate ]
82+ )
6783
68- # -----------------------------
69- # Plotting
70- # -----------------------------
71- if SHOW_PLOTS :
72- plot_basic_workflow (
73- t = t ,
74- rx_signal = rx_signal ,
75- clean_signal = clean_signal ,
76- mf_output = mf_output ,
77- auto = auto ,
78- lags = lags ,
79- peak_lags = peak_lags ,
80- pulse_width_estimates = [pulse_width_estimate ]
81- )
84+ if __name__ == "__main__" :
85+ main ()
0 commit comments