Reduced Sensor-Based Harmonic Resonance Detection and its Compensation in Power distribution System with SAPF

Shunt Active Power Filter (SAPF) is widely used for harmonics and reactive power compensation. However, in addition to the harmonics, harmonic resonance also exists in the network, which is prominent in configurations where both SAPF and capacitor bank are present in the distribution network. Resonance is mainly caused due to interaction between line impedances, capacitor banks and modern electronic equipment with capacitive behaviour. Harmonic resonance leads to an increase in harmonic level around the resonance frequency, which further increases the overall THD of the distribution system. As there can be multiple resonance scenarios which may also vary depending on internal switching of capacitor devices, it is difficult for conventional SAPF to address both harmonic resonance and current harmonics. Therefore, to improve the overall power quality, it is important to first identify/detect and then selectively damp the detected harmonic resonance in the distribution network. Detection of resonance with SAPF commonly require external signal injection, additional circuitry and sensors. This paper deals with non-invasive machine learning (ML)-based resonance detection, which only requires voltage harmonics at the point of common coupling (PCC) as input. Hence, it eliminates the need for any modification in existing control strategy, external signal injection and additional sensors. Also, Resonance detection, resonance damping and harmonic compensation is achieved by utilising only two types of sensors i.e., voltage at PCC and load current.


I. INTRODUCTION
Harmonic resonance is a power quality issue in power distribution networks that arises primarily due to interaction of line impedances, capacitor banks and modern power electronic loads [1], [2]. The main reason behind the increasing resonance issue is the capacitive behaviour of new energy-efficient household electronic equipment and the capacitor banks [3]. However, presence of resonance is more predominant in the case where Shunt Active Power Filter (SAPF) is installed in the system with the capacitor bank. SAPF is one of the most sought-after solution for power quality issues along with other configurations of Active Power Filter (APF) [4]. Capacitor banks are used as a Power Factor Correction (PFC) unit whereas SAPF is widely utilized to address both harmonic as well as reactive power issues. Harmonic resonances cause a significant rise in the harmonic levels of voltage and currents around the resonance frequency [5], [6]. Even if the capacitor bank is detuned, resonance can still be present in the distribution system owing to the capacitive nature of the load. Also, detuning is almost impossible in case of distributed capacitance throughout the distribution network. Therefore, to improve the overall power quality, it is important to classify, detect, and address different harmonic resonance scenarios in the power distribution network.
There are numerous control strategies and optimization techniques for SAPF are available in literature to address different issues [7]- [10], however, very few control strategies focus on addressing harmonic resonance, especially detection of harmonic resonance. A hybrid filter with a capacitor bank in series by coupling transformer is utilized to suppress harmonic resonance in [11], providing a cost-effective solution. Another hybrid APF based on the impedance approach is proposed in [12]- [14]. A conventional control strategy for SAPF is proposed in literature which deals with resonance damping for a particular resonance frequency [15], [16]. Similarly, the concept of Resistive APF is utilized in [17] both for resonance damping at a particular frequency and selective harmonic compensation. The possibility of unwanted amplification of the harmonics caused due to mismatch between Resistive-APF conductance and line impedance is discussed and addressed with the resonant control technique [18]. Resonance damping technique based on current source detection is proposed in [19]. However, this control technique is limited to a narrow frequency range. While most of the techniques discussed in literature focused on resonance damping, there is not much discussion regarding identification or detection of the resonance except in [20],  [21]. Authors in [21] have mainly focused on the resonance in the upstream distribution network caused due to interaction between capacitor bank and source impedance. This method utilizes invasive technique of injecting external signal into the circuit to calculate power index. The disadvantage of invasive techniques is that they can compromise the distribution network performance. Also, this method requires information from four types of sensors to detect resonance frequency. Therefore, most solutions available in literature either utilise passive hybrid SAPF configuration or required additional sensors and/or hardware to address harmonic resonance. The drawback of utilising passive filters and SAPF to address harmonic resonance is that they can only address resonance in the specific frequency range and does not consider variation in system parameters. A detailed comparison between different techniques discussed above is summarised in Table I. Due to continuous variation in the internal switching of capacitive equipment, there can be various possibilities in the resonance's scenarios, e.g., the level of amplification, resonance frequency and the bandwidth of the resonance. Thus, it is important to study various resonance scenarios.
Presence of resonance in the circuit usually does not create a problem as long as it is not excited. There are two types of resonance, parallel and series; both are dangerous to the power distribution network. Parallel resonance is excited by a harmonic current close to the resonance frequency, where impedance of the resonance circuit is minimum. Series resonance is excited by a harmonic voltage close to the resonance frequency, where impedance of the resonance circuit is minimum. Thus, presence of harmonic resonance is observed by measuring the impedance at the busbar or PCC in the distribution network [22]. Machine learning (ML) approach has been proposed in this paper to detect various resonance scenarios. ML has been used reliably to detect several defects, irregularities and disruptions in power grids and other issues with power quality in general [23]- [26]. Harmonic levels are amplified around resonance frequency due to presence of resonance. As a result, harmonic levels are different in presence of resonance in comparison to the case when there is no resonance. This distinction makes it a suitable problem for supervised classification ML approach. ML algorithms works by creating trained model with the help of labelled training datasets and these models are utilized in making data-driven predictions for unseen test dataset. In this paper, ML model is based on classification learning algorithms, i.e., KNN (K-Nearest neighbours) and SVM (Support Vector Machines). A classifier algorithm works by dividing data into different "classes". KNN works on the principle that similar things exist in close proximity i.e., data points that are near to each other belongs to same class [27]. KNN algorithm searches for K number of nearest neighbours for given data sample and predicts class on the basis of majority labelled data sets among K nearest neighbours. In SVM, each data point is plotted in an n-dimensional space and it tries to find a hyperplane that separates the two classes [28]. The objective here is to find a plane that has the maximum margin (distance between the support vectors). Support Vectors are the points that are closer to the hyperplane and influence the position and orientation of the hyperplane. More details regarding theoretical foundation of SVM and KNN is provided in [27] , [28]. This technique only requires voltage harmonics at the PCC as an input. Impedance data from the MATLAB is only required at the training stage to label dataset with corresponding resonance frequency.
Typical behaviour of the power distribution network is presented by an equivalent circuit and the load with capacitive behaviour is modelled with the help of an aggregated load. All parameters are designed on the basis of actual distribution network parameters in a way, that it has distinct resonances well below 2.5 kHz [29].
Paper is presented as follows: Section II deals with the discussion about the effect of resonance on the performance of SAPF and the methodology for the machine learning algorithm. Section III deals with the details regarding building of the realistic database with the help of an equivalent circuit and learning algorithms. Section IV presents control strategy for SAPF. Section V presents machine learning and SAPF results and section VI concludes the work. The main contribution of the paper includes: -(i) Analyse the effect of resonance on the performance of SAPF, (ii) Development of realistic database considering various system parameter variations to study resonance behaviour in power distribution network in the presence of SAPF., (iii) The formulation of a resonance detection method based on machine learning approach. (iv) Resonance detection, damping in addition to the harmonic compensation by utilising reduced number of sensors. Fig. 1 shows the system configuration of a simplified distribution system with SAPF and a PFC unit. Fig. 1  three-phase three-wire system with source voltages, ( = , , ) with line impedance of resistance and inductance , connected to a non-linear and linear load in parallel. Nonlinear consists of an uncontrolled rectifier with an R-L load at its output terminal. The linear load consists of R-L-C parameters connected in parallel at PCC. SAPF unit contains a Voltage Source Converter (VSC) with six IGBTs and a capacitor ( ) at DC side. A coupling inductor ( ) connects SAPF in parallel to the source and load. As shown in Fig. 1, a capacitor bank with capacitance is connected in parallel to the source and load.

A. PARALLEL RESONANCE
Capacitor banks (see Fig. 1) are often used as a PFC unit in the distribution load and are placed near PCC. If seen from PCC towards the source, capacitor bank forms a parallel resonant circuit with the line inductance. This upstream impedance is expressed as; On solving, Assuming the effect of is relatively small, Eqn.
(3) is simplified as: Now, resonance frequency from (4) is expressed as;

B. PERFORMANCE OF SAPF UNDER RESONANCE SCENARIO
SAPF works by injecting compensating current ( = , , ), at PCC to cancel out the harmonics present in source current . Harmonics are injected into the source by load current produced by the non-linear load. Power flow between the source and load is controlled by maintaining a constant DC voltage ( ) across the DC capacitor ( ) as shown in Fig.1. In this paper reference current for source current is generated with the help of Adaptive linear network (ADALINE) based control strategy utilising Least Mean Square (LMS) algorithm [30]. Performance of SAPF is observed for the circuit configuration shown in Fig.1  Results are presented in Fig. 3 and 4. Fig. 3 shows the performance of SAPF in the presence of resonance in terms of PCC voltages and source current for case 1 and 2. It can be observed from Fig. 3(a) and (b) that when SAPF is connected at t=0.05 sec, compensating current ( ) is injected into the circuit and source current ( ) transforms into a sinusoidal waveform in phase with the PCC voltage ( ), without any significant delay. Presence of resonance in case 2 can be observed from Fig. 3(b), which also appears in the harmonic spectra as shown in Fig. 4. Fig. 4 shows harmonic spectra of PCC voltage and the source current under three resonance conditions as explained above in case 1, 2 and 3. For case 1, there is no resonance hence THD of both PCC voltages and source current improved from 8.5 % to 3.0 % and 21.2 % to 1.97 % THD respectively as shown in Fig. 4. For case 2, there is resonance around 1550 Hz (31 harmonic order) frequency.  THD improved from 14.6 % to 9.6 % for PCC voltage and from 24.06 % to 7.54 % for source current. It can be clearly observed that there is harmonic amplification around resonance frequency in comparison to case 1. For case 3, THD improves from 14.3 % to 11.2 % for PCC voltage and 37 % to 23.6 % THD for source current. This increase in THD is due to amplification in harmonics around the resonance frequency i.e., 500 Hz as can be clearly observed in harmonic spectra shown in Fig. 4. In both case 2 and case 3, magnitude of harmonics around resonance frequency does not reduce much even after connection of SAPF, because SAPF is only compensating harmonics injected by load with the help of compensating current. Therefore, it can be concluded that presence of resonance significantly affects overall THD of both voltages and current at PCC and hence performance of SAPF.

C. METHODOLOGY FOR CLASSIFICATION LEARNING BASED DETECTION
Different features of resonance, i.e., bandwidth, and resonance frequency are shown in Fig.5 and corresponding amplification in the harmonic spectrum of PCC voltage | ℎ | and current | ℎ | is shown in Fig.4. Reference impedance ( ) is the impedance value at the 50 Hz frequency, expressed in an extrapolated form. This distinct amplification in harmonic levels around resonance frequency compared to the case without resonance (case 1: without resonance, Fig. 4) forms the basis for the machine learning based resonance classification and detection. Since, in parallel resonance, amplification in voltage harmonic levels is more significant in comparison to the current, thus only voltage harmonic information is utilised here to detect resonance. Fig. 6 shows a methodology for classification learning based detection. Here, voltage | ℎ | spectra is required as an input being trained for respective resonance conditions with the help of learning algorithm. Simulation data, i.e., impedance at PCC, is required for labelling training data set. After training is finished with desired accuracy, unseen test data set, i.e., voltage | ℎ | harmonic spectra are subjected to the trained model for predicted result i.e., resonance frequency. Resonance is classified in terms of the frequency ranges. Thus, the bandwidth of 250 Hz is selected considering the effect in the harmonic amplification, i.e., case with resonance at 1.6 kHz frequency is labelled as "1500-1750 Hz ".

III. PROPOSED RESONANCE DETECTION TECHNIQUE
Three main stages for machine learning includes (a) Data generation and collection, (b) Data pre-processing, (c) Implementation of Algorithm. Fig. 1 is presented in the form of a simplified single line diagram as shown in Fig.7 (a). The network consists of mains, PCC and an R-L branch, SAPF is connected at the load end in parallel to the load and source along with a PFC unit, i.e., capacitor bank, a linear load as well as a non-linear load and harmonic current sources. Harmonic current sources consist of the harmonics injected by current source type non-linear loads. Variation in almost every parameter shown in Fig. 7 (a) is performed to build a database such that it includes all possible cases of different resonance frequencies required for training. Database building, identification and functioning of the training algorithm is discussed in the following section:

A. BUILDING DATABASE FOR THE LEARNING ALGORITHM
Upstream network in Fig.7 (b) consists of line impedance in parallel with shunt capacitance. The downstream network ( Fig. 7(c)) consists of the load and the current harmonic emissions ( ℎ ). Impedance represents the combined impedance of both upstream as well as downstream network. Impedance measurement at PCC ensures all parameters variations at a common point.
is calculated in parts with the help of admittance as follows: Where = + represents loop admittance, represents load admittance of the linear load as shown in Fig.7(c), represents admittance of capacitor bank and represents line admittance.
On simplification, Where, = 1 + 2 , = 1 − 1 , = 1 2 + 1 1 and = ( 2 1 − 1 1 ) Now, loop admittance is calculated as; = + (10) Where, = −(1⁄ ) and = (1⁄ ), on substituting values of and in (17). Where, Total impedance calculated at PCC is utilised to observe different resonance scenarios on varying load and source parameters. The main reason behind resonance is the capacitive behaviour of the load. Therefore, effect of the inductive non-linear load is taken as harmonic current emissions as shown in Fig. 8, and instead of R-L parameters, R-L-C aggregated load is considered to represent load impedance for observing resonance behaviour with the help of total impedance as shown in Fig.8(c). Now, considering non-linear R-L parameters, total load admittance is calculated as: Therefore, harmonic spectrum components voltage at PCC in magnitude form is calculated for various conditions in order to form database. Since, database consists of various datasets, each consisting harmonic spectrum of voltage at PCC. Fig.8 (a) shows magnitude of harmonic spectrum for two different resonance scenarios i.e., for 500 and 1550 Hz considering one household and base parameter values as shown in Table II. Since there are many other possible resonance scenarios possible with different amplification factor, thus final dataset is obtained by considering square of values shown in Fig 8(b). Fig. 8(b) shows datasets for different resonance scenarios each with different resonance frequency as well as magnitude. On comparing harmonic spectrum shown in Fig. 8(a) and 8(b), datasets component in Fig. 8(b) are more distinctive with respect to the harmonic component around resonance frequency.
Effect of parameter variation is observed and discussed below by keeping other parameter values fixed, as shown in Table II.  Variation in total impedance for different values of line inductance is shown in Fig. 10. Resonance frequency decreases from 1.75 kHz to 0.9 kHz with decreases in amplification factor on increasing line inductance from 800 µH to 3000 µH. Fig. 11 shows the variation in the parameters of the aggregated load indirectly by varying number of households. Based on various resonance cases, as shown above, ranges of all parameters are selected for training data formation, shown in Table III. Total load impedance is varied by varying the number of households, values shown in Fig.9 and 10 are for one household load. For clarity, variation in number of VOLUME XX, 2017 9  Table II. Resonance frequency increases from 500 Hz to 1.8 kHz with the decrease in amplification factor on increasing number of households from 30 to 250 as shown in Fig.11. Corresponding variation in phase is also shown in Fig.  11.

4) SOURCE VOLTAGE DISTORTIONS:
Variation in source voltage ( ) distortion is done by varying magnitude and angle within a range as shown in Fig.  12. Total 12 variations for 3rd, 5th, 7th and 11th harmonics are considered to build the database as shown in Fig. 12.

5) CURRENT EMISSIONS:
Current harmonics are injected from the non-linear load. Therefore, variation in current harmonics is mostly governed by variation in the load parameters.

B. ITERATIVE INCREASE IN THE DATABASE POPULATION
To create a realistic database, datasets are identified, selected and artificially increased. The process for determining database for training and testing is explained below.
Based on total and reference impedance obtained after variation of all parameters as discussed earlier. Cases with amplification factor (| | | |) ⁄ smaller than 1 are considered as cases without resonance and cases with amplification factor greater than 10 are not considered in database. Cases with resonance frequency outside the range 0-2.5 kHz are considered as cases without resonance labelled as "No Resonance". Fig. 13 shows the process for iteratively increasing the database on the basis of variations in the equivalent circuit parameters. Based on the variations in different parameters such as voltage distortion, line impedance, PFC capacitance, number of households, and load parameters, different resonance scenarios are generated. All cases generated by individual parameters variations are discussed and presented earlier in this section.

1) DATABASE DETAILS GENERATED FOR TRAINING AND TESTING:
The database is generated in an iterative manner i.e., increasing the size, taking into account one parameter at a time as shown in Fig. 13. Details regarding total number of cases for each parameter is presented in Table IV and Fig.13. Among ten variations in load parameters, half values are considered for testing and the remaining half are considered for testing to separate database.

C. CLASSIFICATION LEARNING ALGORITHMS
Simulations are carried out to build a database consisting of all possibilities associated with different characteristics of harmonic resonance such as resonance frequency, amplification factor and bandwidth. Classification learning app toolbox available in the MATLAB is utilized to perform various operations associated with training, and the database  Fig. 14. Initial three steps are the same for both SVM and KNN, as shown in Fig.14.
Data pre-processing is required to extract only the magnitude of the voltage harmonics samples in per unit. Feature extraction involves only selecting the particular range of harmonics for the training purpose, only harmonics from 0 to 2.5 kHz are considered. Normalization of the input samples ensures that both components with a large and small range have equal weightage in the training process. Further distinct steps for both algorithms are explained as follows:

1) KNN-K NEAREST NEIGHBOURS:
KNN works by calculating the distance between training and test data [27], [31]. Nearest neighbours are selected with the help of the closest distance. K in KNN stands for the number of nearest neighbours considered to predict the class of the unseen test data. The value of K and the distance metric settings are decided such that optimum performance is achieved. Here, the number of input samples (i.e., labelled data samples), is large; therefore, K is decided with the help of cross-validation (CV). In CV, input data samples are arbitrarily divided into train and test data continuously till each data sample is used as test data. Accuracy of the model is checked against CV-data for random K values. The model for which the best accuracy is obtained is considered as the best K value. Here, maximum accuracy for CV datasets is observed at K=15. For distance metric all distance metrics are evaluated to achieve best accuracy.  TABLE IV) After calculating distance ( ) as shown in Fig 15, K nearest neighbours are identified. At the final stage, test data is predicted with the same class as the most common labelled class among K nearest neighbours.

2) SVM-SUPPORT VECTOR MACHINES:
SVM works by creating a hyperplane to separate various classes of the input data set [28]. It has many features to deal with extensive data with overlapping and noise such as creating hyperplane in higher dimensional space, ignoring outliers, kernel tricks etc. This hyperplane is achieved with the help of a decision function ( ) as follows: , is the number of labelled classes.
( ) = ( . ) + (20) and are selected such that hyperplane is created to classify testing data correctly by ensuring distance between the hyperplane, and closest vectors is maximum, this constraint is expressed as: Maximizing the margin between two classes is solved as an optimization problem: is a regularization parameter. Eqn. (22) is solved with the help of Lagrange multipliers and is simplified by the dual VOLUME XX, 2017 9 formulation of the problem. After applying computational techniques and certain simplification, consequently ( ) is expressed as: In (23), is a test vector, is the number of support vectors, and is Lagrange multiplier. Also, for large and complex data, which is not easily linearly separable as is the case discussed in this paper, kernel function is used. can be of different types and is preselected with cross-validation, as shown in Fig.  14. A thorough discussion about SVM fundamentals and detailed derivation is available in the literature [23], [32].
Above operations are performed with the help of SVM library available in MATLAB. Inputs such as , kernel parameters values are required to calculate support vectors and these are decided with the help of CV. The parameter adds penalty for each misclassified data point. Different random values of are validated with CV datasets and this exercise is repeated for multiple times on various CV datasets. The model for which best accuracy is obtained, value corresponding to that model is selected for testing. This process is also called randomized search with cross validation score. = 100 is selected for accuracy of 98.5 %. For kernel, cubic function is selected after evaluating multiple kernel function. Table V shows accuracy corresponding to different kernel functions in SVM against test data. Optimal hyperplane (23)

IV. CONTROL STRATEGY FOR SAPF OPERATION
Control strategy for SAPF to address to perform both harmonic compensation as well as resonance damping is discussed in this section. Complete operation of SAPF in presented in detail in Fig.15. As shown in Fig. 15(a), resonance detection takes place with by sensing voltage at PCC explained in earlier section. With the help of resonance frequency, reference current for damping is generated as shown in Fig. 15(b) which adds up in the reference current generated for harmonic compensation as shown in Fig. 15(c). Here, Reference current generation technique (RCGT) for harmonic compensation only senses load current and PCC voltages sensors as shown in Fig. 15 (c). DC voltage is estimated in order to reduce sensor required for sensing actual DC voltage in power flow control. DC voltage is estimated with the help of MRAS technique discussed in detail in [33]. The technique utilized for Harmonic extraction is shown in Fig. 15(d). Detailed procedure is expressed as follows:

A. REFERENCE CURRENT GENERATION TECHNIQUE
RCGT is developed with the help of Adaline based LMS algorithm. Also, detailed control strategy is provided in reference [30] , [33], [34] LMS algorithm works by calculating weights ( ) such that mean square error between desired and actual quantity is minimum. Corresponding weight update equation for each phase at ℎ instant is expressed as: Where (0 < < 1) is converging coefficient. are unit vector voltages calculated by expressing voltage at the PCC in per unit. Weights are calculated for each phase separately and equivalent weight ( ) is calculated by taking average of three weights as shown in Fig. 15(b). Reference current ( * ) is calculated as follows; * = ( + ) * is loss component of current obtained from DC voltage controller utilized to maintain DC voltage constant at reference value, i.e., * (700 V).
Where, is error between actual and reference DC voltage * . and are proportional and integral gains of the PI controller. Reference harmonic compensation current, ℎ * is generated by subtracting actual load current from sinusoidal reference current * as shown in Fig. 15(c).

B. RESONANCE DAMPING TECHNIQUE
According to detected resonance frequency range ( ), corresponding harmonic component ( ℎ ) and fundamental component ( 1 ) of PCC voltage is extracted as shown in Fig.15(b). With the help of extracted components IHD (Individual Harmonic Distortion) with respect to harmonic order around resonance frequency (ℎ) is calculated as: Where, ℎ and 1 represents RMS value of harmonic order ′ℎ′ and fundamental component of PCC voltage respectively. ℎ * is 3%, standard limit for individual harmonic distortion for voltages according to IEEE standard 519 [35]. The difference between standard and obtained IHD is sent to PI controller in order to regulate actual distortion limits. Thus, reference current for damping resonance is obtained as follows: * = ( ℎ * − ℎ ) ( + ⁄ ) * ℎ (29) Here, it is to be noted that, here only one harmonic order is taken into account. According to predicted frequency range, multiple harmonic orders within frequency range can be taken and reference current is calculated for each order in similar manner. Total reference current for damping is expressed as: * = ∑ ℎ * ℎ (30) Thus, reference current in (30) includes all harmonic orders within resonance frequency range. Similarly, for multiple resonance cases, all such reference components for different harmonic order can be added together to obtain total reference current. Here, extracting total harmonic component of voltage ( ) is avoided as tracking high order damping reference current is difficult considering fixed switching frequency.

1) HARMONIC EXTRACTION ( ):
Three phase PCC voltages are transformed into − coordinates with the help of unit vector generated with the help of PLL. In order to extract particular order harmonic (ℎ), rotating frequency of unit vectors is set accordingly i.e., ′ℎ′ times of the line frequency. DC component is extracted from transformed vectors with the help of LPF of cut off frequency 1 Hz. Using inverse transformation, extracted component in − frame is transformed into three phase positive sequence component. Corresponding negative sequence component can be obtained in a similar way by using unit vector rotating in opposite direction as shown in Fig.15(d).

2) HARMONIC COMPENSATION AND RESONANCE DAMPING REFERENCE CURRENT GENERATION:
Total reference current is obtained by adding both reference harmonic current ℎ * as shown in Fig. 15(b) and reference damping current * as shown in Fig.15(c). * = ℎ * + * ∊ , , VOLUME XX, 2017 9 Reference filter current and actual filter current are sent to PWM current controller to generate pulses for VSC as shown in Fig. 15(a). Here, in place of actual filter current, estimated filter current is utilised to reduce the number of current sensors. Filter current is calculated with the help of switching states and inverter output voltages.
Where, is error between * and . Similarly, and can also be estimated. Detailed derivation is provided in [33].

V. RESULTS AND DISCUSSION
Performance of SAPF is evaluated in three modes. Mode I: Resonance detection, Mode II: Harmonic compensation, Mode III: Harmonic compensation and Resonance damping.

A. MODE I: RESONANCE DETECTION
For resonance detection, the number of datasets produced for both training and testing is shown in Table IV. As shown in Table IV, out of 144000 datasets, there are 61 % cases with resonance within 0-2.5 kHz and 38 % cases without resonance. Each dataset includes a set of voltage harmonic spectra in the range of 0-2.5 kHz. Training and testing data are generated by considering different values of load parameters and the number of households. Now, to label each dataset, the following points are selected. (1). Cases without any resonance: Such datasets include cases without any resonance within 0-2.5 kHz or amplification factor less than 1. Such datasets are labelled as "No Resonance". (2). Cases with resonance: Such datasets include cases with resonance frequency within 0-2.5 kHz. On the basis of the peak in the impedance, i.e., at resonance frequency, amplification of harmonics is generally spread around 200-300 Hz range (see Fig.5). Thus, taking into account bandwidth of the resonance, datasets are labelled in terms of the frequency range. e.g., dataset belonging to 1650 Hz resonance frequency, is labelled as "1500-1750 Hz" frequency range.

1) PERFORMANCE OF CLASSIFICATION LEARNING ALGORITHM FOR TRAINING DATA:
Training data consists of the data labelled with respect to the class it is associated with. Now, data is trained by SVM and KNN algorithm with respect to the corresponding labelled class. At the training stage, algorithms learn from the labels provided as an input to algorithm and then performs the classification as discussed earlier.
The performance of both classifiers SVM and KNN is measured with the help of the Confusion Matrix. Confusion matrix shows actual classes along columns and corresponding predicted classes along rows as shown in Fig. 16. Confusion matrix effectively showcases the performance of the model in detail. In addition to overall accuracy of the trained model, confusion matrix also shows prediction accuracy with respect to each class (different frequency ranges). Overall accuracy of the ML model is defined as total number correctly predicted cases out of all cases. For individual cases, performance parameters like precision and recall can easily be calculated for each class with the help of confusion matrix. Precision is defined as the number of correctly predicted cases of class A out of all predicted cases in class A. Similarly, recall is total number of correctly predicted cases of class A out of actual number of cases in class A, where A represents each class shown in confusion matrix. For example, precision and recall for class "300-550 Hz" from confusion matrix shown in Fig. 16 Accuracy of the trained model by SVM and KNN is 98.55 % and 86.78 % respectively, as shown in Fig. 16 (a) and (b). Considering the case of 100-350 Hz range in confusion matrix shown in Fig.16 (a), 12.7 % of datasets with actual resonance frequency range in 100-350 Hz is falling in 300-550 Hz range, which is true for some instances, as there is 50 Hz overlap and cases with resonance frequency between 300-350 Hz can be classified as in both categories. Similarly, for KNN, 48.9 % of datasets with actual resonance frequency in 100-350 Hz is falling in 300-550 Hz range as shown in Fig. 16(b). It is to be noted here that classification of cases without resonance is attained with 100 % accuracy by both KNN and SVM as shown in Fig. 16 (a) and (b). It can be observed from confusion matrix in Fig. 16 (a-b) that, accuracy for the datasets in higher resonance frequency range is greater than in lower frequency range, which shows that most cases with higher resonance frequency also have relatively higher amplification factor.
Due to the considerable difference in the trained model's accuracy by both KNN and SVM algorithms, a trade-off between computation time and accuracy is made according to the requirements. Table V shows corresponding computation time and accuracy of both SVM and KNN algorithms. The SVM algorithm performs better in terms of accuracy than KNN with more than 90 % accuracy, i.e., 98.55 % and 95.6 % with cubic and Gaussian kernel function, respectively. KNN algorithm with the Cosine distance metric consumes less training time, i.e., 99 secs, which is much lesser than SVM. Therefore, considering the slow speed of SVM, KNN with 86.78 % accuracy and fast speed is preferred for training.

2) PERFORMANCE OF CLASSIFICATION LEARNING ALGORITHM FOR UNSEEN TEST DATA:
Performance of trained model obtained by SVM Cubic (maximum accuracy) and Cosine KNN (minimum training time) is observed by subjecting it with the unseen test data. The trained model with 98.55 % (Fig. 16 (a)) accuracy is tested against new unseen data and predicted class is shown with the confusion matrix in Fig. 16(c). As shown in Fig. 16(c), the prediction accuracy obtained from SVM is 84.1%.
It can be observed from Fig. 16(c) that prediction accuracy for cases without resonance, and for cases with higher resonance frequency is 100 % and ~90 % respectively. Similarly, the accuracy of the trained model by KNN, when subjected to test data is 78.67 %, as shown in Fig. 19. Here, the accuracy of predicted class for "No resonance" cases is 99.3 %, with only 0.7 % falling into "500-750 Hz" and "700-950 Hz" class.
From the confusion matrix shown in Fig.16(c) and (d), it can be found that there is an overlap of 50 Hz in various classes (resonance frequency ranges). Due to this most of the false prediction falls into the nearest range of resonance class. E.g., out of 624 datasets (240+292+92) belonging to "100-350 Hz" class in confusion matrix shown in Fig.16(d), 38.5 % of datasets show true prediction while 61.5 (46.8+14.7) % of datasets show false prediction identified as "300-550 Hz" and "No Resonance", respectively. Here, cases with resonance frequency in "300-350 Hz" range will fall in both "100-350 Hz" and "300-350 Hz" class.

B. PERFORMANCE OF SAPF FOR COMPENSATING HARMONICS AND RESONANCE DAMPING
Performance of SAPF under two different resonance cases is shown in Fig. 17 in terms of PCC voltage, source current, compensating current and FFT analysis. In Fig 17(a), SAPF is connected at t=0.05 sec improving waveforms of PCC voltages and source current from distorted waveforms to sinusoidal. At this instant (t=0.05-0.08), SAPF only operates in Mode II (Harmonic compensation), thus harmonics amplified due to resonance still appears in both PCC voltage and source current waveform. At t=0.08, SAPF starts operating in Mode III, thus adding resonance damping component in compensating current which improves THD of both PCC voltage and source current from 14.6 % to 3.52 % and 24.06 % to 3.12 % respectively as shown in Fig. 17(b). Similarly for case 3, harmonics are considerably reduced when SAPF operates in Mode III at t=0.08 sec in comparison to Mode II improving THD of PCC voltage and source current from 14.3 % to 3.33 % and 37 % to 4.87% respectively as shown in Fig. 17(d). Corresponding FFT analysis is shown in Fig. this and this. Also, IHD of 31st and 10th harmonic in PCC voltage for case 2 and 3 improved from 5% to 1.9 % and 12.2 % to 2.2 % respectively after resonance damping.
Also, estimated quantities i.e., filter current and DC voltage are shown in Fig. 18. These estimated quantities are utilised in control algorithm to reduce the requirement of actual sensors.

C. PERFORMANCE OF PROPOSED TECHNIQUE IN PRESENCE OF NOISE
Performance of SAPF is tested in presence of noise in both voltage and current measurement. Effect of noise is analysed at two stages of the proposed work stated as follows:

1) EFFECT OF NOISE ON PERFORMANCE OF ML MODEL FOR HARMONIC RESONANCE DETECTION
Resonance detection only requires voltage harmonic data as an input. Therefore, noise is added in voltage harmonic data to evaluate performance of the trained model. An example showing difference between harmonic profile of voltage with and without noise is shown with the help of FFT analysis in Fig. 19. Presence of noise can be observed from increased voltage harmonic levels around 1500 Hz shown in Fig 19 (b). Now, previously trained SVM model shown in Fig. 16(a) is utilized for testing i.e., ML model is trained with the samples that do not contain noise. It is to be noted that a pre-trained ML model is used for testing, thus prediction of resonance does not take additional time in the control unit. From unseen test data, noise is added in 25 % of test datasets i.e., from total of 72000 samples (Table IV), noise is added in 18000 samples.
Performance of trained model obtained by SVM is observed by subjecting it with unseen test data containing noise. Predicted class is shown with help of confusion matrix in Fig.20. The prediction accuracy obtained from SVM trained model is 80.24 % as shown in Fig.20. It can be observed from Fig. 20 that prediction accuracy for cases without resonance, and for cases with higher resonance frequency is 99.4 % and ~85-90 % respectively. This is due to high magnification ratio at higher frequency ranges. Accuracy of ML model reduced by 4 % after adding noise. This reduction in accuracy is mainly due to misclassification around lower frequency range (100-1000 Hz). Performance of trained model is tested under worst condition since noise is only added during the test stage. Performance of trained model can be improved if presence of noise is also considered at the training stage.  harmonic compensation and resonance damping and resonance at around 1550 Hz is considered for evaluation. It can be observed from Fig.21 that THD of load current increased from 25.49 % to 29.38 % on adding noise. From t=0.12 to 0.2 sec, white noise is added in phase sensor of load current and from t=0.16 to 0.2 sec, noise is added in all three phase sensors of load current as shown in Fig.22. The presence of noise resulted in an increase in THD of from 3.12 % to 3.65 % during t=0.12 to 0.2 sec. Similarly, for PCC voltage sensors, white noise is added in phase ' ' sensor of PCC voltage from t = 0.12 to 0.2 sec and in all three phases from t = 0.16 to 0.2 sec as shown in Fig. 23. This voltage is shown with " " i.e., measured PCC voltage which is involved in the reference current generation technique. From the source current waveform shown in Fig.  23, it can be observed that performance of SAPF is not significantly affected in presence of noise in PCC voltage sensor. THD of source current only increased from 3.12 % to 3.16 %. This is because unit voltage generation remained unaffected in presence of disturbance in voltage sensors as shown by waveform in Fig. 23. Corresponding FFT analysis of PCC voltage and source current in presence of load current and voltage sensor noise is shown in Fig. 24 (a) and (b) respectively.

VI. CONCLUSION
This paper proposes a new technique to detect resonance in power distribution system. This technique is based on the machine learning based classification approach, which utilizes both KNN as well as SVM algorithm. Machine learning approach solves the problem of external signal injection, complex algorithms and additional circuitry which is usually required to detect harmonic resonance. This paper also provides an insight into various possible cases of resonance caused due to different parameters in the distribution network consisting of both SAPF and a PFC capacitor bank. A realistic database resembling the behaviour of the actual resonance cases in power distribution network is created such that it consists of a variety of resonance scenarios with different characteristics, e.g., resonance frequency, amplification factor and bandwidth. Resonance frequency within 2.5 kHz is detected while considering the bandwidth of 250 Hz.
Accuracy of 84 % from SVM and 78 % from KNN is obtained for classifying the test data. This paper deals with the classification and detection of resonance in terms of different frequency ranges. Further research will focus on resonance identification in terms of amplification factor through machine learning. In addition to this, further testing with real field measurement data is required to assess the accuracy of the machine learning-based detection approach in detecting/classifying practical resonance scenarios.
In addition to resonance detection, resonance damping and harmonic compensation are achieved by utilising only two sensors thus reducing the overall requirement of dedicated sensors.