def setUp(self):
        ABCD = [[1.0, 0.0, 0.0, 0.044408783846879, -0.044408783846879],
                [
                    0.999036450096481, 0.997109907515262, -0.005777399147297,
                    0.0, 0.499759089304780
                ],
                [
                    0.499759089304780, 0.999036450096481, 0.997109907515262,
                    0.0, -0.260002096136488
                ], [0.0, 0.0, 1.0, 0.0, 0.0]]
        ABCD = np.array(ABCD)
        ntf, stf = ds.calculateTF(ABCD)
        ntf_zeros, ntf_poles, _ = ntf
        stf_zeros, stf_poles, _ = stf
        mntf_poles = np.array(
            (1.498975311463384, 1.102565142679772, 0.132677264750882))
        mntf_zeros = np.array((0.997109907515262 + 0.075972576202904j,
                               0.997109907515262 - 0.075972576202904j,
                               1.000000000000000 + 0.000000000000000j))
        mstf_zeros = np.array((-0.999999999999996, ))
        mstf_poles = np.array(
            (1.498975311463384, 1.102565142679772, 0.132677264750882))

        # for some reason, sometimes the zeros are in different order.
        self.ntf_zeros, self.mntf_zeros = (cplxpair(ntf_zeros),
                                           cplxpair(mntf_zeros))
        self.stf_zeros, self.mstf_zeros = (cplxpair(stf_zeros),
                                           cplxpair(mstf_zeros))
        self.ntf_poles, self.mntf_poles = (cplxpair(ntf_poles),
                                           cplxpair(mntf_poles))
        self.stf_poles, self.mstf_poles = (cplxpair(stf_poles),
                                           cplxpair(mstf_poles))
    def setUp(self):
        ABCD = [[1.0, 0.0, 0.0, 0.044408783846879, -0.044408783846879],
                [0.999036450096481, 0.997109907515262, -0.005777399147297,
                 0.0, 0.499759089304780],
                [0.499759089304780, 0.999036450096481, 0.997109907515262,
                 0.0, -0.260002096136488],
                [0.0, 0.0, 1.0,  0.0, 0.0]]
        ABCD = np.array(ABCD)
        ntf, stf = ds.calculateTF(ABCD)
        ntf_zeros, ntf_poles, _ = ntf
        stf_zeros, stf_poles, _ = stf
        mntf_poles = np.array((1.498975311463384, 1.102565142679772,
                               0.132677264750882))
        mntf_zeros = np.array((0.997109907515262 + 0.075972576202904j,
                               0.997109907515262 - 0.075972576202904j,
                               1.000000000000000 + 0.000000000000000j))
        mstf_zeros = np.array((-0.999999999999996,))
        mstf_poles = np.array((1.498975311463384, 1.102565142679772,
                               0.132677264750882))

        # for some reason, sometimes the zeros are in different order.
        self.ntf_zeros, self.mntf_zeros = (cplxpair(ntf_zeros),
                                           cplxpair(mntf_zeros))
        self.stf_zeros, self.mstf_zeros = (cplxpair(stf_zeros),
                                           cplxpair(mstf_zeros))
        self.ntf_poles, self.mntf_poles = (cplxpair(ntf_poles),
                                           cplxpair(mntf_poles))
        self.stf_poles, self.mstf_poles = (cplxpair(stf_poles),
                                           cplxpair(mstf_poles))
 def test_calculateTF4(self):
     """Test function for calculateTF() 4/4"""
     # Easy test for a 2-quantizers system
     # MASH 1-0 cascade
     ABCD = [[1, 1, -1, 0], [1, 0, 0, 0], [1, 0, -1, 0]]
     ABCD = np.array(ABCD, dtype=np.float_)
     k = [1., 1.]
     # here we get back arrays of transfer functions
     ntfs, stfs = ds.calculateTF(ABCD, k=k)
     # stfs
     self.assertTrue(np.allclose(stfs[0][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stfs[0][0]))
     self.assertTrue(np.allclose(stfs[0][2], 1., rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(stfs[1][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stfs[1][0]))
     self.assertTrue(np.allclose(stfs[1][2], 1., rtol=1e-5, atol=1e-8))
     # e1 to V1
     self.assertTrue(np.allclose(ntfs[0, 0][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntfs[0, 0][0], [1.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntfs[0, 0][2], 1., rtol=1e-5, atol=1e-8))
     # e1 to V2
     self.assertTrue(np.allclose(ntfs[1, 0][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(ntfs[1, 0][0]))
     self.assertTrue(np.allclose(ntfs[1, 0][2], -1., rtol=1e-5, atol=1e-8))
     # e2 to V2
     self.assertTrue(not len(ntfs[1, 1][0]))
     self.assertTrue(not len(ntfs[1, 1][1]))
     self.assertTrue(np.allclose(ntfs[1, 1][2], 1., rtol=1e-5, atol=1e-8))
     # e2 to V1
     self.assertTrue(np.allclose(ntfs[0, 1][2], 0., rtol=1e-5, atol=1e-8))
 def test_calculateTF4(self):
     """Test function for calculateTF() 4/4"""
     # Easy test for a 2-quantizers system
     # MASH 1-0 cascade
     ABCD = [[1, 1, -1, 0],
             [1, 0, 0, 0],
             [1, 0, -1, 0]]
     ABCD = np.array(ABCD, dtype=np.float_)
     k = [1., 1.]
     # here we get back arrays of transfer functions
     ntfs, stfs = ds.calculateTF(ABCD, k=k)
     # stfs
     self.assertTrue(np.allclose(stfs[0][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stfs[0][0]))
     self.assertTrue(np.allclose(stfs[0][2], 1., rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(stfs[1][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stfs[1][0]))
     self.assertTrue(np.allclose(stfs[1][2], 1., rtol=1e-5, atol=1e-8))
     # e1 to V1
     self.assertTrue(np.allclose(ntfs[0, 0][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntfs[0, 0][0], [1.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntfs[0, 0][2], 1., rtol=1e-5, atol=1e-8))
     # e1 to V2
     self.assertTrue(np.allclose(ntfs[1, 0][1], [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(ntfs[1, 0][0]))
     self.assertTrue(np.allclose(ntfs[1, 0][2], -1., rtol=1e-5, atol=1e-8))
     # e2 to V2
     self.assertTrue(not len(ntfs[1, 1][0]))
     self.assertTrue(not len(ntfs[1, 1][1]))
     self.assertTrue(np.allclose(ntfs[1, 1][2], 1., rtol=1e-5, atol=1e-8))
     # e2 to V1
     self.assertTrue(np.allclose(ntfs[0, 1][2], 0., rtol=1e-5, atol=1e-8))
示例#5
0
 def __init__(self):
     ABCD = [[1, 0, 0, 0, 1, -1, 0], [1, 1, 0, 0, 0, -2, 0],
             [0, 1, 1, 0, 0, 0, -1], [0, 0, 1, 1, 0, 0, -2],
             [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0]]
     self.ABCD = np.array(ABCD, dtype=np.float_)
     self.nlev = [9, 9]
     k = [1., 1.]
     self.ntfs, self.stfs = ds.calculateTF(self.ABCD, k)
 def __init__(self):
     ABCD = [[1, 0, 0, 0, 1, -1, 0],
             [1, 1, 0, 0, 0, -2, 0],
             [0, 1, 1, 0, 0, 0, -1],
             [0, 0, 1, 1, 0, 0, -2],
             [0, 1, 0, 0, 0, 0, 0],
             [0, 0, 0, 1, 0, 0, 0]]
     self.ABCD = np.array(ABCD, dtype=np.float_)
     self.nlev = [9, 9]
     k = [1., 1.]
     self.ntfs, self.stfs = ds.calculateTF(self.ABCD, k)
 def test_calculateTF3(self):
     """Test function for calculateTF() 3/4"""
     # test for the default k value
     ABCD = np.array([[1., 1., -1.], [1., 0., 0.]])
     ntf, stf = ds.calculateTF(ABCD)
     ntf_zeros, ntf_poles, ntf_gain = ntf
     stf_zeros, stf_poles, stf_gain = stf
     self.assertTrue(np.allclose(stf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stf_zeros))
     self.assertTrue(np.allclose(stf_gain, 1., rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_zeros, [1.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_gain, 1., rtol=1e-5, atol=1e-8))
 def test_calculateTF2(self):
     """Test function for calculateTF() 2/4"""
     # test an easy TF
     ABCD = np.array([[1., 1., -1.], [1., 0., 0.]])
     k = 1.
     ntf, stf = ds.calculateTF(ABCD, k)
     ntf_zeros, ntf_poles, ntf_gain = ntf
     stf_zeros, stf_poles, stf_gain = stf
     self.assertTrue(np.allclose(stf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stf_zeros))
     self.assertTrue(np.allclose(stf_gain, 1., rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_zeros, [1.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_gain, 1., rtol=1e-5, atol=1e-8))
 def test_calculateTF3(self):
     """Test function for calculateTF() 3/4"""
     # test for the default k value
     ABCD = np.array([[1., 1., -1.],
                     [1., 0., 0.]])
     ntf, stf = ds.calculateTF(ABCD)
     ntf_zeros, ntf_poles, ntf_gain = ntf
     stf_zeros, stf_poles, stf_gain = stf
     self.assertTrue(np.allclose(stf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stf_zeros))
     self.assertTrue(np.allclose(stf_gain, 1., rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_zeros, [1.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_gain, 1., rtol=1e-5, atol=1e-8))
 def test_calculateTF2(self):
     """Test function for calculateTF() 2/4"""
     # test an easy TF
     ABCD = np.array([[1., 1., -1.],
                     [1., 0., 0.]])
     k = 1.
     ntf, stf = ds.calculateTF(ABCD, k) 
     ntf_zeros, ntf_poles, ntf_gain = ntf
     stf_zeros, stf_poles, stf_gain = stf
     self.assertTrue(np.allclose(stf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(not len(stf_zeros))
     self.assertTrue(np.allclose(stf_gain, 1., rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_poles, [0.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_zeros, [1.], rtol=1e-5, atol=1e-8))
     self.assertTrue(np.allclose(ntf_gain, 1., rtol=1e-5, atol=1e-8))
示例#11
0
 def test_mapCtoD_1(self):
     """Test function for mapCtoD() 1/6"""
     # The first test comes straight from the DSToolbox doc
     # We map the standard continuous time DS modulator to its DT counterpart
     # and we check whether the TF is (1 - 1/z)**2
     LFc = (np.array([[0., 0.], [1., 0.]]), np.array([[1., -1.], [0.,
                                                                  -1.5]]),
            np.array([[0., 1.]]), np.array(([[0., 0.]])))
     tdac = [0, 1]
     LF, Gp = ds.mapCtoD(LFc, tdac)
     ABCD = np.vstack((np.hstack((LF[0], LF[1])), np.hstack(
         (LF[2], LF[3]))))
     H = ds.calculateTF(ABCD)
     num, den = zpk2tf(*H[0])
     self.assertTrue(np.allclose(num, [1., -2., 1.], atol=1e-8, rtol=1e-5))
     self.assertTrue(np.allclose(den, [1., 0., 0.], atol=1e-8, rtol=1e-5))
示例#12
0
 def test_mapCtoD_1(self):
     """Test function for mapCtoD() 1/6"""
     # The first test comes straight from the DSToolbox doc
     # We map the standard continuous time DS modulator to its DT counterpart
     # and we check whether the TF is (1 - 1/z)**2
     LFc = (np.array([[0., 0.], [1., 0.]]),
            np.array([[1., -1.], [0., -1.5]]),
            np.array([[0., 1.]]),
            np.array(([[0., 0.]]))
           )
     tdac = [0, 1]
     LF, Gp = ds.mapCtoD(LFc, tdac)
     ABCD = np.vstack((np.hstack((LF[0], LF[1])),
                       np.hstack((LF[2], LF[3]))
                     ))
     H = ds.calculateTF(ABCD)
     self.assertTrue(np.allclose(H[0].num, [ 1., -2.,  1.], atol=1e-8, rtol=1e-5))
     self.assertTrue(np.allclose(H[0].den, [1., 0., 0.], atol=1e-8, rtol=1e-5))