如何使用加速度计计算步数? [英] How to count steps using an Accelerometer?

查看:730
本文介绍了如何使用加速度计计算步数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须开发与此计步器应用程序相同的功能

I have to develop the same functionality as of this Pedometer App

我观察过这个计步器应用程序非常详细。

I have observed this Pedometer app in very high detail.

这不是一个完美的计步器应用程序。例如,如果您停留/坐在一个地方并握手,它还会检测步数和距离。

It's not a perfect pedometer app. For example, if you stay/sit at one place and shake your hand, it also detects steps counts and distance.

忽略此理想和重力行为,因为在说明中这个应用程序已经提到你应该绑你的iPhone,或者你应该把它放在口袋里计算步数。
这样,我发现这个应用程序工作得非常好,几乎可以检测到所有步骤。

Ignore this ideal and gravity behavior, because in the instructions of this app it's already been mentioned that you should tie up your iPhone or you should place it in your pocket to count steps. This way, I have found this app working very well, it detects almost all steps.

我的问题是:我根据以上开发了一个样本逻辑,但它没有达到那个水平。例如,有时它会同时检测2-3个步骤。有时它工作正常。

My problem is: I have developed one sample according to the above logic, but it's not working up to that level. For example, sometimes it detects 2-3 steps at the same time. And sometimes it works fine.

我的代码:

在viewDidLoad中:

In viewDidLoad:

[[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.2] 







- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    const float violence = 1.2;
    static BOOL beenhere;
    BOOL shake = FALSE;
    if (beenhere) return;
    beenhere = TRUE;
    if (acceleration.x > violence || acceleration.x < (-1* violence))
       shake = TRUE;
    if (acceleration.y > violence || acceleration.y < (-1* violence))
       shake = TRUE;
    if (acceleration.z > violence || acceleration.z < (-1* violence))
       shake = TRUE;
    if (shake) {
       steps=steps+1;
     }
  beenhere = false;
}

我做错了什么?我无法确定阈值。如果我把它做得很高,就不会发现很小的步骤。如果我把它缩小,它会同时注册3-4个步骤。

What am I doing wrong? I am not able to determine the threshold. If I make it high, it won't detect minor steps. If I make it small, it registers 3-4 steps simultaneously.

是否需要执行其他任何实现,或者在此代码中进行一些调整?

Is there any other implementation required to do this, or some tweaks in this code?

我见过所有其他类似的Stack Overflow链接。我发现的任何内容都达不到这个水平。

I have seen all other similar Stack Overflow links. Nothing I have found performs up to this level.

请帮忙。

推荐答案

一直在计算打鼾,而不是步骤,但有一些相同的问题。没有实际答案,但有些建议:

Been counting snores, not steps, but have some of the same issues. No actual answers, but some suggestions:


  1. 需要步骤之间的时间间隔。是的,有人可以慢慢地走路或慢跑,但即使是最快的步骤之间也可能有1/5秒的时间间隔。如果影响看起来比那更快,那么它们可能只是反弹/嘎嘎作响。

  2. 而不是你的固定门槛(暴力根据之前事件的移动平均值,采用可变阈值。

  3. 考虑保留单独的x,y和z阈值,假设手机不会在短时间内改变方向。

  4. 相反不仅仅是忽略超过一定水平的事件,考虑忽略范围之外的事件,限制由两个阈值指定(一个可能只是另一个阈值的一小部分)。

  5. 考虑走路时会发生什么 - 身体向前/向后加速,非常有节奏,脚部撞击地面时会有震动。最好是尝试忽略震动(一个相当短期的信号),而是寻找有节奏的前进/后退动作。

  1. Require a time interval between steps. Yes, someone can be walking slowly or jogging, but even at the fastest there is a time interval of maybe 1/5 second between steps. If "impacts" appear more rapid than that they're likely just from rebound/rattling.
  2. Rather than your fixed threshold (violence) employ a variable threshold, based on a moving average of previous events.
  3. Consider keeping separate x, y, and z thresholds, based on the assumption that the phone will not, over a short period of time, change orientation.
  4. Rather than just ignoring events stronger than a certain level, consider ignoring those outside a range, with limits specified by two thresholds (one perhaps a fraction of the other).
  5. Consider what happens when you walk -- there is a forward/backward acceleration of the body that is quite rhythmic, along with a "shock" as the foot strikes the ground. It may be best to attempt to ignore the shock (a fairly short-term signal) and instead look for the rhythmic forward/backward motion.



< h2>另一个建议

测试这种野兽现场是不可能的。 (我可以想象你试着在你面前拿着笔记本电脑慢跑,试图让调试器控制台集中注意力。)你应该做的是首先装备你的应用程序来制作包含原始内容的一些录音(即写入文件)测量,然后重新装配您的应用程序(#ifdefs在这里很方便),以便能够回放这些测量,以便您可以使用调试器逐步浏览应用程序并观察其行为。

Another suggestion

Testing this beast "live" would be impossible. (I can imagine you trying to jog along while holding the laptop in front of you, trying to get the debugger console to focus.) What you should do is first rig your app to make some recordings (ie, write files) containing the raw measurements, then re-rig your app (#ifdefs would be handy here) to be able to "play back" those measurements so that you can step through the app with the debugger and observe its behavior.

这篇关于如何使用加速度计计算步数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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