我有一个程序,连接到一个蓝牙加速计和读取数据,以确定实时运动,我正试图找出如何平滑噪声,以便我可以更好地表示运动。我发现了一个巴特沃斯过滤器的scipy函数(请原谅我对过滤器的无知),但它似乎只有当你有整个情节,因为它在平滑噪声的前后看点的工作。如何动态平滑噪音?这是我的密码:
def animator():
global xyz
fig = plt.figure()
xyz_mot = fig.add_subplot(111, projection = "3d")
xyz_mot.set_title("Motion")
xyz_mot.set_xlim3d(-100, 100)
xyz_mot.set_ylim3d(-100, 100)
xyz_mot.set_zlim3d(-100, 100)
xyz = xyz_mot.scatter(0,0,0)
ani = FuncAnimation(fig, updateAni, frames=2, interval=50)
fig.show()
def updateAni(i):
t = float(time_data[-1] / 1000)**2
xmot[0] = .5 * acceleration_data[-1].x * t
ymot[0] = .5 * acceleration_data[-1].y * t
zmot[0] = .5 * acceleration_data[-1].z * t
xyz._offsets3d = (xmot, ymot, zmot)
#print("X Motion: " + str(xmot) + ", Y Motion: " + str(ymot))
#print(time_data[-1])
加速计数据和时间数据正在从另一个线程添加到数组acceleration_data
和time_data
。是否有matplotlib/其他库函数来平滑噪声?感谢您的帮助
查看通过exponential averaging或moving average过滤器运行的数据。指数平均允许你用alpha参数来权衡平均速度和速度。在添加到输出阵列之前,过滤来自加速计的原始数据。你知道吗
下面的代码片段实现了简单的指数平均器
我不想把原始加速数据从辅助线程添加到
acceleration_data
,而是通过使用缓冲区不断地取最后几个测量值的平均值来过滤那里的数据。如果没有线程的代码,我只能给你一些伪代码,但这应该能让你了解它的工作原理相关问题 更多 >
编程相关推荐