如何实时计算加速度计数据的时间导数 (jerk) (Java)?

How should one calculate the time derivative of accelerometer data (jerk) in real-time (Java)?

我正在尝试根据 onReceive() 循环 Android 方法中的流式加速度计数据计算加速度(加加速度)的时间导数。

我假设,从一个传感器更新到下一个传感器更新,我可以通过简单地计算增量加速度 (x, y, z) 和相关的增量时间来对此进行近似。为了确保最大的准确性,我使用了 System.nanoTime() 方法(并除以 10e8)。

一切似乎都很愉快,并且出现了混蛋数据,但我认为检查所有 delta_time 的总和(sumDeltaTime)是否接近 [=16= 之间的差异是明智的] 和 first_time。令我惊讶的是,差异是几千倍。即使将 System.nanoTime() 替换为 System.currentTimeMillis()(除以 10e2)也没有改变这种差异。这是我的代码:

// calculate jerk (time derivative of acceleration)

accel_count++;

if (accel_count == 1) {
    first_time = new_time = System.nanoTime() / 10e8; // captures first time value (in seconds)
    newAccel[0] = accel[0]; // x
    newAccel[1] = accel[1]; // y
    newAccel[2] = accel[2]; // z
    } else {
    prev_time = new_time; // assigns previous time value
    new_time = System.nanoTime() / 10e8; // immediately updates to the new time value (in seconds)
    prevAccel[0] = newAccel[0]; // x
    prevAccel[1] = newAccel[1]; // y
    prevAccel[2] = newAccel[2]; // z
    // set up for next iteration
    newAccel[0] = accel[0]; // x
    newAccel[1] = accel[1]; // y
    newAccel[2] = accel[2]; // z
    }
float[] delta_accel; // difference in acceleration between consecutive sensor measurements
delta_accel = new float[] {
    (newAccel[0] - prevAccel[0]), // x
    (newAccel[1] - prevAccel[1]), // y
    (newAccel[2] - prevAccel[2])  // z
    };
double delta_time = (new_time - prev_time); // time difference between consecutive sensor measurements (in seconds)

float[] jerk;
jerk = new float[] {
    (float) (delta_accel[0] / delta_time), // x
    (float) (delta_accel[1] / delta_time), // y
    (float) (delta_accel[2] / delta_time)  // z
    };

total_time = new_time - first_time; // total time duration of entire recording (in seconds)
sumDeltaTime += delta_time; // testing sum of deltas

有人能看出我做错了什么吗?谢谢!

你没有在第一遍(accel_count == 1)初始化prev_time,所以你第一次计算delta_time时可能是0。这使得第一个 delta_time 异常大,因为 new_time 比 0 大得多,就像 System.nanoTime() 比 0 大得多。