Example #1
0
 def test_network_from_z_or_y(self):
     ' Construct a network from its z or y parameters '
     # test for both real and complex char. impedance
     # and for 2 frequencies
     z0 = [npy.random.rand(), npy.random.rand() + 1j * npy.random.rand()]
     freqs = npy.array([1, 2])
     # generate arbitrary complex z and y
     z_ref = npy.random.rand(2, 3, 3) + 1j * npy.random.rand(2, 3, 3)
     y_ref = npy.random.rand(2, 3, 3) + 1j * npy.random.rand(2, 3, 3)
     # create networks from z or y and compare ntw.z to the reference
     # check that the conversions work for all s-param definitions
     for s_def in S_DEFINITIONS:
         ntwk = rf.Network(s_def=s_def)
         ntwk.z0 = rf.fix_z0_shape(z0, 2, 3)
         ntwk.f = freqs
         # test #1: define the network directly from z
         ntwk.z = z_ref
         npy.testing.assert_allclose(ntwk.z, z_ref)
         # test #2: define the network from s, after z -> s (s_def is important)
         ntwk.s = rf.z2s(z_ref, z0, s_def=s_def)
         npy.testing.assert_allclose(ntwk.z, z_ref)
         # test #3: define the network directly from y
         ntwk.y = y_ref
         npy.testing.assert_allclose(ntwk.y, y_ref)
         # test #4: define the network from s, after y -> s (s_def is important)
         ntwk.s = rf.y2s(y_ref, z0, s_def=s_def)
         npy.testing.assert_allclose(ntwk.y, y_ref)
Example #2
0
    def test_conversions(self):
        #Converting to other format and back to S-parameters should return the original network
        tinyfloat = 1e-12
        for test_z0 in (50, 10, 90+10j, 4-100j):
            for test_ntwk in (self.ntwk1, self.ntwk2, self.ntwk3):
                ntwk = rf.Network(s=test_ntwk.s, f=test_ntwk.f, z0=test_z0)

                self.assertTrue((abs(rf.a2s(rf.s2a(ntwk.s, test_z0), test_z0)-ntwk.s) < tinyfloat).all())
                self.assertTrue((abs(rf.z2s(rf.s2z(ntwk.s, test_z0), test_z0)-ntwk.s) < tinyfloat).all())
                self.assertTrue((abs(rf.y2s(rf.s2y(ntwk.s, test_z0), test_z0)-ntwk.s) < tinyfloat).all())
                self.assertTrue((abs(rf.t2s(rf.s2t(ntwk.s))-ntwk.s) < tinyfloat).all())
Example #3
0
 def test_yz(self):
     tinyfloat = 1e-12
     ntwk = rf.Network()
     ntwk.z0 = npy.array([28,75+3j])
     ntwk.f = npy.array([1000, 2000])
     ntwk.s = rf.z2s(npy.array([[[1+1j,5,11],[40,5,3],[16,8,9+8j]],
                                [[1,20,3],[14,10,16],[27,18,-19-2j]]]))
     self.assertTrue((abs(rf.y2z(ntwk.y)-ntwk.z) < tinyfloat).all())
     self.assertTrue((abs(rf.y2s(ntwk.y, ntwk.z0)-ntwk.s) < tinyfloat).all())
     self.assertTrue((abs(rf.z2y(ntwk.z)-ntwk.y) < tinyfloat).all())
     self.assertTrue((abs(rf.z2s(ntwk.z, ntwk.z0)-ntwk.s) < tinyfloat).all())
Example #4
0
 def test_yz(self):
     tinyfloat = 1e-12
     ntwk = rf.Network()
     ntwk.z0 = npy.array([28,75+3j])
     ntwk.f = npy.array([1000, 2000])
     ntwk.s = rf.z2s(npy.array([[[1+1j,5,11],[40,5,3],[16,8,9+8j]],
                                [[1,20,3],[14,10,16],[27,18,-19-2j]]]))
     self.assertTrue((abs(rf.y2z(ntwk.y)-ntwk.z) < tinyfloat).all())
     self.assertTrue((abs(rf.y2s(ntwk.y, ntwk.z0)-ntwk.s) < tinyfloat).all())
     self.assertTrue((abs(rf.z2y(ntwk.z)-ntwk.y) < tinyfloat).all())
     self.assertTrue((abs(rf.z2s(ntwk.z, ntwk.z0)-ntwk.s) < tinyfloat).all())
 def test_conversions(self):
     #Converting to other format and back to S-parameters should return the original network
     for test_z0 in (50, 10, 90+10j, 4-100j):
         for test_ntwk in (self.ntwk1, self.ntwk2, self.ntwk3):
             ntwk = rf.Network(s=test_ntwk.s, f=test_ntwk.f, z0=test_z0)
             npy.testing.assert_allclose(rf.a2s(rf.s2a(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.z2s(rf.s2z(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.y2s(rf.s2y(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.h2s(rf.s2h(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.t2s(rf.s2t(ntwk.s)), ntwk.s)
     npy.testing.assert_allclose(rf.t2s(rf.s2t(self.Fix.s)), self.Fix.s)        
Example #6
0
    def test_conversions(self):
        #Converting to other format and back to S-parameters should return the original network
        tinyfloat = 1e-12
        for test_z0 in (50, 10, 90+10j, 4-100j):
            for test_ntwk in (self.ntwk1, self.ntwk2, self.ntwk3):
                ntwk = rf.Network(s=test_ntwk.s, f=test_ntwk.f, z0=test_z0)

                self.assertTrue((abs(rf.a2s(rf.s2a(ntwk.s, test_z0), test_z0)-ntwk.s) < tinyfloat).all())
                self.assertTrue((abs(rf.z2s(rf.s2z(ntwk.s, test_z0), test_z0)-ntwk.s) < tinyfloat).all())
                self.assertTrue((abs(rf.y2s(rf.s2y(ntwk.s, test_z0), test_z0)-ntwk.s) < tinyfloat).all())
                self.assertTrue((abs(rf.t2s(rf.s2t(ntwk.s))-ntwk.s) < tinyfloat).all())
Example #7
0
 def test_conversions(self):
     #Converting to other format and back to S-parameters should return the original network
     s_random = npy.random.uniform(-10, 10, (self.freq.npoints, 2, 2)) + 1j * npy.random.uniform(-10, 10, (self.freq.npoints, 2, 2))
     ntwk_random = rf.Network(s=s_random, frequency=self.freq)
     for test_z0 in (50, 10, 90+10j, 4-100j):
         for test_ntwk in (self.ntwk1, self.ntwk2, self.ntwk3, ntwk_random):
             ntwk = rf.Network(s=test_ntwk.s, f=test_ntwk.f, z0=test_z0)
             npy.testing.assert_allclose(rf.a2s(rf.s2a(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.z2s(rf.s2z(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.y2s(rf.s2y(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.h2s(rf.s2h(ntwk.s, test_z0), test_z0), ntwk.s)
             npy.testing.assert_allclose(rf.t2s(rf.s2t(ntwk.s)), ntwk.s)
     npy.testing.assert_allclose(rf.t2s(rf.s2t(self.Fix.s)), self.Fix.s)
Example #8
0
def open_deembed(data, data_open, datadir=None):
    '''
    Subtracts admittance of open from that of device and saves results in new
    network n. If save_deembedded is defined, saves a copy of the deembedded
    network in snp format.
    '''
    d = open_Network(data)
    o = open_Network(data_open)
    n = rf.Network()
    n.frequency = d.frequency
    n.z0 = d.z0
    n.name = d.name
    ### Time Gate before Deembed ###
    #    for i in range(len(d.s[0,:,0])):
    #        for j in range(len(d.s[0,0,:])):
    #            dsub = rf.Network()
    #            osub = rf.Network()
    #            dsub.s = np.zeros((len(d.f),1,1))
    #            osub.s = np.zeros((len(o.f),1,1))
    #            dsub.s[:,0,0] = d.s[:,i,j]
    #            osub.s[:,0,0] = o.s[:,i,j]
    #            d.s[:,i,j] = dsub.s.time_gate(center=0,span=15)
    #            o.s[:,i,j] = osub.s.time_gate(center=0,span=15)
    #    d.y = rf.s2y(d.s)
    #    o.y = rf.s2y(o.s)
    ################################
    #    d.y = rf.z2y(d.z)
    #    o.y = rf.z2y(o.z)
    n.y = d.y - o.y
    n.s = rf.y2s(n.y)
    n.z = rf.y2z(n.y)
    if datadir:
        savedir = os.path.join(datadir, 'deembedded_open')
        if not os.path.isfile(os.path.join(savedir, n.name)):
            n.write_touchstone(dir=savedir)
    return n