def get_att(hd5file, element, freq, group = GROUP_ATT, fsweeploc=FSWEEPLOC): fidx = get_fidx(hd5file, freq, fsweeploc) att_target = [] att_measured = [] phase_measured = [] for att in hd5file[element + group].keys(): dset = element + group + '/' + att att_measured = att_measured + [20*log10(abs(hd5file[dset][fidx]))] att_target = att_target + [int(hd5file[dset].attrs['att'])] phase_measured = phase_measured + [complex_2_degree(hd5file[dset][fidx]) % 360] att_measured = sort_by_array(att_target, att_measured) phase_measured = sort_by_array(att_target, phase_measured) att_target = sort(att_target) return {'att_measured':att_measured, 'att_target':att_target, 'phase_measured':phase_measured}
def get_phase(hd5file, element, freq, group = GROUP_PHASE, fsweeploc=FSWEEPLOC): fidx = get_fidx(hd5file, freq, fsweeploc) phase_target = [] phase_measured = [] att_measured = [] for phase in hd5file[element + group].keys(): dset = element + group + '/' + phase phase_measured = phase_measured + [complex_2_degree(hd5file[dset][fidx])] phase_target = phase_target + [int(hd5file[dset].attrs['phase'])] att_measured = att_measured + [20*log10(abs(hd5file[dset][fidx]))] att_measured = sort_by_array(phase_target, att_measured) phase_measured = sort_by_array(phase_target, phase_measured) phase_target = sort(phase_target) return {'phase_measured':phase_measured, 'phase_target':phase_target, 'att_measured':att_measured}
def test_complex_2_degree(self): """ Test complex to degree conversion with: 90 = angle(0 + 1j) """ assert_almost_equal(rf.complex_2_degree(0 + 1j), 90.0)
# example usage: grabs S21 and S11 from VNA and plots the magnitude and phase if __name__ == "__main__": vna = vna_init() vna_setspan(vna, F_SPAN, F_CENTER, POINTS) f = vna_readspan(vna) # grabs s11 and s21, formatted as complex numbers s11 = vna_get_measurement(vna, 's11meas') s21 = vna_get_measurement(vna, 's21meas') subplot(2,1,1) plot(f/1e9, 20*log10(abs(s11))) plot(f/1e9, 20*log10(abs(s21))) title('amplitude of S11 (blue) and S21 (green)') xlabel('frequency (GHz)') ylabel('amplitude (dB)') xlim([f[0]/1e9, f[-1]/1e9]) grid(True) subplot(2,1,2) plot(f/1e9, skrf.complex_2_degree(s11)) plot(f/1e9, skrf.complex_2_degree(s21)) title('phase of S11 (blue) and S21 (green)') xlabel('frequency (GHz)') ylabel('phase (degrees)') xlim([f[0]/1e9, f[-1]/1e9]) grid(True) show()
# example usage: grabs S21 and S11 from VNA and plots the magnitude and phase if __name__ == "__main__": vna = vna_init() vna_setspan(vna, F_SPAN, F_CENTER, POINTS) f = vna_readspan(vna) # grabs s11 and s21, formatted as complex numbers s11 = vna_get_measurement(vna, 's11meas') s21 = vna_get_measurement(vna, 's21meas') subplot(2, 1, 1) plot(f / 1e9, 20 * log10(abs(s11))) plot(f / 1e9, 20 * log10(abs(s21))) title('amplitude of S11 (blue) and S21 (green)') xlabel('frequency (GHz)') ylabel('amplitude (dB)') xlim([f[0] / 1e9, f[-1] / 1e9]) grid(True) subplot(2, 1, 2) plot(f / 1e9, skrf.complex_2_degree(s11)) plot(f / 1e9, skrf.complex_2_degree(s21)) title('phase of S11 (blue) and S21 (green)') xlabel('frequency (GHz)') ylabel('phase (degrees)') xlim([f[0] / 1e9, f[-1] / 1e9]) grid(True) show()
def get_phase(vna, meas): time.sleep(.01) s = vna_get_measurement(vna, meas) return skrf.complex_2_degree(s)
def get_phase(vna, meas): time.sleep(.01) s = vna_get_measurement(vna, meas) return skrf.complex_2_degree(s)