我試圖計算實驗數據集的傅里葉變換。我最終看到0 Hz分量更高的數據。任何想法如何消除這一點? 0赫茲組件實際代表什麼?如何過濾fft輸出以刪除0 Hz分量
#Program for Fourier Transformation
# last update 131003, aj
import numpy as np
import numpy.fft as fft
import matplotlib.pyplot as plt
def readdat(filename):
"""
Reads experimental data from the file
"""
# read all lines of input files
fp = open(filename, 'r')
lines = fp.readlines() # to read the tabulated data
fp.close()
# Processing the file data
time = []
ampl = []
for line in lines:
if line[0:1] == '#':
continue # ignore comments in the file
try:
time.append(float(line.split()[0]))
#first column is time
ampl.append(float(line.split()[1]))
# second column is corresponding amplitude
except:
# if the data interpretation fails..
continue
return np.asarray(time), np.asarray(ampl)
if __name__ == '__main__':
time, ampl = readdat('VM.dat')
print time
print ampl
spectrum = fft.fft(ampl)
# assume samples at regular intervals
timestep = time[1]-time[0]
freq = fft.fftfreq(len(spectrum),d=timestep)
freq=fft.fftshift(freq)
spectrum = fft.fftshift(spectrum)
plt.figure(figsize=(5.0*1.21,5.0))
plt.plot(freq,spectrum.real)
plt.title("Measured Voltage")
plt.xlabel("frequency(rad/s)")
plt.ylabel("Spectrum")
plt.xlim(0.,5.)
plt.ylim(ymin=0.)
plt.grid()
plt.savefig("VM_figure.png")
爲什麼我會得到直流偏移?是否由於我的波形生成設備或測量設備有問題? – user2288393
可能是其中的任何一種......您如何生成和測量?它也可以是數字表示形式:如果您的A/D轉換器使用無符號數字作爲輸出,則您的信號將以中間值爲中心。 – pcarranzav