# Aligning accelerometer readings with vehicle's frame of reference

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).

• Are you asking about gross-alignment of the coordinate frames? For example if the Y axis of the accelerometer is roughly aligned with the vehicle's X axis, then the rotation matrix will have only 0s and 1s in it. Or are you asking about fine-tuned calibration of the rotation matrix which will account for a misalignment between the coordinate frames of fractions of a degree?
– Ben
Commented Apr 11, 2022 at 23:48
• @Ben - Asking about gross-alignment of the coordinate frames, accelerometer installed in vehicle at arbitrary pitch, roll and yaw angles to vehicle's frame of reference. Commented Apr 12, 2022 at 4:33
• Any suggestions anyone? Commented Apr 19, 2022 at 3:28