频率域中的振幅与python中FFT后不匹配时域信号。解释?
我正在尝试在Python中创建功率频谱密度函数,该功能输出幅度频谱密度和累积功率频谱密度图。我正在使用scipy.fft
来计算输出数据的FFT。然后进行计算PSD的操作。可以在下面看到代码。
df = nyquistFreq/(N/2-1) #frequency increment
spacing = 1
freq = df*(np.linspace(start = 0, stop = (N/2+1)*spacing, num = int((N/2)*spacing), endpoint= True)) #creatiing frequency vector
fftData = fft(output.values) #taking the fft of the data
Pxx = (2*(pow(abs(fftData[1:int((N/2+1))]/N), 2)/df))
然后,我以正弦信号的振幅为68,
N = 10000
sampleTime = 0.0001
timE = np.linspace(0, N*sampleTime, N, endpoint = False)
amp = 68*np.sin(2*np.pi*21*timE)
在图上的频率为21个值,但是峰值的振幅为48.08326112068523,而不是68。这是1/sqrt的降低( 2)无论我使用什么振幅,这一直是不变的。有什么办法可以解决此幅度降低,以便频域中的幅度是时域的振幅?可能与Python执行FFT,光谱缩放/密度的方式有关。
I am trying to create a Power spectral density function in python that outputs the amplitude spectral density and cumulative power spectral density graphs. I am using scipy.fft
to compute the FFT of my output data. Then an operation to compute the PSD. The code can be seen below for this.
df = nyquistFreq/(N/2-1) #frequency increment
spacing = 1
freq = df*(np.linspace(start = 0, stop = (N/2+1)*spacing, num = int((N/2)*spacing), endpoint= True)) #creatiing frequency vector
fftData = fft(output.values) #taking the fft of the data
Pxx = (2*(pow(abs(fftData[1:int((N/2+1))]/N), 2)/df))
I am then running this function with a sine signal with an amplitude of 68 and a frequency of 21
N = 10000
sampleTime = 0.0001
timE = np.linspace(0, N*sampleTime, N, endpoint = False)
amp = 68*np.sin(2*np.pi*21*timE)
Values on plot are hard to see, but the peak frequency has an amplitude of 48.08326112068523, not 68. This is a reduction of 1/sqrt(2) that has been constant no matter what amplitude I've used. Is there a way I can get around this amplitude reduction, so that the amplitude in the frequency domain is that of the time domain? Possibly might have something to do with the way python performs FFT, spectral scaling/density.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论