Here is an example code for Kalman filter based sensor fusion in MATLAB. This code fuses measurements from a gyroscope and an accelerometer to estimate the orientation of an object in 3D space.
main.m1640 chars57 lines
In this code, the state vector contains three angles and their first derivatives, and the observation matrix only measures the three angles from the accelerometer. The process noise covariance matrix and measurement noise covariance matrix are defined based on the expected noise characteristics of the sensors. The Kalman filter loop alternates between prediction and correction steps, where the predicted state and covariance are corrected based on the current measurement. The estimated angles are then stored and plotted.
gistlibby LogSnag