Referring to this stackoverflow thread Transforming accelerometer's data from device's coordinates to real world coordinates
I had similar scope of problem but it differs. I want to implement some sort of an algorithm that could compute the four cardinal directions i.e. North East West South irrespective of the phone facing. For Example, If the phone is facing East and and the user is walking in the north direction then phone will still be showing the east direction , which is wrong the phone now should be show the north direction. In my idea i can get this to work if I could be able to transform the acceleration to the real world and then determining the direction of acceleration to show the real world coordinates.
Looking forward for your people's reply and suggestions.