# An Approach to Industrial Automation Based on Low-Cost Embedded Platforms and Open Software
## 3 System Implementation
### Process Level
#### 3.2.3 Extended Kalman Filter  
The EKF is a variation of the Kalman filter, applied to nonlinear systems. The EKF linearizes the system over an average value, applying the Jacobian to obtain the state matrices \(A_{k}\), \(H_{k}\), \(W_{k}\) and \(V_{k}\), where \(W_{k}\) and \(V_{k}\) are the Jacobians calculated with respect to the random variables \(w_{k}\) and \(v_{k}\), respectively [14]. With these considerations, the equations that define the EKF are  
\[ \begin{split}\bar{\mathbf{x}}_{k}&=f(\hat{\mathbf{ x}}_{k}-1,\mathbf{u}_{k-1},0)\\ \bar{\mathbf{P}}_{k}&=\mathbf{A}_{k}\mathbf{P}_{k-1 }\mathbf{A}_{k}^{T}+\mathbf{W}_{k}\mathbf{Q}_{k}\mathbf{W}_{k}^{T}\\ \mathbf{K}_{k}&=\bar{\mathbf{P}}_{k}\mathbf{H}_{k}^{T }(\mathbf{H}_{k}\bar{\mathbf{P}}_{k}\mathbf{H}_{k}^{T}+\mathbf{R}_{k})^{-1} \\ \hat{\mathbf{x}}_{k}&=\bar{\mathbf{x}}_{k}+\mathbf{K} _{k}(\mathbf{z}_{k}-\mathbf{H}_{k}\bar{\mathbf{x}}_{k})\\ \mathbf{P}_{k}&=(\mathbf{I}-\mathbf{K}_{k}\mathbf{H} _{k})\bar{\mathbf{P}}_{k}\end{split}  \tag{5}\]  
To design the EKF, it is necessary to describe the process as a linear system, as follows:  
\[ \begin{split}\hat{\mathbf{x}}&=\mathbf{A}\mathbf{x }+\mathbf{B}\mathbf{u}\\ \mathbf{y}&=\mathbf{C}\mathbf{x}+\mathbf{D}\mathbf{u} \end{split}  \tag{6}\]  
where \(\hat{\mathbf{x}}\) represents the derivative of \(\mathbf{x}\), \(\mathbf{u}\) represents the control vector \([u_{1}\ u_{2}\ u_{3}]\), \(\mathbf{x}=[h_{1}\ h_{2}]^{T}\) and \(\mathbf{y}=\mathbf{x}\). \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline  & & & & & \multicolumn{4}{c}{\(\hat{e}(k)\)} & \\  & & **NB** & **NM** & **NS** & **ZO** & **PS** & **PM** & **PB** \\ \hline \multirow{6}{*}{\(e(k)\)} & NB & 2 & 2 & 2 & 2 & 2 & 2 & 2 \\  & NM & 3 & 3 & 2 & 2 & 2 & 3 & 3 \\  & NS & 4 & 3 & 3 & 2 & 3 & 3 & 4 \\  & ZO & 5 & 4 & 3 & 3 & 3 & 4 & 5 \\  & PS & 4 & 3 & 3 & 2 & 3 & 3 & 4 \\  & PM & 3 & 3 & 2 & 2 & 2 & 3 & 3 \\  & PB & 2 & 2 & 2 & 2 & 2 & 2 & 2 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Fuzzy rules for \(\alpha\)[13]. \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline  & & & & & & \(\hat{e}(k)\) & & & \\  & & **NB** & **NM** & **NS** & **ZO** & **PS** & **PM** & **PB** \\ \hline \multirow{6}{*}{\(e(k)\)} & NB & B & B & B & B & B & B & B \\  & NM & S & B & B & B & B & B & S \\  & NS & S & S & B & B & S & S \\  & ZO & S & S & S & B & S & S \\  & PS & S & S & B & B & B & S \\  & PM & S & B & B & B & B & B \\  & PB & B & B & B & B & B & B \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Fuzzy rules for \(Kp^{\prime}\)[13]. \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline  & & & & & & \(\hat{e}(k)\) & & & \\  & & **NB** & **NM** & **NS** & **ZO** & **PS** & **PM** & **PB** \\ \hline \multirow{6}{*}{\(e(k)\)} & NB & S & S & S & S & S & S & S \\  & NM & B & B & S & S & S & B & B \\  & NS & B & S & B & S & B & B \\  & ZO & B & B & B & B & B & B \\  & PS & B & B & B & S & B & B \\  & PM & B & B & S & S & S & B \\  & PB & S & S & S & S & S & S \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Fuzzy rules for \(Kd^{\prime}\)[13]. For the Jacobian linearization of the model, the equilibrium point of the system is established at an operating point. The balance points \(\mathbf{x}_{e}=\left[h_{e_{1}}\;\;h_{e_{2}}\right]^{T}\) are obtained considering the control signals \(\mathbf{u}_{e}=\left[u_{e_{1}}\;\;u_{e_{2}}\;\;u_{e_{3}}\right]^{T}\). The relationships to obtain the equilibrium points are  
\[ \begin{split} h_{e_{1}}&=\frac{1}{2g}\left(\frac{q_ {0}u_{e_{1}}}{a_{2}u_{e_{2}}}\right)^{2}\\ h_{e_{2}}&=h_{e_{1}}\left(\frac{q_{2}u_{e_{2}}}{a_{3 }u_{e_{3}}}\right)^{2}\end{split}  \tag{7}\]  
The result of the linearization is presented below:  
\[