This paper presents an orientation filter using complementary filter applicable to low-cost sensors based on micro electro-mechanical system (MEMS). The MEMS implementation incorporates magnetic distortion and gyroscope bias drift compensation. The filter uses a quaternion representation, allowing accelerometer and magnetometer data to be used in an analytically derived andoptimized gradient-descent algorithm to compute the direction of the gyroscope measurement error as a quaternion derivative. The benefits of the filter are: (1) low scalar arithmetic operations for each filter update, (2) It is effective at low sampling rates; e.g. 10 Hz and (3) It contains adjustable parameters defined by observable system characteristics. The Performance was evaluated empirically using a commercially available orientation sensor and reference measurements of orientation obtained usingan accurate servo motor (resolution <0.3 degree). A simple calibration method is presented for the use of the electric-mechanical measurement equipment in this application. Results indicate that the filter achieves levels of accuracy exceeding that of the Kalman-based algorithm; < 0.821◦ for static RMS error and<2.093◦ for dynamic RMS (Root Mean Square) error. The implications of the low computational load and ability to operate at low sampling rates use of MARG(Magnetic, Angular Rate, and Gravity) sensor arrays in real-time applications of limited power, processing resources or applications that demand extremely high sampling rates