当前位置: 首页>>代码示例>>Python>>正文


Python pywt.idwt方法代码示例

本文整理汇总了Python中pywt.idwt方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.idwt方法的具体用法?Python pywt.idwt怎么用?Python pywt.idwt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pywt的用法示例。


在下文中一共展示了pywt.idwt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dwt_idwt_basic

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_dwt_idwt_basic():
    x = [3, 7, 1, 1, -2, 5, 4, 6]
    cA, cD = pywt.dwt(x, 'db2')
    cA_expect = [5.65685425, 7.39923721, 0.22414387, 3.33677403, 7.77817459]
    cD_expect = [-2.44948974, -1.60368225, -4.44140056, -0.41361256,
                 1.22474487]
    assert_allclose(cA, cA_expect)
    assert_allclose(cD, cD_expect)

    x_roundtrip = pywt.idwt(cA, cD, 'db2')
    assert_allclose(x_roundtrip, x, rtol=1e-10)

    # mismatched dtypes OK
    x_roundtrip2 = pywt.idwt(cA.astype(np.float64), cD.astype(np.float32),
                             'db2')
    assert_allclose(x_roundtrip2, x, rtol=1e-7, atol=1e-7)
    assert_(x_roundtrip.dtype == np.float64) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:19,代码来源:test_dwt_idwt.py

示例2: test_dwt_idwt_partial_complex

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_dwt_idwt_partial_complex():
    x = np.asarray([3, 7, 1, 1, -2, 5, 4, 6])
    x = x + 0.5j*x

    cA, cD = pywt.dwt(x, 'haar')
    cA_rec_expect = np.array([5.0+2.5j, 5.0+2.5j, 1.0+0.5j, 1.0+0.5j,
                              1.5+0.75j, 1.5+0.75j, 5.0+2.5j, 5.0+2.5j])
    cA_rec = pywt.idwt(cA, None, 'haar')
    assert_allclose(cA_rec, cA_rec_expect)

    cD_rec_expect = np.array([-2.0-1.0j, 2.0+1.0j, 0.0+0.0j, 0.0+0.0j,
                              -3.5-1.75j, 3.5+1.75j, -1.0-0.5j, 1.0+0.5j])
    cD_rec = pywt.idwt(None, cD, 'haar')
    assert_allclose(cD_rec, cD_rec_expect)

    assert_allclose(cA_rec + cD_rec, x) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:18,代码来源:test_dwt_idwt.py

示例3: check_reconstruction

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def check_reconstruction(pmode, mmode, wavelet, dtype):
    data_size = list(range(2, 40)) + [100, 200, 500, 1000, 2000, 10000,
                                      50000, 100000]
    np.random.seed(12345)
    # TODO: smoke testing - more failures for different seeds

    if dtype == np.float32:
        # was 3e-7 has to be lowered as db21, db29, db33, db35, coif14, coif16 were failing
        epsilon = 6e-7
    else:
        epsilon = 5e-11

    for N in data_size:
        data = np.asarray(np.random.random(N), dtype)

        # compute dwt coefficients
        pa, pd = pywt.dwt(data, wavelet, pmode)

        # compute reconstruction
        rec = pywt.idwt(pa, pd, wavelet, 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))
        assert_(rms_rec < epsilon, msg=msg) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:30,代码来源:test_perfect_reconstruction.py

示例4: test_dwt_idwt_dtypes

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_dwt_idwt_dtypes():
    wavelet = pywt.Wavelet('haar')
    for dt_in, dt_out in zip(dtypes_in, dtypes_out):
        x = np.ones(4, dtype=dt_in)
        errmsg = "wrong dtype returned for {0} input".format(dt_in)

        cA, cD = pywt.dwt(x, wavelet)
        assert_(cA.dtype == cD.dtype == dt_out, "dwt: " + errmsg)

        x_roundtrip = pywt.idwt(cA, cD, wavelet)
        assert_(x_roundtrip.dtype == dt_out, "idwt: " + errmsg) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:13,代码来源:test_dwt_idwt.py

示例5: test_dwt_idwt_basic_complex

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_dwt_idwt_basic_complex():
    x = np.asarray([3, 7, 1, 1, -2, 5, 4, 6])
    x = x + 0.5j*x
    cA, cD = pywt.dwt(x, 'db2')
    cA_expect = np.asarray([5.65685425, 7.39923721, 0.22414387, 3.33677403,
                            7.77817459])
    cA_expect = cA_expect + 0.5j*cA_expect
    cD_expect = np.asarray([-2.44948974, -1.60368225, -4.44140056, -0.41361256,
                            1.22474487])
    cD_expect = cD_expect + 0.5j*cD_expect
    assert_allclose(cA, cA_expect)
    assert_allclose(cD, cD_expect)

    x_roundtrip = pywt.idwt(cA, cD, 'db2')
    assert_allclose(x_roundtrip, x, rtol=1e-10) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:17,代码来源:test_dwt_idwt.py

示例6: test_idwt_invalid_input

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_idwt_invalid_input():
    # Too short, min length is 4 for 'db4':
    assert_raises(ValueError, pywt.idwt, [1, 2, 4], [4, 1, 3], 'db4', 'symmetric') 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:5,代码来源:test_dwt_idwt.py

示例7: test_idwt_single_axis

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_idwt_single_axis():
    x = [[3, 7, 1, 1],
         [-2, 5, 4, 6]]

    x = np.asarray(x)
    x = x + 1j*x   # test with complex data
    cA, cD = pywt.dwt(x, 'db2', axis=-1)

    x0 = pywt.idwt(cA[0], cD[0], 'db2', axis=-1)
    x1 = pywt.idwt(cA[1], cD[1], 'db2', axis=-1)

    assert_allclose(x[0], x0)
    assert_allclose(x[1], x1) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:15,代码来源:test_dwt_idwt.py

示例8: test_idwt_axis_arg

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_idwt_axis_arg():
    x = [[3, 7, 1, 1],
         [-2, 5, 4, 6]]

    cA, cD = pywt.dwt(x, 'db2', axis=1)

    x_ = pywt.idwt(cA, cD, 'db2', axis=-1)
    x = pywt.idwt(cA, cD, 'db2', axis=1)

    assert_allclose(x_, x) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:12,代码来源:test_dwt_idwt.py

示例9: test_dwt_idwt_axis_excess

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_dwt_idwt_axis_excess():
    x = [[3, 7, 1, 1],
         [-2, 5, 4, 6]]
    # can't transform over axes that aren't there
    assert_raises(ValueError,
                  pywt.dwt, x, 'db2', 'symmetric', axis=2)

    assert_raises(ValueError,
                  pywt.idwt, [1, 2, 4], [4, 1, 3], 'db2', 'symmetric', axis=1) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:11,代码来源:test_dwt_idwt.py

示例10: test_dwt_idwt_allmodes

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def test_dwt_idwt_allmodes():
    # Test that :func:`dwt` and :func:`idwt` can be performed using every mode
    x = [1, 2, 1, 5, -1, 8, 4, 6]
    dwt_result_modes = {
        'zero': ([-0.03467518, 1.73309178, 3.40612438, 6.32928585, 6.95094948],
                 [-0.12940952, -2.15599552, -5.95034847, -1.21545369,
                 -1.8625013]),
        'constant': ([1.28480404, 1.73309178, 3.40612438, 6.32928585,
                      7.51935555],
                     [-0.48296291, -2.15599552, -5.95034847, -1.21545369,
                      0.25881905]),
        'symmetric': ([1.76776695, 1.73309178, 3.40612438, 6.32928585,
                       7.77817459],
                      [-0.61237244, -2.15599552, -5.95034847, -1.21545369,
                       1.22474487]),
        'reflect': ([2.12132034, 1.73309178, 3.40612438, 6.32928585,
                     6.81224877],
                    [-0.70710678, -2.15599552, -5.95034847, -1.21545369,
                     -2.38013939]),
        'periodic': ([6.9162743, 1.73309178, 3.40612438, 6.32928585,
                      6.9162743],
                     [-1.99191082, -2.15599552, -5.95034847, -1.21545369,
                      -1.99191082]),
        'smooth': ([-0.51763809, 1.73309178, 3.40612438, 6.32928585,
                    7.45000519],
                   [0, -2.15599552, -5.95034847, -1.21545369, 0]),
        'periodization': ([4.053172, 3.05257099, 2.85381112, 8.42522221],
                          [0.18946869, 4.18258152, 4.33737503, 2.60428326])
    }

    for mode in pywt.Modes.modes:
        cA, cD = pywt.dwt(x, 'db2', mode)
        assert_allclose(cA, dwt_result_modes[mode][0], rtol=1e-7, atol=1e-8)
        assert_allclose(cD, dwt_result_modes[mode][1], rtol=1e-7, atol=1e-8)
        assert_allclose(pywt.idwt(cA, cD, 'db2', mode), x, rtol=1e-10) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:37,代码来源:test_modes.py

示例11: wavy

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def wavy(arr):
    cA, cD = pywt.dwt(arr, 'db2', mode='symmetric')
    y = pywt.idwt(cA, cD, 'db2')
    return y 
开发者ID:Metnew,项目名称:neural-finance,代码行数:6,代码来源:neural_data.py

示例12: _single_tree_synthesis_1d

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def _single_tree_synthesis_1d(coeffs, first_stage, wavelet, mode, axis):
    """
    Single tree of the inverse dual-tree complex wavelet transform.

    Parameters
    ----------
    coeffs : list
    first_stage : Wavelet object
    wavelet : 2-tuple of Wavelet objects
    mode : str
    axis : int

    Returns
    -------
    reconstructed : ndarray, ndim 1
    """
    # Determine the level except first stage:
    # The order of wavelets depends on whether
    # the level is even or odd.
    level = len(coeffs) - 1
    approx, detail_coeffs, first_stage_detail = coeffs[0], coeffs[1:-1], coeffs[-1]

    # Set the right alternating order between real and imag wavelet
    if level % 2 == 1:
        wavelet = reversed(wavelet)

    # In the case of level = 1, coeffs[1:-1] is an empty list. Then, the following
    # loop is not run since zip() iterates as long as the shortest iterable.
    for detail, wav in zip(detail_coeffs, cycle(wavelet)):
        approx = _normalize_size_axis(approx, detail, axis=axis)
        approx = idwt(cA=approx, cD=detail, wavelet=wav, mode=mode, axis=axis)

    approx = _normalize_size_axis(approx, first_stage_detail, axis=axis)
    return idwt(
        cA=approx, cD=first_stage_detail, wavelet=first_stage, mode=mode, axis=axis
    ) 
开发者ID:LaurentRDC,项目名称:scikit-ued,代码行数:38,代码来源:dtcwt.py

示例13: denoise_ecg

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def denoise_ecg(ecg_segment):
	"""
	Remove baseline drafts from ECG signal.
	:param ecg_segment: ecg record, a numpy array.
	:return: denoised ecg record, a numpy array.
	
	Example:
	denoising_ecg = denoise_ecg(raw_ecg)
	"""
	
	denoising_wd_level = 6
	denoising_wd_wavelet = "db6"
	coffes_set = []
	cA_signal = np.reshape(ecg_segment, len(ecg_segment))
	for index_dec in range(denoising_wd_level):
		cA, cD = pywt.dwt(cA_signal, denoising_wd_wavelet)
		coffes_set.append(cD)
		cA_signal = cA
	coffes_set.append(cA_signal)
	coffes_set[denoising_wd_level] = np.zeros(len(coffes_set[denoising_wd_level]))
	
	cA_signal = coffes_set[denoising_wd_level]
	for index_dec in range(denoising_wd_level):
		cD_signal = coffes_set[denoising_wd_level - 1 - index_dec]
		if len(cD_signal) != len(cA_signal):
			cA_signal = np.delete(cA_signal, len(cA_signal) - 1, axis=0)
		cA_signal = pywt.idwt(cA_signal, cD_signal, denoising_wd_wavelet)
	cA_signal = np.reshape(cA_signal, (len(ecg_segment), 1))
	return cA_signal 
开发者ID:zzklove3344,项目名称:ApneaECGAnalysis,代码行数:31,代码来源:denoising.py

示例14: reconstruct_with_approx

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import idwt [as 别名]
def reconstruct_with_approx(cDs, labels, wavelet, fig=None):
    rs = [pywt.idwt(cA=None, cD=cD, wavelet=wavelet) for cD in cDs]

    if fig is None:
        fig = plt.figure()

    for i, r in enumerate(rs):
        plt.plot((np.abs(r))**2, label="Power of reconstructed signal ({})".format(labels[i]))
    plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

    return rs, fig 
开发者ID:gumpy-bci,项目名称:gumpy,代码行数:13,代码来源:plot.py


注:本文中的pywt.idwt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。