diff --git a/rfg_vna_viewer.py b/rfg_vna_viewer.py index 8739963..4039a4a 100644 --- a/rfg_vna_viewer.py +++ b/rfg_vna_viewer.py @@ -136,7 +136,7 @@ def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned): # Normalize by ref amplitude and subtract ref phase of first point ref_amp_safe = np.where(ref_amplitude > 1e-12, ref_amplitude, 1e-12) - z_norm = (ch1_v / ref_amp_safe + 1j * ch2_v / ref_amp_safe) * np.exp(-1j * ref_phase_aligned[0]) + z_norm = (ch1_v / ref_amp_safe + 1j * ch2_v / ref_amp_safe) * np.exp(-1j * ref_phase_aligned) norm_ch1 = np.real(z_norm) norm_ch2 = np.imag(z_norm) @@ -239,7 +239,7 @@ def build_gui(): # --------------------------------------------------------------------------- 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 - state = {"axes_locked": False} + state = {"ref_phase_first": None, "axes_locked": False} queue = deque(maxlen=64) def update(): @@ -272,8 +272,12 @@ def make_update(reader, parser, assembler, curves, plots): sweep["ref_ch1"], sweep["ref_ch2"] ) + # Fix reference phase from the first sweep + if state["ref_phase_first"] is None: + state["ref_phase_first"] = ref_phase[0] + main_amp, ref_amplitude, norm_ch1, norm_ch2, norm_amp, phase, fft_mag, fft_dist = process_main( - sweep["main_ch1"], sweep["main_ch2"], ref_amp, ref_phase + sweep["main_ch1"], sweep["main_ch2"], ref_amp, state["ref_phase_first"] ) c_main_amp.setData(freqs_ghz, main_amp)