def test_realizeQNTF(self):
     """Test function for realizeQNTF()"""
     for i in self.orders:
         if not i in self.res: continue
         for j in self.f0s:
             if not j in self.res[i]: continue
             for ng in self.NG:
                 if not ng in self.res[i][j]: continue
                 for ing in self.ING:
                     if not ing in self.res[i][j][ng]: continue
                     for rot in self.rots:
                         if not rot in self.res[i][j][ng][ing]: continue
                         for f in self.forms:
                             if not f in self.res[i][j][ng][ing][rot]: continue
                             if self.res[i][j][ng][ing][rot][f] is None: continue
                             print("Testing form: %s, order: %d, f0: %f, NG %d ING %d ROT %d" % \
                                   (f, i, j, ng, ing, rot))
                             ntf = ds.synthesizeQNTF(i, self.osr, j, ng, ing)
                             ABCD = ds.realizeQNTF(ntf, f, rot)
                             if not np.allclose(self.res[i][j][ng][ing][rot][f].real,
                                                ABCD.real, atol=1e-3, rtol=1e-3):
                                 print(ntf)
                                 print(ABCD)
                                 print(self.res[i][j][ng][ing][rot][f])
                                 print(ABCD - self.res[i][j][ng][ing][rot][f])
                             self.assertTrue(np.allclose(self.res[i][j][ng][ing][rot][f].real,
                                             ABCD.real, atol=1e-3, rtol=1e-3))
     return
    def test_simulateSNR_4(self):
        """Test function for simulateSNR() 4/4"""
        SNR_ref = np.array([23.0421, 32.1100, 43.3758, 53.1791,
                            65.5504, 70.5023, 73.4608, 76.2416, 77.8770,
                            78.2733, 79.3729, 79.5728, 80.8729, 82.7461,
                            83.0723, 84.8488, 84.3327])
        AMP_ref = np.array([-70, -60, -50, -40, -30, -20, -15, -10, -9, -8, -7,
                            -6, -5, -4, -3, -2, -1, 0])

        order = 4
        osr = 32
        M = 8
        NG = -50
        ING = -10
        f0 = 1./ 16
        quadrature = 1
        form = 'PFB'
        nlev = M + 1
        z0 = np.exp(1j*2*np.pi*f0)
        bw = 1./ osr
        delta = 2
        FullScale = M
        ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
        ABCD = ds.realizeQNTF(ntf0, form, True)
        #print(ABCD)
        #ds.PlotExampleSpectrum(ntf0, M, osr, f0, quadrature=True)
        a, b = ds.simulateSNR(ABCD, osr, None, f0, nlev);
        assert np.allclose(a[6:], SNR_ref, atol=10, rtol=1e-3)
        assert np.allclose(b[5:], AMP_ref, atol=1)
예제 #3
0
    def test_simulateSNR_4(self):
        """Test function for simulateSNR() 4/4"""
        SNR_ref = np.array([
            23.0421, 32.1100, 43.3758, 53.1791, 65.5504, 70.5023, 73.4608,
            76.2416, 77.8770, 78.2733, 79.3729, 79.5728, 80.8729, 82.7461,
            83.0723, 84.8488, 84.3327
        ])
        AMP_ref = np.array([
            -70, -60, -50, -40, -30, -20, -15, -10, -9, -8, -7, -6, -5, -4, -3,
            -2, -1, 0
        ])

        order = 4
        osr = 32
        M = 8
        NG = -50
        ING = -10
        f0 = 1. / 16
        quadrature = 1
        form = 'PFB'
        nlev = M + 1
        z0 = np.exp(1j * 2 * np.pi * f0)
        bw = 1. / osr
        delta = 2
        FullScale = M
        ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
        ABCD = ds.realizeQNTF(ntf0, form, True)
        #print(ABCD)
        #ds.PlotExampleSpectrum(ntf0, M, osr, f0, quadrature=True)
        a, b = ds.simulateSNR(ABCD, osr, None, f0, nlev)
        assert np.allclose(a[6:], SNR_ref, atol=10, rtol=1e-3)
        assert np.allclose(b[5:], AMP_ref, atol=1)
예제 #4
0
 def test_documentNTF3(self):
     """Test function for DocumentNTF(): check plot with QNTF 3/3"""
     order = 4
     osr = 32
     NG = -50
     ING = -10
     f0 = 1. / 16
     ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
     self.assertIsNone(ds.DocumentNTF(ntf0, osr, f0, quadrature=True))
 def test_documentNTF3(self):
     """Test function for DocumentNTF(): check plot with QNTF 3/3"""
     order = 4
     osr = 32
     NG = -50
     ING = -10
     f0 = 1./16
     ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
     self.assertIsNone(ds.DocumentNTF(ntf0, osr, f0, quadrature=True))
예제 #6
0
 def test_PlotExampleSpectrum_QNTF(self):
     """Test function for PlotExampleSpectrum() with QNTF"""
     order = 4
     osr = 32
     M = 8
     NG = -50
     ING = -10
     f0 = 1 / 16
     delta = 2
     ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
     ret = ds.PlotExampleSpectrum(ntf0, M, osr, f0, quadrature=True)
     self.assertIsNone(ret)
 def test_PlotExampleSpectrum_QNTF(self):
     """Test function for PlotExampleSpectrum() with QNTF"""
     order = 4
     osr = 32
     M = 8
     NG = -50
     ING = -10
     f0 = 1 / 16
     delta = 2
     ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
     ret = ds.PlotExampleSpectrum(ntf0, M, osr, f0, quadrature=True)
     self.assertIsNone(ret)
 def test_synthesizeQNTF_1(self):
     """Test function for synthesizeQNTF() 1/4"""
     ntf = synthesizeQNTF(4, 32, 1/16, -50, -10)
     z, p, k = ntf
     p_ref = [0.573877782470855 + 0.569921695571522j,
              0.808788367241398 + 0.002797375873482j,
              0.591250299914031 + 0.244903892981552j,
              0.673072277003855 - 0.278795665592338j]
     z_ref = [0.888037198535288 + 0.459771610712905j,
              0.953044748762363 + 0.302829501298050j,
              0.923879532511340 + 0.382683432365112j,
              0.923879532511287 - 0.382683432365090j]
     k_ref = 1.
     np.allclose(p, p_ref, atol=1e-4, rtol=1e-3)
     np.allclose(z, z_ref, atol=1e-4, rtol=1e-3)
     np.allclose(k, k_ref, atol=1e-4, rtol=1e-3)
 def test_synthesizeQNTF_4(self):
     """Test function for synthesizeQNTF() 4/4"""
     # order 2
     order = 2
     osr = 32
     NG = -50
     ING = -10
     f0 = 1./ 16
     ntf0 = synthesizeQNTF(order, osr, f0, NG, ING)
     z_ref = [0.900716472438935 + 0.434407454214544j,
              0.944075182261086 + 0.329730268914908j]
     p_ref = [0.112333561599987 - 0.126178981177517j,
              -0.00979019007164386 + 0.168653836396020j]
     k_ref = 1
     assert np.allclose(z_ref, ntf0[0])
     assert np.allclose(p_ref, ntf0[1])
     assert ntf0[2] == k_ref
    def test_synthesizeQNTF_2(self):
        """Test function for synthesizeQNTF() 2/4"""
        ntf = synthesizeQNTF(4, 32, 1/16, -50, -10, 0)
        z, p, k = ntf
        z_ref = [0.910594282901269 + 0.413301405692653j,
                 0.936135618988396 + 0.351639165709982j,
                 0.888265620891369 + 0.459330150047295j,
                 0.952894107929043 + 0.303303180125290j]

        p_ref = [0.767590403998773 + 0.239841808290628j,
                 0.712362148895601 + 0.373174610786908j,
                 0.899297507221408 + 0.158408031000048j,
                 0.747910758574959 + 0.523887972745873j]
        k_ref = 1.
        np.allclose(p, p_ref, atol=1e-4, rtol=1e-3)
        np.allclose(z, z_ref, atol=1e-4, rtol=1e-3)
        np.allclose(k, k_ref, atol=1e-4, rtol=1e-3)
 def test_synthesizeQNTF_1(self):
     """Test function for synthesizeQNTF() 1/4"""
     ntf = synthesizeQNTF(4, 32, 1 / 16, -50, -10)
     z, p, k = ntf
     p_ref = [
         0.573877782470855 + 0.569921695571522j,
         0.808788367241398 + 0.002797375873482j,
         0.591250299914031 + 0.244903892981552j,
         0.673072277003855 - 0.278795665592338j
     ]
     z_ref = [
         0.888037198535288 + 0.459771610712905j,
         0.953044748762363 + 0.302829501298050j,
         0.923879532511340 + 0.382683432365112j,
         0.923879532511287 - 0.382683432365090j
     ]
     k_ref = 1.
     np.allclose(p, p_ref, atol=1e-4, rtol=1e-3)
     np.allclose(z, z_ref, atol=1e-4, rtol=1e-3)
     np.allclose(k, k_ref, atol=1e-4, rtol=1e-3)
예제 #12
0
 def test_simulateQSNR(self):
     """Test function for simulateSNR() 4/4"""
     order = 4
     osr = 32
     M = 8
     NG = -50
     ING = -10
     f0 = 1. / 16
     quadrature = 1
     form = 'PFB'
     nlev = M + 1
     z0 = np.exp(1j * 2 * np.pi * f0)
     bw = 1. / osr
     delta = 2
     FullScale = M
     ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
     ABCD = ds.realizeQNTF(ntf0, form, True)
     a, b = ds.simulateQSNR(ABCD, osr, None, f0, nlev)
     assert np.allclose(a[6:], self.SNR_ref, atol=6, rtol=1e-3)
     assert np.allclose(b[5:], self.AMP_ref, atol=1)
 def test_synthesizeQNTF_3(self):
     """Test function for synthesizeQNTF() 3/4"""
     order = 4
     osr = 32
     NG = -50
     ING = -10
     f0 = 1. / 16
     ntf0 = synthesizeQNTF(order, osr, f0, NG, ING)
     zeros_ref = np.array((0.8880 + 0.4598j, 0.9530 + 0.3028j,
                           0.9239 + 0.3827j, 0.9239 - 0.3827j))
     poles_ref = np.array((0.5739 + 0.5699j, 0.8088 + 0.0028j,
                           0.5913 + 0.2449j, 0.6731 - 0.2788j))
     # round down to the same precision as the results data
     # or np.sort_complex will find slightly different floats
     # to be different and sort wrongly, resulting in a failed test
     zeros = np.round(ntf0[0], 4)
     poles = np.round(ntf0[1], 4)
     assert np.allclose(zeros, zeros_ref, atol=1e-2, rtol=1e-2)
     assert np.allclose(poles, poles_ref, atol=1e-2, rtol=1e-2)
     assert ntf0[2] == 1.
 def test_simulateQSNR(self):
     """Test function for simulateSNR() 4/4"""
     order = 4
     osr = 32
     M = 8
     NG = -50
     ING = -10
     f0 = 1./ 16
     quadrature = 1
     form = 'PFB'
     nlev = M + 1
     z0 = np.exp(1j*2*np.pi*f0)
     bw = 1./ osr
     delta = 2
     FullScale = M
     ntf0 = ds.synthesizeQNTF(order, osr, f0, NG, ING)
     ABCD = ds.realizeQNTF(ntf0, form, True)
     a, b = ds.simulateQSNR(ABCD, osr, None, f0, nlev);
     assert np.allclose(a[6:], self.SNR_ref, atol=6, rtol=1e-3)
     assert np.allclose(b[5:], self.AMP_ref, atol=1)
    def test_synthesizeQNTF_2(self):
        """Test function for synthesizeQNTF() 2/4"""
        ntf = synthesizeQNTF(4, 32, 1 / 16, -50, -10, 0)
        z, p, k = ntf
        z_ref = [
            0.910594282901269 + 0.413301405692653j,
            0.936135618988396 + 0.351639165709982j,
            0.888265620891369 + 0.459330150047295j,
            0.952894107929043 + 0.303303180125290j
        ]

        p_ref = [
            0.767590403998773 + 0.239841808290628j,
            0.712362148895601 + 0.373174610786908j,
            0.899297507221408 + 0.158408031000048j,
            0.747910758574959 + 0.523887972745873j
        ]
        k_ref = 1.
        np.allclose(p, p_ref, atol=1e-4, rtol=1e-3)
        np.allclose(z, z_ref, atol=1e-4, rtol=1e-3)
        np.allclose(k, k_ref, atol=1e-4, rtol=1e-3)
 def test_synthesizeQNTF_4(self):
     """Test function for synthesizeQNTF() 4/4"""
     # order 2
     order = 2
     osr = 32
     NG = -50
     ING = -10
     f0 = 1. / 16
     ntf0 = synthesizeQNTF(order, osr, f0, NG, ING)
     z_ref = [
         0.900716472438935 + 0.434407454214544j,
         0.944075182261086 + 0.329730268914908j
     ]
     p_ref = [
         0.112333561599987 - 0.126178981177517j,
         -0.00979019007164386 + 0.168653836396020j
     ]
     k_ref = 1
     assert np.allclose(z_ref, ntf0[0])
     assert np.allclose(p_ref, ntf0[1])
     assert ntf0[2] == k_ref
예제 #17
0
 def test_realizeQNTF(self):
     """Test function for realizeQNTF()"""
     for i in self.orders:
         if not i in self.res: continue
         for j in self.f0s:
             if not j in self.res[i]: continue
             for ng in self.NG:
                 if not ng in self.res[i][j]: continue
                 for ing in self.ING:
                     if not ing in self.res[i][j][ng]: continue
                     for rot in self.rots:
                         if not rot in self.res[i][j][ng][ing]: continue
                         for f in self.forms:
                             if not f in self.res[i][j][ng][ing][rot]:
                                 continue
                             if self.res[i][j][ng][ing][rot][f] is None:
                                 continue
                             print("Testing form: %s, order: %d, f0: %f, NG %d ING %d ROT %d" % \
                                   (f, i, j, ng, ing, rot))
                             ntf = ds.synthesizeQNTF(
                                 i, self.osr, j, ng, ing)
                             ABCD = ds.realizeQNTF(ntf, f, rot)
                             if not np.allclose(
                                     self.res[i][j][ng][ing][rot][f].real,
                                     ABCD.real,
                                     atol=1e-3,
                                     rtol=1e-3):
                                 print(ntf)
                                 print(ABCD)
                                 print(self.res[i][j][ng][ing][rot][f])
                                 print(ABCD -
                                       self.res[i][j][ng][ing][rot][f])
                             self.assertTrue(
                                 np.allclose(
                                     self.res[i][j][ng][ing][rot][f].real,
                                     ABCD.real,
                                     atol=1e-3,
                                     rtol=1e-3))
     return
 def test_synthesizeQNTF_3(self):
     """Test function for synthesizeQNTF() 3/4"""
     order = 4
     osr = 32
     NG = -50
     ING = -10
     f0 = 1./16
     ntf0 = synthesizeQNTF(order, osr, f0, NG, ING)
     zeros_ref = np.array((0.8880 + 0.4598j,
                           0.9530 + 0.3028j,
                           0.9239 + 0.3827j,
                           0.9239 - 0.3827j))
     poles_ref = np.array((0.5739 + 0.5699j,
                           0.8088 + 0.0028j,
                           0.5913 + 0.2449j,
                           0.6731 - 0.2788j))
     # round down to the same precision as the results data
     # or np.sort_complex will find slightly different floats
     # to be different and sort wrongly, resulting in a failed test
     zeros = np.round(ntf0[0], 4)
     poles = np.round(ntf0[1], 4)
     assert np.allclose(zeros, zeros_ref, atol=1e-2, rtol=1e-2)
     assert np.allclose(poles, poles_ref, atol=1e-2, rtol=1e-2)
     assert ntf0[2] == 1.