maxframe.tensor.fft.fftfreq#

maxframe.tensor.fft.fftfreq(n, d=1.0, gpu=None, chunk_size=None)[源代码]#

返回离散傅里叶变换的采样频率。

返回的浮点张量 f 包含以采样间隔单位为周期的频率箱中心(起始为零)。例如,如果采样间隔是以秒为单位,则频率单位为周期/秒。

给定窗口长度 n 和采样间隔 d::

f = [0, 1, ...,   n/2-1,     -n/2, ..., -1] / (d*n)   if n is even
f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n)   if n is odd
参数:
  • n (int) -- 窗口长度。

  • d (scalar, optional) -- 采样间隔(采样率的倒数)。默认为 1。

  • gpu (bool, optional) -- 如果为 True,则将张量分配在 GPU 上,默认为 False

  • chunk_size (int or tuple of int or tuple of ints, optional) -- 每个维度上期望的块大小

返回:

f -- 包含采样频率的长度为 n 的数组。

返回类型:

Tensor

示例

>>> import maxframe.tensor as mt
>>> signal = mt.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
>>> fourier = mt.fft.fft(signal)
>>> n = signal.size
>>> timestep = 0.1
>>> freq = mt.fft.fftfreq(n, d=timestep)
>>> freq.execute()
array([ 0.  ,  1.25,  2.5 ,  3.75, -5.  , -3.75, -2.5 , -1.25])