## 5 Temperature Online Estimation
### Online Temperature Estimation Based on Kalman Filter Algorithm  
According to Equation (3), two matrixes are defined as follows:  
\[A=\left[ \begin{array}{ccc}a_{11}&a_{12}&a_{13}\\ a_{21}&a_{22}&a_{23}\\ a_{31}&a_{32}&a_{33}\end{array} \right], \tag{17}\]  
\[B=\left[ \begin{array}{ccc}b_{11}&b_{12}&0\\ 0&0&b_{23}\\ b_{31}&0&0\end{array} \right]. \tag{18}\]  
With respect to PMSMs, in order to prevent the winding temperature from being too high, a winding temperature sensor is usually installed. Therefore, the winding temperature can be regarded as the measurement variable in Kalman filter scheme. The corresponding measurement equation can be expressed as:  
\[T_{s}=\left[ \begin{array}{ccc}1&0&0\\ \end{array} \right]\left[ \begin{array}{ccc}T_{s}\\ T_{R}\\ T_{B}\end{array} \right]. \tag{19}\]  
Definite:  
\[H=\left[ \begin{array}{ccc}1&0&0\\ \end{array} \right]. \tag{20}\]  
The specific application of the Kalman filter algorithm regarding the motor temperature estimation is as follows:  
1. Considering the process noise and measurement noise of the system, the discrete state equations and measurement equations of the motor thermal model can be expressed as:  
\[ \begin{array}{l}x(k)=A\cdot x(k-1)+B\cdot u(k)+w(k)\\ y(k)=H\cdot x(k)+v(k)\end{array} , \tag{21}\]  
where \(x(k)\) represents the state of the system at time k; \(u(k)\) represents the control variable, that is, the input variable of the thermal model; \(w(k)\) represents the process noise that conforms to the Gaussian distribution, and its covariance is \(Q\); \(y(k)\) represents the observation variable of the system at time \(k\), that is, the stator temperature sampled by the stator temperature sensor; \(v(k)\) indicates the measurement noise in accordance with the Gaussian distribution, and its covariance is \(R\); \(A\), \(B\) are parameter matrices in the system state equation; and \(H\) is the parameter matrices in the observation equation. 2. The filter needs to be initialized before making an estimation. The initial values of the state variable, \(x\), and error covariance, \(P\), of the priori estimation during each period are calculated as follows:  
\[ \begin{array}{l}\hat{x}_{0}^{+}=E(x_{0})\\ P_{0}^{+}=E[(x_{0}-\hat{x}_{0}^{+})(x_{0}-\hat{x}_{0}^{+})^{T}]\end{array} . \tag{22}\]  
In this paper, the temperature measured by the stator sensor is taken as the initial temperature of the stator, rotor, and end cap. 3. The estimation process for each cycle is divided into five steps:  
(a) Based on the estimation results at the previous moment and the state equation, the priori estimation of system state variables is made:  
\[x(k|k-1)=A\cdot x(k-1|k-1)+B\cdot u(k). \tag{23}\]  
(b) The error covariance of the priori results is calculated as follows:  
\[P(k|k-1)=A\cdot P(k-1|k-1)\cdot A^{T}+Q, \tag{24}\]where \(P\) is the error covariance of the priori estimation in first step and \(Q\) represents the covariance of the process noise. (c) \(K(k)\) is the filter gain matrix, which is the optimal estimated coefficient matrix of the priori estimation and measurements. It can be expressed as follows:  
\[K(k)=P(k|k-1)\cdot H^{T}\cdot\left(H\cdot P(k|k-1)\cdot H^{T}+R\right)^{-1}, \tag{25}\]  
where \(R\) represents the covariance of the measurement noise. (d) The priori estimation is corrected based on the filter gain matrix:  
\[x(k|k)=x(k|k-1)+K(k)\cdot\left(y(k)-H\cdot x(k|k-1)\right). \tag{26}\]  
(e) The error covariance of the priori estimation is adjusted for the next calculation:  
\[P(k|k)=\left(1-K(k)\cdot H\right)\cdot P(k|k-1). \tag{27}\]  
The different choice of \(Q\) and \(R\) will result in variance of the temperature prediction. The increase of the value \(Q\) will result in improvements of the dynamic performance and steady error, while the rise of the value \(R\) will lead to the opposite results. In this study, the calculation of the value, \(Q\), is based on the error between the estimation results of the state equation and the measured values.