【问题标题】:Do I need to low pass filter Sensor.TYPE_ROTATION_VECTOR?我需要低通滤波器 Sensor.TYPE_ROTATION_VECTOR 吗?
【发布时间】:2016-06-12 23:43:15
【问题描述】:

正如Readme 中所述,建议对 Android 传感器进行低通滤波。对于软件传感器 TYPE_ROTATION_VECTOR 传感器,是否也建议这样做?

【问题讨论】:

    标签: android sensors android-sensors lowpass-filter


    【解决方案1】:

    是的。你需要这样做。在某些设备上,低通滤波器不适用于软件传感器:

    public class LowPassFilter {
        // Time constant in seconds
        static final float timeConstant = 0.297f;
        private float alpha = 0.15f;
        private float dt = 0;
        private float timestamp = System.nanoTime();
        private float timestampOld = System.nanoTime();
        private float output[] = new float[]{ 0, 0, 0 };
    
        private long count = 0;
    
        public float[] lowPass(float[] input)
        {
            timestamp = System.nanoTime();
    
            // Find the sample period (between updates).
            // Convert from nanoseconds to seconds
            dt = 1 / (count / ((timestamp - timestampOld) / 1000000000.0f));
    
            count++;
    
            // Calculate alpha
            alpha = timeConstant / (timeConstant + dt);
    
            output[0] = calculate(input[0], output[0]);
            output[1] = calculate(input[1], output[1]);
            output[2] = calculate(input[2], output[2]);
    
            return output;
        }
    
    
        float calculate(float input, float output){
            float out = alpha * output  + (1 - alpha) * input;
            return out;
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-29
      • 2011-05-29
      • 2019-04-29
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多