Hi,
I have a problem with the translation of the accelerometer results
from the phone to the world orientation.
The Z results seem OK  but the X and Y  get wrong values.
It was tested on HTC Hero in horizontal and vertical orientation and
on stable state and during  phone movement.
The Z results gave pretty accurate numbers. it allows to calculate
vertical speed and distance  but the aX and aY values where
unreasonable.
Do you think that the above mentioned filters will solve the X Y
problem?

Attached is the code.
                public void onSensorChanged(SensorEvent event) {
                synchronized (this) {
//                      Log.d("MotionTest", "sensor: " + sensor + ",
x: " + values[0] +
", y: " + values[1] + ", z: " + values[2]);
                        int type = event.sensor.getType();
                        if(type == Sensor.TYPE_ACCELEROMETER) {
                                acceleValues = event.values.clone();
                        } else if (type == Sensor.TYPE_MAGNETIC_FIELD)
{
                                magnetValues = event.values.clone();
                        } else if (type == Sensor.TYPE_ORIENTATION) {
                                orientValues = event.values.clone();
                        }
                SensorManager.getRotationMatrix(mR, mI,
acceleValues ,magnetValues);
//              SensorManager.getOrientation(mR, orientValues);
acceleEarthValues[0]=mR[0]*acceleValues[0]+mR[1]*acceleValues[1]+mR[2]*acce
leValues[2];
acceleEarthValues[1]=mR[3]*acceleValues[0]+mR[4]*acceleValues[1]+mR[5]*acce
leValues[2];
acceleEarthValues[2]=mR[6]*acceleValues[0]+mR[7]*acceleValues[1]+mR[8]*acce
leValues[2];
            }
                drawData();
        }
The mR and mI are defined as:
            private float[] mR = new float[9];
            private float[] mI = new float[9];
Please advice
Thanks
Ofer




On Feb 12, 8:44 am, Frank Weiss <[email protected]> wrote:
> I finally got to spend some time on this, if anyone is still interested. The
> results are promising. I had to brush up on my DSP skills. The core of my
> proof of concept is this:
>
>   /**
>   * A recursive digital band-pass filter with sampling frequency of 12 Hz,
> center 3.6 Hz, bandwidth 3 Hz,
>   * low cut-off 2.1 Hz, high cut-off 5.1 Hz.
>   *
>   * Source:http://www.dspguide.com/ch19/3.htm
>   */
>  class Filter // inner class
>  extends TimerTask {
>   private float a0 = (float) 0.535144118;
>   private float a1 = (float) -0.132788237;
>   private float a2 = (float) -0.402355882;
>   private float b1 = (float) -0.154508496;
>   private float b2 = (float) -0.0625;
>   private float x_1, x_2, y_1, y_2; // x_1 means x[n-1], etc.
>   @Override
>   public void run() {
>    float x_0 = currentInput; // from the enclosing Activity
>    float y_0 = a0 * x_0 + a1 * x_1 + a2 * x_2
>      + b1 * y_1 + b2 * y_2;
>    currentOutput = y_0; // to the enclosing Activity
>    x_2 = x_1;
>    x_1 = x_0;
>    y_2 = y_1;
>    y_1 = y_0;
>   }
>  }
>
> I ran this on a java.util.Timer at 83 ms period, using the highest
> accelerometer sampling of about 10 ms on a Droid. I only used the X axis for
> the proof of concept. For testing, I displayed the RMS of the currentFilter
> output in a horizontal progress bar. The bar remains at zero when the device
> is stationary, < 10% at most movements, including when the accelerometer X
> is +9, when the device is gently tapped on the X axis, or when the vibrator
> kicks in by changing the ringer volume. It goes to 100% when the device is
> shaken at a good 2 Hz or so along the X axis by hand. Checking the cut-off
> frequency (aside from taps and vibrator) is not really possibly manually. I
> did run into some forced closes, probably because in the proof of concept I
> didn't handle the timer in the Activity lifecycle correctly. The main
> problem is the battery use is very high, but this may be because of some
> other processing in my code in the sensor event listener.
>
> Let me know if you guys are still interested in detecting shake and if you
> have any questions. I'll try to post the the complete demo code when I get
> some time.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to