本文整理汇总了Python中scipy.fft方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.fft方法的具体用法?Python scipy.fft怎么用?Python scipy.fft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy
的用法示例。
在下文中一共展示了scipy.fft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ihfft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def ihfft(x, n=None, axis=-1, norm=None, overwrite_x=False, *, plan=None):
"""Compute the FFT of a signal that has Hermitian symmetry.
Args:
a (cupy.ndarray): Array to be transform.
n (None or int): Number of points along transformation axis in the
input to use. If ``n`` is not given, the length of the input along
the axis specified by ``axis`` is used.
axis (int): Axis over which to compute the FFT.
norm (None or ``"ortho"``): Keyword to specify the normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (None): This argument is currently not supported.
Returns:
cupy.ndarray:
The transformed array which shape is specified by ``n`` and type
will convert to complex if the input is other. The length of the
transformed axis is ``n//2+1``.
.. seealso:: :func:`scipy.fft.ihfft`
"""
# TODO(leofang): support R2C & C2R plans
if plan is not None:
raise NotImplementedError('ihfft plan is currently not yet supported')
return _ihfft(x, n, axis, norm)
示例2: _stft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def _stft(self, stim):
x = stim.data
framesamp = int(self.frame_size * stim.sampling_rate)
hopsamp = int(self.hop_size * stim.sampling_rate)
w = np.hanning(framesamp)
X = np.array([fft(w * x[i:(i + framesamp)])
for i in range(0, len(x) - framesamp, hopsamp)])
nyquist_lim = int(X.shape[1] // 2)
X = np.log(X[:, :nyquist_lim])
X = np.absolute(X)
if self.spectrogram:
import matplotlib.pyplot as plt
bins = np.fft.fftfreq(framesamp, d=1. / stim.sampling_rate)
bins = bins[:nyquist_lim]
plt.imshow(X.T, origin='lower', aspect='auto',
interpolation='nearest', cmap='RdYlBu_r',
extent=[0, stim.duration, bins.min(), bins.max()])
plt.xlabel('Time')
plt.ylabel('Frequency')
plt.colorbar()
plt.show()
return X
示例3: write_fft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def write_fft(fft_features, fn):
"""
Write the FFT features to separate files to speed up processing.
"""
base_fn, ext = os.path.splitext(fn)
data_fn = base_fn + ".fft"
np.save(data_fn, fft_features)
print("Written "%data_fn)
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:11,代码来源:fft.py
示例4: create_fft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def create_fft(fn):
sample_rate, X = scipy.io.wavfile.read(fn)
fft_features = abs(scipy.fft(X)[:1000])
write_fft(fft_features, fn)
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:7,代码来源:fft.py
示例5: read_fft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def read_fft(genre_list, base_dir=GENRE_DIR):
X = []
y = []
for label, genre in enumerate(genre_list):
genre_dir = os.path.join(base_dir, genre, "*.fft.npy")
file_list = glob.glob(genre_dir)
assert(file_list), genre_dir
for fn in file_list:
fft_features = np.load(fn)
X.append(fft_features[:2000])
y.append(label)
return np.array(X), np.array(y)
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:16,代码来源:fft.py
示例6: plot_wav_fft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def plot_wav_fft(wav_filename, desc=None):
plt.clf()
plt.figure(num=None, figsize=(6, 4))
sample_rate, X = scipy.io.wavfile.read(wav_filename)
spectrum = np.fft.fft(X)
freq = np.fft.fftfreq(len(X), 1.0 / sample_rate)
plt.subplot(211)
num_samples = 200.0
plt.xlim(0, num_samples / sample_rate)
plt.xlabel("time [s]")
plt.title(desc or wav_filename)
plt.plot(np.arange(num_samples) / sample_rate, X[:num_samples])
plt.grid(True)
plt.subplot(212)
plt.xlim(0, 5000)
plt.xlabel("frequency [Hz]")
plt.xticks(np.arange(5) * 1000)
if desc:
desc = desc.strip()
fft_desc = desc[0].lower() + desc[1:]
else:
fft_desc = wav_filename
plt.title("FFT of %s" % fft_desc)
plt.plot(freq, abs(spectrum), linewidth=5)
plt.grid(True)
plt.tight_layout()
rel_filename = os.path.split(wav_filename)[1]
plt.savefig("%s_wav_fft.png" % os.path.splitext(rel_filename)[0],
bbox_inches='tight')
plt.show()
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:37,代码来源:fft.py
示例7: aggregate_raw_batch
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def aggregate_raw_batch(self, features, output):
"""Aggregate batch.
All post processing goes here.
Parameters:
-----------
features : 3D float tensor
Input tensor
output : 2D integer tensor
Output classes
"""
channels = 2 if self.complex_ else 1
features_out = numpy.zeros(
[features.shape[0], self.window_size, channels])
if self.fourier:
if self.complex_:
data = fft(features, axis=1)
features_out[:, :, 0] = numpy.real(data[:, :, 0])
features_out[:, :, 1] = numpy.imag(data[:, :, 0])
else:
data = numpy.abs(fft(features, axis=1))
features_out = data
elif self.stft:
_, _, data = stft(features, nperseg=120, noverlap=60, axis=1)
length = data.shape[1]
n_feats = data.shape[3]
if self.complex_:
features_out = numpy.zeros(
[len(self.train_data), length, n_feats * 2])
features_out[:, :, :n_feats] = numpy.real(data)
features_out[:, :, n_feats:] = numpy.imag(data)
else:
features_out = numpy.abs(data[:, :, 0, :])
else:
features_out = features
return features_out, output
示例8: fft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def fft(x, n=None, axis=-1, norm=None, overwrite_x=False, *, plan=None):
"""Compute the one-dimensional FFT.
Args:
x (cupy.ndarray): Array to be transformed.
n (None or int): Length of the transformed axis of the output. If ``n``
is not given, the length of the input along the axis specified by
``axis`` is used.
axis (int): Axis over which to compute the FFT.
norm (None or ``'ortho'``): Normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.Plan1d` or ``None``): a cuFFT plan for
transforming ``x`` over ``axis``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, n, axis)
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array which shape is specified by ``n`` and type
will convert to complex if that of the input is another.
.. seealso:: :func:`scipy.fft.fft`
"""
return _fft(x, (n,), (axis,), norm, cufft.CUFFT_FORWARD,
overwrite_x=overwrite_x, plan=plan)
示例9: ifft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def ifft(x, n=None, axis=-1, norm=None, overwrite_x=False, *, plan=None):
"""Compute the one-dimensional inverse FFT.
Args:
x (cupy.ndarray): Array to be transformed.
n (None or int): Length of the transformed axis of the output. If ``n``
is not given, the length of the input along the axis specified by
``axis`` is used.
axis (int): Axis over which to compute the FFT.
norm (None or ``'ortho'``): Normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.Plan1d` or ``None``): a cuFFT plan for
transforming ``x`` over ``axis``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, n, axis)
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array which shape is specified by ``n`` and type
will convert to complex if that of the input is another.
.. seealso:: :func:`scipy.fft.ifft`
"""
return _fft(x, (n,), (axis,), norm, cufft.CUFFT_INVERSE,
overwrite_x=overwrite_x, plan=plan)
示例10: fft2
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def fft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, *, plan=None):
"""Compute the two-dimensional FFT.
Args:
x (cupy.ndarray): Array to be transformed.
s (None or tuple of ints): Shape of the transformed axes of the
output. If ``s`` is not given, the lengths of the input along
the axes specified by ``axes`` are used.
axes (tuple of ints): Axes over which to compute the FFT.
norm (None or ``'ortho'``): Normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for
transforming ``x`` over ``axes``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, s, axes)
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array which shape is specified by ``s`` and
type will convert to complex if that of the input is another.
.. seealso:: :func:`scipy.fft.fft2`
"""
return fftn(x, s, axes, norm, overwrite_x, plan=plan)
示例11: ifft2
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def ifft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, *,
plan=None):
"""Compute the two-dimensional inverse FFT.
Args:
x (cupy.ndarray): Array to be transformed.
s (None or tuple of ints): Shape of the transformed axes of the
output. If ``s`` is not given, the lengths of the input along
the axes specified by ``axes`` are used.
axes (tuple of ints): Axes over which to compute the FFT.
norm (None or ``'ortho'``): Normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for
transforming ``x`` over ``axes``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, s, axes)
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array which shape is specified by ``s`` and
type will convert to complex if that of the input is another.
.. seealso:: :func:`scipy.fft.ifft2`
"""
return ifftn(x, s, axes, norm, overwrite_x, plan=plan)
示例12: fftn
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def fftn(x, s=None, axes=None, norm=None, overwrite_x=False, *, plan=None):
"""Compute the N-dimensional FFT.
Args:
x (cupy.ndarray): Array to be transformed.
s (None or tuple of ints): Shape of the transformed axes of the
output. If ``s`` is not given, the lengths of the input along
the axes specified by ``axes`` are used.
axes (tuple of ints): Axes over which to compute the FFT.
norm (None or ``'ortho'``): Normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for
transforming ``x`` over ``axes``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, s, axes)
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array which shape is specified by ``s`` and
type will convert to complex if that of the input is another.
.. seealso:: :func:`scipy.fft.fftn`
"""
s = _assequence(s)
axes = _assequence(axes)
func = _default_fft_func(x, s, axes)
return func(x, s, axes, norm, cufft.CUFFT_FORWARD, overwrite_x=overwrite_x,
plan=plan)
示例13: rfft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def rfft(x, n=None, axis=-1, norm=None, overwrite_x=False, *, plan=None):
"""Compute the one-dimensional FFT for real input.
The returned array contains the positive frequency components of the
corresponding :func:`fft`, up to and including the Nyquist frequency.
Args:
x (cupy.ndarray): Array to be transformed.
n (None or int): Length of the transformed axis of the output. If ``n``
is not given, the length of the input along the axis specified by
``axis`` is used.
axis (int): Axis over which to compute the FFT.
norm (None or ``'ortho'``): Normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.Plan1d` or ``None``): a cuFFT plan for
transforming ``x`` over ``axis``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, n, axis,
value_type='R2C')
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array.
.. seealso:: :func:`scipy.fft.rfft`
"""
return _fft(x, (n,), (axis,), norm, cufft.CUFFT_FORWARD, 'R2C',
overwrite_x=overwrite_x, plan=plan)
示例14: irfft
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def irfft(x, n=None, axis=-1, norm=None, overwrite_x=False, *, plan=None):
"""Compute the one-dimensional inverse FFT for real input.
Args:
x (cupy.ndarray): Array to be transformed.
n (None or int): Length of the transformed axis of the output. If ``n``
is not given, the length of the input along the axis specified by
``axis`` is used.
axis (int): Axis over which to compute the FFT.
norm (None or ``'ortho'``): Normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.Plan1d` or ``None``): a cuFFT plan for
transforming ``x`` over ``axis``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, n, axis,
value_type='C2R')
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array.
.. seealso:: :func:`scipy.fft.irfft`
"""
return _fft(x, (n,), (axis,), norm, cufft.CUFFT_INVERSE, 'C2R',
overwrite_x=overwrite_x, plan=plan)
示例15: rfft2
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import fft [as 别名]
def rfft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, *,
plan=None):
"""Compute the two-dimensional FFT for real input.
Args:
a (cupy.ndarray): Array to be transform.
s (None or tuple of ints): Shape to use from the input. If ``s`` is not
given, the lengths of the input along the axes specified by
``axes`` are used.
axes (tuple of ints): Axes over which to compute the FFT.
norm (None or ``"ortho"``): Keyword to specify the normalization mode.
overwrite_x (bool): If True, the contents of ``x`` can be destroyed.
plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for
transforming ``x`` over ``axes``, which can be obtained using::
plan = cupyx.scipy.fftpack.get_fft_plan(x, s, axes,
value_type='R2C')
Note that ``plan`` is defaulted to ``None``, meaning CuPy will use
an auto-generated plan behind the scene.
Returns:
cupy.ndarray:
The transformed array which shape is specified by ``s`` and type
will convert to complex if the input is other. The length of the
last axis transformed will be ``s[-1]//2+1``.
.. seealso:: :func:`scipy.fft.rfft2`
"""
return rfftn(x, s, axes, norm, overwrite_x, plan=plan)