【发布时间】:2019-10-11 07:31:05
【问题描述】:
我似乎正在使用 np.fft.fft 为原始波计算不正确的幅度。
显示了 fft 的图,您可以看到显示的幅度在 3 和 1.5 左右,但是如果您查看代码,我正在使用幅度 7 和 3 来生成信号。该图应该有两个尖峰,在 x=13 处达到 y=3,在 x=15 处达到 y=7
我需要做什么才能在图表中看到正确的幅度(3 和 7)?
我可以通过实验看到我需要将振幅乘以 2.3 的常数,但我如何准确计算这个数字?
import numpy as np
import matplotlib.pyplot as plt
t0 = 0
t1 = 20
n_samples = 1000
xs = np.linspace(t0, t1, n_samples)
# Generate signal with amplitudes 7 and 3
ys = 7*np.sin(15 * 2 * np.pi * xs) + 3*np.sin(13 * 2 * np.pi * xs)
np_fft = np.fft.fft(ys)
amplitudes = 1/n_samples * np.abs(np_fft) #This gives wrong results
frequencies = np.fft.fftfreq(n_samples) * n_samples * 1/(t1-t0)
plt.plot(frequencies[:len(frequencies)//2], amplitudes[:len(np_fft)//2])
plt.show()
【问题讨论】:
-
你会在这里找到信息:dsp.stackexchange.com/questions/16438/…
-
@Dadep 谢谢你是对的,如果我乘以 2 并添加更多频率区间,它就可以工作。