import matplotlib.pyplot as plt
mu, sigma = 0, 500
x = np.arange(1, 100, 0.1) # x axis
z = np.random.normal(mu, sigma, len(x)) # noise
y = x ** 2 + z # data
plt.plot(x, y, linewidth=2, linestyle="-", c="b") # it include some noise
后过滤器
from scipy.signal import lfilter
n = 15 # the larger n is, the smoother curve will be
b = [1.0 / n] * n
a = 1
yy = lfilter(b,a,y)
plt.plot(x, yy, linewidth=2, linestyle="-", c="b") # smooth by filter
import matplotlib.pyplot as plt
import numpy as np
mu, sigma = 0, 500
x = np.arange(1, 100, 0.1) # x axis
z = np.random.normal(mu, sigma, len(x)) # noise
y = x ** 2 + z # data
plt.plot(x, y, linewidth=2, linestyle="-", c="b") # it include some noise
并应用Savitzky Golay滤波器
from scipy.signal import savgol_filter
w = savgol_filter(y, 101, 2)
plt.plot(x, w, 'b') # high frequency noise removed
这取决于你如何定义“噪音”以及它是如何引起的。既然你没有提供多少关于你的案子的信息,我就把你的问题当作“如何使曲线平滑”。卡尔曼滤波器可以做到,但太复杂了,我更喜欢简单的IIR滤波器
后过滤器
lfilter
是来自scipy.signal的函数。顺便说一下,如果您想使用Kalman滤波器进行平滑,scipy还提供了一个example。卡尔曼滤波也应该在这种情况下工作,只是没有那么必要。
根据您有多喜欢消除噪音,您还可以使用来自
scipy
的Savitzky Golay过滤器。下面以@lyken syu为例:
并应用Savitzky Golay滤波器
将
window_length
增加到501:阅读有关筛选器的详细信息here
相关问题 更多 >
编程相关推荐