我试图计算这组实验数据的傅里叶变换。我最终查看了 0 Hz 分量较高的数据。关于如何删除它的任何想法?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")