1.5.12.3. 对信号进行去趋势化

scipy.signal.detrend() 去除线性趋势。

生成具有趋势的随机信号

import numpy as np
t = np.linspace(0, 5, 100)
rng = np.random.default_rng()
x = t + rng.normal(size=100)

去趋势

import scipy as sp
x_detrended = sp.signal.detrend(x)

绘图

import matplotlib.pyplot as plt
plt.figure(figsize=(5, 4))
plt.plot(t, x, label="x")
plt.plot(t, x_detrended, label="x_detrended")
plt.legend(loc="best")
plt.show()
plot detrend

脚本总运行时间:(0 分钟 0.053 秒)

由 Sphinx-Gallery 生成的图库