FFT :与示例的边界不同

FFT : not the same boundaries as the example

我必须重新制作一个示例的 FFT 进行训练,但我遇到了一个问题:当我绘制它的 FFT 时,我成功地得到了相同的形状,但边界与示例不同。

这是我必须绘制并进行 FFT 的函数:

该函数预期的截止频率为 2 Hz(0.5 秒)。
(如果你不明白:这意味着在 0.5 秒(FFT 为 2 Hz)时,函数等于 0)

左边是时间相关的函数,右边是傅里叶变换
这就是例子。 纯红线,就是我正在处理的函数

这是我得到的:

如您所见,我的 FFT 图的边界与示例有很大不同。 我在图中有一个因子 10²

你认为问题出在我使用 FFT 的方式上吗? 据说函数归一化了,你觉得区别是从这里来的吗?

这是我写的代码:

npas      = 32768                                # steps for discretization
t         = np.linspace(0,200,npas)              # time discretized (array of npas elements, from 0 to 200)     
f         = np.fft.fftfreq(t.size, d=1.0/npas)   # frequency (for Fourier Transform)  d = sample spacing (inverse of the sampling rate)
swh       = np.zeros(npas)                       # initialization of the array swh (the function we use)
tau0      = 1.0/20

# creation of the function and it's Fourier transform
swh      = (1/tau0)*np.exp(-t/tau0)*(1 + t/tau0 + (t**2)/(2*tau0**2) + (t**3)/(3*tau0**3) - 0.490*t**4/tau0**4) - np.exp(-t/tau0)*(1/tau0 + t/tau0**2 + t**2/tau0**3 - 0.490*(4*t**3)/tau0**4)
swh_f    = np.fft.fft(swh)                       # Fourier transform of swh

##### Plot #####

plt.figure(1)
plt.subplot(1,2,1)
plt.title("Time Function")
plt.plot(t, swh, 'r'  ,  linewidth=1, label = "SWH B = 0.490")             # plot of swh, function of t
plt.legend(loc = 1, prop={'size': 7})                                      # legend position
plt.xlim(0,1.5)

plt.subplot(1,2,2)
plt.title("Frequency Function")
plt.plot(f[0:f.size//2], abs(swh_f[0:npas//2]), 'r'  ,  linewidth=1)       # plot of the Fourier transform, function of f (frequency)
plt.xscale('log')
plt.yscale('log')

plt.show()

感谢您的关注!

您可能想在 FFT 中使用选项 'norm' :

swh_f = np.fft.fft(swh, norm = "ortho")

您可以在此处找到有关 NumPy 的 FFT 实现的更多信息:https://docs.scipy.org/doc/numpy/reference/routines.fft.html#module-numpy.fft