# Research on Permanent Magnet Synchronous Motor Control System Based on Adaptive Kalman Filter
## 2 Theoretical Analysis of the EKF
### The EKF Model of the PMSM  
The mathematical model of PMSM in the \(\alpha\beta\) coordinate system is as follows (1). The model is a prerequisite for the application of EKF:  
\[\left[ \begin{array}{c}u_{\alpha}\\ u_{\beta}\end{array} \right]=\left[ \begin{array}{cc}R_{s}&0\\ 0&R_{s}\end{array} \right]\left[ \begin{array}{c}i_{\alpha}\\ i_{\beta}\end{array} \right]+L_{s}\frac{d}{dt}\left[ \begin{array}{c}i_{ \alpha}\\ i_{\beta}\end{array} \right]+\psi_{f}\frac{d}{dt}\left[ \begin{array}{c}\cos \theta\\ \sin\theta\end{array} \right] \tag{1}\]  
where \(\left[ \begin{array}{cc}u_{\alpha}&u_{\beta}\end{array} \right]^{T}\) and \(\left[ \begin{array}{cc}i_{\alpha}&i_{\beta}\end{array} \right]^{T}\) are stator voltage and the stator current, respectively, \(R_{s}\) is the stator resistance, \(L_{s}\) is the PMSM winding inductance, \(\psi_{f}\) is the rotor permanent magnet flux. Based on (1), the speed is assumed to be constant in a short sampling time. In the \(\alpha\)-\(\beta\) coordinate system, the PMSM equation can be expressed as:  
\[ \begin{array}{c}\frac{di_{\alpha}}{dt}=-\frac{R_{s}}{L_{s}}i_{\alpha}+\frac{ \frac{\psi_{f}\omega_{e}}{L_{s}}}{\sin\theta}+\frac{u_{\alpha}}{L_{s}}\\ \frac{di_{\alpha}}{dt}=-\frac{R_{s}}{L_{s}}i_{\beta}-\frac{\psi_{f}\omega_{e}}{ L_{s}}\cos\theta+\frac{u_{\beta}}{L_{s}}\\ \frac{d\omega_{e}}{dt}=0\\ \frac{d\omega_{e}}{dt}=\omega_{e}\end{array}  \tag{2}\]  
where \(x=\left[ \begin{array}{cc}i_{\alpha}&i_{\beta}&\omega_{e}\end{array} \right]^ {T}\) is a state variable, \(u=\left[ \begin{array}{cc}u_{\alpha}&u_{\beta}\end{array} \right]^{T}\) is a control matrix, \(y=\left[ \begin{array}{cc}i_{\alpha}&i_{\beta}\end{array} \right]^{T}\) is an output variable. So Equation (2) can be expressed as the nonlinear state equation of PMSM:  
\[ \begin{array}{c}\dot{x}(t)=f[x(t)]+B\cdot u(t)+\omega(t)\\ \dot{y}(t)=h[x(t)]+\upsilon(t)\end{array}  \tag{3}\]  
where \(B\) is the input matrix, \(w(t)\) is the state noise, \(\upsilon(t)\) is the measurement noise. Based on the comparison of Formula (2) and Equation (3), the coefficient equation in (4) can be obtained:  
\[ \begin{array}{c}f[x(t)]=\left[\begin{array}{cc}-\frac{R_{s}}{L_{s}}i_{ \alpha}+\frac{\psi_{f}\omega_{e}}{L_{s}}\sin\theta\\ -\frac{R_{s}}{L_{s}}i_{\beta}-\frac{\psi_{f}\omega_{e}}{L_{s}}\cos\theta\\ 0\\ i_{\alpha}\end{array}\right],\\ B=\left[\begin{array}{cc}\frac{1}{L_{s}}&0\\ 0&\frac{1}{L_{s}}\\ 0&0\\ 0&0\\ i_{\alpha}\end{array}\right],\\ h[x(t)]=\left[\begin{array}{c}i_{\alpha}\\ i_{\beta}\end{array}\right]\end{array}  \tag{4}\]  
Since PMSM is a continuous nonlinear system, the continuous nonlinear system of the EKF model should be linearized and discretized. The nonlinear Equation (3) can be expressed in the linearization by using the Taylor-level number:  
\[ \begin{array}{c}\dot{x}=F[x]x+B\cdot u+\omega,\\ \dot{y}=H[x]x+\upsilon\end{array}  \tag{5}\]  
The Jacobian matrices \(F(x)\) and \(H(x)\) can be expressed as:  
\[F(x)=\left.\frac{\partial f}{\partial x}\right|_{x=x(t)}=\left[ \begin{array}[ ]{cccc}-\frac{R_{s}}{L_{s}}&0&\frac{\psi_{f}}{L_{s}}\sin\theta&\frac{\psi_{f}} {L_{s}}\omega_{e}\cos\theta\\ 0&-\frac{R_{s}}{L_{s}}&-\frac{\psi_{f}}{L_{s}}\cos\theta&\frac{\psi_{f}}{L_{s}} \omega_{e}\sin\theta\\ 0&0&0&0\\ 0&0&1&0\end{array} \right] \tag{6}\]\[H(x)=\frac{\partial h}{\partial x}=\left[ \begin{array}{cccc}1&0&0&0\\ 0&1&0&0\end{array} \right] \tag{7}\]  
The sampling time is assumed to be \(T\), the linear state equation of PMSM can be expressed in the discrete equation:  
\[ \begin{array}{l}x_{k}=\Phi x_{k-1}+BTu_{k-1}+\omega_{k-1},\\ y_{k}=Hx_{k}+\
u_{k}\end{array}  \tag{8}\]  
where \(\Phi\) is the state transition matrix of the system, and \(\Phi=e^{FT}\approx I+FT\). The EKF equations of PMSM consist of prediction Equation (9) and correction Equation (10), which can be obtained based on the Kalman filter equations:  
\[ \begin{array}{l}\hat{x}_{k|k-1}=\hat{x}_{k-1}+[f(\hat{x}_{k-1})+Bu_{k-1}]T,\\ P_{k|k-1}=\Phi P_{k-1}\Phi^{T}+Q.\end{array}  \tag{9}\]  
\[