1. A method of determining an attitude matrix on a portable electronic device, comprising: determining a first attitude matrix gradient using data from at least one of an accelerometer and a magnetometer; determining a second attitude matrix gradient using data from a gyroscope; determining, on a processor, in real time or substantially real time, a mixing coefficient having a value between 0 and 1, the value of the mixing coefficient based on an acceleration and a magnetic field currently experienced by the portable electronic device; fusing the first attitude matrix gradient and the second attitude matrix gradient based on a mixing coefficient to generate a fused gradient D according to: 
 D =Î²(1âˆ’Î±) C+Î”Î±B wherein C is the first attitude matrix, B is the second attitude matrix, Î² and Î” are first and second weighting parameters, and Î± is the mixing coefficient; and based on the fused gradient, updating a fine attitude matrix for the portable electronic device.