Edited
I would to preface this question, that I understand the effects of noise/error on this.
I have a bunch of data in x, y,z coordinates of linear acceleration as well as time.
I am looking to get distance traveled over time using this data via a double integral. Does this look like the right way to do this?
private class SampleReading
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public long TimeTick { get; set; }
}
private static void ProcessSamples(IList<SampleReading> samples)
{
float dx = 0;
float vx = 0;
float dy = 0;
float vy = 0;
float dz = 0;
float vz = 0;
var graphSb = new StringBuilder();
for (var i = 1; i < samples.Count; i++)
{
var curr = samples[i];
var prev = samples[i - 1];
var dt = curr.TimeTick - prev.TimeTick;
if (dt == 0) continue;
vx += (prev.X + curr.X) / 2.0f * dt;
dx += vx * dt;
vy += (prev.Y + curr.Y) / 2.0f * dt;
dy += vy * dt;
vz += (prev.Z + curr.Z) / 2.0f * dt;
dz += vz * dt;
var distance = Math.Sqrt(dx * dx + dy * dy + dz * dz);
graphSb.AppendLine(curr.TimeTick + ", " + distance);
}
var foo = graphSb.ToString();
}
I've read this post an all of the supporting materials: How can I find distance traveled with a gyroscope and accelerometer?
My result for stationary reading is a an exponential curve. Just want to make sure that my algo is correct and this is just a result of the side effect.