new graph

This commit is contained in:
awe
2026-06-09 16:16:05 +03:00
parent d968545617
commit 3bb972b8d5

View File

@ -193,10 +193,14 @@ def process_reference(ref_ch1, ref_ch2, ref_phase_first, freqs_hz):
def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned): def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned):
"""Normalize main channel by reference. Return (amp, phase, fft_mag, fft_dist).""" """Normalize main channel by reference.
Returns (main_amp, ref_amp, amp_norm, phase_norm, fft_mag, fft_dist).
"""
ch1_v = main_ch1 * TTY_SCALE ch1_v = main_ch1 * TTY_SCALE
ch2_v = main_ch2 * TTY_SCALE ch2_v = main_ch2 * TTY_SCALE
z_main = ch1_v + 1j * ch2_v 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 = 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_ref_safe = np.where(np.abs(z_ref) > 1e-12, z_ref, 1e-12 + 0j)
@ -215,7 +219,7 @@ def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned):
dist_step = C_M_S / (2.0 * FFT_LEN * df_hz) dist_step = C_M_S / (2.0 * FFT_LEN * df_hz)
fft_dist = np.arange(FFT_LEN // 2) * dist_step fft_dist = np.arange(FFT_LEN // 2) * dist_step
return amp_norm, phase_norm, fft_mag, fft_dist return main_amp, ref_amplitude, amp_norm, phase_norm, fft_mag, fft_dist
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -227,33 +231,46 @@ def build_gui():
win = pg.GraphicsLayoutWidget(show=True, title="RFG VNA Viewer") win = pg.GraphicsLayoutWidget(show=True, title="RFG VNA Viewer")
win.resize(1200, 800) win.resize(1200, 800)
p_amp = win.addPlot(row=0, col=0, title="Нормированная амплитуда |S|") # Row 0: raw amplitudes of both channels
p_amp.showGrid(x=True, y=True, alpha=0.3) p_raw = win.addPlot(row=0, col=0, title="Амплитуды каналов")
p_amp.setLabel("bottom", "Частота", units="ГГц") p_raw.showGrid(x=True, y=True, alpha=0.3)
p_amp.setLabel("left", "Амплитуда") p_raw.setLabel("bottom", "Частота", units="ГГц")
c_amp = p_amp.plot(pen=pg.mkPen((80, 120, 255), width=1)) p_raw.setLabel("left", "Амплитуда", units="В")
p_raw.addLegend(offset=(10, 10))
c_main_amp = p_raw.plot(pen=pg.mkPen((80, 120, 255), width=1), name="Main (0a00)")
c_ref_amp = p_raw.plot(pen=pg.mkPen((255, 80, 80), width=1), name="Ref (a800)")
p_ph = win.addPlot(row=1, col=0, title="Нормированная фаза arg(S)") # Row 1: normalized amplitude
p_norm = win.addPlot(row=1, col=0, title="Нормированная амплитуда |S|")
p_norm.showGrid(x=True, y=True, alpha=0.3)
p_norm.setLabel("bottom", "Частота", units="ГГц")
p_norm.setLabel("left", "Амплитуда")
p_norm.setXLink(p_raw)
c_norm_amp = p_norm.plot(pen=pg.mkPen((80, 120, 255), width=1))
# Row 2: normalized phase
p_ph = win.addPlot(row=2, col=0, title="Нормированная фаза arg(S)")
p_ph.showGrid(x=True, y=True, alpha=0.3) p_ph.showGrid(x=True, y=True, alpha=0.3)
p_ph.setLabel("bottom", "Частота", units="ГГц") p_ph.setLabel("bottom", "Частота", units="ГГц")
p_ph.setLabel("left", "Фаза", units="рад") p_ph.setLabel("left", "Фаза", units="рад")
p_ph.setXLink(p_amp) p_ph.setXLink(p_raw)
c_ph = p_ph.plot(pen=pg.mkPen((230, 180, 40), width=1)) c_ph = p_ph.plot(pen=pg.mkPen((230, 180, 40), width=1))
p_fft = win.addPlot(row=2, col=0, title="FFT — расстояние") # Row 3: FFT distance
p_fft = win.addPlot(row=3, col=0, title="FFT — расстояние")
p_fft.showGrid(x=True, y=True, alpha=0.3) p_fft.showGrid(x=True, y=True, alpha=0.3)
p_fft.setLabel("bottom", "Расстояние", units="м") p_fft.setLabel("bottom", "Расстояние", units="м")
p_fft.setLabel("left", "Магнитуда", units="дБ") p_fft.setLabel("left", "Магнитуда", units="дБ")
c_fft = p_fft.plot(pen=pg.mkPen((60, 200, 80), width=1)) c_fft = p_fft.plot(pen=pg.mkPen((60, 200, 80), width=1))
return app, win, (c_amp, c_ph, c_fft) return app, win, (c_main_amp, c_ref_amp, c_norm_amp, c_ph, c_fft)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Update loop # Update loop
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def make_update(reader, accumulator, curves): def make_update(reader, accumulator, curves):
c_amp, c_ph, c_fft = curves c_main_amp, c_ref_amp, c_norm_amp, c_ph, c_fft = curves
state = {"ref_phase_first": None} state = {"ref_phase_first": None}
def update(): def update():
@ -277,11 +294,13 @@ def make_update(reader, accumulator, curves):
sweep["ref_ch1"], sweep["ref_ch2"], state["ref_phase_first"], freqs_hz sweep["ref_ch1"], sweep["ref_ch2"], state["ref_phase_first"], freqs_hz
) )
amp, phase, fft_mag, fft_dist = process_main( main_amp, ref_amplitude, 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, ref_phase
) )
c_amp.setData(freqs_ghz, amp) c_main_amp.setData(freqs_ghz, main_amp)
c_ref_amp.setData(freqs_ghz, ref_amplitude)
c_norm_amp.setData(freqs_ghz, norm_amp)
c_ph.setData(freqs_ghz, phase) c_ph.setData(freqs_ghz, phase)
fft_db = 20.0 * np.log10(fft_mag + 1e-12) fft_db = 20.0 * np.log10(fft_mag + 1e-12)