1

我发现此代码用于计算用户的脚步,但它无法正常工作。它没有显示确切的结果。

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

它也在检测错误的步骤。如何通过应用过滤器删除错误步骤?

几天来我一直在寻找信息,并在这里找到了一些信息:http ://www.analog.com/library/analogDialogue/archives/41-03/pedometer.html ,但我无法应用它。

4

1 回答 1

0

它可能有助于获得加速度矢量的大小,而不是测试 x、y 或 z。你为什么不绘制数据,看看哪里出错了?例如,保留一组加速度矢量幅度,并标记它们触发步骤的位置。像这样的东西:

typedef struct accelData {
    float mag;
    BOOL causedStep;
} accelData;
accelData gAcceleration[kMaxDataPoints];
int i = 0;
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    const float violence = 1.2;
    float magnitudeOfAcceleration = sqrt (acceleration.x*acceleration.x + acceleration.y * acceleration.y + acceleration.z * acceleration.z);
    BOOL shake = magnitudeOfAcceleration > violence;
    gAcceleration[i].mag = magnitudeOfAcceleration;
    if (shake)
    {
        steps++;
        gAcceleration[i].causedStep = YES;
    }
    else
    {
        gAcceleration[i].causedStep = NO;
    }
}

一旦你有了这些数据,你就可以分析它,看看是什么导致了错误的步骤记录。也许您需要对数据进行低通滤波以减少噪声或类似的东西。

于 2012-10-28T00:15:11.013 回答