用FFTW包进行FFT分析时,结果与理论相差较大,请问是我哪里用法不对吗?
using PyCall,FFTW
function fft_gear(Fs,x,fmin,fmax)
YY = complex(x)
L = length(x)
NFFT = nextpow(2,L)
fft!(YY)
ff = Fs/2*LinRange(0.0,1.0,div(NFFT,2)+1)
YFT = 2*abs.(YY[1:div(NFFT,2)+1]/L)
AFT = 2*angle.(YY[1:div(NFFT,2)+1]/L)
ff[findall(x-> x<fmin || x>fmax, ff)] .= 0
YFT[findall(x-> x<fmin || x>fmax, ff)] .= 0
return ff,YFT
end
f = 300
w = 2pi*f
t = LinRange(0,1,2000)
x = @. 10sin(w*t)+5cos(2w*t)
ff,YFT = fft_gear(2000,x,0.0,3000.0)
plt.figure(1)
plt.plot(ff,YFT,"c")
plt.show()
理论频率为300、600HZ,计算出来的292、584Hz左右
理论幅值为10、5,计算出来的也偏小