def notSoRandomWalk(shape, std=1, trendFilterLength=32, lpfLength=16):
"""bandpass filter a random walk so that the low-frequency trend /
drift is eliminated and the high-frequency noise is attenuated"""
walk = randwalk(shape, std=std)
filt = np.hamming(trendFilterLength)
filt /= np.sum(filt)
whichAxis = len(walk.shape) > 1 # 0 iff 1d, else 1
# subtract baseline drift, roughly
trend = filters.convolve1d(walk, weights=filt, axis=whichAxis, mode='reflect')
walk -= trend
# subtract noisey spikes
walk = filters.convolve1d(walk, weights=np.hamming(lpfLength), axis=whichAxis, mode='reflect')
return walk
评论列表
文章目录