I have a device with an accelerometer installed in a vehicle. Its orientation in relation to the vehicle is unknown. So I am looking for a reliable way to align the coordinate system of the accelerometer with that of the vehicle. This will allow me to determine acceleration and braking on the x-axis of the vehicle (the driving direction), as well as to identify right and left turns (acceleration around the z-axis).
I am able to capture the stream of accelerometer readings when the vehicle is stationary on level ground, and average the readings (I am using exponential moving average). Let's say the averaged reading (in mG) is {271:-507:-785}. I am also able to accelerate while driving straight ahead (for say 5 seconds), and collect the corresponding accelerometer readings.
My question:
Is it possible, based on the data obtained as described above, to determine the rotation matrix with which I can rotate any future accelerometer readings so they as to align them with the vehicle's frame of reference? Can this be done with a single matrix, and if so, how exactly?
I have found this answer to a similar question. I can understand the general explanation (in terms of what needs to be done), but don't know how to execute it (the "how" aspect). Will appreciate any help as I am not an expert in the maths involved (a simple example would be great).