2016-06-12 4 views

답변

0

예. 당신은 그것을해야합니다. 일부 장치에서는 소프트웨어 센서에 저역 통과 필터가 적용되지 않습니다.

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


} 
관련 문제