{'fraction_non_alphanumeric': 0.026420791545346704, 'fraction_numerical': 0.017254394478593768, 'mean_word_length': 4.749225046497211, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Zero-Crossing Point Detection of Sinusoidal Signal in Presence of Noise and Harmonics Using Deep Neural Networks

: Zero-crossing point detection is necessary to establish a consistent performance in various power system applications, such as grid synchronization, power conversion and switch-gear protection. In this paper, zero-crossing points of a sinusoidal signal are detected using deep neural networks. In order to train and evaluate the deep neural network model, new datasets for sinusoidal signals having noise levels from 5% to 50% and harmonic distortion from 10% to 50% are developed. This complete study is implemented in Google Colab using deep learning framework Keras. Results shows that the proposed deep learning model is able to detect zero-crossing points in a distorted sinusoidal signal with good accuracy.


Introduction
Zero-crossing point (ZCP) detection is very useful for frequency estimation of a sinusoidal signal under various disturbances, such as noise and harmonics. Zero-crossing point detection is an important mechanism that is useful in various power system and power electronics applications, such as synchronization of a power grid [1], the switching pulse generation in triggering circuits for power electronics devices, control of switch gear, equipment for load shedding or protection and signal processing, and it is also used in other fields such as radar and nuclear magnetics [2]. This technique's appeal stems largely from its ease of implementation and resilience in the presence of frequency fluctuation.
The ZCP estimation tools have certain flaws such as the technique's accuracy in the presence of transients, harmonics and signal noise, which is still dubious. The most important requirement for properly determining the ZCP of any signal using digital control methods is that the signal should be free of any false ZCPs. Harmonics due to nonlinear loads will have an impact on zero-crossing points of voltage signals and also lead to power quality issues such as malfunction of protection devices, lower power factor, increasing losses and decreasing power system efficiency [3]. The existence of transients, harmonics or noise in the system enhances the probability of a false ZCP occurrence. This issue has not been effectively addressed since there has been relatively little study on the subject.
Artificial intelligence (AI) is now used in a variety of sectors, especially in electrical for load forecasting [4] and image processing [5]. In this paper, an AI approach is used to predict the ZCP class in a distorted sinusoidal signal. AI analyzes the system and predicts outcomes based on previously known data.
ZCP detection technique is developed to estimate the distorted sinusoidal signal in a power grid using least square optimization in [6]. However, this method is not suitable where fast zero-crossing detection is required. A neural network-based approach is developed in [7] to detect the ZCP for a sinusoidal signal with only frequency variation from 49Hz to 51Hz but not considered the distortion in the signal with noise. Opto-coupler based ZCP detection is developed in [8]. This approach results in phase distortion due to the diode's non-zero forward voltage.
A novel ZCP tool is developed in [9] using a differentiation circuit and reset flipflop that leads to less delay time for ZCP detection. This tool performance is examined up to 7.27% total harmonic distortion (THD) only. Support vector machine based ZCP detection tools are developed in [10] by considering the 100 microseconds sample-distorted sinusoidal signal.
A new zero-crossing detection algorithm based on narrow-band filtering is developed in [11]. In this algorithm, normalized electrical quantity is passed through a narrow band filter. A ZCP detection algorithm is developed in [12] based on linear behavior of the sinusoidal signal at the zero-crossing point. In this methodology, the author has used multistage filtering and line fitting techniques.
A zero-crossing detection based digital signal processing method is proposed in [13] for an ultrasonic gas flow meter, and this methodology is used for ultrasonic wave propagation time calculation. If the freewheeling angle exceeds 30, the zero crossing of back EMF will be undetectable. Detection of ZCP in the back EMF signal for brushless DC motors under sensorless safety operation, i.e., the maximum free-wheeling angle, is proposed in [14]. Multiple ZCP detections in ultrasonic flow meters to determine time of flight are proposed in [15]. In this paper, time taken to obtain ZCP is used as time of flight. Hardware support for measuring the periodic components of signals based on the number of ZCP is proposed in [15]. ZCP detection circuits are complex and require more accurate detection; due to this complexity few works are carried out by avoiding ZCP, such as soft-switching control without zero-crossing detection for the cascaded buck-boost converters [16]. Detection of ZCP using Proteus ISIS software with a microcontroller is proposed in [17] for power factor correction and a trigger angle on the SCR trigger for DC motor speed control is for the rocket launch angle adjuster. A simple detection method for the ZCP of converter current using a saturable transformer for use in high-current and high-frequency pulse-width modulated power electronic converter applications is proposed in [18].
All the methodologies mentioned above provide valuable contributions to the ZCP problem. However, to improve the accuracy in predicting the true ZCPs, a new deep neural network (DNN) based machine learning model is developed in this paper. In order to make this DNN model more generalized, a variety of distorted signals are generated and extensive features such as slope, y-intercept, correlation and root mean square are extracted and used as dataset samples.
The main motivation for this work is to identify the most accurate zero-crossing points of distorted voltage signals for proper protection of a power system using switchgear equipment and efficient power conversion by generating proper triggering pulses in conversion circuits.
The main contributions of this paper are as follows: • A properly tuned DNN model is developed for accurate ZCP detection. • Four new datasets are created with a variety of distorted sinusoidal signals by considering noise levels from 5% to 15% and THD levels from 10% to 50%.
The remaining part of this paper is structured as follows: Section 2 presents a methodology that includes DNN model configuration and dataset preparation, Section 3 demonstrates results analysis and Section 4 describes conclusions.

Methodology
Four new datasets are created using MATLAB software for the ZCP detection problem and are available in [19]. The first dataset developed using distorted sinusoidal signals with noise levels from 10% to 50% consists of 4936 samples. The second dataset developed using distorted sinusoidal signals with THD levels from 10% to 50% consists of 4436 samples. The third dataset developed using distorted sinusoidal signals with noise levels from 10% to 40% and with THD level 50% consists of 3949 samples. The fourth dataset developed using distorted sinusoidal signals with noise levels from 5% to 20% consists of 3949 samples.

Dataset Formulation
Data samples are collected every 100 microseconds duration over 5 cycles. The complete dataset preparation mechanism is presented in Figure 1.

Sinusoidal Signals Used for Data Preparation
The data of the various sinusoidal voltage signals with noise (5 to 50%) is extracted by generating the signals in MATLAB as shown in Figure 2. In this paper, distorted sinusoidal signals are generated with white gaussian noise. Similarly, the data of the various sinusoidal voltage signals with total harmonic distortion from 10% to 50% is extracted by generating the signals in MATLAB as shown in Figure 3. Distorted sinusoidal signals are generated by adding unity amplitude fundamental signal with 5th order harmonic signals with varying amplitude from 0.1 to 0.5. THD of these distorted signals is estimated using FFT analysis based on equation where V h is RMS value of harmonic voltage signal and V f is RMS value of fundamental voltage signal. In the same way, a few more sinusoidal signals were generated in MATLAB with a combination of both noise and harmonics as shown in Figure 4.

Windowing of Data Points in Distorted Sinusoidal Signal
Data samples extracted from various signals are formed into data windows of a specific length. The best window size (i.e., number of data points for each data window) should be preferred for better accuracy of the classification model. The number of data points in a particular window for calculating features represents the window size. Different window sizes of 5, 10, 12 and 15 data points are used to train the model. For a 50 Hz signal with distinct levels of harmonic distortion and noise, the greatest accuracy is obtained for the data window with 15 data points in the classification of zero-crossing and non-zerocrossing points. Therefore, the window with 15 data points is used for all the tests that are carried out further. Each data window is classified into two classes, as ZCP class or non-zero-crossing point (NZCP) class based on the availability of ZCP in that window. ZCP class is labelled as 1 and NZCP class is labelled as 0. Date sampling based on window size 15 along with its class is shown in Figure 5.

Feature Extraction
Complete distorted sinusoidal signal data points over 5 cycles are split into multiple sets based on the sliding window approach. Each set consists of 15 data points since the window size is considered as 15. Four features called slope (m), intercept (c), correlation coefficient (R) and root mean square error (RMSE) are extracted from each set that consists of 15 data samples by comparing unity amplitude fundamental signal using below equations where m is slope, c is intercept, R is correlation coefficient, n is number of samples, t k is time value of k th data point, v k is voltage magnitude of distorted signal at time t k and U k is voltage magnitude of unity fundamental signal at time t k . These four features are the input features for the selected window. If ZCP exists within the window then the class label (output variable) is 1, i.e., ZCP class. If ZCP does not exist within the window then the class label is 0, i.e., NZCP class. Hence, every sample in the dataset consists of four input features and one output variable that represents the class.

Deep Neural Network
Deep neural networks (DNN) are the most accepted and essential machine learning model to solve either regression or classification problems [20]. Deep neural networks are an assembly of layers that can be mathematically described, in the literature, as a "network function" that associates an input tensor with an output tensor [21]. A DNN is developed to predict the zero-crossing point using four input features of a distorted sinusoidal signal, i.e., slope, intercept, correlation and RMSE. The complete architecture of DNN used in this paper for accurate prediction of ZCP class is shown in Figure 6 and the model parameters are presented in Table 1. In the proposed DNN model, the ReLU activation function is used in hidden layers, whereas the sigmoid activation function is used in the output layer. Mathematical modeling of ReLU [22] and sigmoid activation functions [23] are g(x) = 1 1 + e −x (7) Figure 6. DNN model topology. Adam optimizer [24,25] is used to train the DNN model by considering minimization of the binary cross-entropy loss function shown below.
where y i is actual class and p i is predicted class. Accuracy of the proposed DNN model on various datasets is evaluated using: where TP is the number of samples correctly identified as ZCP, TN is the number of samples correctly identified as NZCP, FN is the number of samples incorrectly identified as NZCP and FP is the number of samples incorrectly identified as ZCP.

Training and Testing Strategy
All the data samples in each dataset are split into two groups to train and test the DNN model by considering the test data size of 5%. The data split is performed randomly, and no duplicate samples are present between training and testing data. DNN models are trained and tested with four datasets independently. Starting weights of the DNN model while training with each dataset are different and these are generated randomly at beginning of the algorithm. DNN models are trained and tested on each dataset 10 times with different starting weights but with the same training and testing data. The best accuracy model among all simulations is considered for the prediction of ZCP class. In this paper, the DNN models are trained with the same training data but different initial weights for 10 times. The DNN model with the best training and testing accuracy over 10 runs is presented in the results.

Results
The dataset that is created, as per the discussion in Section 3, is for the training and testing of DNN models. Statistical features of all ZCP datasets, which are Dataset-1: noise levels 10% to 50%, Dataset-2: THD levels 10% to 50%, Dataset-3: noise levels 10% to 40% with THD level 50% and Dataset-4: Noise levels 5% to 20%, have been used to train the DNN model presented in Tables 2-5 respectively. The back-propagation through time (BPTT) algorithm with the Adam optimizer is used to train the proposed DNN model. The proposed DNN model is being implemented and tested in Google Colab.   Box plots are used to identify the outliers against each input feature in every dataset mentioned above. Box plots against each feature for Dataset-1, Dataset-2, Dataset-3 and Dataset-4 are shown in Figures 7-10, respectively. From all these plots, it has been observed that features in all datasets, such as intercept, correlation and slope, have outliers as data exist below the 25% interquartile range and above the 75% interquartile range. These outliers are due to spikes in distorted signals due to noise and harmonics and cannot be removed from data to make the model predict zero-crossing points under noise and harmonics.  All four datasets that contain four input features and one output label are used to train the DNN model. The training accuracy of the DNN model against each variety of datasets for various hidden neurons and hidden layers combinations are shown in Figure 11. From the figure, it has been observed that the DNN model's training performance is good with maximum accuracy with 3 hidden layers and 64 hidden neurons. Similarly, the testing accuracy of the DNN model against each variety of datasets for various hidden neurons and hidden layers combinations is shown in Figure 12. From the figure, it has been observed that the DNN model's testing performance is good with maximum accuracy using 3 hidden layers and 64 hidden neurons. The proposed DNN model with 3 hidden layers and 64 hidden neurons is trained with various batch sizes on all the datasets mentioned in this paper, and accuracy levels for each batch size are presented in Figure 13. From Figure 13, it has been observed that the DNN model trained with a batch size of 15 provides good training accuracy of 96.26%, 99.73%, 100% and 99.26% and testing accuracy of 96.88%, 99.73%, 100% and 99.32% on Dataset-1, Dataset-2, Dataset-3 and Dataset-4, respectively. The proposed DNN model with 3 hidden layers, 64 hidden neurons and 250 epochs for all the datasets mentioned in this paper is trained with various window sizes as presented in Table 6. From Table 6, it can be observed that the proposed DNN model performs better for all the datasets with window size 15. The proposed model with 3 hidden layers, 64 hidden neurons and 250 epochs for all the datasets mentioned in this paper with a window size of 15 data points is trained and tested 10 times. The accuracies for all the simulations are presented in Table 7. The best accuracy among all the 10 simulations was chosen as the final accuracy for respective datasets.

Discussion
The proposed DNN model with 3 hidden layers and 64 hidden neurons trained with a batch size of 15 and epoch size of 250 is used to predict the zero-crossing point class in real time as an optimal model. The proposed DNN model is validated by comparing it with some existing models, such as decision tree [26] and support vector machine (SVM) [27], as shown in Figure 15. From Figure 15, it has been observed that the training accuracy of the proposed model is a bit low if only either noisy or THD distorted signals are considered, but if the signal is highly distorted due to both noise and harmonics then the proposed model learning is good with better training accuracy. However, the proposed model is more generalized in comparison with decision tree and support vector machine, with better testing accuracy of 97.97%, 98.87%, 100% and 99.5% on Dataset-1, Dataset-2, Dataset-3 and Dataset-4, respectively, and that is required for real-time deployment.

Conclusions
Zero-crossing point detection is an essential task in various power system applications, such as grid synchronization, and power electronics applications, such as firing pulse generation for switching devices. The proposed good accuracy DNN model to predict the zero-crossing point can be used in the mentioned applications.
In this paper, four datasets with different noise levels and THD values are developed and used to train the DNN model for the accurate prediction of ZCP. A final DNN model with good accuracy was developed after tuning the hyper-parameters such as hidden layers, hidden neurons, batch size, window size and epochs.
In this paper, a new DNN model with 3 hidden layers and 64 hidden neurons in each hidden layer is developed and ZCP classes were predicted with good accuracy in comparison with decision tree and SVM. The DNN model with a highly distorted signal, i.e., the signal that is distorted due to both noise and harmonics, has high accuracy in both training and testing as the model is well generalized with the high variance data. The proposed DNN model can predict the ZCP well on highly distorted signals. This work can be further extended by considering the distorted sinusoidal voltage with voltage sag and swells.  Data Availability Statement: The datasets generated during and/or analyzed during the current study are available in the Mendeley Data repository, https://data.mendeley.com/datasets/jbwy5 fjcdj/2 (accessed on 7 November 2021).