简体   繁体   English

信号fft的幅度错误

[英]Wrong Amplitude of the fft of a signal

I am trying to calculate an fft with Python . 我试图用Python计算fft I am using the function fft.fft and I am applying it to a simple Sinusoidal signal. 我正在使用函数fft.fft,我将它应用于一个简单的正弦信号。 Here is my code: 这是我的代码:

import numpy as np
import matplotlib.pyplot as plt

frames=100
fps=1000

t=np.linspace(0, frames, frames)/fps
x=np.sin(2*np.pi*80*t)+1
plt.plot(t, x, 'o-')
plt.title('seno')
plt.ylabel('sin')
plt.xlabel('time $s$')
plt.grid()
plt.show()

#calculating the fft
sin_fft=np.fft.fft(x)

#calculating the absolute value
sin_fft_abs=np.ones(len(sin_fft))

for i in range(len(sin_fft)):
    sin_fft_abs[i]=np.sqrt((sin_fft[i].real**2)+(sin_fft[i].imag**2))

sin_fft_final=sin_fft_abs/frames

#calculating the frequencies
inc=fps/frames
freq=np.linspace(0, fps-inc, fps/inc)

plt.plot(freq, sin_fft_final, 'o-')
plt.xlim(xmax=fps/2)
plt.title('seno fft')
plt.ylabel('sin fft')
plt.xlabel('f $Hz$')
plt.grid()
plt.show()

It can find the right offset (1 in this simple case), but the amplitude of the peak corresponding to the Sinus Frequency (80 in this case) is half the Amplitude of the Signal, always. 它可以找到正确的偏移(在这个简单的情况下为1),但是对应于正弦频率(在这种情况下为80)的峰值幅度始终是信号幅度的一半。 I have no idea why it finds the correct Offset, but not the correct Amplitude! 我不知道它为什么找到正确的偏移,但不是正确的振幅!

I would be grateful if somebody could help me, Thanks a lot, Francesca 如果有人能帮助我,我将不胜感激,非常感谢Francesca

This is a property of the Fourier transformation that also appears in the FFT. 这是傅里叶变换的一个属性,也出现在FFT中。 Actually, if you plot the full data, you'll see a second peak. 实际上,如果您绘制完整数据,您将看到第二个峰值。 You might want to check numpy.fft.fftfreq at what frequency this actually is. 你可能想以实际的频率检查numpy.fft.fftfreq The frequecies in an FFT usuall go [0, df,..., fmax, -fmax, ..., -df]. FFT中的频率通常为[0,df,...,fmax,-fmax,..., - df]。 So your first peak is at omega , the second at -omega . 所以你的第一个高峰是omega ,第二个高峰是-omega This is because it is a complex analysis, meaning the Fourier Kernel is exp( -1j * omega * t) . 这是因为它是一个复杂的分析,意味着傅里叶核是exp( -1j * omega * t) As sin( omega * t) = 1 / 2j * ( exp( 1j * omega * t) - exp( -1j * omega * t)) , you'll get the two peaks. 由于sin( omega * t) = 1 / 2j * ( exp( 1j * omega * t) - exp( -1j * omega * t)) ,你将获得两个峰值。

In the opposite direction, with a peak amplitude A you'll have your signal as A * exp( 1j * omega * t) + (-A * exp( 1j * (-omega) * t) . If you expand this you'll get 1j * 2 * A * sin( omega * t ) . Hence A is and must be half the amplitude of your sine wave. 在相反的方向,具有峰值幅度A你将把你的信号作为A * exp( 1j * omega * t) + (-A * exp( 1j * (-omega) * t) 。如果你展开这个你'得到1j * 2 * A * sin( omega * t ) 。因此A 并且必须是正弦波振幅的一半。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM