On-line Detection and Classiﬁcation of PMSM Stator Winding Faults Based on Stator Current Symmetrical Components Analysis and the KNN Algorithm

: The signiﬁcant advantages of permanent magnet synchronous motors, such as very good dynamic properties, high efﬁciency and power density, have led to their frequent use in many drive systems today. However, like other types of electric motors, they are exposed to various types of faults, including stator winding faults. Stator winding faults are mainly inter-turn short circuits and are among the most common faults in electric motors. In this paper, the possibility of using the spectral analysis of symmetrical current components to extract fault symptoms and the machine-learning-based K-Nearest Neighbors (KNN) algorithm for the detection and classiﬁcation of the PMSM stator winding fault is presented. The impact of the key parameters of this classiﬁer on the effectiveness of stator winding fault detection and classiﬁcation is presented and discussed in detail, which has not been researched in the literature so far. The proposed solution was veriﬁed experimentally using a 2.5 kW PMSM, the construction of which was specially prepared for carrying out controlled inter-turn short circuits.


Introduction
The popularity of Permanent Magnet Synchronous Motors (PMSMs) has continued to increase in recent years. This is due to the fact that they are characterized by very good properties such as very high efficiency, high reliability, control of a wide range of rotational speeds and a low rotor moment of inertia [1,2]. Because of this, PMSMs are largely applied to automotive motors, home appliances and other industrial automatic control applications, gradually replacing induction motors [3,4].
In general, electric motors, even when operated under normal conditions, are exposed to various types of damages. The most common faults of electric machines are bearing (41%), stator (36%) and rotor (9%) faults, whereas 14% correspond to other failures [5]. This also applies to highly efficient and durable PMSMs. The stator winding fault is one of the most common faults of PMSMs. Apart from the wrong connection of windings, stator faults include various types of short circuits ( Figure 1): inter-turn short circuits, short circuits between the coils in one phase, phase-to-phase short circuits, phase-to-ground short circuits and open circuits (breaks in phases) [6]. However, the most common situation is that a stator winding fault starts with an inter-turn short circuit, which is very difficult to detect at an early stage.
Inter-turn short circuits are mainly caused by stator winding insulation damage due to electrical stresses, mechanical stresses and overload [7]. This type of failure is very destructive. An imperceptible short circuit between adjacent turns can spread very quickly over the whole winding, causing the main short circuit and leading to an emergency stop of the drive system [8]. This spreading is the result of a large circulating fault current Inter-turn short circuits are mainly caused by stator winding insulation damage due to electrical stresses, mechanical stresses and overload [7]. This type of failure is very destructive. An imperceptible short circuit between adjacent turns can spread very quickly over the whole winding, causing the main short circuit and leading to an emergency stop of the drive system [8]. This spreading is the result of a large circulating fault current induced in the faulted loop, which is associated with a significant temperature increase in a given part of the winding, rapidly degrading the winding insulation [9]. Moreover, stator winding faults can have a negative impact on rotor permanent magnets. Due to the high temperature in the shorted part of the stator winding and magnetic field value amplified to greater than magnet coercivity, partial or complete irreversible demagnetization may occur [10].
Taking into account the aforementioned increasing popularity of PMSMs, with the nature of stator winding faults and the constant pursuit of the most reliable solutions in mind, new methods of detecting and classifying this type of failure with the highest possible efficiency and at an early stage are still being sought. The development of such methods may prevent the complete and costly failure of the drive system. Emergency downtimes may also cause long delays in the industrial process. Moreover, an effective diagnostic system guarantees safe operation and extends the lifetime of the motor [11,12].
There are many methods used for electric motor fault detection, including PMSMs [13][14][15][16][17]. Diagnostic methods are mostly based on the processed signal. Signal processing allows for the extraction of fault features [18]. Mathematical apparatuses used for symptom extraction from the stator phase current signal include those that perform frequency and time-frequency domain analysis. The phase current signal is the most commonly used signal in the process of stator winding fault detection [19]. One of the most popular fault diagnosis techniques based on motor current analysis is Motor Current Signature Analysis (MCSA). Fast Fourier Transform (FFT) is also a powerful and simple MCSA technique [20]. The effectiveness of the application of this method for the detection of inter-turn short circuits was confirmed among others in [8] and [21]. The group of methods that performs time-frequency domain analysis is dominated by Continuous Wavelet Transform (CWT) [22,23], Discrete Wavelet Transform (DWT) [24,25], Short-Time Fourier Transform (STFT) [26] and Hilbert-Huang Transform [27]. Signal processing methods based on High-Order Transforms (HOTs) are also used in PMSM stator winding fault diagnostics. HOTs that Taking into account the aforementioned increasing popularity of PMSMs, with the nature of stator winding faults and the constant pursuit of the most reliable solutions in mind, new methods of detecting and classifying this type of failure with the highest possible efficiency and at an early stage are still being sought. The development of such methods may prevent the complete and costly failure of the drive system. Emergency downtimes may also cause long delays in the industrial process. Moreover, an effective diagnostic system guarantees safe operation and extends the lifetime of the motor [11,12].
There are many methods used for electric motor fault detection, including PMSMs [13][14][15][16][17]. Diagnostic methods are mostly based on the processed signal. Signal processing allows for the extraction of fault features [18]. Mathematical apparatuses used for symptom extraction from the stator phase current signal include those that perform frequency and time-frequency domain analysis. The phase current signal is the most commonly used signal in the process of stator winding fault detection [19]. One of the most popular fault diagnosis techniques based on motor current analysis is Motor Current Signature Analysis (MCSA). Fast Fourier Transform (FFT) is also a powerful and simple MCSA technique [20]. The effectiveness of the application of this method for the detection of interturn short circuits was confirmed among others in [8] and [21]. The group of methods that performs time-frequency domain analysis is dominated by Continuous Wavelet Transform (CWT) [22,23], Discrete Wavelet Transform (DWT) [24,25], Short-Time Fourier Transform (STFT) [26] and Hilbert-Huang Transform [27]. Signal processing methods based on High-Order Transforms (HOTs) are also used in PMSM stator winding fault diagnostics. HOTs that have been applied in diagnostics are bispectrum [28,29], MUltiple Signal Classification (MUSIC) [30] and Estimation of Signal Parameters via Rotational Invariance Techniques (ESPRIT) [31]. In addition to the processing of the stator phase current signal, attempts have also been made to use the symmetrical components of the stator current for stator winding fault detection of induction motors [32] and PMSMs [33].
Except for the extraction of fault symptoms from which the signal is carrying diagnostic information, it is extremely important to develop an algorithm that infers the condition of the motor and classifies the degree of damage. In recent years, this function has been entrusted more and more often to fault classifiers that are based on Machine Learning (ML) algorithms. These algorithms are used in knowledge-based approaches, and they are constantly being improved. Therefore, it seems to be a promising research direction in the field of fault diagnostics [34].
ML has become a very popular technique and is an inherent part of the Artificial Intelligence (AI) field. Subcategories of classic ML algorithms, such as Decision Tree (DT), Support Vector Machine (SVM) and K-Nearest Neighbors (KNN), are algorithms whose operation is inspired by the human brain operation principle-Artificial Neural Networks (ANNs) and Deep Neural Networks (DNN).
The usage of the above-mentioned methods can minimize human participation in fault diagnosis and help in automating this process. Therefore, the usage of selected MLbased classifiers, shallow and deep neural networks, has been verified to detect various types of electric motor faults [10,[35][36][37][38][39][40][41][42][43][44][45]. Taking into account an electric motor fault other than mechanical failure, there are still very few scientific papers in which the usage of simple machine learning algorithms to detect PMSM stator winding faults is presented, especially taking into account the analysis of the key parameter selection of fault classifiers on their effectiveness.
It is also important that due to the increasing requirements for the reliability of drive systems, classical diagnostic methods are not sufficient. In order to meet these requirements, nowadays, it is recommended to use intelligent diagnostic methods. An extensive review of AI-based fault diagnostic methods for PMSMs is presented in [46]. The authors discussed methods that use artificial knowledge technology such as neural networks, expert systems and fuzzy logic to realize complex motor fault detection and condition monitoring. Moreover, the idea of Industry 4.0, the popularity of which has increased rapidly in recent years, is also closely connected with the condition monitoring of drives systems or even whole industrial processes. More and more often, the solutions ensuring the wireless transmission of information about machine conditions and other promising smart approaches are being proposed [47][48][49], as well as those that demonstrate an advanced embedded online monitoring algorithm [50].
The main goal of this article is inter-turn short-circuit detection and classification in PMSM stator windings using the spectral analysis of symmetrical current components to extract the fault symptoms and a simple ML-based classifier (KNN). Furthermore, the impact of the key parameters of this classifier on the effectiveness of stator winding fault detection and classification during off-line and on-line verification is presented and discussed in detail. The efficiency of the KNN algorithm to detect various faults of induction motors has been proven in recent years among others in [34,[51][52][53]. Nonetheless, there is a visible gap in current research with regard to the usage of simple AI-based algorithms such as KNN to PMSM stator winding fault detection and classification. In particular, there is a lack of solutions that allow for the detection of this type of fault at a very early stage, with just one shorted turn in the stator winding coil. Widely discussed in the diagnostic literature, artificial neural networks require a long training time, while there are relatively few solutions guaranteeing both a short training time and effective classification with a resolution to one turn.
The novelty of the solution presented in this paper results from:

•
The proposal of a solution that allows the detection of failure at a very early stage, with one shorted turn in a stator winding and under various motor operating conditions.
The article is divided into seven sections. After this introduction, Section 2 discusses the proposed KNN-based fault classifiers. Successively, the extraction of the stator fault features using the spectral analysis of stator current symmetrical components is presented. In Section 4, the test stand and methodology of the experimental research are presented. Next, in Section 5, the training process of the proposed fault classifier is discussed. In Section 6, the experimental verification of its effectiveness during off-line and on-line tests is presented. Final conclusions from the conducted research are discussed in Section 7.

K-Nearest Neighbors
The KNN algorithm is one of the most fundamental, simple and effective machine learning algorithms used for data classification [54,55]. To classify unknown data represented by the feature vector as a point in the feature space, the KNN calculates the distance between the new point and points that were used in the training process-the training data set. Then, this classifier assigns the point to the class among its K-nearest neighbors, where K is a pre-determined integer value [56,57].
This concept is shown in Figure 2. The new data point is represented as *. If K is equal to 3, then there are two neighbors in Class A and one in Class B, hence this new data point must belong to Class A. However, if K = 5, two points in the neighborhood are in Class A, and three are in Class B, so the new data point will be classified as Class B. It follows that the choice of the value of K has a big impact on the accuracy of the trained model [58]. There is no specific way to determine the best K value, so it is necessary to try different values to find the best one.


A detailed examination of the impact of key parameter (hyper-parameters) changes of the tested classifier on its effectiveness and a proposal of the best solution,  The proposal of a solution that allows the detection of failure at a very early stage, with one shorted turn in a stator winding and under various motor operating conditions.
The article is divided into seven sections. After this introduction, Section 2 discusses the proposed KNN-based fault classifiers. Successively, the extraction of the stator fault features using the spectral analysis of stator current symmetrical components is presented. In Section 4, the test stand and methodology of the experimental research are presented. Next, in Section 5, the training process of the proposed fault classifier is discussed. In Section 6, the experimental verification of its effectiveness during off-line and on-line tests is presented. Final conclusions from the conducted research are discussed in Section 7.

K-Nearest Neighbors
The KNN algorithm is one of the most fundamental, simple and effective machine learning algorithms used for data classification [54,55]. To classify unknown data represented by the feature vector as a point in the feature space, the KNN calculates the distance between the new point and points that were used in the training process-the training data set. Then, this classifier assigns the point to the class among its K-nearest neighbors, where K is a pre-determined integer value [56,57].
This concept is shown in Figure 2. The new data point is represented as *. If K is equal to 3, then there are two neighbors in Class A and one in Class B, hence this new data point must belong to Class A. However, if K = 5, two points in the neighborhood are in Class A, and three are in Class B, so the new data point will be classified as Class B. It follows that the choice of the value of K has a big impact on the accuracy of the trained model [58]. There is no specific way to determine the best K value, so it is necessary to try different values to find the best one. Various distance metrics for calculating the distance between adjacent points are presented in the literature [56]. In this work, apart from the impact of the number of K closest neighbors on the accuracy of the classifier, the impact of different distance metrics is also verified. Various distance metrics for calculating the distance between adjacent points are presented in the literature [56]. In this work, apart from the impact of the number of K closest neighbors on the accuracy of the classifier, the impact of different distance metrics is also verified.
Let A and B be feature vectors: A = (x 1 , x 2 , . . . , x n ) and B = (y 1 , y 2 , . . . , y n ), where n is the dimensionality of the feature space [48]. The most common functions used to calculate the distance are Euclidean, Minkowski, Mahalanobis and Correlation. These distance metrics are expressed by Equations (1)-(4), respectively. The most popular distance metric is the Minkowski distance [59]. Algorithm 1 presented below defines the basic KNN classifier algorithm steps in detail [60]. where: x i , y i -elements of the A and B feature vector, respectively; n-feature space dimension; r-order of the Minkowski distance metric; σ-standard deviation of the x i and y i over the data set; x, y-mean value of the x i and y i elements (for i = 1 to i = n) of the A and B feature vectors, respectively.

Algorithm 1 The basic KNN algorithm
is an observation that belongs to class c i , n is a number of elements in the data set and m is a number of features in the input vector Data: Z = (z 1 , z 2 . . . , z m ) new data to be classified Result: class to which new input data Z belongs Sort distances {d i , for i = 1 to n} in ascending order; Get the first K cases closer to Z (with the shortest distance), D K z ; class ← most frequent class in D K However, despite its many advantages, this algorithm has some disadvantages: • The KNN algorithm is generally not recommended for analyzing very large data sets; • To obtain the proper and effective operation of this algorithm, it is necessary to choose the optimal number of K, which involves the need to test the algorithm several times during the training process; • It can be challenging to apply the KNN algorithm to high-dimensional data (a high number of features).

Spectral Analysis of Symmetrical Components of Stator Phase Currents
The effectiveness of fault classifiers strongly depends on the selected fault features. Therefore, it is essential to select those that are most susceptible to damages. Symptoms of the inter-turn short circuits that allow for their detection at an early stage are still being searched. In this paper, the spectral analysis of the positive and negative sequence symmetrical components of stator phase currents is proposed to extract inter-turn shortcircuit symptoms.
A negative sequence component value of the phase current is a significant indicator of unbalance in motor phases. This unbalance may be caused by short circuits in the stator winding [7]. Zero, positive and negative sequence components of the phase current can be calculated as follows: where: I 0 , I 1 , I 2 -zero, positive and negative stator phase current component in the steady state, respectively; I sA , I sB , I sC -Phases A, B and C stator current, respectively; And: a = e j 2π 3 .
In the case of three-phase PMSMs, the I 0 component does not exist; therefore, it is necessary to calculate only the positive and negative symmetrical current components.
The matrix Equation (5) concerns the sinusoidal signals of stator phase currents in the steady state. However, supplying motors from Voltage Source Inverters (VSIs) introduces a number of additional harmonics that cause the distortion of voltages and currents. In such cases, in order to use the classic symmetrical component calculation method, it is necessary to filter out the disturbing harmonics or extract the fundamental components of the supply voltage (f s ). In this paper, the second approach is proposed. This approach is based on the calculation of the instantaneous values of the stator current symmetrical components using the 90 • shift operator in the time domain, according to [61]: where: i 1 , i 2 -instantaneous values of the positive and negative stator phase component, respectively; i sA , i sB , i sC -Phases A, B and C instantaneous values of stator current, respectively; S 90 -operator of a phase shift by an angle of 90 • in the time domain.
In the next step, spectral analysis of the instantaneous values of symmetrical current components calculated according to Equation (7) is performed. In Figure 3, the spectra of the stator phase current's positive sequence component ( Figure 3a) and negative sequence component ( Figure 3b) for PMSM, the parameters of which are grouped in Appendix A, are shown. These spectra concern the operation of the motor at f s = 100 Hz (n = n N = 1500 rpm), with nominal load torque (T L = T N ) for an undamaged winding and with a different number of shorted turns (N sh ).
components calculated according to Equation (7) is performed. In Figure 3, the spectra of the stator phase current's positive sequence component ( Figure 3a) and negative sequence component ( Figure 3b) for PMSM, the parameters of which are grouped in Appendix A, are shown. These spectra concern the operation of the motor at fs = 100 Hz (n = nN = 1500 rpm), with nominal load torque (TL = TN) for an undamaged winding and with a different number of shorted turns (Nsh). In these spectra, an increase in the amplitude of the fs fundamental frequency components after an inter-turn short circuit in the stator winding can be observed. It is clearly visible that the increase in the amplitude of this component due to the inter-turn short circuit is greater for the negative sequence component analysis. In order to clearly define the symbols and avoid misunderstanding, the fs frequency component in the i1 spectrum will be hereinafter denoted as fsi1 and in the i2 as fsi2.
The effect of the number of shorted turns Nsh and the load torque TL on the amplitude value of the fsi1 component is shown in Figure 4a, whereas the dependence on the supply voltage frequency value fs is illustrated in Figure 4b. It can be concluded from the presented results that the load torque changes have an impact on the value of the fsi1 component amplitude, but the frequency of supply voltage does not affect these values. In these spectra, an increase in the amplitude of the f s fundamental frequency components after an inter-turn short circuit in the stator winding can be observed. It is clearly visible that the increase in the amplitude of this component due to the inter-turn short circuit is greater for the negative sequence component analysis. In order to clearly define the symbols and avoid misunderstanding, the f s frequency component in the i 1 spectrum will be hereinafter denoted as f si1 and in the i 2 as f si2 .
The effect of the number of shorted turns N sh and the load torque T L on the amplitude value of the f si 1 component is shown in Figure 4a, whereas the dependence on the supply voltage frequency value f s is illustrated in Figure 4b. It can be concluded from the presented results that the load torque changes have an impact on the value of the f si 1 component amplitude, but the frequency of supply voltage does not affect these values.      (rotational speeds n). Therefore, it can be concluded that the f si2 component, because of its changes due to damage to the stator winding, is a very good diagnostic indicator. The greatest sensitivity to the increasing number of shorted turns N sh occurs when the motor is operating at high rotational speeds, close to the rated value. Based on these observations, it was decided to use the values of the amplitudes of the f si1 and f si2 components as input features of the KNN model.   Figure 5a,b shows the effect of the number of shorted turns Nsh, the load torque TL and the power supply frequency voltage fs on the fsi2 component amplitude. The results below show that the TL does not have a significant impact on the value of the fsi2 component amplitude. Moreover, this value increases as a result of inter-turn short circuits in a wide range of the power supply frequency fs (rotational speeds n). Therefore, it can be concluded that the fsi2 component, because of its changes due to damage to the stator winding, is a very good diagnostic indicator. The greatest sensitivity to the increasing number of shorted turns Nsh occurs when the motor is operating at high rotational speeds, close to the rated value. Based on these observations, it was decided to use the values of the amplitudes of the fsi1 and fsi2 components as input features of the KNN model. It has to be noted that despite the insensitivity of the amplitude fsi2 to the change in TL value, its increase as a result of an inter-turn short-circuit drops with the decreasing It has to be noted that despite the insensitivity of the amplitude f si2 to the change in T L value, its increase as a result of an inter-turn short-circuit drops with the decreasing frequency of the supply voltage, which is a minor limitation. However, even at a lower speed (power supply frequency), changes due to the stator winding damage are still visible.

Experimental Setup
The experimental verification of the proposed KNN-based stator winding fault classifier was carried out on a specially designed laboratory setup with PMSM with nominal power equal to 2.5 kW, operating in a closed-loop structure and powered by a VSI. The loading machine was a second PMSM with nominal power equal to 4.7 kW. The laboratory stand is shown in Figure 6. The main parameters of the tested PMSM are grouped in Appendix A.
The construction of the tested PMSM was specially prepared to allow the physical modeling of the inter-turn short circuits of a selected number of turns in a phase. Each of the three phases of the stator winding consists of two coils, 125 turns each. An illustrative schema of the tested PMSM stator winding is shown in Figure 7a. One of the two winding coils in each of the three phases was modified to provide controlled short circuits. This modification consisted of leading out a group of coils to the terminal board. The diagram of the terminal board with the derived phases of the PMSM stator winding is shown in Figure 7b. During the experimental verification, a maximum of three turns in Phase A was short circuited, which accounted for 1.2% of all turns in one phase. Direct short circuits were performed by connecting the taps on the terminal board with a wire without limiting the current in a short-circuit loop with an additional resistor. The experimental verification of the proposed KNN-based stator winding fault classifier was carried out on a specially designed laboratory setup with PMSM with nominal power equal to 2.5 kW, operating in a closed-loop structure and powered by a VSI. The loading machine was a second PMSM with nominal power equal to 4.7 kW. The laboratory stand is shown in Figure 6. The main parameters of the tested PMSM are grouped in Appendix A. The construction of the tested PMSM was specially prepared to allow the physical modeling of the inter-turn short circuits of a selected number of turns in a phase. Each of the three phases of the stator winding consists of two coils, 125 turns each. An illustrative schema of the tested PMSM stator winding is shown in Figure 7a. One of the two winding coils in each of the three phases was modified to provide controlled short circuits. This modification consisted of leading out a group of coils to the terminal board. The diagram of the terminal board with the derived phases of the PMSM stator winding is shown in Figure 7b. During the experimental verification, a maximum of three turns in Phase A was short circuited, which accounted for 1.2% of all turns in one phase. Direct short circuits were performed by connecting the taps on the terminal board with a wire without limiting the current in a short-circuit loop with an additional resistor.
The block diagram of the experimental setup is shown in Figure 8. The tested PMSM was fed from an industrial VSI by Lenze. The used diagnostic signals, stator phase currents, were measured with LEM LA 25-NP transducers. The output signals from the transducers were passed to the data acquisition measurement card (DAQ NI PXI-4492) by National Instruments (NI, Austin, TX, USA) and then pre-processed by the LabVIEW programming environment. The sampling frequency of the phase current measurement was equal to 8192 Hz. The DAQ card was placed in the NI PXI 1082 industrial computer. The control of the tested motor was performed in Lenze Engineer software, whereas the load torque was set in Veristand.   The block diagram of the experimental setup is shown in Figure 8. The tested PMSM was fed from an industrial VSI by Lenze. The used diagnostic signals, stator phase currents, were measured with LEM LA 25-NP transducers. The output signals from the transducers were passed to the data acquisition measurement card (DAQ NI PXI-4492) by National Instruments (NI, Austin, TX, USA) and then pre-processed by the LabVIEW programming environment. The sampling frequency of the phase current measurement was equal to 8192 Hz. The DAQ card was placed in the NI PXI 1082 industrial computer. The control of the tested motor was performed in Lenze Engineer software, whereas the load torque was set in Veristand.

PMSM -LOAD
The described experimental setup was used to collect the measurement data, which were used for training the proposed KNN classifier and its off-line verification but also for further on-line tests. The experimental studies were carried out for various load torque values in the range of (0 ÷ 1)T N with 0.2T N step and for various rotational speeds (frequency of the supply voltage (60 ÷ 100) Hz). It allowed evaluating the influence of the motor operating conditions on the effectiveness of the fault classifier.  The described experimental setup was used to collect the measurement data, which were used for training the proposed KNN classifier and its off-line verification but also for further on-line tests. The experimental studies were carried out for various load torque values in the range of (0 ÷ 1)TN with 0.2TN step and for various rotational speeds (frequency of the supply voltage (60 ÷ 100) Hz). It allowed evaluating the influence of the motor operating conditions on the effectiveness of the fault classifier.

Training Process of the Proposed KNN Fault Classifier
The effectiveness of the classifier model depends on the appropriate selection of its input vector elements, so they have to be carefully selected. This article proposes a spectral

Training Process of the Proposed KNN Fault Classifier
The effectiveness of the classifier model depends on the appropriate selection of its input vector elements, so they have to be carefully selected. This article proposes a spectral analysis of the symmetrical component of the stator phase current for inter-turn short-circuit symptoms extraction, which allowed the selection of a two-element input vector consisting of f si1 and f si2 component amplitudes, X i = (Af si1 ,Af si2 ). In ML, the input data set is typically split into training data and test data. In the training process of the proposed KNN fault classifier model, 240 input vectors corresponding to different states of the stator winding state and operating conditions were used. These conditions are grouped in Table 1.  The distribution of the training data points is shown in Figure 9. Due to the fact that the classifier input vector is a two-element vector, it can be represented in the Cartesian coordinate system (two-dimensional space). Based on the analysis of the scatter chart (Figure 9), it can be concluded that these input features are promising fault symptoms, as there is a clear distribution of classes. These classes correspond to the stator winding states of the tested PMSM. Electronics 2021, 10, x FOR PEER REVIEW 12 of 21  To choose the best configuration from those characterized by 100% accuracy, the times needed to train each type are compared in Figure 11. The fastest training time was obtained for KNN with the Euclidean distance metric and K = 3. Based on this detailed analysis, the authors decided to carry out the off-line and on-line experimental verification tests for this classifier. To choose the best model of the KNN, the accuracy of the classifiers was verified for four different distance metrics, which are described by Equations (1)-(4) and a different number of K-nearest neighbors. The impact of these parameters is very often overlooked in papers on the application of KNN, especially with regard to the electric motor fault diagnosis. The classifier's model accuracy for different configurations is shown in Figure 10 and grouped in Table 2. Based on these values, it is concluded that 100% accuracy of the KNN model to the training data set was achieved for KNN with the Euclidean, Minkowski and Mahalanobis distance metrics both for K = 3 and K = 5. The verification of the influence of the K value on the accuracy of the model led to the conclusion that a value that is too large may cause a significant decrease in the accuracy of the classifier. An increasing number of nearest neighbors is connected with the phenomenon of overfitting, which is clearly confirmed by the discussed results. Moreover, a large K value significantly increases the computational complexity of the algorithm. A K that is too low will increase bias and cause misclassifications, leading to underfitting [62]. In the analyzed case, the underfitting is visible for K = 1 and K = 2. Furthermore, setting K to an odd value helps to eliminate the possibility of a statistical stalemate and invalid results.
Nonetheless, the inverse trend is characteristic for KNN with the Correlation distance metric. In this case, for low values of the K parameter, the classifier accuracy has the lowest value and gradually increases with increasing K. This is typical for a function that takes into account the correlation between two points.
To choose the best configuration from those characterized by 100% accuracy, the times needed to train each type are compared in Figure 11. The fastest training time was obtained for KNN with the Euclidean distance metric and K = 3. Based on this detailed analysis, the authors decided to carry out the off-line and on-line experimental verification tests for this classifier.  To choose the best configuration from those characterized by 100% accuracy, the times needed to train each type are compared in Figure 11. The fastest training time was obtained for KNN with the Euclidean distance metric and K = 3. Based on this detailed analysis, the authors decided to carry out the off-line and on-line experimental verification tests for this classifier.

The Off-Line and On-Line Verification of the KNN-Based Fault Classifier
In the process of verification of the classifier's operation during the off-line tests, a set of test data was used. This set consisted of 120 input vectors that were not involved in the KNN training process and corresponded to different states of the stator winding state (Nsh) and operating conditions (TL). These conditions are grouped in Table 3.
In order to assess the effectiveness of the proposed stator winding fault classifier, the CEFF index was introduced, which determines the ratio of the correctly classified stator winding states to the number of input vectors-the sum of the correct classifications and misclassifications. This index is defined by the following equation:

The Off-Line and On-Line Verification of the KNN-Based Fault Classifier
In the process of verification of the classifier's operation during the off-line tests, a set of test data was used. This set consisted of 120 input vectors that were not involved in the KNN training process and corresponded to different states of the stator winding state (N sh ) and operating conditions (T L ). These conditions are grouped in Table 3. Table 3. Test data set. In order to assess the effectiveness of the proposed stator winding fault classifier, the C EFF index was introduced, which determines the ratio of the correctly classified stator winding states to the number of input vectors-the sum of the correct classifications and misclassifications. This index is defined by the following equation:

Training Packages
where: Y C -number of correct stator winding state classifications performed by the proposed KNN model; Y M -number of stator winding state misclassifications performed by the proposed KNN model.
The KNN classifier's response to the test data set is shown in Figure 12. The C EFF value of this classifier for the vectors that were not used in the learning process is equal to 100%. It means that the classifier's response was correct for each of the investigated PMSM stator winding states and also for only one shorted turn in a coil at a very early stage of the failure.

Test vector number [-]
Test vector number (-) Off-line verification tests showed that this classifier provides high efficiency in the detection and classification of inter-turn short circuits. For this reason, it was decided to continue experimental tests during the on-line operation of the drive system.
The flowchart of the proposed on-line fault classification algorithm is shown in Figure 13. The diagnostic application responsible for the data acquisition and signal pre-processing (calculation and spectral analysis of i 1 and i 2 ) was developed in the Lab-VIEW programming environment. The script to call pre-trained KNN stator winding state classifier model was prepared in MATLAB. The first on-line verification scenario (Test 1) was carried out for motor operation in such conditions for which the model of the KNN classifier was trained, i.e., TL = (0 ÷ 1)TN with a 0.2TN step and fs = fsN = 100 Hz. In this scenario, one, two and three turns were short circuited for several seconds. This is referred to hereinafter as steady short circuits. The efficiency of the classifier CEFF for this condition was as high as 99.4%. The classifier responses and the actual states of the stator winding during this scenario are shown in The first on-line verification scenario (Test 1) was carried out for motor operation in such conditions for which the model of the KNN classifier was trained, i.e., T L = (0 ÷ 1)T N with a 0.2T N step and f s = f sN = 100 Hz. In this scenario, one, two and three turns were short circuited for several seconds. This is referred to hereinafter as steady short circuits. The efficiency of the classifier C EFF for this condition was as high as 99.4%. The classifier responses and the actual states of the stator winding during this scenario are shown in Figure 14.
The first on-line verification scenario (Test 1) was carried out for motor operation in such conditions for which the model of the KNN classifier was trained, i.e., TL = (0 ÷ 1)TN with a 0.2TN step and fs = fsN = 100 Hz. In this scenario, one, two and three turns were short circuited for several seconds. This is referred to hereinafter as steady short circuits. The efficiency of the classifier CEFF for this condition was as high as 99.4%. The classifier responses and the actual states of the stator winding during this scenario are shown in Figure 14. In the next scenario (Test 2), the operation of the proposed KNN classifier was verified during the momentary (for 1 ÷ 2 s) short circuiting of one, two and three shorted turns, respectively. This test was also carried out for different load torques TL = (0 ÷ 1)TN and fs = fsN = 100 Hz. In this case, the CEFF was equal to 98.6%, which confirmed the satisfying properties of this solution ( Figure 15).
Finally, the last test (Test 3) was carried out to verify the classifier operation for power supply frequency (rotational speeds) different from the rated value (fsN). Before the test, the training data set was extended with vectors corresponding to the motor operation at frequencies lower than the rated one-fs = {90 Hz; 80 Hz; 70 Hz; 60 Hz}. With this set, the classifier was re-trained without changing its parameters, and an on-line verification test was performed. The classifier responses and the actual states of the stator winding for In the next scenario (Test 2), the operation of the proposed KNN classifier was verified during the momentary (for 1 ÷ 2 s) short circuiting of one, two and three shorted turns, respectively. This test was also carried out for different load torques T L = (0 ÷ 1)T N and f s = f sN = 100 Hz. In this case, the C EFF was equal to 98.6%, which confirmed the satisfying properties of this solution ( Figure 15). such motor operating conditions are shown in Figure 16. As can be seen, the supply voltage frequency was reduced with a step of 10 Hz down to the value of 60 Hz. In this test, the KNN correctly recognizes the stator winding state in 99.5% of all cases. The confusion matrices for each of the test scenarios are shown in Figure 17. The analysis of these matrices shows that the most misclassifications (7.4%) were found in the case of distinguishing between an undamaged PMSM stator winding and one shorted turn in the coil during Test 2. Nonetheless, it should be emphasized that in each of the discussed cases the effectiveness of winding states classifications is very high, especially that it has been tested on a real drive system during the on-line operation, where disturbances and motor parameters change such as temperature also have a negative influence.
Moreover, in order to summarize the on-line tests and clarify the scenarios, they are described in Table 4, while classifier key parameters, properties and CEFF values are grouped in Table 5. The analysis of Table 5 allows concluding that the proposed construction of the classifier input vector and its parameters allow achieving very good efficiency in the detection of inter-turn short circuits with a resolution to one turn at an early stage of the damage. Finally, the last test (Test 3) was carried out to verify the classifier operation for power supply frequency (rotational speeds) different from the rated value (f sN ). Before the test, the training data set was extended with vectors corresponding to the motor operation at frequencies lower than the rated one-f s = {90 Hz; 80 Hz; 70 Hz; 60 Hz}. With this set, the classifier was re-trained without changing its parameters, and an on-line verification test was performed. The classifier responses and the actual states of the stator winding for such motor operating conditions are shown in Figure 16. As can be seen, the supply voltage frequency was reduced with a step of 10 Hz down to the value of 60 Hz. In this test, the KNN correctly recognizes the stator winding state in 99.5% of all cases.   The confusion matrices for each of the test scenarios are shown in Figure 17. The analysis of these matrices shows that the most misclassifications (7.4%) were found in the case of distinguishing between an undamaged PMSM stator winding and one shorted turn in the coil during Test 2. Nonetheless, it should be emphasized that in each of the discussed cases the effectiveness of winding states classifications is very high, especially that it has been tested on a real drive system during the on-line operation, where disturbances and motor parameters change such as temperature also have a negative influence.   Moreover, in order to summarize the on-line tests and clarify the scenarios, they are described in Table 4, while classifier key parameters, properties and C EFF values are grouped in Table 5. The analysis of Table 5 allows concluding that the proposed construction of the classifier input vector and its parameters allow achieving very good efficiency in the detection of inter-turn short circuits with a resolution to one turn at an early stage of the damage. Table 4. Details of the test scenarios.

Test Scenario
Description f S N sh T L 1 One, two and three turns were short circuited for several seconds (steady short-circuits). The motor was operating under the following conditions: T L = (0 ÷ 1)T N with a 0.2T N step and nominal supply frequency.
100 Hz (f sN ) 0; 1; 2; 3 var 2 The momentary (for 1 ÷ 2 s) short-circuiting of one, two and three shorted turns was conducted. The motor was operating under the following conditions: T L = (0 ÷ 1)T N with a 0.2T N step and nominal supply frequency.
100 Hz (f sN ) 0; 1; 2; 3 var 3 One, two and three turns were short circuited for several seconds (steady short-circuits). The motor was operating under the following conditions: T L = (0 ÷ 1)T N with a 0.2T N step and f s = (60 ÷ 100) Hz with 10Hz step. var 0; 1; 2; 3 var The analysis of the results of all three tests showed that in most cases, when there is a misclassification, it occurs for a condition where there is one shorted turn in the PMSM stator winding coil. However, these misclassifications do not occur as often, so it can be considered that they are a significant limitation of the proposed method.

Conclusions
This paper focuses on the two important elements of electric motors diagnosis-the extraction of failure symptoms and fault classification. For the successful realization of the first issue, the spectral analysis of negative and positive symmetrical components was proposed. For the detection and classification of the inter-turn short circuits of PMSM stator winding, a simple machine learning algorithm (KNN) was successfully implemented. The presented experimental research results confirm the effectiveness of such a solution, even during the on-line operation of the drive system under different motor operating conditions. What has not been analyzed in the diagnostic literature, the verification of the key parameters of the KNN classifier on its effectiveness, was discussed and compared in detail. To evaluate the classifier's effectiveness, the C EFF index was introduced, the average value of which during the on-line tests was equal to 99.1%. Moreover, the proposed classifier allows achieving very good efficiency in inter-turn short-circuit detection with a resolution to one turn at a very early stage of the winding damage.
The original virtual diagnostic tool developed in the LabVIEW and MATLAB environments performed the function of data acquisition, diagnostic signal pre-processing, extraction of stator winding failure-sensitive symptoms and fault detection and classification. In addition to very good fault classification effectiveness, the training time, which is only 1.024 s, should be highlighted as an important advantage of the proposed solution. Compared to artificial neural networks, especially those with a deep structure, which can take up to several hours to train, this is a clear advantage. Due to the low computational complexity of the KNN classifier, the algorithm that is described in the paper, it will be easy to implement even on a low-cost micro-controller.
Author Contributions: All of the authors contributed equally to the concept of the paper, and proposed the methodology; investigation and formal analyses, P.P. and M.W.; software and data curation, P.P.; measurements, P.P. and M.W.; proposed the paper organization, P.P. and M.W.; validated the obtained results, M.W. All authors have read and agreed to the published version of the manuscript.

Conflicts of Interest:
The authors declare no conflict of interest. Table A1. Rated parameters of the tested PMSM.