平滑值随着时间的推移:移动平均或更好的东西? [英] Smoothing values over time: moving average or something better?

查看:191
本文介绍了平滑值随着时间的推移:移动平均或更好的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码东西的时刻,我从硬件指南针采取了一堆价值随着时间的推移。该罗盘是非常准确的,而且往往更新,其结果是,如果它摇晃咯,我结束了与奇值与邻国的疯狂不一致。我要平滑这些值了。

I'm coding something at the moment where I'm taking a bunch of values over time from a hardware compass. This compass is very accurate and updates very often, with the result that if it jiggles slightly, I end up with the odd value that's wildly inconsistent with its neighbours. I want to smooth those values out.

已经做了一些阅读周围,这样看来,我要的是一个高通滤波器,低通滤波器或移动平均线。移动平均线我可以打倒,只要保持过去的5个值或任何一个历史,我在那里曾经只是使用的是最新值使用这些值的平均值下游在我的code。

Having done some reading around, it would appear that what I want is a high-pass filter, a low-pass filter or a moving average. Moving average I can get down with, just keep a history of the last 5 values or whatever, and use the average of those values downstream in my code where I was once just using the most recent value.

这是应该的,我想,理顺那些摇晃得很好,但它让我觉得,这可能是非常低效的,而且这可能是那些已知的问题,以正确的程序员之一,它有一个非常灵巧聪明的数学解决方案。

That should, I think, smooth out those jiggles nicely, but it strikes me that it's probably quite inefficient, and this is probably one of those Known Problems to Proper Programmers to which there's a really neat Clever Math solution.

我,但是,那些可怕的自学成才的程序员没有接受正规教育的任何东西,甚至隐约相关CompSci或数学一丝一毫之一。读了一下周围暗示,这可能是高或低通滤波器,但我无法找到任何解释条款COM prehensible给像我这样的黑客对这些算法的影响将是值的数组什么,更遑论如何数学工程。给出的答案<一href="http://stackoverflow.com/questions/2272527/how-do-you-use-a-moving-average-to-filter-out-accelerometer-values-in-iphone-os">here,举例来说,在技术上不回答我的问题,但只有在条件COM prehensible那些谁很可能已经知道如何解决这个问题。

I am, however, one of those awful self-taught programmers without a shred of formal education in anything even vaguely related to CompSci or Math. Reading around a bit suggests that this may be a high or low pass filter, but I can't find anything that explains in terms comprehensible to a hack like me what the effect of these algorithms would be on an array of values, let alone how the math works. The answer given here, for instance, technically does answer my question, but only in terms comprehensible to those who would probably already know how to solve the problem.

这将是一个非常可爱和聪明的人确实谁可以解释的问题排序是这样的,而解决方案是如何工作的,无论从理解到学院毕业。

It would be a very lovely and clever person indeed who could explain the sort of problem this is, and how the solutions work, in terms understandable to an Arts graduate.

推荐答案

如果您均线已经长,以达到所需的平滑,而你并不真正需要的内核的任何特定的形状,那么你更好,如果您使用的是指数衰减的移动平均线:

If your moving average has to be long in order to achieve the required smoothing, and you don't really need any particular shape of kernel, then you're better off if you use an exponentially decaying moving average:

a(i+1) = tiny*data(i+1) + (1.0-tiny)*a(i)

你选择微小是一个合适的常量(例如,如果你选择微小= 1- 1 / N,这将有平均为窗口等量大小N,但分布在不同的年长点)。

where you choose tiny to be an appropriate constant (e.g. if you choose tiny = 1- 1/N, it will have the same amount of averaging as a window of size N, but distributed differently over older points).

总之,由于均线的下一个值只依赖于previous之一,你的数据,你没有保持队列或任何东西。你可以认为这是做这样的事情,嗯,我已经有了一个新的起点,但我真的不相信它,所以我要保持80%的测量我的老估计,只有相信这个新的数据点的20%。这是pretty的一样一样的说:好吧,我只相信这个新的点20%以上,我将使用4,我相信同样数量其它点,不同的是,而不是明确采取其他4点,你假设平均跟上次是明智的,所以你可以用你的previous工作。

Anyway, since the next value of the moving average depends only on the previous one and your data, you don't have to keep a queue or anything. And you can think of this as doing something like, "Well, I've got a new point, but I don't really trust it, so I'm going to keep 80% of my old estimate of the measurement, and only trust this new data point 20%". That's pretty much the same as saying, "Well, I only trust this new point 20%, and I'll use 4 other points that I trust the same amount", except that instead of explicitly taking the 4 other points, you're assuming that the averaging you did last time was sensible so you can use your previous work.

这篇关于平滑值随着时间的推移:移动平均或更好的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆