消除记录的加速度计/陀螺仪数据中的噪声

时间:2013-08-14 10:47:30

标签: android accelerometer sensor gyroscope noise

我已经看到了一些答案,可以减少听音时加速度计x,y,z值的噪音,但我的问题有点不同。

我已经有一些记录数据(在csv文件中),如果可能的话,我想删除/减少噪音。

以下是记录的数据:

来自陀螺仪的X,Y,Z

来自陀螺仪的Delta 0-3,以这种方式计算:

axisX = 0;
axisY = 0;
axisZ = 0;
// This timestep's delta rotation to be multiplied by the
// current rotation
// after computing it from the gyro sample data.
if (timestamp != 0) {
        final float dT = (event.timestamp - timestamp) * NS2S;
        // Axis of the rotation sample, not normalized yet.
        axisX = event.values[0];
        axisY = event.values[1];
        axisZ = event.values[2];

        // Calculate the angular speed of the sample
        float omegaMagnitude = FloatMath.sqrt(axisX * axisX + axisY
                * axisY + axisZ * axisZ);

        // Normalize the rotation vector if it's big enough to get
        // the axis (that is, EPSILON should represent your maximum
        // allowable margin of error)
        if (omegaMagnitude > 0.000000001f) {
            axisX /= omegaMagnitude;
            axisY /= omegaMagnitude;
            axisZ /= omegaMagnitude;
        }

        // Integrate around this axis with the angular speed by the
        // timestep in order to get a delta rotation from this
        // sample over the timestep We will convert this axis-angle
        // representation of the delta rotation into a quaternion
        // before turning it into the rotation matrix.
        float thetaOverTwo = omegaMagnitude * dT / 2.0f;
        float sinThetaOverTwo = FloatMath.sin(thetaOverTwo);
        float cosThetaOverTwo = FloatMath.cos(thetaOverTwo);
        deltaRotationVector[0] = sinThetaOverTwo * axisX;
        deltaRotationVector[1] = sinThetaOverTwo * axisY;
        deltaRotationVector[2] = sinThetaOverTwo * axisZ;
        deltaRotationVector[3] = cosThetaOverTwo;

}
timestamp = event.timestamp;
float[] deltaRotationMatrix = new float[9];
SensorManager.getRotationMatrixFromVector(deltaRotationMatrix,deltaRotationVector);

俯仰/滚转/方位/倾斜,以这种方式计算:

// Calculation of the orientation through the
// magnetic-field and accelerometer sensors.
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
    mGravity = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
    mGeomagnetic = event.values;
if (mGravity != null && mGeomagnetic != null) {
    float R[] = new float[9];
    float I[] = new float[9];

    boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
    if (success) {
        float orientation[] = new float[3];
        SensorManager.getOrientation(R, orientation);
        // get the current orientation
        // orientation consist of: azimut, pitch and roll in radians
        azimut = orientation[0] * (180 / (float) java.lang.Math.PI);
        pitch = orientation[1] * (180 / (float) java.lang.Math.PI);
        roll = orientation[2] * (180 / (float) java.lang.Math.PI);
        inclination = SensorManager.getInclination(I) * (180 / (float) java.lang.Math.PI);
    }
}

加速度计的X / Y / Z未写入文件中。

所以我的问题是: 我可以从这些数据中删除噪音吗?

提前致谢。

2 个答案:

答案 0 :(得分:1)

我不知道你是否为时已晚,只要写下以防你仍然需要它。

您可以使用它实现某种过滤器。低通滤波器是典型的。否则,请尝试补充过滤器。

我个人更喜欢卡尔曼滤波器,虽然它的计算成本有点贵。

答案 1 :(得分:0)

由于您没有记录加速计,如果我正确理解您使用的是方向。我建议将欧拉角转换为四元数表示并使用平均来平滑数据,这不是常规平均,见下文。 您可以使用此matlab代码示例通过平均来实现滚动窗口过滤器: https://stackoverflow.com/a/29315869/6589074

一切顺利, 列夫