本文整理汇总了Python中scipy.fftpack.ifft方法的典型用法代码示例。如果您正苦于以下问题:Python fftpack.ifft方法的具体用法?Python fftpack.ifft怎么用?Python fftpack.ifft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.fftpack
的用法示例。
在下文中一共展示了fftpack.ifft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quadrature_cc_1D
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def quadrature_cc_1D(N):
""" Computes the Clenshaw Curtis nodes and weights """
N = np.int(N)
if N == 1:
knots = 0
weights = 2
else:
n = N - 1
C = np.zeros((N,2))
k = 2*(1+np.arange(np.floor(n/2)))
C[::2,0] = 2/np.hstack((1, 1-k*k))
C[1,1] = -n
V = np.vstack((C,np.flipud(C[1:n,:])))
F = np.real(ifft(V, n=None, axis=0))
knots = F[0:N,1]
weights = np.hstack((F[0,0],2*F[1:n,0],F[n,0]))
return knots, weights
示例2: _centered
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def _centered(arr, newsize):
# Return the center newsize portion of the array.
newsize = numpy.asarray(newsize)
currsize = numpy.array(arr.shape)
startind = (currsize - newsize) // 2
endind = startind + newsize
myslice = [slice(startind[k], endind[k]) for k in range(len(endind))]
return arr[tuple(myslice)]
#def _rfftn(a, s=None, axes=None):
# s, axes = _cook_nd_args(a, s, axes);
# a = fft.rfft(a, s[-1], axes[-1], overwrite_x = True)
# for ii in range(len(axes)-1):
# a = fft.fft(a, s[ii], axes[ii], overwrite_x = True)
# return a
#def _irfftn(a, s=None, axes=None):
# #a = asarray(a).astype('complex64')
# s, axes = _cook_nd_args(a, s, axes, invreal=1)
# for ii in range(len(axes)-1):
# a = fft.ifft(a, s[ii], axes[ii], overwrite_x = True);
# a = fft.ifft(a, s[-1], axes[-1], overwrite_x = True);
# a = a.real;
# return a
示例3: spectralwhitening
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def spectralwhitening(stream):
"""
Apply spectral whitening to data.
Data is divided by its smoothed (Default: None) amplitude spectrum.
"""
stream2 = copy.deepcopy(stream)
for trace in arange(len(stream2)):
data = stream2[trace].data
n = len(data)
nfft = nextpow2(n)
spec = fft(data, nfft)
spec_ampl = sqrt(abs(multiply(spec, conjugate(spec))))
spec /= spec_ampl # Do we need to do some smoothing here?
ret = real(ifft(spec, nfft)[:n])
stream2[trace].data = ret
return stream2
示例4: spectralwhitening_smooth
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def spectralwhitening_smooth(stream, N):
"""
Apply spectral whitening to data.
Data is divided by its smoothed (Default: None) amplitude spectrum.
"""
stream2 = copy.deepcopy(stream)
for trace in arange(len(stream2)):
data = stream2[trace].data
n = len(data)
nfft = nextpow2(n)
spec = fft(data, nfft)
spec_ampl = sqrt(abs(multiply(spec, conjugate(spec))))
spec_ampl = smooth(spec_ampl, N)
spec /= spec_ampl # Do we need to do some smoothing here?
ret = real(ifft(spec, nfft)[:n])
stream2[trace].data = ret
return stream2
示例5: carr_madan_fraction_fft_call_pricer
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def carr_madan_fraction_fft_call_pricer(N, d_u, d_k, alpha, r, t, S0, q, chf_ln_st):
rou = (d_u * d_k) / (2 * np.pi)
beta = np.log(S0) - d_k * N / 2
u_arr = np.arange(N) * d_u
k_arr = beta + np.arange(N) * d_k
delta_arr = np.zeros(N)
delta_arr[0] = 1
w_arr = d_u / 3 * (3 + (-1) ** (np.arange(N) + 1) - delta_arr)
call_chf = (np.exp(-r * t) / ((alpha + 1j * u_arr) * (alpha + 1j * u_arr + 1))) * chf_ln_st(
u_arr - (alpha + 1) * 1j,
t, r, q=q, S0=S0)
x_arr = np.exp(-1j * beta * u_arr) * call_chf * w_arr
y_arr = np.zeros(2 * N) * 0j
y_arr[:N] = np.exp(-1j * np.pi * rou * np.arange(N) ** 2) * x_arr
z_arr = np.zeros(2 * N) * 0j
z_arr[:N] = np.exp(1j * np.pi * rou * np.arange(N) ** 2)
z_arr[N:] = np.exp(1j * np.pi * rou * np.arange(N - 1, -1, -1) ** 2)
ffty = (fft(y_arr))
fftz = (fft(z_arr))
fftx = ffty * fftz
fftpsi = ifft(fftx)
fft_prices = np.exp(-1j * np.pi * (np.arange(N) ** 2) * rou) * fftpsi[:N]
call_prices = (np.exp(-alpha * k_arr) / np.pi) * fft_prices.real
return np.exp(k_arr), call_prices
示例6: test_definition
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def test_definition(self):
x1 = [1,2,3,4,1,2,3,4]
x1_1 = [1,2+3j,4+1j,2+3j,4,2-3j,4-1j,2-3j]
x2 = [1,2,3,4,1,2,3,4,5]
x2_1 = [1,2+3j,4+1j,2+3j,4+5j,4-5j,2-3j,4-1j,2-3j]
def _test(x, xr):
y = irfft(np.array(x, dtype=self.rdt))
y1 = direct_irdft(x)
self.assertTrue(y.dtype == self.rdt,
"Output dtype is %s, expected %s" % (y.dtype, self.rdt))
assert_array_almost_equal(y,y1, decimal=self.ndec)
assert_array_almost_equal(y,ifft(xr), decimal=self.ndec)
_test(x1, x1_1)
_test(x2, x2_1)
示例7: test_pdos_1d
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def test_pdos_1d():
pad=lambda x: pad_zeros(x, nadd=len(x)-1)
n=500; w=welch(n)
# 1 second signal
t=np.linspace(0,1,n); dt=t[1]-t[0]
# sum of sin()s with random freq and phase shift, 10 frequencies from
# f=0...100 Hz
v=np.array([np.sin(2*np.pi*f*t + rand()*2*np.pi) for f in rand(10)*100]).sum(0)
f=np.fft.fftfreq(2*n-1, dt)[:n]
c1=mirror(ifft(abs(fft(pad(v)))**2.0)[:n].real)
c2=correlate(v,v,'full')
c3=mirror(acorr(v,norm=False))
assert np.allclose(c1, c2)
assert np.allclose(c1, c3)
p1=(abs(fft(pad(v)))**2.0)[:n]
p2=(abs(fft(mirror(acorr(v,norm=False)))))[:n]
assert np.allclose(p1, p2)
p1=(abs(fft(pad(v*w)))**2.0)[:n]
p2=(abs(fft(mirror(acorr(v*w,norm=False)))))[:n]
assert np.allclose(p1, p2)
示例8: istft
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def istft(X, fftsize=128, step="half", wsola=False, mean_normalize=True,
real=False, compute_onesided=True):
"""
Compute ISTFT for STFT transformed X
"""
if real:
local_ifft = fftpack.irfft
X_pad = np.zeros((X.shape[0], X.shape[1] + 1)) + 0j
X_pad[:, :-1] = X
X = X_pad
else:
local_ifft = fftpack.ifft
if compute_onesided:
X_pad = np.zeros((X.shape[0], 2 * X.shape[1])) + 0j
X_pad[:, :fftsize // 2 + 1] = X
X_pad[:, fftsize // 2 + 1:] = 0
X = X_pad
X = local_ifft(X).astype("float64")
if step == "half":
X = invert_halfoverlap(X)
else:
X = overlap_add(X, step, wsola=wsola)
if mean_normalize:
X -= np.mean(X)
return X
示例9: test_size_accuracy
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def test_size_accuracy(self):
# Sanity check for the accuracy for prime and non-prime sized inputs
if self.rdt == np.float32:
rtol = 1e-5
elif self.rdt == np.float64:
rtol = 1e-10
for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
np.random.seed(1234)
x = np.random.rand(size).astype(self.rdt)
y = ifft(fft(x))
_assert_close_in_norm(x, y, rtol, size, self.rdt)
y = fft(ifft(x))
_assert_close_in_norm(x, y, rtol, size, self.rdt)
x = (x + 1j*np.random.rand(size)).astype(self.cdt)
y = ifft(fft(x))
_assert_close_in_norm(x, y, rtol, size, self.rdt)
y = fft(ifft(x))
_assert_close_in_norm(x, y, rtol, size, self.rdt)
示例10: polyval
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def polyval(self, chebcoeff):
"""
Compute the interpolation values at Chebyshev points.
chebcoeff: Chebyshev coefficients
"""
N = len(chebcoeff)
if N == 1:
return chebcoeff
data = even_data(chebcoeff)/2
data[0] *= 2
data[N-1] *= 2
fftdata = 2*(N-1)*fftpack.ifft(data, axis=0)
complex_values = fftdata[:N]
# convert to real if input was real
if np.isrealobj(chebcoeff):
values = np.real(complex_values)
else:
values = complex_values
return values
示例11: idft
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def idft(modes, null_hypothesis, counts=1):
"""
Inverts the dft 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 dft function
"""
z = _np.sqrt(len(modes)) * _ifft(modes) # TIM CHECK THIS: len(*modes*) correct?
x = unstandardizer(z, null_hypothesis, counts)
return x
示例12: compute_beat_spectrum
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def compute_beat_spectrum(power_spectrogram):
""" Computes the beat spectrum averages (over freq's) the autocorrelation matrix of a one-sided spectrogram.
The autocorrelation matrix is computed by taking the autocorrelation of each row of the spectrogram and
dismissing the symmetric half.
Args:
power_spectrogram (:obj:`np.array`): 2D matrix containing the one-sided power spectrogram of an audio signal
Returns:
(:obj:`np.array`): array containing the beat spectrum based on the power spectrogram
See Also:
J Foote's original derivation of the Beat Spectrum:
Foote, Jonathan, and Shingo Uchihashi. "The beat spectrum: A new approach to rhythm analysis."
Multimedia and Expo, 2001. ICME 2001. IEEE International Conference on. IEEE, 2001.
(`See PDF here <http://rotorbrain.com/foote/papers/icme2001.pdf>`_)
"""
freq_bins, time_bins = power_spectrogram.shape
# row-wise autocorrelation according to the Wiener-Khinchin theorem
power_spectrogram = np.vstack([power_spectrogram, np.zeros_like(power_spectrogram)])
nearest_power_of_two = 2 ** np.ceil(np.log(power_spectrogram.shape[0]) / np.log(2))
pad_amount = int(nearest_power_of_two - power_spectrogram.shape[0])
power_spectrogram = np.pad(power_spectrogram, ((0, pad_amount), (0, 0)), 'constant')
fft_power_spec = scifft.fft(power_spectrogram, axis=0)
abs_fft = np.abs(fft_power_spec) ** 2
autocorrelation_rows = np.real(
scifft.ifft(abs_fft, axis=0)[:freq_bins, :]) # ifft over columns
# normalization factor
norm_factor = np.tile(np.arange(freq_bins, 0, -1), (time_bins, 1)).T
autocorrelation_rows = autocorrelation_rows / norm_factor
# compute the beat spectrum
beat_spectrum = np.mean(autocorrelation_rows, axis=1)
# average over frequencies
return beat_spectrum
示例13: bench_random
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def bench_random(self):
from numpy.fft import ifft as numpy_ifft
print()
print(' Inverse Fast Fourier Transform')
print('===============================================')
print(' | real input | complex input ')
print('-----------------------------------------------')
print(' size | scipy | numpy | scipy | numpy ')
print('-----------------------------------------------')
for size,repeat in [(100,7000),(1000,2000),
(256,10000),
(512,10000),
(1024,1000),
(2048,1000),
(2048*2,500),
(2048*4,500),
]:
print('%5s' % size, end=' ')
sys.stdout.flush()
for x in [random([size]).astype(double),
random([size]).astype(cdouble)+random([size]).astype(cdouble)*1j
]:
if size > 500:
y = ifft(x)
else:
y = direct_idft(x)
assert_array_almost_equal(ifft(x),y)
print('|%8.2f' % measure('ifft(x)',repeat), end=' ')
sys.stdout.flush()
assert_array_almost_equal(numpy_ifft(x),y)
print('|%8.2f' % measure('numpy_ifft(x)',repeat), end=' ')
sys.stdout.flush()
print(' (secs for %s calls)' % (repeat))
sys.stdout.flush()
示例14: direct_diff
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def direct_diff(x,k=1,period=None):
fx = fft(x)
n = len(fx)
if period is None:
period = 2*pi
w = fftfreq(n)*2j*pi/period*n
if k < 0:
w = 1 / w**k
w[0] = 0.0
else:
w = w**k
if n > 2000:
w[250:n-250] = 0.0
return ifft(w*fx).real
示例15: direct_tilbert
# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import ifft [as 别名]
def direct_tilbert(x,h=1,period=None):
fx = fft(x)
n = len(fx)
if period is None:
period = 2*pi
w = fftfreq(n)*h*2*pi/period*n
w[0] = 1
w = 1j/tanh(w)
w[0] = 0j
return ifft(w*fx)