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

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

问题描述

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

我非常详细地观察了这个计步器应用.>

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

忽略这种理想和重力行为,因为在这个应用程序的说明中已经提到你应该把你的 iPhone 绑起来或者你应该把它放在你的口袋里来计算步数.通过这种方式,我发现这款应用运行良好,几乎可以检测所有步骤.

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

我的代码:

在 viewDidLoad 中:

[[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.2]

<小时>

- (void)accelerationometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {const float 暴力 = 1.2;静态 BOOL 在这里;布尔抖动 = FALSE;如果(去过)返回;去过这里 = TRUE;if (acceleration.x > 暴力 || 加速度.x <(-1* 暴力))摇=真;if (acceleration.y >暴力 || 加速度.y < (-1*暴力))摇=真;if (acceleration.z > 暴力 || 加速度.z <(-1* 暴力))摇=真;如果(摇晃){步数=步数+1;}去过这里=假;}

我做错了什么?我无法确定阈值.如果我把它调高,它就不会检测到小步骤.如果我把它变小,它会同时注册 3-4 个步骤.

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

我看过所有其他类似的 Stack Overflow 链接.我发现没有任何东西达到这个水平.

请帮忙.

解决方案

一直在数鼾声,而不是步数,但有一些相同的问题.没有实际答案,但有一些建议:

  1. 步骤之间需要时间间隔.是的,有人可以慢走或慢跑,但即使在最快的情况下,步骤之间也可能有 1/5 秒的时间间隔.如果影响"看起来比它们可能只是由于反弹/嘎嘎作响来得更快.
  2. 而不是您的固定阈值(暴力)采用可变阈值,基于之前事件的移动平均线.
  3. 假设手机在短时间内不会改变方向,请考虑保持单独的 x、y 和 z 阈值.
  4. 与其仅仅忽略强度超过某个级别的事件,还可以考虑忽略范围之外的事件,其限制由两个阈值(一个可能是另一个阈值的一小部分)指定.
  5. 想想你走路时会发生什么——身体有节奏地向前/向后加速,同时伴随着震动".当脚着地时.最好尝试忽略冲击(一个相当短期的信号),而是寻找有节奏的向前/向后运动.

另一个建议

测试这个野兽活"是不可能.(我可以想象你一边拿着笔记本电脑一边慢跑,一边试图让调试器控制台聚焦.)你应该做的是首先装备你的应用程序来制作一些包含原始数据的录音(即,写入文件)测量,然后重新装配您的应用程序(#ifdefs 在这里很方便)以便能够回放";这些测量值,以便您可以使用调试器单步调试应用程序并观察其行为.

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.

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.

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.

My code:

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;
}

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?

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

Please help.

解决方案

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

  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.

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天全站免登陆