2016-06-12 28 views

Antwort

0

Ja. Du musst es tun. Bei einigen Geräten wird der Tiefpassfilter nicht auf Software-Sensoren angewendet:

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


}