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)
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)
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)
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)
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)
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)
def test1(self): a = 'asymh' pyyawt.dwtmode(a) ST = pyyawt.dwtmode('status','nodisp') b = (ST == a) x = np.random.randn(50) [cA,cD] = pyyawt.dwt(x,'db2') [caa,cdd] = pyyawt.dwt(x,'db2','mode',a) # x0 = pyyawt.idwt(cA,cD,'db2',len(x)) np.testing.assert_almost_equal(cA, caa) np.testing.assert_almost_equal(cD, cdd) # np.testing.assert_almost_equal(x, x0) np.testing.assert_equal(b,True) a = 'sp1' pyyawt.dwtmode(a) ST = pyyawt.dwtmode('status','nodisp') b = (ST == a) x = np.random.randn(50) [cA,cD] = pyyawt.dwt(x,'db2') [caa,cdd] = pyyawt.dwt(x,'db2','mode',a) # x0=pyyawt.idwt(cA,cD,'db2',length(x)) np.testing.assert_almost_equal(cA, caa) np.testing.assert_almost_equal(cD, cdd) # np.testing.assert_almost_equal(x, x0) np.testing.assert_equal(b,True) pyyawt.dwtmode("symh")
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)
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(len(wnames)): wname = wnames[N] [cA1, cD1] = pyyawt.dwt(s1, wname) [cA2, cD2] = pyyawt.dwt(cA1, wname) [cA3, cD3] = pyyawt.dwt(cA2, wname) c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, wname) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
def test_bior2(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 ST = pyyawt.dwtmode("status", "nodisp") 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(len(wnames)): wname = wnames[N] [Lo_D, Hi_D, Lo_R, Hi_R] = pyyawt.wfilters(wname) [c, l] = pyyawt.wavedec(s1, 3, wname) s0 = pyyawt.waverec(c, l, wname) [cA1, cD1] = pyyawt.dwt(s1, wname) [cA2, cD2] = pyyawt.dwt(cA1, wname) [cA3, cD3] = pyyawt.dwt(cA2, wname) ca2 = pyyawt.idwt(cA3, cD3, wname, np.size(cA2)) ca1 = pyyawt.idwt(ca2, cD2, wname, np.size(cA1)) a0 = pyyawt.idwt(ca1, cD1, wname, np.size(s1)) np.testing.assert_almost_equal(a0, s0) Lo_D = np.random.randn(np.size(Lo_D)) Hi_D = np.random.randn(np.size(Lo_D)) ca2 = pyyawt.idwt(cA3, cD3, Lo_R, Hi_R, np.size(cA2)) ca1 = pyyawt.idwt(ca2, cD2, Lo_R, Hi_R, np.size(cA1)) a0 = pyyawt.idwt(ca1, cD1, Lo_R, Hi_R, np.size(s1)) s0 = pyyawt.waverec(c, l, Lo_R, Hi_R) np.testing.assert_almost_equal(a0, s0)
def test_bior2(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 ST = pyyawt.dwtmode("status","nodisp") 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(len(wnames)): wname = wnames[N] [Lo_D,Hi_D,Lo_R,Hi_R] = pyyawt.wfilters(wname) [c,l] = pyyawt.wavedec(s1,3,wname) s0 = pyyawt.waverec(c,l,wname) [cA1,cD1] = pyyawt.dwt(s1,wname) [cA2,cD2] = pyyawt.dwt(cA1,wname) [cA3,cD3] = pyyawt.dwt(cA2,wname) ca2 = pyyawt.idwt(cA3,cD3,wname,np.size(cA2)) ca1 = pyyawt.idwt(ca2,cD2,wname,np.size(cA1)) a0 = pyyawt.idwt(ca1,cD1,wname,np.size(s1)) np.testing.assert_almost_equal(a0, s0) Lo_D = np.random.randn(np.size(Lo_D)) Hi_D = np.random.randn(np.size(Lo_D)) ca2 = pyyawt.idwt(cA3,cD3,Lo_R,Hi_R,np.size(cA2)) ca1 = pyyawt.idwt(ca2,cD2,Lo_R,Hi_R,np.size(cA1)) a0 = pyyawt.idwt(ca1,cD1,Lo_R,Hi_R,np.size(s1)) s0 = pyyawt.waverec(c,l,Lo_R,Hi_R) np.testing.assert_almost_equal(a0, s0)
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)
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)
def test1(self): a = 'asymh' pyyawt.dwtmode(a) ST = pyyawt.dwtmode('status', 'nodisp') b = (ST == a) x = np.random.randn(50) [cA, cD] = pyyawt.dwt(x, 'db2') [caa, cdd] = pyyawt.dwt(x, 'db2', 'mode', a) # x0 = pyyawt.idwt(cA,cD,'db2',len(x)) np.testing.assert_almost_equal(cA, caa) np.testing.assert_almost_equal(cD, cdd) # np.testing.assert_almost_equal(x, x0) np.testing.assert_equal(b, True) a = 'sp1' pyyawt.dwtmode(a) ST = pyyawt.dwtmode('status', 'nodisp') b = (ST == a) x = np.random.randn(50) [cA, cD] = pyyawt.dwt(x, 'db2') [caa, cdd] = pyyawt.dwt(x, 'db2', 'mode', a) # x0=pyyawt.idwt(cA,cD,'db2',length(x)) np.testing.assert_almost_equal(cA, caa) np.testing.assert_almost_equal(cD, cdd) # np.testing.assert_almost_equal(x, x0) np.testing.assert_equal(b, True) pyyawt.dwtmode("symh")
def test_haar(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 [cA1,cD1] = pyyawt.dwt(s1,'haar') [cA2,cD2] = pyyawt.dwt(cA1,'haar') [cA3,cD3] = pyyawt.dwt(cA2,'haar') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,'haar') np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
def test_haar(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 [c,l] = pyyawt.wavedec(s1,3,'haar') [cA1,cD1] = pyyawt.dwt(s1,'haar') [cA2,cD2] = pyyawt.dwt(cA1,'haar') [cA3,cD3] = pyyawt.dwt(cA2,'haar') ca2 = pyyawt.idwt(cA3,cD3,'haar',np.size(cA2)) ca1 = pyyawt.idwt(ca2,cD2,'haar',np.size(cA1)) a0 = pyyawt.idwt(ca1,cD1,'haar',np.size(s1)) s0 = pyyawt.waverec(c,l,'haar') np.testing.assert_almost_equal(a0, s0)
def test_haar(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 [c, l] = pyyawt.wavedec(s1, 3, 'haar') [cA1, cD1] = pyyawt.dwt(s1, 'haar') [cA2, cD2] = pyyawt.dwt(cA1, 'haar') [cA3, cD3] = pyyawt.dwt(cA2, 'haar') ca2 = pyyawt.idwt(cA3, cD3, 'haar', np.size(cA2)) ca1 = pyyawt.idwt(ca2, cD2, 'haar', np.size(cA1)) a0 = pyyawt.idwt(ca1, cD1, 'haar', np.size(s1)) s0 = pyyawt.waverec(c, l, 'haar') np.testing.assert_almost_equal(a0, s0)
def test_sym(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 for N in np.arange(2,21): wname = "sym" + str(N) [cA1,cD1] = pyyawt.dwt(s1,wname) [cA2,cD2] = pyyawt.dwt(cA1,wname) [cA3,cD3] = pyyawt.dwt(cA2,wname) c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,wname) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
def test_type2(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 Lo_D = np.random.randn(20) Hi_D = np.random.randn(20) [cA1,cD1] = pyyawt.dwt(s1,Lo_D,Hi_D) [cA2,cD2] = pyyawt.dwt(cA1,Lo_D,Hi_D) [cA3,cD3] = pyyawt.dwt(cA2,Lo_D,Hi_D) c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
def test_sym(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 for N in np.arange(2,21): wname = "sym" + str(N) [c,l] = pyyawt.wavedec(s1,3,wname) [cA1,cD1] = pyyawt.dwt(s1,wname) [cA2,cD2] = pyyawt.dwt(cA1,wname) [cA3,cD3] = pyyawt.dwt(cA2,wname) ca2 = pyyawt.idwt(cA3,cD3,wname,np.size(cA2)) ca1 = pyyawt.idwt(ca2,cD2,wname,np.size(cA1)) a0 = pyyawt.idwt(ca1,cD1,wname,np.size(s1)) s0 = pyyawt.waverec(c,l,wname) np.testing.assert_almost_equal(a0, s0)
def test_sym(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 for N in np.arange(2, 21): wname = "sym" + str(N) [c, l] = pyyawt.wavedec(s1, 3, wname) [cA1, cD1] = pyyawt.dwt(s1, wname) [cA2, cD2] = pyyawt.dwt(cA1, wname) [cA3, cD3] = pyyawt.dwt(cA2, wname) ca2 = pyyawt.idwt(cA3, cD3, wname, np.size(cA2)) ca1 = pyyawt.idwt(ca2, cD2, wname, np.size(cA1)) a0 = pyyawt.idwt(ca1, cD1, wname, np.size(s1)) s0 = pyyawt.waverec(c, l, wname) np.testing.assert_almost_equal(a0, s0)
def check_reconstruction(pmode, wavelet, dtype, epsilon=None): data_size = [500, 1000, 2000, 10000, 50000, 100000] np.random.seed(12345) # TODO: smoke testing - more failures for different seeds if epsilon is None: if dtype == np.float32: epsilon = 3e-7 else: # FIXME: limit was 5e-11, but gave failures. Investigate epsilon = 5e-11 for N in data_size: data = np.asarray(np.random.random(N), dtype) # compute dwt coefficients pa, pd = pyyawt.dwt(data, wavelet, 'mode', pmode) # compute reconstruction rec = pyyawt.idwt(pa, pd, wavelet,'mode', pmode) if len(data) % 2: rec = rec[:len(data)] rms_rec = np.sqrt(np.mean((data-rec)**2)) msg = ('[RMS_REC > EPSILON] for Mode: %s, Wavelet: %s, ' 'Length: %d, rms=%.3g' % (pmode, wavelet, len(data), rms_rec)) np.testing.assert_equal(rms_rec < epsilon,True, err_msg=msg)
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(len(wnames)): wname = wnames[N] [cA1,cD1] = pyyawt.dwt(s1,wname) [cA2,cD2] = pyyawt.dwt(cA1,wname) [cA3,cD3] = pyyawt.dwt(cA2,wname) c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,wname) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
def test_haar(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 [cA1, cD1] = pyyawt.dwt(s1, 'haar') [cA2, cD2] = pyyawt.dwt(cA1, 'haar') [cA3, cD3] = pyyawt.dwt(cA2, 'haar') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, 'haar') np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
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(len(wnames)): wname = wnames[N] [c,l] = pyyawt.wavedec(s1,3,wname) [cA1,cD1] = pyyawt.dwt(s1,wname) [cA2,cD2] = pyyawt.dwt(cA1,wname) [cA3,cD3] = pyyawt.dwt(cA2,wname) ca2 = pyyawt.idwt(cA3,cD3,wname,np.size(cA2)) ca1 = pyyawt.idwt(ca2,cD2,wname,np.size(cA1)) a0 = pyyawt.idwt(ca1,cD1,wname,np.size(s1)) s0 = pyyawt.waverec(c,l,wname) np.testing.assert_almost_equal(a0, s0)
def test_type2(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 Lo_D = np.random.randn(20) Hi_D = np.random.randn(20) [cA1, cD1] = pyyawt.dwt(s1, Lo_D, Hi_D) [cA2, cD2] = pyyawt.dwt(cA1, Lo_D, Hi_D) [cA3, cD3] = pyyawt.dwt(cA2, Lo_D, Hi_D) c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
def test_sym(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 for N in np.arange(2, 21): wname = "sym" + str(N) [cA1, cD1] = pyyawt.dwt(s1, wname) [cA2, cD2] = pyyawt.dwt(cA1, wname) [cA3, cD3] = pyyawt.dwt(cA2, wname) c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, wname) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0)
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(len(wnames)): wname = wnames[N] [c, l] = pyyawt.wavedec(s1, 3, wname) [cA1, cD1] = pyyawt.dwt(s1, wname) [cA2, cD2] = pyyawt.dwt(cA1, wname) [cA3, cD3] = pyyawt.dwt(cA2, wname) ca2 = pyyawt.idwt(cA3, cD3, wname, np.size(cA2)) ca1 = pyyawt.idwt(ca2, cD2, wname, np.size(cA1)) a0 = pyyawt.idwt(ca1, cD1, wname, np.size(s1)) s0 = pyyawt.waverec(c, l, wname) np.testing.assert_almost_equal(a0, s0)
def test1(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 level = 10 [c,l] = pyyawt.wavedec(s1,level,'sym10') cA = [] cD = [] [ca,cd] = pyyawt.dwt(s1,'sym10') cA.append(ca) cD.append(cd) for i in np.arange(1,level): [ca,cd] = pyyawt.dwt(cA[i-1],'sym10') cA.append(ca) cD.append(cd) cddetMax = pyyawt.detcoef(c,l) cdet = [] for i in np.arange(level): cdet.append(pyyawt.detcoef(c,l,i+1)) np.testing.assert_almost_equal(cddetMax, cD[level-1]) for i in np.arange(level): np.testing.assert_almost_equal(cdet[i], cD[i])
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)
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)
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)
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)
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)
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)
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)
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)
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)
def test_bior2(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 ST = pyyawt.dwtmode("status", "nodisp") 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(len(wnames)): wname = wnames[N] [cA1, cD1] = pyyawt.dwt(s1, wname) [cA2, cD2] = pyyawt.dwt(cA1, wname) [cA3, cD3] = pyyawt.dwt(cA2, wname) Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("asymh") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'asymh') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'asymh') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'asymh') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("symw") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'symw') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'symw') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'symw') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("asymw") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'asymw') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'asymw') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'asymw') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("zpd") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'zpd') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'zpd') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'zpd') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("sp0") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'sp0') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'sp0') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'sp0') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("sp1") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'sp1') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'sp1') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'sp1') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("ppd") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'ppd') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'ppd') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'ppd') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("per") [cA1, cD1] = pyyawt.dwt(s1, wname, 'mode', 'per') [cA2, cD2] = pyyawt.dwt(cA1, wname, 'mode', 'per') [cA3, cD3] = pyyawt.dwt(cA2, wname, 'mode', 'per') Lo_D, Hi_D = pyyawt.wfilters(wname, 'd') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [ np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1) ] c, l = pyyawt.wavedec(s1, 3, Lo_D, Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode(ST)
def test_bior2(self): s1 = self.s1 x1 = self.x1 x2 = self.x2 ST = pyyawt.dwtmode("status","nodisp") 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(len(wnames)): wname = wnames[N] [cA1,cD1] = pyyawt.dwt(s1,wname) [cA2,cD2] = pyyawt.dwt(cA1,wname) [cA3,cD3] = pyyawt.dwt(cA2,wname) Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("asymh") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','asymh') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','asymh') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','asymh') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("symw") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','symw') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','symw') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','symw') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("asymw") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','asymw') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','asymw') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','asymw') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("zpd") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','zpd') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','zpd') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','zpd') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("sp0") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','sp0') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','sp0') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','sp0') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("sp1") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','sp1') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','sp1') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','sp1') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("ppd") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','ppd') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','ppd') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','ppd') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode("per") [cA1,cD1] = pyyawt.dwt(s1,wname,'mode','per') [cA2,cD2] = pyyawt.dwt(cA1,wname,'mode','per') [cA3,cD3] = pyyawt.dwt(cA2,wname,'mode','per') Lo_D,Hi_D = pyyawt.wfilters(wname,'d') c0 = np.concatenate([cA3, cD3, cD2, cD1]) l0 = [np.size(cA3), np.size(cD3), np.size(cD2), np.size(cD1), np.size(s1)] c, l = pyyawt.wavedec(s1,3,Lo_D,Hi_D) np.testing.assert_almost_equal(c, c0) np.testing.assert_almost_equal(l, l0) pyyawt.dwtmode(ST)