This paper presents an extended Kalman filter for real-time estimation of rigid body orientation using the newly developed MARG (Magnetic, Angular Rate, and Gravity) sensors. Each MARG sensor contains a three-axis magnetometer, a three-axis angular rate sensor, and a three-axis accelerometer. The filter represents rotations using quaternions rather than Euler angles, which eliminates the long-standing problem of singularities associated with attitude estimation. A process model for rigid body angular motions and angular rate measurements is defined. The process model converts angular rates into quaternion rates, which are integrated to obtain quaternions. The Gauss-Newton iteration algorithm is utilized to find the best quaternion that relates the measured accelerations and earth magnetic field in the body coordinate frame to calculated values in the earth coordinate frame. The best quaternion is used as part of the measurements for the Kalman filter. As a result of this approach, the measurement equations of the Kalman filter become linear, and the computational requirements are significantly reduced, making it possible to estimate orientation in real time. Extensive testing of the filter with synthetic data and actual sensor data proved it to be satisfactory. Test cases included the presence of large initial errors as well as high noise levels. In all cases the filter was able to converge and accurately track rotational motions.