Further research suggests the following options;
- add support for the onboard Digital Motion Processor (DMP) which fuses gyro and accelerometer data to yield, amongst other things, linear acceleration
Pros: should be accurate.
Cons: unknown algorithm used in the processor and no ability to refine or change it if required, sample rate is limited to 200Hz at most (possibly 100Hz, it's not entirely clear).
- roll my own sensor fusion algorithm based on the raw data.
Pros: can maintain the higher sample rate, can use potentially more computationally expensive (and accurate) filters, should be accurate if I write it properly
Cons: I have to write this myself which entails some risk given that I don't know how (quite a few articles on line how to do it thoough), will be inaccurate if I do a bad job
- use a simple low pass filter to calculate gravity per axis and then subtract that from the raw values
Pros: trivial to implement
Cons: seems this must be inherently inaccurate when the sensor is in motion (as this means the actual gravity vector is changing so an estimate of gravity calculated by a low pass filter will be wrong as the estimate lags reality)
still not sure what the best way to go is, the last one is obviously easy to do and is how an app like Vibsensor does it (which means this app should have results that are no worse than VS) so will do that first. I guess it will then mean implementing both the other two options and comparing the 3 approaches to see which one works best in reality.