# Review on System Identification and Mathematical Modeling of Flapping Wing Micro-Aerial Vehicles
## 3 System Identification and Mathematical Modeling of Flapping Wing Micro Air Vehicles (FWMAVs)
### Tailed Flapping Wing Micro-Air Vehicles
#### 3.1.2 System Identification of DelFly II Based on Extended Kalman Filter  
Another system identification approach that has been applied to obtain the flight dynamics equations of DelFly II is the extended Kalman filter (EKF) [134]. This approach is the nonlinear version of the Kalman filter that is used to fuse the flight data obtained from the on-board inertial measurement unit (IMU) and external optical tracker OptiTrack [134]. The idea is to use the slow time-scale, but highly accurate data (with the typical average tracking error of 1-2 mm) from the OptiTrack as a basis, especially on cycle-averaged and long-term level, and the fast time-scale data (in this case 512 Hz was used) such as the attitude and the rates and acceleration data from IMU to provide accurate high-frequency data and compensate for error in the tracking data. Therefore, this system identification approach is essentially a closed-loop system identification in which the sensor dynamics are included in the model. The EKF approach is based on the Kalman filter idea and results in a linear model. However, it is able to deal with nonlinear systems, and it provides optimal estimates to identified parameters. It consists of two phases: the prediction and innovation phases [134]. The main equations are described in the state-space Equations (6)-(12):  
\[x(t_{k+1})=f(x_{k},\ u_{k},\ t_{k})+g(u_{k},t_{k})+w(t_{k}), \tag{6}\]  
\[z(t_{k})=h(x,u,t_{k})+v(t_{k}), \tag{7}\]  
where \(x\), \(u\), \(z\), \(w\), and \(v\) denote the states, input, measured output, process noise, and measurement noise, respectively. Both process and measurement noise are assumed to be white and Gaussian, and defined by the covariance matrices \(Q\) and \(R\), respectively. Prediction phase:  
\[\hat{x}_{k+1,k}=\hat{x}_{k,k}+\int_{t_{k}}^{t_{k+1}}f(\hat{x}_{k,k},u_{k},t)dt \tag{8}\]  
\[P_{k+1,k}=\Phi_{k+1,k}P_{k,k}\Phi_{k+1,k}^{T}+\Gamma_{k+1,k}Q_{k+1}\Gamma_{k+1,k}^{T} \tag{9}\]  
Innovation phase:  
\[K_{k+1}=P_{k+1,k}H_{k}^{T}\Big{[}H_{k}P_{k+1,k}H_{k}^{T}+R_{k+1}\Big{]}^{-1}, \tag{10}\]  
\[\hat{x}_{k+1,k+1}=\hat{x}_{k+1,k}+K_{k+1}[z_{k+1}-h(\hat{x}_{k+1,k},u_{k+1})], \tag{11}\]  
\[P_{k+1,k+1}=P_{k+1,k}-K_{k+1}H_{k}P_{k+1,k}^{T} \tag{12}\]  
where \(x_{k}\) is the discretized state vector of the linearized system at step \(k\); \(\Phi\) is the discretized state transition; \(P\) is the estimated measurement error covariance matrix; \(\Gamma\) is the corresponding input matrix; \(K\) is the Kalman gain; and \(H\) is the Jacobian of the measurement equation. \(Q\) and \(R\) are the covariance matrices that describe the process and measurement noise, respectively. The EKF was designed to estimate the velocities, body attitude, gyro, and accelerometer biases. The IMU and OptiTrack data were used as the input variables and output measurements, respectively. The OptiTrack provided positions and attitude data, which were computed from the OptiTrack-measured quaternions. From these data, through numerical differentiation and relevant coordinate transforms, the velocities were computed and were fed to the EKF as measurements, \(\big{[}\ u_{b}^{s}\quad v_{b}^{s}\quad w_{b}^{s}\big{]}\). With the z-axis positive upward, the body-frame velocities were given by [134]. \[\left[ \begin{array}{c}u_{b}^{s}\\ v_{b}^{s}\\ w_{b}^{s}\end{array} \right]=\left[ \begin{array}{ccc}\cos\psi\cos\theta&\cos \theta\sin\psi&-sin\theta\\ \cos\psi\sin\phi-\cos\phi\sin\psi&\cos\phi\cos\psi+\sin\phi\sin\psi\sin\theta& \cos\theta\sin\phi\\ \sin\phi\sin\psi+\cos\phi\cos\psi\sin\theta&\cos\phi\sin\psi\sin\theta-\cos\psi \sin\phi&\cos\phi\cos\theta\end{array} \right]\left[ \begin{array}{c}\dot{x}\\ \dot{y}\\ \dot{z}\end{array} \right]_{OT} \tag{13}\]  
The quaternions were then used to calculate the Euler angles as it is done in the conventional mathematical modeling of aircraft.