我从这里下载了 marple 数据:
http://www.ece.rice.edu/dsp/courses/elec532/DATA/
然后我尝试从这里运行示例:
http://thomas-cokelaer.info/software/spectrum/html/user/ref_param.html#module-burg
起初,我认为可能是数据格式错误,因此我将数据转换为删除任何前导空格并将其间的空格转换为单个逗号:
cat marple.ascii | sed 's/^[ \t]*//;s/[ \t]*$//' > output.txt
sed 's/ \{1,\}/,/g' output.txt > marple_comma.dat
然后使用以下命令读取文件:
marple_data = numpy.loadtxt('marple_comma.dat', delimiter = ',', dtype = numpy.complex128)
但我得到一个不同的错误:
TypeError: only length-1 arrays can be converted to Python scalars
我尝试了下面的示例。但我得到这个错误。怎么了?
runfile('/home/idf/marple.py', wdir='/home/idf')
Traceback (most recent call last):
File "<ipython-input-14-e02af4ddfead>", line 1, in <module>
runfile('/home/idf/marple.py', wdir='/home/idf')
File "/home/idf/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 682, in runfile
execfile(filename, namespace)
File "/home/idf/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
builtins.execfile(filename, *where)
File "/home/idf/marple.py", line 17, in <module>
p()
File "/home/idf/anaconda/lib/python2.7/site-packages/spectrum/arma.py", line 314, in __call__
ma_params, rho = ma(self.data, self.ma_order, self.ar_order)
File "/home/idf/anaconda/lib/python2.7/site-packages/spectrum/arma.py", line 377, in ma
a, rho, _c = yulewalker.aryule(X, M, 'biased') #! Eq. (10.5)
File "/home/idf/anaconda/lib/python2.7/site-packages/spectrum/yulewalker.py", line 110, in aryule
r = CORRELATION(X, maxlags=order, norm=norm)
File "/home/idf/anaconda/lib/python2.7/site-packages/spectrum/correlation.py", line 131, in CORRELATION
r[k-1] = sum / float(N)
ValueError: setting an array element with a sequence.
import numpy as np
from pylab import *
from spectrum import *
#marple_data = np.genfromtxt('marple.ascii')
marple_data = numpy.loadtxt('marple.ascii')
p = pma(marple_data, 15, 30, NFFT=4096)
p()
p.plot(sides='centerdc')