def test_WaveletFilter_hard_10_known(): """WaveletFilter.filter 'hard' reproduces analytic result (high T)""" from electrolib.filters.dwtfile import WaveletFilter w = WaveletFilter('db1', 1, 'hard', 10) x = np.array([0, 2, 4, 6, 8, 10, 12, 14]) xf_th = np.array([1, 1, 5, 5, 9, 9, 13, 13]) xf = w.filter(x) assert np.allclose(xf, xf_th)
def test_WaveletFilter_hard_0_identity(): """WaveletFilter.filter with 'hard', '0' should reproduce signal""" from electrolib.filters.dwtfile import WaveletFilter for nlevels in range(5): w = WaveletFilter('db2', nlevels, 'hard', 0) x = np.sin(np.arange(0,10,0.1)) xf = w.filter(x) assert np.allclose(x, xf)
def test_WaveletFilter_low_stop(): """WaveletFilter.filter 'soft' reproduces analytic result (low T)""" from electrolib.filters.dwtfile import WaveletFilter w = WaveletFilter('db1', 1, 'soft', np.sqrt(2), low_stop=True) xl = np.array([ 0, 0, 1, 1, 2, 2, 3, 3]) xh = np.array([ -1, 1, -1, 1, -2, 2, -2, 2]) xhf = np.array([ 0, 0, 0, 0, -1, 1, -1, 1]) x = xl + xh xf = w.filter(x) assert np.allclose(xf, xhf)
def test_WaveletFilter_hard_2_known(): """WaveletFilter.filter 'hard' reproduces analytic result (low T)""" from electrolib.filters.dwtfile import WaveletFilter w = WaveletFilter('db1', 1, 'hard', 2) xl = np.array([ 0, 0, 1, 1, 2, 2, 3, 3]) xh = np.array([ -1, 1, -1, 1, -2, 2, -2, 2]) xhf = np.array([ 0, 0, 0, 0, -2, 2, -2, 2]) x = xl + xh xf_th = xl + xhf xf = w.filter(x) assert np.allclose(xf, xf_th)