def test_compare_with_skrf_wilkison(self): ''' Create a Wilkinson power divider using skrf usual Network methods. ''' z0_port = 50 z0_lines = self.line_branches.z0[0] z0_R = self.line_resistor.z0[0] # require to create the three tees T0 = self.line_branches.splitter(3, z0=[z0_port, z0_lines, z0_lines]) T1 = self.line_branches.splitter(3, z0=[z0_lines, z0_R, z0_port]) T2 = self.line_branches.splitter(3, z0=[z0_lines, z0_R, z0_port]) _wilkinson1 = rf.connect(T0, 1, self.branch1, 0) _wilkinson2 = rf.connect(_wilkinson1, 2, self.branch2, 0) _wilkinson3 = rf.connect(_wilkinson2, 0, T1, 0) _wilkinson4 = rf.connect(_wilkinson3, 0, T2, 0) _wilkinson5 = rf.connect(_wilkinson4, 1, self.resistor, 0) wilkinson = rf.innerconnect(_wilkinson5, 0, 3) ntw_C = self.C.network # the following is failing and I don't know why #assert_array_almost_equal(ntw_C.s_db, wilkinson.s_db) assert_array_almost_equal(ntw_C.z0, wilkinson.z0)
def test_compare_with_skrf_wilkison(self): ''' Create a Wilkinson power divider using skrf usual Network methods. ''' z0_port = 50 z0_lines = self.line_branches.z0[0] z0_R = self.line_resistor.z0[0] # require to create the three tees T0 = self.line_branches.splitter(3, z0=[z0_port, z0_lines, z0_lines]) T1 = self.line_branches.splitter(3, z0=[z0_lines, z0_R, z0_port]) T2 = self.line_branches.splitter(3, z0=[z0_lines, z0_R, z0_port]) _wilkinson1 = rf.connect(T0, 1, self.branch1, 0) _wilkinson2 = rf.connect(_wilkinson1, 2, self.branch2, 0) _wilkinson3 = rf.connect(_wilkinson2, 1, T1, 0) _wilkinson4 = rf.connect(_wilkinson3, 1, T2, 0) _wilkinson5 = rf.connect(_wilkinson4, 1, self.resistor, 0) wilkinson = rf.innerconnect(_wilkinson5, 1, 3) ntw_C = self.C.network # the following is failing and I don't know why #assert_array_almost_equal(ntw_C.s_db, wilkinson.s_db) assert_array_almost_equal(ntw_C.z0, wilkinson.z0)
def test_connect(self): self.assertEqual(rf.connect(self.ntwk1, 1, self.ntwk2, 0) , \ self.ntwk3) xformer = rf.Network() xformer.frequency=(1,) xformer.s = ((0,1),(1,0)) # connects thru xformer.z0 = (50,25) # transforms 50 ohm to 25 ohm c = rf.connect(xformer,0,xformer,1) # connect 50 ohm port to 25 ohm port self.assertTrue(npy.all(npy.abs(c.s-rf.impedance_mismatch(50, 25)) < 1e-6))
def test_flip(self): self.assertEqual(rf.connect(self.ntwk1, 1, self.ntwk2, 0) , \ self.ntwk3) gain = rf.Network() gain.frequency=(1,) gain.s = ((0,2),(0.5,0)) # connects thru with gain of 2.0 gain.z0 = (37,82) flipped = gain.copy() flipped.flip() c = rf.connect(gain,1,flipped,0) self.assertTrue(npy.all(npy.abs(c.s - npy.array([[0,1],[1,0]])) < 1e-6))
def test_connect_multiports(self): a = rf.Network() a.frequency=(1,) a.s = npy.arange(16).reshape(4,4) a.z0 = range(4) b = rf.Network() b.frequency=(1,) b.s = npy.arange(16).reshape(4,4) b.z0 = npy.arange(4)+10 c=rf.connect(a,2,b,0,2) self.assertTrue((c.z0==[0,1,12,13]).all()) d=rf.connect(a,0,b,0,3) self.assertTrue((d.z0==[3,13]).all())
def test_connect_multiports(self): a = rf.Network() a.frequency = (1, ) a.s = npy.arange(16).reshape(4, 4) a.z0 = npy.arange(4) + 1 # Z0 should never be zero b = rf.Network() b.frequency = (1, ) b.s = npy.arange(16).reshape(4, 4) b.z0 = npy.arange(4) + 10 c = rf.connect(a, 2, b, 0, 2) self.assertTrue((c.z0 == [1, 2, 12, 13]).all()) d = rf.connect(a, 0, b, 0, 3) self.assertTrue((d.z0 == [4, 13]).all())
def test_connect_nport_2port(self): freq = rf.Frequency(1, 10, npoints=10, unit='GHz') # create a line which can be connected to each port med = rf.DefinedGammaZ0(freq) line = med.line(1, unit='m') line.z0 = [10, 20] for nport_portnum in [3,4,5,6,7,8]: # create a Nport network with port impedance i at port i nport = rf.Network() nport.frequency = freq nport.s = npy.zeros((10, nport_portnum, nport_portnum)) nport.z0 = npy.arange(nport_portnum) # Connect the line to each port and check for port impedance for port in range(nport_portnum): nport_line = rf.connect(nport, port, line, 0) z0_expected = nport.z0 z0_expected[:,port] = line.z0[:,1] npy.testing.assert_allclose( nport_line.z0, z0_expected )
def test_4ports_different_characteristic_impedances(self): """ Connect two 4-ports networks in a resulting 4-ports network, with different characteristic impedances """ z0 = [1, 2, 3, 4] freq = rf.Frequency(start=1, npoints=1) a = rf.Network(name='a') a.frequency = freq a.s = np.random.rand(16).reshape(4, 4) a.z0 = z0 b = rf.Network(name='b') b.frequency = freq b.s = np.random.rand(16).reshape(4, 4) b.z0 = [11, 12, 13, 14] # classic connecting _c = rf.connect(a, 2, b, 0) c = rf.innerconnect(_c, 2, 3) # Circuit connecting port1 = rf.Circuit.Port(freq, z0=1, name='port1') port2 = rf.Circuit.Port(freq, z0=2, name='port2') port3 = rf.Circuit.Port(freq, z0=13, name='port3') port4 = rf.Circuit.Port(freq, z0=14, name='port4') connections = [[(port1, 0), (a, 0)], [(port2, 0), (a, 1)], [(a, 2), (b, 0)], [(a, 3), (b, 1)], [(b, 2), (port3, 0)], [(b, 3), (port4, 0)]] circuit = rf.Circuit(connections) assert_array_almost_equal(c.s, circuit.s_external)
def test_2ports_different_characteristic_impedances(self): ''' Connect two 2-ports networks in a resulting 2-ports network, different characteristic impedances for each network ports ''' freq = rf.Frequency(start=1, npoints=1) a = rf.Network(name='a') a.frequency = freq a.s = np.random.rand(4).reshape(2,2) a.z0 = [1, 2] # Z0 should never be zero b = rf.Network(name='b') b.frequency = freq b.s = np.random.rand(4).reshape(2,2) b.z0 = [11, 12] # classic connecting c = rf.connect(a, 1, b, 0) # Circuit connecting port1 = rf.Circuit.Port(freq, z0=1, name='port1') port2 = rf.Circuit.Port(freq, z0=12, name='port2') connections = [[(port1, 0), (a, 0)], [(a, 1), (b, 0)], [(b, 1), (port2, 0)] ] circuit = rf.Circuit(connections) assert_array_almost_equal(c.s, circuit.s_external)
def test_4ports_complex_characteristic_impedances(self): ''' Connect two 4-ports networks in a resulting 4-ports network, with same complex characteric impedances ''' z0 = 5 + 4j freq = rf.Frequency(start=1, npoints=1) a = rf.Network(name='a') a.frequency = freq a.s = np.random.rand(16).reshape(4, 4) a.z0 = z0 b = rf.Network(name='b') b.frequency = freq b.s = np.random.rand(16).reshape(4, 4) b.z0 = z0 # classic connecting c = rf.connect(a, 2, b, 0, 2) # circuit connecting port1 = rf.Circuit.Port(freq, z0=z0, name='port1') port2 = rf.Circuit.Port(freq, z0=z0, name='port2') port3 = rf.Circuit.Port(freq, z0=z0, name='port3') port4 = rf.Circuit.Port(freq, z0=z0, name='port4') connections = [ [(port1, 0), (a, 0)], [(port2, 0), (a, 1)], [(a, 2), (b, 0)], [(a, 3), (b, 1)], [(b, 2), (port3, 0)], [(b, 3), (port4, 0)]] circuit = rf.Circuit(connections) assert_array_almost_equal(c.s, circuit.s_external)
def test_2ports_complex_characteristic_impedance(self): ''' Connect two 2-ports networks in a resulting 2-ports network, same complex charact impedance (1+1j) for all ports ''' z0 = 1 + 1j freq = rf.Frequency(start=1, npoints=1) a = rf.Network(name='a') a.frequency = freq a.s = np.random.rand(4).reshape(2, 2) a.z0 = z0 b = rf.Network(name='b') b.frequency = freq b.s = np.random.rand(4).reshape(2, 2) b.z0 = z0 # classic connecting c = rf.connect(a, 1, b, 0) # Circuit connecting port1 = rf.Circuit.Port(freq, z0=z0, name='port1') port2 = rf.Circuit.Port(freq, z0=z0, name='port2') connections = [[(port1, 0), (a, 0)], [(a, 1), (b, 0)], [(b, 1), (port2, 0)]] circuit = rf.Circuit(connections) assert_array_almost_equal(c.s, circuit.s_external)
def variable_coupler_network_from_connect(self, phase_deg): ps = self.phase_shifter(phase_deg) hybrid1, hybrid2 = self.hybrid(), self.hybrid() # connecting the networks together. # NB: in order to know which port corresponds to which, it is usefull # to define different port characteristic impedances like # hybrid1.z0 = [11, 12, 13, 14] # hybrid2.z0 = [21, 22, 23, 24] # ps.z0 = [31, 32] # and to make a drawing of each steps. # This is not convenient, that's why the Circuit approach can be easier. _temp = rf.connect(hybrid1, 2, ps, 0) _temp = rf.connect(_temp, 2, hybrid2, 0) _temp = rf.innerconnect(_temp, 1, 5) # re-order port numbers to match the example _temp.renumber([0, 1, 2, 3], [3, 0, 2, 1]) return _temp
def variable_coupler_network_from_connect(self, phase_deg): ps = self.phase_shifter(phase_deg) hybrid1, hybrid2 = self.hybrid(), self.hybrid() # connecting the networks together. # NB: in order to know which port corresponds to which, it is usefull # to define different port characteristic impedances like # hybrid1.z0 = [11, 12, 13, 14] # hybrid2.z0 = [21, 22, 23, 24] # etc # and to make a drawing of each steps. # This is not convenient, that's why the Circuit approach can be easier. _temp = rf.connect(hybrid1, 2, ps, 0) _temp = rf.connect(_temp, 1, hybrid2, 0) _temp = rf.innerconnect(_temp, 1, 5) # re-order port numbers to match the example _temp.renumber([0, 1, 2, 3], [3, 0, 2, 1]) return _temp
def test_connect_multiports(self): a = rf.Network() a.frequency = (1, ) a.s = npy.arange(16).reshape(4, 4) a.z0 = range(4) b = rf.Network() b.frequency = (1, ) b.s = npy.arange(16).reshape(4, 4) b.z0 = npy.arange(4) + 10 c = rf.connect(a, 2, b, 0, 2) self.assertTrue((c.z0 == [0, 1, 12, 13]).all())
def to_network(self, frequency): ''' Return the resonator Network for a given frequency Parameter --------- frequency : skrf.Frequency Frequency to evaluate the Network on Return ------ network : krf.Network Resonator Network ''' if self.is_valid(): # Calculate all Networks networks = self.networks_list(frequency) # traverse the list until we found the Tee for (idx, section) in enumerate(networks): if section.name == 'tee': idx_tee = idx # split the resonator in two branches networks_branch_left = networks[:idx_tee] tee = networks[idx_tee] networks_branch_right = networks[idx_tee + 1:] # caccade left and right branches branch_left = rf.cascade_list( networks_branch_left[-1::-1] ) # cascade in reverse order to keep the short at the end branch_right = rf.cascade_list(networks_branch_right) # connect the tee resonator = rf.connect(rf.connect(branch_left, 0, tee, 1), 1, branch_right, 0) resonator.name = 'Resonator' return resonator else: with self.output: print('Resonator is not valid. Check its consistency !')
def test_4ports_different_characteristic_impedances(self): ''' Connect two 4-ports networks in a resulting 4-ports network, with different characteristic impedances ''' z0 = [1, 2, 3, 4] freq = rf.Frequency(start=1, npoints=1) a = rf.Network(name='a') a.frequency = freq a.s = np.random.rand(16).reshape(4, 4) a.z0 = z0 b = rf.Network(name='b') b.frequency = freq b.s = np.random.rand(16).reshape(4, 4) b.z0 = [11, 12, 13, 14] # classic connecting _c = rf.connect(a, 2, b, 0) c = rf.innerconnect(_c, 2, 3) # Circuit connecting port1 = rf.Circuit.Port(freq, z0=1, name='port1') port2 = rf.Circuit.Port(freq, z0=2, name='port2') port3 = rf.Circuit.Port(freq, z0=13, name='port3') port4 = rf.Circuit.Port(freq, z0=14, name='port4') connections = [[(port1, 0), (a, 0)], [(port2, 0), (a, 1)], [(a, 2), (b, 0)], [(a, 3), (b, 1)], [(b, 2), (port3, 0)], [(b, 3), (port4, 0)]] circuit = rf.Circuit(connections) assert_array_almost_equal(c.s, circuit.s_external)
def measure(self,ntwk): out = rf.connect(self.Z, 1, ntwk, 0, num=2) out.name = ntwk.name return out
def measure(self,ntwk): out = self.terminate(rf.connect(self.Z, 1, ntwk, 0, num=2)) out.name = ntwk.name return out
def measure(self, ntwk): out = rf.connect(self.Z, 1, ntwk, 0, num=2) out.name = ntwk.name return out
def measure(self, ntwk): out = self.terminate(rf.connect(self.Z, 1, ntwk, 0, num=2)) out.name = ntwk.name return out
def test_connect(self): self.assertEqual(rf.connect(self.ntwk1, 1, self.ntwk2, 0) , \ self.ntwk3)
cal_load.f[-1], len(cal_load.f), unit='hz') media = rf.media.Freespace(f) sdrkit_open = media.line(42.35, 'ps', z0=50)**media.open() # 42.35 sdrkit_short = media.line(26.91, 'ps', z0=50)**media.short() # TODO: add parallel 2fF capacitance to load? sdrkit_load = rf.Network(f=cal_load.f / 1e9, s=-.0126 * np.ones(len(cal_load.f)), z0=50) # read in actual vat3+ vat3_mini = rf.Network('VAT-3+___PLus25degC.s2p') pdb.set_trace() mini_open = rf.media.Freespace(vat3_mini.frequency).open() vat3_mini = rf.connect(vat3_mini, 0, mini_open, 0) #sdrkit_open.write_touchstone('ideal_open.s1p') #sdrkit_short.write_touchstone('ideal_short.s1p') #sdrkit_load.write_touchstone('ideal_load.s1p') my_ideals = [sdrkit_short, sdrkit_open, sdrkit_load] my_measured = [cal_short, cal_open, cal_load] cal = rf.OnePort(ideals=my_ideals, measured=my_measured) cal.run() source_match = cal.coefs_3term_ntwks['source match'] directivity = cal.coefs_3term_ntwks['directivity'] reflection_tracking = cal.coefs_3term_ntwks['reflection tracking']