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


Python fftpack.idct方法代码示例

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


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

示例1: block_idct

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def block_idct(x, block_size=8, masked=False, ratio=0.5, linf_bound=0.0):
    z = torch.zeros(x.size())
    num_blocks = int(x.size(2) / block_size)
    mask = np.zeros((x.size(0), x.size(1), block_size, block_size))
    if type(ratio) != float:
        for i in range(x.size(0)):
            mask[i, :, :int(block_size * ratio[i]), :int(block_size * ratio[i])] = 1
    else:
        mask[:, :, :int(block_size * ratio), :int(block_size * ratio)] = 1
    for i in range(num_blocks):
        for j in range(num_blocks):
            submat = x[:, :, (i * block_size):((i + 1) * block_size), (j * block_size):((j + 1) * block_size)].numpy()
            if masked:
                submat = submat * mask
            z[:, :, (i * block_size):((i + 1) * block_size), (j * block_size):((j + 1) * block_size)] = torch.from_numpy(idct(idct(submat, axis=3, norm='ortho'), axis=2, norm='ortho'))
    if linf_bound > 0:
        return z.clamp(-linf_bound, linf_bound)
    else:
        return z 
开发者ID:cg563,项目名称:simple-blackbox-attack,代码行数:21,代码来源:utils.py

示例2: dct_uncompress

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def dct_uncompress(X_compressed, window_size=128):
    """
    Uncompress a DCT compressed signal (such as returned by ``compress``).

    Parameters
    ----------
    X_compressed : ndarray, shape=(n_samples, n_features)
        Windowed and compressed array.

    window_size : int, optional (default=128)
        Size of the window used when ``compress`` was called.

    Returns
    -------
    X_reconstructed : ndarray, shape=(n_samples)
        Reconstructed version of X.
    """
    if X_compressed.shape[1] % window_size != 0:
        append = np.zeros((X_compressed.shape[0],
                           window_size - X_compressed.shape[1] % window_size))
        X_compressed = np.hstack((X_compressed, append))
    X_r = fftpack.idct(X_compressed, norm='ortho')
    return X_r.ravel() 
开发者ID:kastnerkyle,项目名称:tools,代码行数:25,代码来源:audio_tools.py

示例3: overlap_dct_uncompress

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def overlap_dct_uncompress(X_compressed, window_size):
    """
    Uncompress X as returned from ``overlap_compress``.

    Parameters
    ----------
    X_compressed : ndarray, shape=(n_windows, n_components)
        Windowed and compressed version of X

    window_size : int
        Size of windows originally used when compressing X

    Returns
    -------
    X_reconstructed : ndarray, shape=(n_samples,)
        Reconstructed version of X
    """
    if X_compressed.shape[1] % window_size != 0:
        append = np.zeros((X_compressed.shape[0], window_size -
                           X_compressed.shape[1] % window_size))
        X_compressed = np.hstack((X_compressed, append))
    X_r = fftpack.idct(X_compressed, norm='ortho')
    return invert_halfoverlap(X_r) 
开发者ID:kastnerkyle,项目名称:tools,代码行数:25,代码来源:audio_tools.py

示例4: run_fft_dct_example

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def run_fft_dct_example():
    random_state = np.random.RandomState(1999)

    fs, d = fetch_sample_speech_fruit()
    n_fft = 64
    X = d[0]
    X_stft = stft(X, n_fft)
    X_rr = complex_to_real_view(X_stft)
    X_dct = fftpack.dct(X_rr, axis=-1, norm='ortho')
    X_dct_sub = X_dct[1:] - X_dct[:-1]
    std = X_dct_sub.std(axis=0, keepdims=True)
    X_dct_sub += .01 * std * random_state.randn(
        X_dct_sub.shape[0], X_dct_sub.shape[1])
    X_dct_unsub = np.cumsum(X_dct_sub, axis=0)
    X_idct = fftpack.idct(X_dct_unsub, axis=-1, norm='ortho')
    X_irr = real_to_complex_view(X_idct)
    X_r = istft(X_irr, n_fft)[:len(X)]

    SNR = 20 * np.log10(np.linalg.norm(X - X_r) / np.linalg.norm(X))
    print(SNR)

    wavfile.write("fftdct_orig.wav", fs, soundsc(X))
    wavfile.write("fftdct_rec.wav", fs, soundsc(X_r)) 
开发者ID:kastnerkyle,项目名称:tools,代码行数:25,代码来源:audio_tools.py

示例5: idctii

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def idctii(x, axes=None):
    """
    Compute a multi-dimensional inverse DCT-II over specified array axes.
    This function is implemented by calling the one-dimensional inverse
    DCT-II :func:`scipy.fftpack.idct` with normalization mode 'ortho'
    for each of the specified axes.

    Parameters
    ----------
    a : array_like
      Input array
    axes : sequence of ints, optional (default None)
      Axes over which to compute the inverse DCT-II.

    Returns
    -------
    y : ndarray
      Inverse DCT-II of input array
    """

    if axes is None:
        axes = list(range(x.ndim))
    for ax in axes[::-1]:
        x = fftpack.idct(x, type=2, axis=ax, norm='ortho')
    return x 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:27,代码来源:linalg.py

示例6: uncompress

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def uncompress(X_compressed, window_size=128):
    """
    Uncompress a DCT compressed signal (such as returned by ``compress``).

    Parameters
    ----------
    X_compressed : ndarray, shape=(n_samples, n_features)
        Windowed and compressed array.

    window_size : int, optional (default=128)
        Size of the window used when ``compress`` was called.

    Returns
    -------
    X_reconstructed : ndarray, shape=(n_samples)
        Reconstructed version of X.
    """
    if X_compressed.shape[1] % window_size != 0:
        append = np.zeros((X_compressed.shape[0],
                           window_size - X_compressed.shape[1] % window_size))
        X_compressed = np.hstack((X_compressed, append))
    X_r = fftpack.idct(X_compressed, norm='ortho')
    return X_r.ravel() 
开发者ID:dagbldr,项目名称:dagbldr,代码行数:25,代码来源:audio_tools.py

示例7: overlap_uncompress

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def overlap_uncompress(X_compressed, window_size):
    """
    Uncompress X as returned from ``overlap_compress``.

    Parameters
    ----------
    X_compressed : ndarray, shape=(n_windows, n_components)
        Windowed and compressed version of X

    window_size : int
        Size of windows originally used when compressing X

    Returns
    -------
    X_reconstructed : ndarray, shape=(n_samples,)
        Reconstructed version of X
    """
    if X_compressed.shape[1] % window_size != 0:
        append = np.zeros((X_compressed.shape[0], window_size -
                           X_compressed.shape[1] % window_size))
        X_compressed = np.hstack((X_compressed, append))
    X_r = fftpack.idct(X_compressed, norm='ortho')
    return invert_halfoverlap(X_r) 
开发者ID:dagbldr,项目名称:dagbldr,代码行数:25,代码来源:audio_tools.py

示例8: uncompress

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def uncompress(X_compressed, window_size=128):
    """
    Uncompress a DCT compressed signal (such as returned by ``compress``).

    Parameters
    ----------
    X_compressed : ndarray, shape=(n_samples, n_features)
        Windowed and compressed array.

    window_size : int, optional (default=128)
        Size of the window used when ``compress`` was called.

    Returns
    -------
    X_reconstructed : ndarray, shape=(n_samples)
        Reconstructed version of X.
    """
    if X_compressed.shape[1] % window_size != 0:
        append = np.zeros((X_compressed.shape[0], window_size - X_compressed.shape[1] % window_size))
        X_compressed = np.hstack((X_compressed, append))
    X_r = fftpack.idct(X_compressed, norm='ortho')
    return X_r.ravel() 
开发者ID:dagbldr,项目名称:dagbldr,代码行数:24,代码来源:preprocessing_utils.py

示例9: run_fft_dct_example

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def run_fft_dct_example():
    random_state = np.random.RandomState(1999)

    fs, d = fetch_sample_speech_fruit()
    n_fft = 64
    X = d[0]
    X_stft = stft(X, fftsize=n_fft)
    X_rr = complex_to_real_view(X_stft)
    X_dct = fftpack.dct(X_rr, axis=-1, norm='ortho')
    X_dct_sub = X_dct[1:] - X_dct[:-1]
    std = X_dct_sub.std(axis=0, keepdims=True)
    X_dct_sub += .01 * std * random_state.randn(
        X_dct_sub.shape[0], X_dct_sub.shape[1])
    X_dct_unsub = np.cumsum(X_dct_sub, axis=0)
    X_idct = fftpack.idct(X_dct_unsub, axis=-1, norm='ortho')
    X_irr = real_to_complex_view(X_idct)
    X_r = istft(X_irr, n_fft)[:len(X)]

    SNR = 20 * np.log10(np.linalg.norm(X - X_r) / np.linalg.norm(X))
    print(SNR)

    wavfile.write("fftdct_orig.wav", fs, soundsc(X))
    wavfile.write("fftdct_rec.wav", fs, soundsc(X_r)) 
开发者ID:kastnerkyle,项目名称:representation_mixing,代码行数:25,代码来源:audio.py

示例10: idct

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def idct(modes, null_hypothesis, counts=1):
    """
    Inverts the dct function.

    Parameters
    ----------
    modes : array
        The fourier modes to be transformed to the time domain.

    null_hypothesis : array
        The array that was used in the normalization before the dct. This is
        commonly the mean of the time-domain data vector. All elements of this
        array must be in (0,1).

     counts : int, optional
        A factor in the normalization, that should correspond to the counts-per-timestep (so
        for full time resolution this is 1).

    Returns
    -------
    array
        Inverse of the dct function

    """
    z = _idct(modes, norm='ortho')
    x = unstandardizer(z, null_hypothesis, counts)
    return x 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:29,代码来源:signal.py

示例11: lowpass_filter

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def lowpass_filter(data, max_freq=None):
    """
    Implements a low-pass filter on the input array, by DCTing the input, mapping all but the lowest
    `max_freq` modes to zero, and then inverting the transform.

    Parameters
    ----------
    data : numpy.array,
        The vector to low-pass filter

    max_freq : None or int, optional
        The highest frequency to keep. If None then it keeps the minimum of 50 or l/10 frequencies, where l is the
        length of the data vector

    Returns
    -------
    numpy.array
        The low-pass-filtered data.
    """
    n = len(data)

    if max_freq is None:
        max_freq = min(int(_np.ceil(n / 10)), 50)

    modes = _dct(data, norm='ortho')

    if max_freq < n - 1:
        modes[max_freq + 1:] = _np.zeros(len(data) - max_freq - 1)

    out = _idct(modes, norm='ortho')

    return out 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:34,代码来源:signal.py

示例12: idct2

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def idct2(image_channel):
    return fftpack.idct(fftpack.idct(image_channel.T, norm='ortho').T, norm='ortho') 
开发者ID:AshishBora,项目名称:csgm,代码行数:4,代码来源:celebA_estimators.py

示例13: idct2

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def idct2(x, norm='ortho'):
    return idct(idct(x, norm=norm).T, norm=norm).T 
开发者ID:wuhuikai,项目名称:GP-GAN,代码行数:4,代码来源:gp_gan.py

示例14: _powerCosineTransform

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def _powerCosineTransform(self, p_spec):
        """Calculating the cosine transform of the power spectrum.

            The cosine transform of the power spectrum is an estimate
            of the data covariance (see Hanssen, 2001)."""
        cos = fft.idct(p_spec, type=3)
        return cos 
开发者ID:pyrocko,项目名称:kite,代码行数:9,代码来源:covariance.py

示例15: run_world_dct_example

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import idct [as 别名]
def run_world_dct_example():
    # on chromebook
    # enc 114.229
    # synth 5.165
    fs, d = fetch_sample_speech_tapestry()
    d = d.astype("float32") / 2 ** 15

    def enc():
        temporal_positions_h, f0_h, vuv_h, f0_candidates_h = harvest(d, fs)
        temporal_positions_ct, spectrogram_ct, fs_ct = cheaptrick(d, fs,
                temporal_positions_h, f0_h, vuv_h)
        temporal_positions_d4c, f0_d4c, vuv_d4c, aper_d4c, coarse_aper_d4c = d4c(d, fs,
                temporal_positions_h, f0_h, vuv_h)

        return spectrogram_ct, f0_d4c, vuv_d4c, coarse_aper_d4c

    start = time.time()
    spectrogram_ct, f0_d4c, vuv_d4c, coarse_aper_d4c = enc()
    dct_buf = fftpack.dct(spectrogram_ct)
    n_fft = 512
    n_dct = 20
    dct_buf = dct_buf[:, :n_dct]
    idct_buf = np.zeros((dct_buf.shape[0], n_fft + 1))
    idct_buf[:, :n_dct] = dct_buf
    ispectrogram_ct = fftpack.idct(idct_buf)
    enc_done = time.time()

    y = world_synthesis(f0_d4c, vuv_d4c, coarse_aper_d4c, spectrogram_ct, fs)
    synth_done = time.time()

    print("enc time: {}".format(enc_done - start))
    print("synth time: {}".format(synth_done - enc_done))
    #y = world_synthesis(f0_d4c, vuv_d4c, aper_d4c, sp_r, fs)
    wavfile.write("out_dct.wav", fs, soundsc(y))


#run_world_mgc_example()
#run_world_base_example() 
开发者ID:kastnerkyle,项目名称:tools,代码行数:40,代码来源:test_audio_extract.py


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