This commit is contained in:
awe
2026-04-14 19:59:48 +03:00
parent 2a65b7a92a
commit d170fc11e5

View File

@ -815,6 +815,18 @@ def run_pyqtgraph(args) -> None:
spec_left_line.setVisible(False) spec_left_line.setVisible(False)
spec_right_line.setVisible(False) spec_right_line.setVisible(False)
p_complex_calib = win.addPlot(row=2, col=1, title="Комплексная калибровка: Re/Im после деления")
p_complex_calib.showGrid(x=True, y=True, alpha=0.3)
curve_complex_calib_real = p_complex_calib.plot(pen=pg.mkPen((80, 120, 255), width=1))
curve_complex_calib_imag = p_complex_calib.plot(pen=pg.mkPen((120, 200, 120), width=1))
p_complex_calib.setLabel("bottom", "ГГц")
p_complex_calib.setLabel("left", "Амплитуда")
try:
p_complex_calib.setXLink(p_line)
p_complex_calib.setVisible(bool(complex_sweep_mode))
except Exception:
pass
calib_cb = QtWidgets.QCheckBox("калибровка по огибающей") calib_cb = QtWidgets.QCheckBox("калибровка по огибающей")
complex_calib_cb = QtWidgets.QCheckBox("комплексная калибровка") complex_calib_cb = QtWidgets.QCheckBox("комплексная калибровка")
range_group = QtWidgets.QGroupBox("Рабочий диапазон") range_group = QtWidgets.QGroupBox("Рабочий диапазон")
@ -1249,44 +1261,13 @@ def run_pyqtgraph(args) -> None:
runtime.current_sweep_norm = None runtime.current_sweep_norm = None
runtime.current_fft_input = None runtime.current_fft_input = None
complex_calib_applied = False complex_calib_applied = False
if complex_calib_enabled and runtime.complex_calib_curve is not None: if complex_calib_enabled and runtime.complex_calib_curve is not None and fft_source is not None:
complex_source: Optional[np.ndarray] = None
if runtime.current_aux_curves is not None:
try:
aux_1, aux_2 = runtime.current_aux_curves
aux_1_arr = np.asarray(aux_1, dtype=np.float32).reshape(-1)
aux_2_arr = np.asarray(aux_2, dtype=np.float32).reshape(-1)
aux_width = min(aux_1_arr.size, aux_2_arr.size)
if aux_width > 0:
complex_source = (
aux_1_arr[:aux_width].astype(np.complex64)
+ (1j * aux_2_arr[:aux_width].astype(np.complex64))
)
except Exception:
complex_source = None
if complex_source is None and fft_source is not None:
fft_arr = np.asarray(fft_source).reshape(-1) fft_arr = np.asarray(fft_source).reshape(-1)
if fft_arr.size > 0 and np.iscomplexobj(fft_arr): if fft_arr.size > 0 and np.iscomplexobj(fft_arr):
complex_source = np.asarray(fft_arr, dtype=np.complex64) runtime.current_fft_input = normalize_by_complex_calibration(
np.asarray(fft_arr, dtype=np.complex64),
if complex_source is not None and complex_source.size > 0:
complex_norm = normalize_by_complex_calibration(
complex_source,
runtime.complex_calib_curve, runtime.complex_calib_curve,
) )
runtime.current_fft_input = np.asarray(complex_norm, dtype=np.complex64).reshape(-1)
norm_real = runtime.current_fft_input.real.astype(np.float32, copy=False)
norm_imag = runtime.current_fft_input.imag.astype(np.float32, copy=False)
runtime.current_aux_curves = (norm_real, norm_imag)
if bin_iq_power_mode:
norm_real_f64 = norm_real.astype(np.float64, copy=False)
norm_imag_f64 = norm_imag.astype(np.float64, copy=False)
runtime.current_sweep_norm = np.asarray(
(norm_real_f64 * norm_real_f64) + (norm_imag_f64 * norm_imag_f64),
dtype=np.float32,
)
else:
runtime.current_sweep_norm = np.abs(runtime.current_fft_input).astype(np.float32, copy=False)
complex_calib_applied = True complex_calib_applied = True
if not complex_calib_applied: if not complex_calib_applied:
@ -2153,6 +2134,35 @@ def run_pyqtgraph(args) -> None:
p_line.setXRange(line_x_bounds[0], line_x_bounds[1], padding=0) p_line.setXRange(line_x_bounds[0], line_x_bounds[1], padding=0)
p_line_phase.setXRange(line_x_bounds[0], line_x_bounds[1], padding=0) p_line_phase.setXRange(line_x_bounds[0], line_x_bounds[1], padding=0)
complex_calib_plot_signal: Optional[np.ndarray] = None
if (
complex_sweep_mode
and complex_calib_enabled
and runtime.current_fft_input is not None
and np.iscomplexobj(runtime.current_fft_input)
):
complex_calib_plot_signal = np.asarray(runtime.current_fft_input, dtype=np.complex64).reshape(-1)
if complex_calib_plot_signal is not None and complex_calib_plot_signal.size > 0:
xs_complex = resolve_curve_xs(complex_calib_plot_signal.size)
real_after = complex_calib_plot_signal.real.astype(np.float32, copy=False)
imag_after = complex_calib_plot_signal.imag.astype(np.float32, copy=False)
real_x, real_y = decimate_curve_for_display(xs_complex[: real_after.size], real_after)
imag_x, imag_y = decimate_curve_for_display(xs_complex[: imag_after.size], imag_after)
real_x, real_y = sanitize_curve_data_for_display(real_x, real_y)
imag_x, imag_y = sanitize_curve_data_for_display(imag_x, imag_y)
curve_complex_calib_real.setData(real_x, real_y, autoDownsample=False)
curve_complex_calib_imag.setData(imag_x, imag_y, autoDownsample=False)
complex_ylim = compute_auto_ylim(real_after, imag_after)
if complex_ylim is not None:
p_complex_calib.setYRange(complex_ylim[0], complex_ylim[1], padding=0)
complex_x_bounds = resolve_axis_bounds(xs_complex)
if complex_x_bounds is not None:
p_complex_calib.setXRange(complex_x_bounds[0], complex_x_bounds[1], padding=0)
else:
curve_complex_calib_real.setData([], [])
curve_complex_calib_imag.setData([], [])
sweep_for_fft = runtime.current_fft_input sweep_for_fft = runtime.current_fft_input
if sweep_for_fft is None: if sweep_for_fft is None:
sweep_for_fft = runtime.current_sweep_norm if runtime.current_sweep_norm is not None else runtime.current_sweep_raw sweep_for_fft = runtime.current_sweep_norm if runtime.current_sweep_norm is not None else runtime.current_sweep_raw