我对python完全陌生。我进行了一个波浪数据测试实验。我有可用的时间序列数据。我如何继续在频域中显示它?有什么可以参考的例子吗?我想出了一个如下所示的程序,但它似乎不起作用。请帮忙。
#Program for Fourier Transformation
import numpy as np
import numpy.fft as fft
import matplotlib.pyplot as plt
def readdat( filename ):
"""
Reads sectional area curve data from file filename
"""
# read all lines of input files
fp = open( filename, 'r')
lines = fp.readlines() # to read the tabulated data
fp.close()
# interpret 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( 'data.dat')
print time
print ampl
spectrum = fft.fft(ampl)
freq = fft.fftfreq(len(spectrum))
print freq