예제 #1
0
 def test_from_csv(self):
     fname = os.path.join(self.files_dir,\
             'out.csv')
     self.dummy_media.write_csv(fname)
     a_media = DefinedGammaZ0.from_csv(fname)
     self.assertEqual(a_media,self.dummy_media)
     os.remove(fname)
예제 #2
0
    def test_abcd_lossy_line(self):
        '''
        Lossy transmission line of characteristic impedance Z0, length l
        and propagation constant gamma = alpha + j beta

        ○---------○

        ○---------○

        has ABCD matrix of the form:

        [ cosh(gamma l)       Z0 sinh(gamma l) ]
        [ 1/Z0 sinh(gamma l)  cosh(gamma l) ]
        '''
        l = 5.0
        z0 = 30.0
        alpha = 0.5
        beta = 2.0
        lossy_media = DefinedGammaZ0(frequency=Frequency(1, 100, 21, 'GHz'),
                                     gamma=alpha + 1j * beta,
                                     z0=z0)
        ntw = lossy_media.line(d=l, unit='m', z0=z0)
        gamma = lossy_media.gamma
        npy.testing.assert_array_almost_equal(ntw.a[:, 0, 0],
                                              npy.cosh(gamma * l))
        npy.testing.assert_array_almost_equal(ntw.a[:, 0, 1],
                                              z0 * npy.sinh(gamma * l))
        npy.testing.assert_array_almost_equal(ntw.a[:, 1, 0],
                                              1.0 / z0 * npy.sinh(gamma * l))
        npy.testing.assert_array_almost_equal(ntw.a[:, 1, 1],
                                              npy.cosh(gamma * l))
예제 #3
0
 def test_from_csv(self):
     fname = os.path.join(self.files_dir,\
             'out.csv')
     self.dummy_media.write_csv(fname)
     a_media = DefinedGammaZ0.from_csv(fname)
     self.assertEqual(a_media, self.dummy_media)
     os.remove(fname)
예제 #4
0
 def setUp(self):
     self.files_dir = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'qucs_prj')
     self.dummy_media = DefinedGammaZ0(
         frequency=Frequency(1, 100, 21, 'ghz'),
         gamma=1j,
         z0=50,
     )
예제 #5
0
    def test_complex_ports(self):
        m = DefinedGammaZ0(
            frequency=Frequency(1, 1, 1, 'ghz'),
            gamma=1j,
            z0=50,
            Z0=10 + 20j,
        )
        self.assertTrue(m.Z0.imag != 0)

        # Powerwave short is -Z0.conj()/Z0
        short = m.short(z0=m.Z0, s_def='power')
        self.assertTrue(short.s != -1)
        # Should be -1 when converted to traveling s_def
        npy.testing.assert_allclose(short.s_traveling, -1)

        short = m.short(z0=m.Z0, s_def='traveling')
        npy.testing.assert_allclose(short.s, -1)

        short = m.short(z0=m.Z0, s_def='pseudo')
        npy.testing.assert_allclose(short.s, -1)

        # Mismatches agree with real port impedances
        mismatch_traveling = m.impedance_mismatch(z1=10,
                                                  z2=50,
                                                  s_def='traveling')
        mismatch_pseudo = m.impedance_mismatch(z1=10, z2=50, s_def='pseudo')
        mismatch_power = m.impedance_mismatch(z1=10, z2=50, s_def='power')
        npy.testing.assert_allclose(mismatch_traveling.s, mismatch_pseudo.s)
        npy.testing.assert_allclose(mismatch_traveling.s, mismatch_power.s)

        mismatch_traveling = m.impedance_mismatch(z1=10 + 10j,
                                                  z2=50 - 20j,
                                                  s_def='traveling')
        mismatch_pseudo = m.impedance_mismatch(z1=10 + 10j,
                                               z2=50 - 20j,
                                               s_def='pseudo')
        mismatch_power = m.impedance_mismatch(z1=10 + 10j,
                                              z2=50 - 20j,
                                              s_def='power')

        # Converting thru to new impedance should give impedance mismatch.
        # The problem is that thru Z-parameters have infinities
        # and renormalization goes through Z-parameters making
        # it very inaccurate.
        thru_traveling = m.thru(s_def='traveling')
        thru_traveling.renormalize(z_new=[10 + 10j, 50 - 20j])
        thru_pseudo = m.thru(s_def='pseudo')
        thru_pseudo.renormalize(z_new=[10 + 10j, 50 - 20j])
        thru_power = m.thru(s_def='power')
        thru_power.renormalize(z_new=[10 + 10j, 50 - 20j])

        npy.testing.assert_allclose(thru_traveling.s,
                                    mismatch_traveling.s,
                                    rtol=1e-3)
        npy.testing.assert_allclose(thru_pseudo.s,
                                    mismatch_pseudo.s,
                                    rtol=1e-3)
        npy.testing.assert_allclose(thru_power.s, mismatch_power.s, rtol=1e-3)
예제 #6
0
 def test_scalar_gamma_z0_media(self):
     """
     test ability to create a Media from scalar quantities for gamma/z0
     """
     freq = Frequency(1, 10, 101)
     a = DefinedGammaZ0(freq, gamma=1j, z0=50)
     self.assertEqual(len(freq), len(a))
     self.assertEqual(len(freq), len(a.gamma))
     self.assertEqual(len(freq), len(a.z0))
예제 #7
0
    def test_scalar_gamma_z0_media(self):
        '''
        test ability to create a Media from scalar quanties for gamma/z0
        and change frequency resolution
        '''
        a = DefinedGammaZ0(Frequency(1, 10, 101), gamma=1j, z0=50)
        self.assertEqual(a.line(1), a.line(1))

        # we should be able to re-sample the media
        a.npoints = 21
        self.assertEqual(len(a.gamma), len(a))
        self.assertEqual(len(a.z0), len(a))
        self.assertEqual(len(a.z0), len(a))
예제 #8
0
 def test_vector_gamma_z0_media(self):
     """
     test ability to create a Media from vector quantities for gamma/z0
     """
     freq = Frequency(1, 10, 101)
     a = DefinedGammaZ0(
         freq,
         gamma=1j * npy.ones(len(freq)),
         z0=50 * npy.ones(len(freq)),
     )
     self.assertEqual(len(freq), len(a))
     self.assertEqual(len(freq), len(a.gamma))
     self.assertEqual(len(freq), len(a.z0))
예제 #9
0
    def test_vector_gamma_z0_media(self):
        '''
        test ability to create a Media from vector quanties for gamma/z0
        '''
        freq = Frequency(1, 10, 101)
        a = DefinedGammaZ0(
            freq,
            gamma=1j * npy.ones(len(freq)),
            z0=50 * npy.ones(len(freq)),
        )

        self.assertEqual(a.line(1), a.line(1))
        with self.assertRaises(NotImplementedError):
            a.npoints = 4
예제 #10
0
 def setUp(self):
     self.dummy_media = DefinedGammaZ0(
         frequency=Frequency(1, 100, 21, 'GHz'),
         gamma=1j,
         z0=50,
     )