diff --git a/rfg_vna_viewer.py b/rfg_vna_viewer.py index d9a9b58..b694fa2 100644 --- a/rfg_vna_viewer.py +++ b/rfg_vna_viewer.py @@ -202,9 +202,13 @@ def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned): z_main = ch1_v + 1j * ch2_v main_amp = np.abs(z_main) - z_ref = ref_amplitude * np.exp(1j * ref_phase_aligned) - z_ref_safe = np.where(np.abs(z_ref) > 1e-12, z_ref, 1e-12 + 0j) - z_norm = z_main / z_ref_safe + # Normalize ch1/ch2 individually by ref amplitude + ref_amp_safe = np.where(ref_amplitude > 1e-12, ref_amplitude, 1e-12) + norm_ch1 = ch1_v / ref_amp_safe + norm_ch2 = ch2_v / ref_amp_safe + + # Build normalized complex signal and subtract ref phase + z_norm = (norm_ch1 + 1j * norm_ch2) * np.exp(-1j * ref_phase_aligned) amp_norm = np.abs(z_norm) phase_norm = np.unwrap(np.angle(z_norm)) @@ -219,10 +223,6 @@ def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned): dist_step = C_M_S / (2.0 * FFT_LEN * df_hz) fft_dist = np.arange(FFT_LEN // 2) * dist_step - # Normalized ch1/ch2 (real/imag parts of z_norm) - norm_ch1 = np.real(z_norm) - norm_ch2 = np.imag(z_norm) - return main_amp, ref_amplitude, norm_ch1, norm_ch2, amp_norm, phase_norm, fft_mag, fft_dist