fix method

This commit is contained in:
awe
2026-06-09 18:48:45 +03:00
parent f6dd20cdc9
commit cbd0e40897

View File

@ -110,10 +110,10 @@ def extract_sweep(packet):
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Signal processing # Signal processing
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def process_reference(ref_ch1, ref_ch2, ref_phase_first, freqs_hz): def process_reference(ref_ch1, ref_ch2, freqs_hz):
"""Process reference channel: amplitude, phase with linear alignment. """Process reference channel: amplitude, phase aligned to first point.
Returns (amplitude, aligned_phase, ref_phase_first). Returns (amplitude, aligned_phase).
""" """
ch1_v = ref_ch1 * TTY_SCALE ch1_v = ref_ch1 * TTY_SCALE
ch2_v = ref_ch2 * TTY_SCALE ch2_v = ref_ch2 * TTY_SCALE
@ -121,15 +121,11 @@ def process_reference(ref_ch1, ref_ch2, ref_phase_first, freqs_hz):
amplitude = np.sqrt(ch1_v ** 2 + ch2_v ** 2) amplitude = np.sqrt(ch1_v ** 2 + ch2_v ** 2)
phase = np.unwrap(np.arctan2(ch2_v, ch1_v)) phase = np.unwrap(np.arctan2(ch2_v, ch1_v))
if ref_phase_first is None: # Align phase to first point of this sweep, scaled by frequency
return amplitude, phase, phase.copy() correction = phase[0] * (freqs_hz / freqs_hz[0])
# Linear correction: Δφ at first point, scaled by f/f₁
delta_phi = phase[0] - ref_phase_first[0]
correction = delta_phi * (freqs_hz / freqs_hz[0])
aligned = phase - correction aligned = phase - correction
return amplitude, aligned, ref_phase_first return amplitude, aligned
def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned): def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned):
@ -248,7 +244,7 @@ def build_gui():
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def make_update(reader, parser, assembler, curves, plots): def make_update(reader, parser, assembler, curves, plots):
c_main_amp, c_ref_amp, c_norm_ch1, c_norm_ch2, c_norm_amp, c_ph, c_ph_line, c_ph_dev, c_fft = curves c_main_amp, c_ref_amp, c_norm_ch1, c_norm_ch2, c_norm_amp, c_ph, c_ph_line, c_ph_dev, c_fft = curves
state = {"ref_phase_first": None, "axes_locked": False} state = {"axes_locked": False}
queue = deque(maxlen=64) queue = deque(maxlen=64)
def update(): def update():
@ -277,8 +273,8 @@ def make_update(reader, parser, assembler, curves, plots):
freqs_ghz = np.linspace(F_START_HZ / 1e9, F_STOP_HZ / 1e9, n) freqs_ghz = np.linspace(F_START_HZ / 1e9, F_STOP_HZ / 1e9, n)
freqs_hz = freqs_ghz * 1e9 freqs_hz = freqs_ghz * 1e9
ref_amp, ref_phase, state["ref_phase_first"] = process_reference( ref_amp, ref_phase = process_reference(
sweep["ref_ch1"], sweep["ref_ch2"], state["ref_phase_first"], freqs_hz sweep["ref_ch1"], sweep["ref_ch2"], freqs_hz
) )
main_amp, ref_amplitude, norm_ch1, norm_ch2, norm_amp, phase, fft_mag, fft_dist = process_main( main_amp, ref_amplitude, norm_ch1, norm_ch2, norm_amp, phase, fft_mag, fft_dist = process_main(