我敢打赌你的正弦波在第一个和最后一个样本中为零?不应该。应该对齐,使最后一个样本之后的下一个样本为零,这样您就可以一个接一个地复制和粘贴信号副本,它们看起来是连续的,没有重复的样本。也许可以把它想象成平铺的桌面壁纸,其中一个边缘在平铺时必须无缝地与另一边缘相接。:)
有关python 示例,请参见https://gist.github.com/endolith/236567 :
# Sampling rate
fs = 128 # Hz
# Time is from 0 to 1 seconds, but leave off the endpoint, so that 1.0 seconds is the first sample of the *next* chunk
length = 1 # second
N = fs * length
t = linspace(0, length, num = N, endpoint = False)
# Generate a sinusoid at frequency f
f = 10 # Hz
a = cos(2 * pi * f * t)
# Use FFT to get the amplitude of the spectrum
ampl = 1/N * abs(fft(a))
查看信号的两个副本如何端到端组合在一起以形成连续波:
发生这种情况时,FFT 能量完全包含在单个 bin 中: