def detrend(x, order=1, axis=-1):
"""Detrend the array x.
Parameters
----------
x : n-d array
Signal to detrend.
order : int
Fit order. Currently must be '0' or '1'.
axis : integer
Axis of the array to operate on.
Returns
-------
xf : array
x detrended.
Examples
--------
As in scipy.signal.detrend:
>>> randgen = np.random.RandomState(9)
>>> npoints = int(1e3)
>>> noise = randgen.randn(npoints)
>>> x = 3 + 2*np.linspace(0, 1, npoints) + noise
>>> (detrend(x) - noise).max() < 0.01
True
"""
from scipy.signal import detrend
if axis > len(x.shape):
raise ValueError('x does not have %d axes' % axis)
if order == 0:
fit = 'constant'
elif order == 1:
fit = 'linear'
else:
raise ValueError('order must be 0 or 1')
y = detrend(x, axis=axis, type=fit)
return y
filter.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录