Example #1
0
    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)
Example #2
0
def rsHRF_iterative_wiener_deconv(y, h, Iterations=1000):
    N = y.shape[0]
    nh = max(h.shape)
    h = np.append(h, np.zeros((N - nh, 1)))
    H = np.fft.fft(h, axis=0)
    Y = np.fft.fft(y, axis=0)
    [c, l] = pyyawt.wavedec(abs(y), 1, 'db2')
    sigma = pyyawt.wnoisest(c, l, 1)
    Phh = np.square(abs(H))
    sqrdtempnorm = ((((np.linalg.norm(y - np.mean(y), 2)**2) - (N - 1) *
                      (sigma**2))) / (np.linalg.norm(h, 1))**2)
    Nf = (sigma**2) * N
    tempreg = Nf / sqrdtempnorm
    Pxx0 = np.square(
        abs(np.multiply(Y, (np.divide(np.conj(H), (Phh + N * tempreg))))))
    Pxx = Pxx0
    for i in range(0, Iterations):
        M = np.divide(np.multiply(np.multiply(np.conjugate(H), Pxx), Y),
                      np.add(np.multiply(np.square(abs(H)), Pxx), Nf))
        PxxY = np.divide(np.multiply(Pxx, Nf),
                         np.add(np.multiply(np.square(abs(H)), Pxx), Nf))
        Pxx = np.add(PxxY, np.square(abs(M)))
    WienerFilterEst = np.divide(
        np.multiply(np.conj(H), Pxx),
        np.add(np.multiply(np.square(abs(H)), Pxx), Nf))
    return np.real(np.fft.ifft(np.multiply(WienerFilterEst, Y)))
Example #3
0
    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)
Example #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(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)
Example #5
0
 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)
Example #6
0
 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)
Example #7
0
 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)
Example #8
0
 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)
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 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)
Example #12
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(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)
Example #13
0
 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)
Example #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(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)
Example #15
0
 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)
Example #16
0
 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)
Example #17
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(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)
Example #18
0
 def test_bior3(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'
     ]
     ST = pyyawt.dwtmode("status", "nodisp")
     for N in np.arange(len(wnames)):
         wname = wnames[N]
         [c, l] = pyyawt.wavedec(s1, 3, wname)
         pyyawt.dwtmode("symh")
         a0 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("symw")
         a1 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("asymh")
         a2 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("asymw")
         a3 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("zpd")
         a4 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("sp0")
         a5 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("sp1")
         a6 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("ppd")
         a7 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode("per")
         a8 = pyyawt.waverec(c, l, wname)
         pyyawt.dwtmode(ST)
         np.testing.assert_almost_equal(a0, a1)
         np.testing.assert_almost_equal(a0, a2)
         np.testing.assert_almost_equal(a0, a3)
         np.testing.assert_almost_equal(a0, a4)
         np.testing.assert_almost_equal(a0, a5)
         np.testing.assert_almost_equal(a0, a6)
         np.testing.assert_almost_equal(a0, a7)
         np.testing.assert_almost_equal(a0, a8)
Example #19
0
 def test_bior3(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']
     ST = pyyawt.dwtmode("status","nodisp")
     for N in np.arange(len(wnames)):
         wname = wnames[N]
         [c,l] = pyyawt.wavedec(s1,3,wname)
         pyyawt.dwtmode("symh")
         a0 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("symw")
         a1 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("asymh")
         a2 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("asymw")
         a3 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("zpd")
         a4 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("sp0")
         a5 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("sp1")
         a6 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("ppd")
         a7 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode("per")
         a8 = pyyawt.waverec(c,l,wname)
         pyyawt.dwtmode(ST)
         np.testing.assert_almost_equal(a0, a1)
         np.testing.assert_almost_equal(a0, a2)
         np.testing.assert_almost_equal(a0, a3)
         np.testing.assert_almost_equal(a0, a4)
         np.testing.assert_almost_equal(a0, a5)
         np.testing.assert_almost_equal(a0, a6)
         np.testing.assert_almost_equal(a0, a7)
         np.testing.assert_almost_equal(a0, a8)
Example #20
0
def rsHRF_iterative_wiener_deconv(y, h, Iterations=1000):
    N = y.shape[0]
    nh = max(h.shape)
    h = np.append(h, np.zeros((N - nh, 1)))
    H = np.fft.fft(h, axis=0)
    Y = np.fft.fft(y, axis=0)
    [c, l] = pyyawt.wavedec(abs(y), 1, 'db2')
    sigma = pyyawt.wnoisest(c, l, 1)
    Phh = np.square(abs(H))
    sqrdtempnorm = ((((np.linalg.norm(y - np.mean(y), 2)**2) - (N - 1) *
                      (sigma**2))) / (np.linalg.norm(h, 1))**2)
    Nf = (sigma**2) * N
    tempreg = Nf / sqrdtempnorm
    Pxx0 = np.square(
        abs(np.multiply(Y, (np.divide(np.conj(H), (Phh + N * tempreg))))))
    Pxx = Pxx0
    Sf = Pxx.reshape(-1, 1)
    for i in range(0, Iterations):
        M = np.divide(np.multiply(np.multiply(np.conjugate(H), Pxx), Y),
                      np.add(np.multiply(np.square(abs(H)), Pxx), Nf))
        PxxY = np.divide(np.multiply(Pxx, Nf),
                         np.add(np.multiply(np.square(abs(H)), Pxx), Nf))
        Pxx = np.add(PxxY, np.square(abs(M)))
        Sf = np.concatenate((Sf, Pxx.reshape(-1, 1)), axis=1)
    dSf = np.diff(Sf, 1, 1)
    dSfmse = np.mean(np.square(dSf), axis=1)
    _, idx = knee.knee_pt(dSfmse)
    idm = np.argmin(dSfmse)
    ratio = np.abs(dSfmse[idx] -
                   dSfmse[idm]) / (np.abs(np.max(dSfmse) - np.min(dSfmse)))
    if ratio > 0.5:
        id0 = idm
    else:
        id0 = idx
    Pxx = Sf[:, id0 + 1]
    WienerFilterEst = np.divide(
        np.multiply(np.conj(H), Pxx),
        np.add(np.multiply(np.square(abs(H)), Pxx), Nf))
    return np.real(np.fft.ifft(np.multiply(WienerFilterEst, Y)))
Example #21
0
 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])
Example #22
0
numlog = np.shape(log[1])
level = 5

GR = log[:, 0]
NPHI = log[:, 1]
RHOB = log[:, 2]

GR = np.array(GR, dtype=float)
NPHI = np.array(NPHI, dtype=float)
RHOB = np.array(RHOB, dtype=float)

# # WAVELET DENOISING FILTER # #

# GR #
[CLog, LLog] = wavedec(GR, level, 'sym8')
[XDLog, CXDLog, LDXLog] = wden(CLog, LLog, 'heursure', 's', 'one', level,
                               'sym8')
deno_log_GR = waverec(CXDLog, LDXLog, 'sym8')  # Use this for GR Input
# print(np.shape(deno_log_GR))

spec_log = fft(GR)
spec_log = abs(spec_log)

spec_deno_log_GR = fft(deno_log_GR)
spec_deno_log_GR = abs(spec_deno_log_GR)

# VISUALIZING BEFORE AND AFTER DENOISING

# f, ax = plt.subplots(nrows=4,ncols=2, figsize=(20,10))
# ax[0,0].plot(spec_log)
Example #23
0
    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)
Example #24
0
    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)