Пример #1
0
def test_dwt_idwt_inverse():
    """dwt/idwt should invert each other (to machine precision)"""
    from electrolib.filters.dwtfile import WaveletFilter as W
    x = np.sin(np.arange(0,10,0.1))
    w = W.wavelet('db2')
    zi = W.zero_state(w)
    cA, cD, zf = W.dwt(x, w, zi)
    x_rec = W.idwt(cA, cD, w)
    assert np.allclose(x, x_rec)
Пример #2
0
def test_dwt_blocks():
    """dwt block filtering should be nearly equal to dwt1 in one go"""
    # Basic setup
    from electrolib.filters.dwtfile import WaveletFilter as W
    x = np.sin(np.arange(0,10,0.1))
    w = W.wavelet('db2')
    zi = W.zero_state(w)
    overlap = len(zi[0])
    # Prepare for loop
    nstep = 10
    cA = np.zeros(len(x)/2)
    cD = np.zeros_like(cA)
    state = zi
    for n in range(0, len(x), nstep):
        cAn, cDn, state = W.dwt(x[n:n+nstep], w, state)
        cA[n/2:(n+nstep)/2] = cAn[:-overlap]
        cD[n/2:(n+nstep)/2] = cDn[:-overlap]
    # Do in one go
    cA1, cD1, zf = W.dwt(x, w, zi)
    cA1 = cA1[:-overlap]
    cD1 = cD1[:-overlap]
    assert np.allclose(cA1, cA)
    assert np.allclose(cD1, cD)