**3.2. EKF strategy**

A quaternion-based EKF is proposed in this section for determining the attitude of the AUV from the outputs of IMU. Attitude estimation is a very important part of the AIRS. If the initial data are double integrated into larger errors without bound, it brings on the misclassification of ANN algorithm with wrong attitude values. For the sake of this error, we used a series of measurements and observed over time for signal processing. The main

Design and Estimation of an AUV Portable Intelligent Rescue System Based on Attitude Recognition Algorithm http://dx.doi.org/10.5772/intechopen.79980 55

**Figure 5.** Overview of the SCEKF structure.

advantage of the KF is its ability to provide the quality of the estimate, but the KF only applies to linear and Gaussian models. The EKF conversely is a nonlinear version of the KF which linearizes about an estimate of the current mean and covariance. In view of this, we chose the EKF to filter IMU outputs with a balance of noise canceling and adaptability simultaneously, used in sensing attitude algorithm for AIRS. We proposed the EKF fusing with the accelerometer, gyroscope, and magnetometer integrated with sensor calibration (SC). SCEKF results in an improvement of the orientation accuracy from IMU. A flowchart of structure performed by the proposed SCEKF is capsuled in **Figure 5**.

#### *3.2.1. Prediction step*

$$
\hat{\mathbf{x}}\_k = \Phi(T\_s, \hat{\boldsymbol{\omega}}\_{k-1}) \mathbf{x}\_{k-1}^{(2)} + \hat{\boldsymbol{\nu}}\_{k-1} \tag{1}
$$

$$
\hat{P}\_k = F\_{k-1} P\_{k-1}^{(2)} F\_{k-1}^{-T} + B\_{k-1} Q B\_{k-1}^T \tag{2}
$$

The first step of EKF predicts a current state and covariance matrix at time *k*. We estimated a current state based on the previous states *x*^*<sup>k</sup>*�<sup>1</sup> ¼ ½ � ^*ak*�<sup>1</sup>*ω*^ *<sup>k</sup>*�<sup>1</sup>*m*^ *<sup>k</sup>*�<sup>1</sup> *<sup>T</sup>* that are composed of the gyroscope measurement *ω*^ *<sup>k</sup>*�<sup>1</sup> and white noise *ν* ^*<sup>k</sup>*�<sup>1</sup> <sup>¼</sup> *<sup>a</sup> ν* ^*<sup>k</sup>*�<sup>1</sup> ω*ν* ^*<sup>k</sup>*�<sup>1</sup> *mν* ^*<sup>k</sup>*�<sup>1</sup> *<sup>T</sup>* and the priori covariance matrix *P*^*<sup>k</sup>* based on a previous covariance matrix *P*ð Þ<sup>2</sup> <sup>k</sup>�<sup>1</sup>, covariance *<sup>Q</sup>* and a state noise coefficient matrix *Bk*�1.

#### *3.2.2. Jacobian computation*

$$F\_{k-1} = \frac{\partial \mathcal{O}}{\partial \mathbf{x}} \Big|\_{T\_{\nu}, \hat{\omega}\_{k-1}} = f\_f(T\_s, \hat{\omega}\_{k-1}) \tag{3}$$

$$\check{y}\_k = \mathbf{z}\_k - h(\hat{\mathbf{x}}\_k, \mathbf{0}), \quad H\_k = \frac{\partial h}{\partial \mathbf{x}}\Big|\_{\hat{\mathbf{x}}\_k} = J\_h(\hat{\mathbf{x}}\_k) \tag{4}$$

However, in view of the nonlinear process of state transition *Fk*�<sup>1</sup> and observation *Hk* directly, the EKF approach requires estimation by computing the Jacobian.

#### *3.2.3. Gravity corrections*

$$\mathbf{S}\_k = H\_k \hat{\mathbf{P}}\_k \mathbf{H}\_k^T + \mathbf{R}\_a \tag{5}$$

$$K\_k = \hat{P}\_k H\_k^{\;\!\!\/} \left( H\_k \hat{P}\_k H\_k^{\;\!\/^T} + R\_a \right)^{-1} \tag{6}$$

$$\mathbf{x}\_k^{(1)} = \hat{\mathbf{x}}\_k + \mathbf{K}\_k (\mathbf{a}\_k - H\_k \hat{\mathbf{x}}\_k) \tag{7}$$

$$P\_k^{(1)} = (I\_{4 \times 4} - K\_k H\_k)\hat{P}\_k \tag{8}$$

where the innovation covariance matrix *Sk* is based on the a priori error covariance matrix *P*^*<sup>k</sup>* and the measurement covariance matrix of accelerometer *Ra*, whose main diagonal elements are from the accelerometer values, and nonmain diagonal elements are all zero conversely. The Kalman gain *Kk* is the error covariance matrix after gravity measurement is corrected.

#### *3.2.4. Yaw corrections*

$$S\_k = H\_k P\_k^{(1)} H\_k^T + R\_m \tag{9}$$

$$K\_k = P\_k^{(1)} H\_k^{\;T} \left( H\_k P\_k^{(1)} H\_k^{\;T} + R\_m \right)^{-1} \tag{10}$$

$$\mathbf{x}\_{k}^{(2)} = \mathbf{x}\_{k}^{(1)} + \mathbf{K}\_{k} \left( m\_{k} - H\_{k} \mathbf{x}\_{k}^{(1)} \right) \tag{11}$$

$$P\_k^{(2)} = (I\_{4 \times 4} - S\_k H\_k) P\_k^{(1)} \tag{12}$$

where the measurement covariance matrix of magnetometers *Rm*, which main diagonal elements are from the magnetometer values, non-main diagonal elements are all zero conversely. *P*ð Þ<sup>2</sup> *<sup>k</sup>* is the error covariance matrix after yaw measurement is corrected.

#### **3.3. Feature extraction (FE)**

AUV motions are defined by the six degrees of freedom, including heave, surge, sway, pitch, roll, and yaw, and they are coupling by the vehicle shape, trends, and current interaction. Therefore, the attitude data of AUV is of high dimension and very complex. The value of FE is to reduce the dimension of the large measurement data and prevent program operation to run out of memories. The characteristics of a data segment are to keep the most meaningful features and remove the redundant data. Therefore, the FE methods have been applied for activity detection from accelerometer data [24, 25]. İn order to extract features easily, the continuous measurement data of sensors are divided into many overlapping segments of which each is 20 seconds long, as illustrated in **Figure 6**. A sliding window technique cuts the sensors' data into 20 seconds (550 samples) in each short-term window with 50% overlapping. As previous studies found that the effectiveness of FE on windows with 50% overlap is an effective window size [24].

In this chapter, we adopted principal component analysis (PCA) as the feature selection procedure to lower the dimension of the original features. Feature extraction is highly subjective in nature, it depends on applications. Here, we introduced the following features that are beneficial to the classification of AUV failure detection, and used these features to discriminate the type of AUV activity: (1) min, max; (2) mean; (3) interquartile range (IQR); (4) root mean square (RMS); (5) standard deviation (STD); (6) root mean square error (RMSE); (7) signal magnitude area (SMA); (8) signal vector magnitude (SVM); and (9) averaged acceleration energy (AEE).
