在任意时间获取过滤器的值

发布于 2024-09-01 09:08:11 字数 635 浏览 3 评论 0 原文

上下文:我正在尝试改进 iPhone CLLocationManager 返回的值,尽管这是一个更普遍适用的问题。关键是 CLLocationManger 在感觉合适时返回当前速度的数据,而不是以固定的采样率。

我想使用反馈方程来提高精度

v=(k*v)+(1-k)*currentVelocity

其中 currentVelocity 是 didUpdateToLocation:fromLocation: 返回的速度,v 是输出速度(也用于反馈元件)。

由于 didUpdateToLocation:fromLocation: 的“as and when”性质,我可以计算自上次调用以来的时间间隔,并执行类似

for (i=0;i

可以工作,但浪费周期。特别是因为我可能希望将 timeintervalsincelastcalls 测量为十分之一秒。

有没有办法在没有循环的情况下解决这个问题?即重写(积分?)公式,以便我在方程中放入一个区间,并得到与迭代相同的答案?

Context: I'm trying to improve the values returned by the iPhone CLLocationManager, although this is a more generally applicable problem. The key is that CLLocationManger returns data on current velocity as and when it feels like it, rather than at a fixed sample rate.

I'd like to use a feedback equation to improve accuracy

v=(k*v)+(1-k)*currentVelocity

where currentVelocity is the speed returned by didUpdateToLocation:fromLocation: and v is the output velocity (and also used for the feedback element).

Because of the "as and when" nature of didUpdateToLocation:fromLocation: I could calculate the time interval since it was last called, and do something like

for (i=0;i<timeintervalsincelastcalled;i++) v=(k*v)+(1-k)*currentVelocity

which would work, but is wasteful of cycles. Especially as I probably want timeintervalsincelastcalled to be measured as 10ths of a second.

Is there a way to solve this without the loop ? i.e. rework (integrate?) the formula so I put an interval into the equation and get the same answer as I would have by iteration ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一生独一 2024-09-08 09:08:11

如果您编写原始方程,则

v = k*vCurrent + (1-k)*v 

可以应用另一个SO问题

If you write your original equation as

v = k*vCurrent + (1-k)*v 

you can apply the answer from another SO question.

独夜无伴 2024-09-08 09:08:11

您可以根据间隔的大小选择 k 的值,而不是迭代。例如,如果间隔长度是一小时 - 您可能希望 k 为 0。

可以很容易地预先计算各种间隔大小的 k,以给出与迭代给出的相同答案。只需通过迭代计算变化(您已经有相应的代码),然后计算 k 的值即可以代数方式得出该值。

使用查找值表来代替昂贵的计算是一个常见的程序员绝地技巧。 (现在我的答案与代码有关!)

Instead of iterating, you could just choose the value of k based on the size of the interval. For example, if the interval length is an hour - you'd probably want k to be 0.

It would be easy to precompute k for a variety of interval sizes to give the same answer as the iteration would give. Just compute the change by iterating (you already have code for that), and then compute the value of k that would give you that algebraicly.

It's a common programmer jedi trick to have a table of lookup values in place of expensive calculations. (there, now my answer has something to do with code!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文