# Sparse Representation and SVM Diagnosis Method for Inter-Turn Short-Circuit Fault in PMSM
## 3 Svm  
SVM is a two-class model whose purpose is to find a hyperplane to segment the sample space. The principle of segmentation is to enable the hyperplane to classify the samples correctly and maximize the margin between the samples and the hyperplane. The samples closest to the hyperplane that determines the position of the hyperplane are support vectors.  
Let the sample points for training be \((x_{i},y_{i})\), \(i=1,2,\cdots,l\). The input is \(x_{i}\in R^{d}\), and the output is \(y_{i}\in\{-1,1\}\). If let \(w\) be the normal vector of the hyperplane and \(b\) be the displacement, the equation of the hyperplane is:  
\[w^{T}x+b=0 \tag{4}\]  
The margin is equal to the projection of the difference between two different types of support vectors on \(w\), which is \(\frac{2}{\|w\|}\). Maximizing the classification margin is equal to the following:  
\[\underset{w,b}{min}\frac{\|w\|^{2}}{2},s.t.y_{i}\Big{(}w^{T}x_{i}+b\Big{)}\geq 1 \tag{5}\]  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Input: signal \(x\), dictionary matrix \(D\), sparse degree K** \\ \hline (1) & Initialize residual signal \(R_{0}=x\), index set \(\Lambda_{0}=\varnothing\), matrix \(A_{0}=\varnothing\), number of iterations \(t=1\). \\ (2) & Select the atom \(d_{t}\) that best matches the residual signal in the dictionary. The selection condition is \(|\langle R_{t-1},d_{t}\rangle|=\sup|\langle R_{t-1},d_{k}\rangle|\) and the column number of the selected atom satisfies that \(\lambda_{t}\
otin\Lambda_{t-1}\). \\ (3) & Update the index set \(\Lambda_{t}=\Lambda_{t-1}\cup\{\lambda_{t}\}\) with \(\lambda_{t}\), and update the matrix \(A_{t}=A_{t-1}\cup d_{t}\). \\ (4) & Calculate the least squares solution \(\hat{\alpha}=argmin\|x-A_{t}\alpha_{t}\|=(A_{t}^{T}A_{t})^{-1}A_{t}^{T}x\). \\ (5) & Update residual \(R_{t}=x-A_{t}\hat{\alpha}=x-A_{t}(A_{t}^{T}A_{t})^{-1}A_{t}^{T}x\). \\ (6) & Update \(t=t+1\) and repeat steps 2-5 until \(t=K\). \\ Output: sparse representation coefficients \(\alpha\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: Workflow of orthogonal matching pursuit (OMP).  
Its Lagrange function is:  
\[L(w,b,\alpha)=\frac{\|w\|^{2}}{2}+\sum\limits_{i=1}^{m}\alpha_{i}\Big{(}1-y\Big{(} w^{T}x_{i}+b\Big{)}\Big{)} \tag{6}\]  
where \(\alpha_{i}\geq 0\) is the Lagrange multiplier. Let the partial derivatives of \(L(w,b,\alpha)\) with respect to \(w\) and \(b\) respectively equal to 0, and then the following equations can be obtained:  
\[\left\{\begin{array}{c}w=\sum\limits_{i=1}^{m}\alpha_{i}y_{i}x_{i}\\ \sum\limits_{i=1}^{m}\alpha_{i}y_{i}=0\end{array}\right. \tag{7}\]  
Substitute the above equation into the original function, and the original question becomes:  
\[\underset{\alpha}{max}\sum\limits_{i=1}^{m}\alpha_{i}-\frac{1}{2}\sum\limits _{i=1}^{m}\sum\limits_{i=1}^{m}\alpha_{i}y_{i}y_{j}x_{i}x_{j},s.t.\sum\limits_ {i=1}^{m}\alpha_{i}y_{i}=0,\alpha_{i}\geq 0,i=1,2,\cdots,m \tag{8}\]  
From this, the decision function corresponding to the segmentation hyperplane equation can be solved, which is:  
\[f(x)=sign\Big{(}w^{T}x+b\Big{)}=sign(\sum\limits_{i=1}^{m}\alpha_{i}y_{i}x_{i} ^{T}x+b) \tag{9}\]  
In this paper, the input vector of sample point is four-dimensional, which means \(x_{i}\in R^{4}\). As for the output \(y_{i}\in\{-1,1\}\), 1 represents the signal of the normal motor and -1 represents the signal of the inter-turn short circuit motor. First, the training sets where fault types are known are input into the SVM to solve the decision function. Then, input the test set to test the diagnosis effect of the inter-turn short-circuit fault in PMSM based on SVM.