I was trying to get roll ,pitch, yaw by applying direction cosine matrix , used accelerometer and gyro for roll and pitch, and magnetometer and gyro for yaw. I could get the readings perfectly but after rotating the my cicuit board in 3D space and bringing it back to original position i found that the roll and pitch remain almost same as original but there was a considerable change in yaw. Can anyone provide a solution to stabilize yaw???