예제 #1
0
파일: test_conv.py 프로젝트: holgern/pyyawt
 def test1(self):
     a = np.random.random((51,1))
     b = np.random.randn(100,1)
     c = pyyawt.conv(a,b)
     c1 = pyyawt.conv(a.T,b).T
     c2 = pyyawt.conv(a,b.T)
     c3 = pyyawt.conv(a.T,b.T).T
     expected = np.convolve(a.flatten(),b.flatten())
     np.testing.assert_almost_equal(c.flatten(), expected)
     np.testing.assert_almost_equal(c1.flatten(), expected)
     np.testing.assert_almost_equal(c2.flatten(), expected)
     np.testing.assert_almost_equal(c3.flatten(), expected)
예제 #2
0
 def test1(self):
     a = np.random.random((51, 1))
     b = np.random.randn(100, 1)
     c = pyyawt.conv(a, b)
     c1 = pyyawt.conv(a.T, b).T
     c2 = pyyawt.conv(a, b.T)
     c3 = pyyawt.conv(a.T, b.T).T
     expected = np.convolve(a.flatten(), b.flatten())
     np.testing.assert_almost_equal(c.flatten(), expected)
     np.testing.assert_almost_equal(c1.flatten(), expected)
     np.testing.assert_almost_equal(c2.flatten(), expected)
     np.testing.assert_almost_equal(c3.flatten(), expected)
예제 #3
0
파일: test_idwt.py 프로젝트: holgern/pyyawt
 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)
예제 #4
0
파일: test_idwt.py 프로젝트: holgern/pyyawt
 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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
0
파일: test_idwt.py 프로젝트: holgern/pyyawt
    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)
예제 #9
0
파일: test_idwt.py 프로젝트: holgern/pyyawt
    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)
예제 #10
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)
예제 #11
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)
예제 #12
0
파일: test_idwt.py 프로젝트: holgern/pyyawt
    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)
예제 #13
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)
예제 #14
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)
예제 #15
0
파일: test_idwt.py 프로젝트: holgern/pyyawt
    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)
예제 #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)
예제 #17
0
파일: test_idwt.py 프로젝트: holgern/pyyawt
    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)
예제 #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)
예제 #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)
예제 #20
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)