本文整理匯總了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
示例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()
示例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)
示例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))
示例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
示例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()
示例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)
示例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()
示例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))
示例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
示例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
示例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')
示例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
示例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
示例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()