如何计算移动平均线的速度从全球定位系统?平均、速度

2023-09-06 00:06:39 作者:一生就爱浪

我正在开发使用GPS Android应用程序。我想实现一个功能,在15年1月5日分显示用户平均速度。像UNIX上的CPU负载。我可以很容易地计算平均通过累计的距离第二次旅行了第二和经过时间把它,但我想不出计算移动平均线的一个聪明的办法。

I'm developing an android application using GPS. I'd like to implement a feature that displays the users average speed over the 1/5/15 minute. Something like the CPU load on unix. I can calculate average easily by cumulating the distance traveled second by second and divide it by the elapsed time, but I can't think of a smart way of calculating the moving average.

很显然,我可以得到ID通过将距离上次和当前位置之间在一个阵列每秒,同时删除最早的值来完成。

Obviously I can get id done by putting the distance between the last and the current position in an array every second while deleting the oldest value.

我正在寻找一个整洁的方式这样做的。

I'm looking for a neat way of doing this.

推荐答案

您将需要存储的所有值的整个时间跨度,因为你已经建议。其原因是,你以某种方式需要忘记的旧值移动平均的贡献。你可以这样做,完全如果你不知道这些值,其中(也就是说,如果你不将它们存储)。

You will need to store all the values for the whole time span, as you already suggested. The reason is that you somehow need to "forget" the contributions of the old values to the moving average. You can't do that exactly if you don't know what these values where (i.e. if you do not store them).

在你的情况下,1值每秒15分钟,相当于15 * 60 = 900个数据点,这应该是确定。

In your case, 1 value each second for 15 minutes amounts to 15 * 60 = 900 data points, that should be OK.

请注意,你并不需要在整个阵列每次执行金额更新:你可以计算出新的移动平均线从数据点你忘记在那一刻的数量,新的价值和价值

Note that you do not need to perform a sum over the whole array each time you update: You can calculate the new moving average from the number of data points, the new value and the value you are "forgetting" at that moment:

new_average = (n * old_average - x_forget + x_new)

下面, N 是数据点的数量(在你的案件900), x_forget 是你的价值被遗忘和 x_new 是最新的值。然后你把 x_forget 从您的阵列和存储 x_new 在年底前。而不是一个数组,你可能要使用通过链表实现队列。

Here, n is the number of data points (900 in your case), x_forget is the value you are "forgetting" and x_new is the latest value. You then drop x_forget from the front of your array and store x_new at the end. Instead of an array you might want to use a queue implemented via a linked list.