从iPhone加速度计数据计算Jerk和Jounce

时间:2013-12-24 02:06:20

标签: iphone objective-c math accelerometer physics

我正在尝试用加速度计的加速度数据来计算Jerk(http://en.wikipedia.org/wiki/Jerk_(physics))和jounce(http://en.wikipedia.org/wiki/Jounce)。我想我已经想到了Jerk,但我不确定我为jounce所做的是正确的。任何人都可以确认或否认我正在做的是给我正确的价值(我是否需要考虑时间?)

#define kFilteringFactor    0.4
float prevAccelerationX;
float prevAccelerationY;
float prevAccelerationZ;

float prevJerkX;
float prevJerkY;
float prevJerkZ;



- (void)viewDidLoad
{
[super viewDidLoad];

prevAccelerationX = 0;
prevAccelerationY = 0;
prevAccelerationZ = 0;

prevJerkX = 0;
prevJerkY = 0;
prevJerkZ = 0;

[self changeFilter:[LowpassFilter class]];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0 / kUpdateFrequency];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
}

// UIAccelerometerDelegate method, called when the device accelerates.
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
float pax = prevAccelerationX;
float pay = prevAccelerationY;
float paz = prevAccelerationZ;

float pjx = prevJerkX;
float pjy = prevJerkY;
float pjz = prevJerkZ;

prevAccelerationX = acceleration.x - ( (acceleration.x * kFilteringFactor) +
                                  (prevAccelerationX * (1.0 - kFilteringFactor)) );
prevAccelerationY = acceleration.y - ( (acceleration.y * kFilteringFactor) +
                                  (prevAccelerationY * (1.0 - kFilteringFactor)) );
prevAccelerationZ = acceleration.z - ( (acceleration.z * kFilteringFactor) +
                                  (prevAccelerationZ * (1.0 - kFilteringFactor)) );

// Compute the derivative (which represents change in acceleration).
float jerkX = ABS((prevAccelerationX - pax));
float jerkY = ABS((prevAccelerationY - pay));
float jerkZ = ABS((prevAccelerationZ - paz));


prevJerkX = jerkX - ( ( jerkX * kFilteringFactor) +
                     (prevJerkX * (1.0 - kFilteringFactor)));
prevJerkY = jerkY- ( (jerkY * kFilteringFactor) +
                                      (prevJerkY* (1.0 - kFilteringFactor)) );
prevJerkZ = jerkZ - ( (jerkZ * kFilteringFactor) +
                                      (prevJerkZ * (1.0 - kFilteringFactor)) );

// Compute the derivative (which represents change in acceleration).
float jounceX = ABS((prevJerkX - pjx));
float jounceY = ABS((prevJerkY - pjy));
float jounceZ = ABS((prevJerkZ - pjz));
}

2 个答案:

答案 0 :(得分:2)

为了计算衍生品,是的,您需要花时间考虑。基本上你可以用(a2-a1)/ samplingtime来估计混蛋。它的时间导数是相似的。你使用kFilteringFactor的方式对我来说似乎很奇怪,但可能适合你的特定采样时间。你不应该使用ABS(),因为它对导数来说是完全有效的。

然而,一个大问题可能是低采样频率。手机中的采样频率通常约为60 Hz。这意味着您加速的实际带宽为30 Hz(奈奎斯特频率)。把它减半,这就是你的混蛋带宽。将它和你的带宽减半,即7.5 Hz。粗略地说。超过15赫兹的所有混蛋(仍然是一个有趣的词)和超过7.5赫兹的跳跃不会消失,而是在你的结果之上混淆。因此,不仅您错过了一些信息,您错过的信息实际上会对您的结果造成更大的损害。如果做得好,你需要在每个导数之前进行低通滤波。

答案 1 :(得分:0)

从acclerometer中取几个时间序列点并执行B-Spline Interpolation并找到控制点。 取这些点并利用三阶Berstein多项式,取其一阶导数并将控制点从B样条解决方案馈入导出多项式,其中t介于0和1之间(假设1 Hz采样率.0到1插值一切在那第二个时间)。这些值将是Jerk / Jounce。你将计算前面和侧面以及加速度值。