Accelerometer with Sound

If you play a sound on the HTC G1 or Magic via the speaker, the vibrations caused by the speaker makes the accelerometer go crazy. The louder the sound, the worse the effect.

It is discussed here https://groups.google.com/group/android-developers/browse_thread/thread/324a61badc59d58f with no solution.

Someone tried to do some damper code using averaging here https://groups.google.com/group/android-developers/browse_thread/thread/5b4ce338d4c57669/c405d018e26683ab#c405d018e26683ab, however, I tried it out and it reduced the effect, but it was still horrible.

I was thinking maybe there was a better algorithm (not just taking the average) for filtering out the crazy values caused by the sound? Any ideas would be greatly appreciated.

It’s a little annoying, as it really is a hardware problem (accelerometers are not properly shielded from the speaker), however, a software fix would be great.

Cheers.

I suspect that this is going to be distinctly non-trivial. Filtering out high-frequency noise to get the low-frequency signal is tricky, and can make the output feel a bit laggy. Look here and here for some things to try.

One potentially crutch that you have is that you know, or can find out, the frequency and amplitude of the noise signal. It probably won’t just be the frequency that the speaker is playing, as the vibrations picked up by the accelerometer will depend on the design of the phone. You could try playing a range of different frequencies on through the speaker, analyse the resulting accelerometer signal, and try and compute some relationship between speaker signal and accelerometer output. With this knowledge, you have a much better idea of the characteristics of the unwanted accelerometer noise and thus a better chance at filtering it.
However, this is a lot of work and probably not practical for the dalvik VM to be bothering with at runtime.