我正在尝试使用pandas,NumPy和SciPy过滤大量的加速度计数据。我想自定义我的频率响应,所以我发现firwin2是一个很好的过滤选项。这是我过滤数据流的代码:
def actigraph_filter(series):
SF=25
Nyq=SF/2
points = np.arange(0,13,1)
gain = [0, .05, .4, .95, 1, .9, .85, .7, .6, .45, .35, .25, 0]
b = signal.firwin2(numtaps=170, freq=points, gain=gain, nyq=Nyq)
return signal.filtfilt(b, [1.0], series)
我的数据以25 Hz的速度录制,正如您所看到的,我勾勒出一个(非常)粗略的频率响应,只是为了让事情变得有效。 此函数在管道中运行以读取,过滤并最终为我的数据生成计数,但是当我在一段数据上运行代码时,我收到此错误:
File "/Users/wharper/Accelerometry-Data-Processing/geneactiv_counts.py", line 45, in actigraph_filter
return signal.filtfilt(b, [1.0], series)
File "/Users/wharper/accelerometry/lib/python2.7/site-packages/scipy/signal/signaltools.py", line 3087, in filtfilt
ntaps=max(len(a), len(b)))
File "/Users/wharper/accelerometry/lib/python2.7/site-packages/scipy/signal/signaltools.py", line 3145, in _validate_pad
ext = odd_ext(x, edge, axis=axis)
File "/Users/wharper/accelerometry/lib/python2.7/site-packages/scipy/signal/_arraytools.py", line 102, in odd_ext
ext = np.concatenate((2 * left_end - left_ext,
TypeError: unsupported operand type(s) for -: 'str' and 'str'
我不太确定如何继续。 有没有人有任何见解?