我编写了一个 python 代码来获取 2D 信号并对其进行 FFT,现在我想提取与 FFT 相关的频率。失败,np.fft.fftfreq
给我错误
File "/usr/lib64/python2.7/site-packages/numpy/fft/helper.py", line 153, in fftfreq
assert isinstance(n,types.IntType) or isinstance(n, integer)
AssertionError
我的代码是:
import numpy as np
import scipy as sp
import pylab
import sys
import math
filename = sys.argv[1] # Get name of file to open
ifp = open(filename, "r")
ifp.seek(0)
nrows = 0
ncols = 0
nrows = sum(1 for line in ifp) # Sum over all the lines in the file ptr
ifp.seek(0) # Set the fptr back to beginning of file
for line in ifp:
ncols = len(line.split()) #Split and count number of words in a line
if ncols > 0:
break
OrigData = np.zeros([nrows, ncols], dtype=np.float32) #Allocate numpy array
FFTData = np.zeros([nrows, ncols], dtype=complex)
IFFTData = np.zeros([nrows, ncols], dtype=complex)
FreqComp = np.zeros([nrows, ncols], dtype=np.float32)
ii = 0
jj = 0
ifp.seek(0)
for line in ifp:
linedata = line.split()
jj = 0
for el in linedata:
OrigData[ii,jj] = float(el)
jj+=1
ii+=1
ifp.close()
FFTData = np.fft.fft2(OrigData)
FreqComp = np.fft.fftfreq(FFTData, d=2)
#--- Continue with more code ---#
我知道除了这np.fft.fftfreq
条线之外的其他一切都有效,因为我最后添加了它。如何提取二维频率分量?