Exemplo n.º 1
0
    def test_haar(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wname = 'haar'
        [cA,cD] = pyyawt.dwt(x1,wname)
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
        r = pyyawt.idwt(cA,cD,wname)
        np.testing.assert_almost_equal(r, x0)

        [cA,cD] = pyyawt.dwt(x1,wname)
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
        r = pyyawt.idwt(cA,cD,wname)
        np.testing.assert_almost_equal(r, x0)

        [cA,cD] = pyyawt.dwt(x1,wname)
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
        r = pyyawt.idwt(cA,cD,wname)
        np.testing.assert_almost_equal(r, x0)
Exemplo n.º 2
0
    def test_type2(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wname = "bior3.9"
        [cA,cD] = pyyawt.dwt(x1,wname)
        Lo_R = np.random.randn(20)
        Hi_R = np.random.randn(20)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
        r = pyyawt.idwt(cA,cD,Lo_R.flatten(),Hi_R.flatten())
        np.testing.assert_almost_equal(r, x0)

        [cA,cD] = pyyawt.dwt(x2,wname)
        Lo_R = np.random.randn(20)
        Hi_R = np.random.randn(20)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
        r = pyyawt.idwt(cA,cD,Lo_R.flatten(),Hi_R.flatten())
        np.testing.assert_almost_equal(r, x0)

        [cA,cD] = pyyawt.dwt(s1,wname)
        Lo_R = np.random.randn(20)
        Hi_R = np.random.randn(20)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
        r = pyyawt.idwt(cA,cD,Lo_R.flatten(),Hi_R.flatten())
        np.testing.assert_almost_equal(r, x0)
Exemplo n.º 3
0
    def test_coif(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        for N in np.arange(1, 6):
            wname = "coif" + str(N)
            [cA, cD] = pyyawt.dwt(x1, wname)
            [cA, cD] = pyyawt.dwt(x1, wname)
            [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
            x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
            r = pyyawt.idwt(cA, cD, wname)
            np.testing.assert_almost_equal(r, x0)

            [cA, cD] = pyyawt.dwt(x1, wname)
            [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
            x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
            r = pyyawt.idwt(cA, cD, wname)
            np.testing.assert_almost_equal(r, x0)

            [cA, cD] = pyyawt.dwt(x1, wname)
            [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
            x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
            r = pyyawt.idwt(cA, cD, wname)
            np.testing.assert_almost_equal(r, x0)
Exemplo n.º 4
0
    def test_bior(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wnames = ['bior1.1', 'bior1.3', 'bior1.5', 'bior2.2', 'bior2.4', 'bior2.6',
                  'bior2.8', 'bior3.1', 'bior3.3', 'bior3.5', 'bior3.7', 'bior3.9',
                  'bior4.4', 'bior5.5', 'bior6.8']
        for N in np.arange(1,13):
            wname = wnames[N]
            [cA,cD] = pyyawt.dwt(x1,wname)
            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
            x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
            r = pyyawt.idwt(cA,cD,wname)
            np.testing.assert_almost_equal(r, x0)

            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
            x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
            r = pyyawt.idwt(cA,cD,wname)
            np.testing.assert_almost_equal(r, x0)

            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
            x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
            r = pyyawt.idwt(cA,cD,wname)
            np.testing.assert_almost_equal(r, x0)
Exemplo n.º 5
0
    def test_haar(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wname = 'haar'
        [cA, cD] = pyyawt.dwt(x1, wname)
        [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
        r = pyyawt.idwt(cA, cD, wname)
        np.testing.assert_almost_equal(r, x0)

        [cA, cD] = pyyawt.dwt(x1, wname)
        [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
        r = pyyawt.idwt(cA, cD, wname)
        np.testing.assert_almost_equal(r, x0)

        [cA, cD] = pyyawt.dwt(x1, wname)
        [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
        r = pyyawt.idwt(cA, cD, wname)
        np.testing.assert_almost_equal(r, x0)
Exemplo n.º 6
0
    def test_type2(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wname = "bior3.9"
        [cA, cD] = pyyawt.dwt(x1, wname)
        Lo_R = np.random.randn(20)
        Hi_R = np.random.randn(20)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
        r = pyyawt.idwt(cA, cD, Lo_R.flatten(), Hi_R.flatten())
        np.testing.assert_almost_equal(r, x0)

        [cA, cD] = pyyawt.dwt(x2, wname)
        Lo_R = np.random.randn(20)
        Hi_R = np.random.randn(20)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
        r = pyyawt.idwt(cA, cD, Lo_R.flatten(), Hi_R.flatten())
        np.testing.assert_almost_equal(r, x0)

        [cA, cD] = pyyawt.dwt(s1, wname)
        Lo_R = np.random.randn(20)
        Hi_R = np.random.randn(20)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
        r = pyyawt.idwt(cA, cD, Lo_R.flatten(), Hi_R.flatten())
        np.testing.assert_almost_equal(r, x0)
Exemplo n.º 7
0
    def test_bior(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wnames = [
            'bior1.1', 'bior1.3', 'bior1.5', 'bior2.2', 'bior2.4', 'bior2.6',
            'bior2.8', 'bior3.1', 'bior3.3', 'bior3.5', 'bior3.7', 'bior3.9',
            'bior4.4', 'bior5.5', 'bior6.8'
        ]
        for N in np.arange(1, 13):
            wname = wnames[N]
            [cA, cD] = pyyawt.dwt(x1, wname)
            [cA, cD] = pyyawt.dwt(x1, wname)
            [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
            x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
            r = pyyawt.idwt(cA, cD, wname)
            np.testing.assert_almost_equal(r, x0)

            [cA, cD] = pyyawt.dwt(x1, wname)
            [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
            x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
            r = pyyawt.idwt(cA, cD, wname)
            np.testing.assert_almost_equal(r, x0)

            [cA, cD] = pyyawt.dwt(x1, wname)
            [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
            x0 = pyyawt.wkeep(a0 + d0, 2 * np.size(cA) - np.size(Lo_R) + 2)
            r = pyyawt.idwt(cA, cD, wname)
            np.testing.assert_almost_equal(r, x0)
Exemplo n.º 8
0
    def test_coif(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        for N in np.arange(1,6):
            wname = "coif" + str(N)
            [cA,cD] = pyyawt.dwt(x1,wname)
            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
            x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
            r = pyyawt.idwt(cA,cD,wname)
            np.testing.assert_almost_equal(r, x0)

            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
            x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
            r = pyyawt.idwt(cA,cD,wname)
            np.testing.assert_almost_equal(r, x0)

            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
            d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
            x0 = pyyawt.wkeep(a0+d0,2*np.size(cA)-np.size(Lo_R)+2)
            r = pyyawt.idwt(cA,cD,wname)
            np.testing.assert_almost_equal(r, x0)
Exemplo n.º 9
0
 def test_matrix(self):
     a = np.random.randn(50,51)
     b = pyyawt.wkeep(a,[27,26])
     b1 = pyyawt.wkeep(a,[27,26],[2,3])
     c = a[11:38,:][:,12:38]
     c1 = a[1:28,:][:,2:28]
     np.testing.assert_almost_equal(b, c)
     np.testing.assert_almost_equal(b1, c1)
Exemplo n.º 10
0
 def test_matrix(self):
     a = np.random.randn(50, 51)
     b = pyyawt.wkeep(a, [27, 26])
     b1 = pyyawt.wkeep(a, [27, 26], [2, 3])
     c = a[11:38, :][:, 12:38]
     c1 = a[1:28, :][:, 2:28]
     np.testing.assert_almost_equal(b, c)
     np.testing.assert_almost_equal(b1, c1)
Exemplo n.º 11
0
 def test_type5(self):
     s1 = self.s1
     x1 = self.x1
     x2 = self.x2
     wname = "db7"
     dwtModes = ['symw', 'asymh', 'asymw', 'zpd', 'sp0', 'sp1',
                 'ppd','per']
     [cA,cD] = pyyawt.dwt(x1,wname)
     [Lo_R,Hi_R] = pyyawt.wfilters(wname,'r')
     a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
     d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
     x0 = pyyawt.wkeep(a0+d0,50)
     for N in np.arange(len(dwtModes)-1):
         r = pyyawt.idwt(cA,cD,wname,50,'mode',dwtModes[N])
         np.testing.assert_almost_equal(r, x0)
     r = pyyawt.idwt(cA,cD,wname,50,'mode','per')
     x0 = pyyawt.wkeep(a0+d0,50)
     np.testing.assert_almost_equal(r, x0)
Exemplo n.º 12
0
 def test_type6(self):
     s1 = self.s1
     x1 = self.x1
     x2 = self.x2
     wname = "db7"
     dwtModes = ['symw', 'asymh', 'asymw', 'zpd', 'sp0', 'sp1',
                 'ppd','per']
     [cA,cD] = pyyawt.dwt(x1,wname)
     Lo_R = np.random.rand(14)
     Hi_R = np.random.rand(14)
     a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R.flatten())
     d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R.flatten())
     x0 = pyyawt.wkeep(a0+d0,50)
     for N in np.arange(len(dwtModes)-1):
         r = pyyawt.idwt(cA,cD,Lo_R,Hi_R,50,'mode',dwtModes[N])
         np.testing.assert_almost_equal(r, x0)
     r = pyyawt.idwt(cA,cD,Lo_R,Hi_R,50,'mode','per')
     x0 = pyyawt.wkeep(a0+d0,50)
     np.testing.assert_almost_equal(r, x0)
Exemplo n.º 13
0
 def test_type5(self):
     s1 = self.s1
     x1 = self.x1
     x2 = self.x2
     wname = "db7"
     dwtModes = [
         'symw', 'asymh', 'asymw', 'zpd', 'sp0', 'sp1', 'ppd', 'per'
     ]
     [cA, cD] = pyyawt.dwt(x1, wname)
     [Lo_R, Hi_R] = pyyawt.wfilters(wname, 'r')
     a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
     d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
     x0 = pyyawt.wkeep(a0 + d0, 50)
     for N in np.arange(len(dwtModes) - 1):
         r = pyyawt.idwt(cA, cD, wname, 50, 'mode', dwtModes[N])
         np.testing.assert_almost_equal(r, x0)
     r = pyyawt.idwt(cA, cD, wname, 50, 'mode', 'per')
     x0 = pyyawt.wkeep(a0 + d0, 50)
     np.testing.assert_almost_equal(r, x0)
Exemplo n.º 14
0
 def test_type6(self):
     s1 = self.s1
     x1 = self.x1
     x2 = self.x2
     wname = "db7"
     dwtModes = [
         'symw', 'asymh', 'asymw', 'zpd', 'sp0', 'sp1', 'ppd', 'per'
     ]
     [cA, cD] = pyyawt.dwt(x1, wname)
     Lo_R = np.random.rand(14)
     Hi_R = np.random.rand(14)
     a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R.flatten())
     d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R.flatten())
     x0 = pyyawt.wkeep(a0 + d0, 50)
     for N in np.arange(len(dwtModes) - 1):
         r = pyyawt.idwt(cA, cD, Lo_R, Hi_R, 50, 'mode', dwtModes[N])
         np.testing.assert_almost_equal(r, x0)
     r = pyyawt.idwt(cA, cD, Lo_R, Hi_R, 50, 'mode', 'per')
     x0 = pyyawt.wkeep(a0 + d0, 50)
     np.testing.assert_almost_equal(r, x0)
Exemplo n.º 15
0
    def test_bior(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wnames = ['bior1.1', 'bior1.3', 'bior1.5', 'bior2.2', 'bior2.4', 'bior2.6',
                  'bior2.8', 'bior3.1', 'bior3.3', 'bior3.5', 'bior3.7', 'bior3.9',
                  'bior4.4', 'bior5.5', 'bior6.8']
        for N in np.arange(1,13):
            wname = wnames[N]
            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x1,np.size(Lo_D),'b'),Lo_D),(np.size(x1)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x1,np.size(Lo_D),'b'),Hi_D),(np.size(x1)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)

            [cA,cD] = pyyawt.dwt(x2,wname)
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x2,np.size(Lo_D),'b'),Lo_D),(np.size(x2)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x2,np.size(Lo_D),'b'),Hi_D),(np.size(x2)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)

            [cA,cD] = pyyawt.dwt(s1,wname)
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',s1,np.size(Lo_D),'b'),Lo_D),(np.size(s1)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',s1,np.size(Lo_D),'b'),Hi_D),(np.size(s1)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)
Exemplo n.º 16
0
    def test_type3(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wname = "sym8"
        [cA, cD] = pyyawt.dwt(x1, wname)
        r = pyyawt.idwt(cA, cD, wname, 50)
        [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 50)
        np.testing.assert_almost_equal(r, x0)

        [cA, cD] = pyyawt.dwt(x2, wname)
        r = pyyawt.idwt(cA, cD, wname, 50)
        [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 50)
        np.testing.assert_almost_equal(r, x0)

        [cA, cD] = pyyawt.dwt(s1, wname)
        r = pyyawt.idwt(cA, cD, wname, 50)
        [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 50)
        np.testing.assert_almost_equal(r, x0)

        Lo_R = np.random.randn(50)
        Hi_R = np.random.randn(50)
        a0 = pyyawt.conv(pyyawt.dyadup(cA), Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD), Hi_R)
        x0 = pyyawt.wkeep(a0 + d0, 50)
        r = pyyawt.idwt(cA, cD, Lo_R.flatten(), Hi_R.flatten(), 50)
        np.testing.assert_almost_equal(r, x0)
Exemplo n.º 17
0
    def test_type3(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        wname = "sym8"
        [cA,cD] = pyyawt.dwt(x1,wname)
        r = pyyawt.idwt(cA,cD,wname,50)
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,50)
        np.testing.assert_almost_equal(r, x0)

        [cA,cD] = pyyawt.dwt(x2,wname)
        r = pyyawt.idwt(cA,cD,wname,50)
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,50)
        np.testing.assert_almost_equal(r, x0)

        [cA,cD] = pyyawt.dwt(s1,wname)
        r = pyyawt.idwt(cA,cD,wname,50)
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,50)
        np.testing.assert_almost_equal(r, x0)

        Lo_R = np.random.randn(50)
        Hi_R = np.random.randn(50)
        a0 = pyyawt.conv(pyyawt.dyadup(cA),Lo_R)
        d0 = pyyawt.conv(pyyawt.dyadup(cD),Hi_R)
        x0 = pyyawt.wkeep(a0+d0,50)
        r = pyyawt.idwt(cA,cD,Lo_R.flatten(),Hi_R.flatten(),50)
        np.testing.assert_almost_equal(r, x0)
Exemplo n.º 18
0
    def test_haar(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        [cA,cD] = pyyawt.dwt(x1,'haar')
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters('haar')
        caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x1,np.size(Lo_D),'b'),Lo_D),(np.size(x1)+np.size(Lo_D)-1)))
        cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x1,np.size(Lo_D),'b'),Hi_D),(np.size(x1)+np.size(Lo_D)-1)))
        np.testing.assert_almost_equal(caa.flatten(), cA)
        np.testing.assert_almost_equal(cdd.flatten(), cD)

        [cA,cD] = pyyawt.dwt(x2,'haar')
        caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x2,np.size(Lo_D),'b'),Lo_D),(np.size(x2)+np.size(Lo_D)-1)))
        cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x2,np.size(Lo_D),'b'),Hi_D),(np.size(x2)+np.size(Lo_D)-1)))
        np.testing.assert_almost_equal(caa.flatten(), cA)
        np.testing.assert_almost_equal(cdd.flatten(), cD)

        [cA,cD] = pyyawt.dwt(s1,'haar')
        caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',s1,np.size(Lo_D),'b'),Lo_D),(np.size(s1)+np.size(Lo_D)-1)))
        cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',s1,np.size(Lo_D),'b'),Hi_D),(np.size(s1)+np.size(Lo_D)-1)))
        np.testing.assert_almost_equal(caa.flatten(), cA)
        np.testing.assert_almost_equal(cdd.flatten(), cD)
Exemplo n.º 19
0
    def test_sym(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        for N in np.arange(4,11):
            wname = "sym" + str(N)
            [cA,cD] = pyyawt.dwt(x1,wname)
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x1,np.size(Lo_D),'b'),Lo_D),(np.size(x1)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x1,np.size(Lo_D),'b'),Hi_D),(np.size(x1)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)

            [cA,cD] = pyyawt.dwt(x2,wname)
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x2,np.size(Lo_D),'b'),Lo_D),(np.size(x2)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',x2,np.size(Lo_D),'b'),Hi_D),(np.size(x2)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)

            [cA,cD] = pyyawt.dwt(s1,wname)
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',s1,np.size(Lo_D),'b'),Lo_D),(np.size(s1)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,'symh',s1,np.size(Lo_D),'b'),Hi_D),(np.size(s1)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)
Exemplo n.º 20
0
    def test_vector_odd(self):
        a = np.random.randn(51)
        b = pyyawt.wkeep(a,26)
        b1 = pyyawt.wkeep(a,26,'c')
        b2 = pyyawt.wkeep(a,26,'l')
        b3 = pyyawt.wkeep(a,26,'r')
        b4 = pyyawt.wkeep(a,26,2)
        b5 = pyyawt.wkeep(a,26)
        b6 = pyyawt.wkeep(a,26,'c')
        b7 = pyyawt.wkeep(a,26,'l')
        b8 = pyyawt.wkeep(a,26,'r')
        b9 = pyyawt.wkeep(a,26,2)
        c = a[12:38]
        c1 = a[0:26]
        c2 = a[-26:]
        c3 = a[1:27]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, c3)
        np.testing.assert_almost_equal(b5, b)
        np.testing.assert_almost_equal(b6, b)
        np.testing.assert_almost_equal(b7, b2)
        np.testing.assert_almost_equal(b8, b3)
        np.testing.assert_almost_equal(b9, c3)

        a = np.random.randn(1,51)
        b = pyyawt.wkeep(a,26)
        b1 = pyyawt.wkeep(a,26,'c')
        b2 = pyyawt.wkeep(a,26,'l')
        b3 = pyyawt.wkeep(a,26,'r')
        b4 = pyyawt.wkeep(a,26,2)
        b5 = pyyawt.wkeep(a.T,26)
        b6 = pyyawt.wkeep(a.T,26,'c')
        b7 = pyyawt.wkeep(a.T,26,'l')
        b8 = pyyawt.wkeep(a.T,26,'r')
        b9 = pyyawt.wkeep(a.T,26,2)
        c = a[:,12:38]
        c1 = a[:,0:26]
        c2 = a[:,-26:]
        c3 = a[:,1:27]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, c3)
        np.testing.assert_almost_equal(b5, b.T)
        np.testing.assert_almost_equal(b6, b.T)
        np.testing.assert_almost_equal(b7, b2.T)
        np.testing.assert_almost_equal(b8, b3.T)
        np.testing.assert_almost_equal(b9, c3.T)
Exemplo n.º 21
0
    def test_vector_even(self):
        a = np.random.randn(50)
        b = pyyawt.wkeep(a,27)
        b1 = pyyawt.wkeep(a,27,'c')
        b2 = pyyawt.wkeep(a,27,'l')
        b3 = pyyawt.wkeep(a,27,'r')
        b4 = pyyawt.wkeep(a,27)
        b5 = pyyawt.wkeep(a,27,'c')
        b6 = pyyawt.wkeep(a,27,'l')
        b7 = pyyawt.wkeep(a,27,'r')
        b8 = pyyawt.wkeep(a,27,2)
        b9 = pyyawt.wkeep(a,27,2)
        c = a[11:38]
        c1 = a[0:27]
        c2 = a[-27:]
        c3 = a[1:28]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b1, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, b1)
        np.testing.assert_almost_equal(b5, b1)
        np.testing.assert_almost_equal(b6, b2)
        np.testing.assert_almost_equal(b7, b3)
        np.testing.assert_almost_equal(b8, c3)
        np.testing.assert_almost_equal(b9, c3)

        a = np.random.randn(1,50)
        b = pyyawt.wkeep(a,27)
        b1 = pyyawt.wkeep(a,27,'c')
        b2 = pyyawt.wkeep(a,27,'l')
        b3 = pyyawt.wkeep(a,27,'r')
        b4 = pyyawt.wkeep(a.T,27)
        b5 = pyyawt.wkeep(a.T,27,'c')
        b6 = pyyawt.wkeep(a.T,27,'l')
        b7 = pyyawt.wkeep(a.T,27,'r')
        b8 = pyyawt.wkeep(a,27,2)
        b9 = pyyawt.wkeep(a.T,27,2)
        c = a[:,11:38]
        c1 = a[:,0:27]
        c2 = a[:,-27:]
        c3 = a[:,1:28]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b1, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, b1.T)
        np.testing.assert_almost_equal(b5, b1.T)
        np.testing.assert_almost_equal(b6, b2.T)
        np.testing.assert_almost_equal(b7, b3.T)
        np.testing.assert_almost_equal(b8, c3)
        np.testing.assert_almost_equal(b9, c3.T)
Exemplo n.º 22
0
    def test_vector_odd(self):
        a = np.random.randn(51)
        b = pyyawt.wkeep(a, 26)
        b1 = pyyawt.wkeep(a, 26, 'c')
        b2 = pyyawt.wkeep(a, 26, 'l')
        b3 = pyyawt.wkeep(a, 26, 'r')
        b4 = pyyawt.wkeep(a, 26, 2)
        b5 = pyyawt.wkeep(a, 26)
        b6 = pyyawt.wkeep(a, 26, 'c')
        b7 = pyyawt.wkeep(a, 26, 'l')
        b8 = pyyawt.wkeep(a, 26, 'r')
        b9 = pyyawt.wkeep(a, 26, 2)
        c = a[12:38]
        c1 = a[0:26]
        c2 = a[-26:]
        c3 = a[1:27]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, c3)
        np.testing.assert_almost_equal(b5, b)
        np.testing.assert_almost_equal(b6, b)
        np.testing.assert_almost_equal(b7, b2)
        np.testing.assert_almost_equal(b8, b3)
        np.testing.assert_almost_equal(b9, c3)

        a = np.random.randn(1, 51)
        b = pyyawt.wkeep(a, 26)
        b1 = pyyawt.wkeep(a, 26, 'c')
        b2 = pyyawt.wkeep(a, 26, 'l')
        b3 = pyyawt.wkeep(a, 26, 'r')
        b4 = pyyawt.wkeep(a, 26, 2)
        b5 = pyyawt.wkeep(a.T, 26)
        b6 = pyyawt.wkeep(a.T, 26, 'c')
        b7 = pyyawt.wkeep(a.T, 26, 'l')
        b8 = pyyawt.wkeep(a.T, 26, 'r')
        b9 = pyyawt.wkeep(a.T, 26, 2)
        c = a[:, 12:38]
        c1 = a[:, 0:26]
        c2 = a[:, -26:]
        c3 = a[:, 1:27]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, c3)
        np.testing.assert_almost_equal(b5, b.T)
        np.testing.assert_almost_equal(b6, b.T)
        np.testing.assert_almost_equal(b7, b2.T)
        np.testing.assert_almost_equal(b8, b3.T)
        np.testing.assert_almost_equal(b9, c3.T)
Exemplo n.º 23
0
    def test_dwtMode(self):
        s1 = self.s1
        x1 = self.x1
        x2 = self.x2
        # ST = pyyawt.dwtmode("status","nodisp")
        dwtModes = ['symw', 'asymh', 'asymw', 'zpd', 'sp0', 'sp1',
                  'ppd','per']
        wname = "db10"
        for N in np.arange(len(dwtModes)-1):
            # pyyawt.dwtmode(dwtModes[N])
            [cA,cD] = pyyawt.dwt(x1,wname,"mode",dwtModes[N])
            [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x1,np.size(Lo_D),'b'),Lo_D),(np.size(x1)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x1,np.size(Lo_D),'b'),Hi_D),(np.size(x1)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)

            [cA,cD] = pyyawt.dwt(x2,wname,"mode",dwtModes[N])
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x2,np.size(Lo_D),'b'),Lo_D),(np.size(x2)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x2,np.size(Lo_D),'b'),Hi_D),(np.size(x2)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)

            [cA,cD] = pyyawt.dwt(s1,wname,"mode",dwtModes[N])
            caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],s1,np.size(Lo_D),'b'),Lo_D),(np.size(s1)+np.size(Lo_D)-1)))
            cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],s1,np.size(Lo_D),'b'),Hi_D),(np.size(s1)+np.size(Lo_D)-1)))
            np.testing.assert_almost_equal(caa.flatten(), cA)
            np.testing.assert_almost_equal(cdd.flatten(), cD)

        N = len(dwtModes) - 1
        [cA,cD] = pyyawt.dwt(x1,wname,"mode",dwtModes[N])
        [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname)
        caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x1,np.size(Lo_D),'b'),Lo_D),(np.size(x1))))
        cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x1,np.size(Lo_D),'b'),Hi_D),(np.size(x1))))
        np.testing.assert_almost_equal(caa.flatten(), cA)
        np.testing.assert_almost_equal(cdd.flatten(), cD)

        [cA,cD] = pyyawt.dwt(x2,wname,"mode",dwtModes[N])
        caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x2,np.size(Lo_D),'b'),Lo_D),(np.size(x2))))
        cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],x2,np.size(Lo_D),'b'),Hi_D),(np.size(x2))))
        np.testing.assert_almost_equal(caa.flatten(), cA)
        np.testing.assert_almost_equal(cdd.flatten(), cD)

        [cA,cD] = pyyawt.dwt(s1,wname,"mode",dwtModes[N])
        caa = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],s1,np.size(Lo_D),'b'),Lo_D),(np.size(s1))))
        cdd = pyyawt.dyaddown(pyyawt.wkeep(pyyawt.conv(pyyawt.wextend(1,dwtModes[N],s1,np.size(Lo_D),'b'),Hi_D),(np.size(s1))))
        np.testing.assert_almost_equal(caa.flatten(), cA)
        np.testing.assert_almost_equal(cdd.flatten(), cD)
Exemplo n.º 24
0
    def test_vector_even(self):
        a = np.random.randn(50)
        b = pyyawt.wkeep(a, 27)
        b1 = pyyawt.wkeep(a, 27, 'c')
        b2 = pyyawt.wkeep(a, 27, 'l')
        b3 = pyyawt.wkeep(a, 27, 'r')
        b4 = pyyawt.wkeep(a, 27)
        b5 = pyyawt.wkeep(a, 27, 'c')
        b6 = pyyawt.wkeep(a, 27, 'l')
        b7 = pyyawt.wkeep(a, 27, 'r')
        b8 = pyyawt.wkeep(a, 27, 2)
        b9 = pyyawt.wkeep(a, 27, 2)
        c = a[11:38]
        c1 = a[0:27]
        c2 = a[-27:]
        c3 = a[1:28]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b1, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, b1)
        np.testing.assert_almost_equal(b5, b1)
        np.testing.assert_almost_equal(b6, b2)
        np.testing.assert_almost_equal(b7, b3)
        np.testing.assert_almost_equal(b8, c3)
        np.testing.assert_almost_equal(b9, c3)

        a = np.random.randn(1, 50)
        b = pyyawt.wkeep(a, 27)
        b1 = pyyawt.wkeep(a, 27, 'c')
        b2 = pyyawt.wkeep(a, 27, 'l')
        b3 = pyyawt.wkeep(a, 27, 'r')
        b4 = pyyawt.wkeep(a.T, 27)
        b5 = pyyawt.wkeep(a.T, 27, 'c')
        b6 = pyyawt.wkeep(a.T, 27, 'l')
        b7 = pyyawt.wkeep(a.T, 27, 'r')
        b8 = pyyawt.wkeep(a, 27, 2)
        b9 = pyyawt.wkeep(a.T, 27, 2)
        c = a[:, 11:38]
        c1 = a[:, 0:27]
        c2 = a[:, -27:]
        c3 = a[:, 1:28]
        np.testing.assert_almost_equal(b, b1)
        np.testing.assert_almost_equal(b1, c)
        np.testing.assert_almost_equal(b2, c1)
        np.testing.assert_almost_equal(b3, c2)
        np.testing.assert_almost_equal(b4, b1.T)
        np.testing.assert_almost_equal(b5, b1.T)
        np.testing.assert_almost_equal(b6, b2.T)
        np.testing.assert_almost_equal(b7, b3.T)
        np.testing.assert_almost_equal(b8, c3)
        np.testing.assert_almost_equal(b9, c3.T)