如何将文本文件中保存的加速度计信号转换为频谱图?

时间:2017-11-04 11:30:10

标签: python python-3.x signal-processing accelerometer spectrogram

这是我在python 3.6.1中尝试的代码,但它让我错误!!

import numpy as np
data = np.genfromtxt('filename', dtype=None , delimiter=",")
NFFT = 200     # the length of the windowing segments
Fs = 500  # the sampling rate
Pxx, freqs, bins, im = plt.specgram(data, NFFT=NFFT,   Fs=Fs,noverlap=100, cmap=plt.cm.gist_heat)
plt.show()

还有另一行代码,而不是使用plt.specgram,但它也会出错:

f, t, Sxx = signal.spectrogram(data, Fs)

这是文本文件信号数据:

33,4.9106E+13,-0.6946377,12.680544,0.50395286;
33,4.91061E+13,5.012288,11.264028,0.95342433;
33,4.91061E+13,4.903325,10.882658,-0.08172209;
33,4.91062E+13,-0.61291564,18.496431,3.0237172;

这是错误..

Warning (from warnings module):
  File "C:\Python36\lib\site-packages\matplotlib\mlab.py", line 1281
    "(=%d) >= signal length (=%d)." % (NFFT, len(x)))
UserWarning: Only one segment is calculated since parameter NFFT (=200) >= signal length (=4).
Traceback (most recent call last):
  File "C:/Users/hp/Desktop/hispectrogram.py", line 96, in <module>
    Pxx, freqs, bins, im = plt.specgram(data, NFFT=NFFT,   Fs=Fs,noverlap=100, cmap=plt.cm.gist_heat)
  File "C:\Python36\lib\site-packages\matplotlib\pyplot.py", line 3427, in specgram
    vmin=vmin, vmax=vmax, data=data, **kwargs)
  File "C:\Python36\lib\site-packages\matplotlib\__init__.py", line 1710, in inner
    return func(ax, *args, **kwargs)
  File "C:\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 7215, in specgram
    mode=mode)
  File "C:\Python36\lib\site-packages\matplotlib\mlab.py", line 1288, in specgram
    mode=mode)
  File "C:\Python36\lib\site-packages\matplotlib\mlab.py", line 716, in _spectral_helper
    return_window=True)
  File "C:\Python36\lib\site-packages\matplotlib\mlab.py", line 265, in apply_window
    windowVals = window(np.ones(xshapetarg, dtype=x.dtype))
  File "C:\Python36\lib\site-packages\matplotlib\mlab.py", line 214, in window_hanning
    return np.hanning(len(x))*x
TypeError: invalid type promotion

0 个答案:

没有答案