# Deep Learning Algorithm for Automatic Classification of Power Quality Disturbances
## 3 Materials and Methods
### Convolution Layers  
This study is based on the utilization of a 1-D CNN model for the classification of power quality disturbances. Specifically, a sliding window approach is employed to segment the signals for input into the 1-D CNN model. This strategy allows for the extraction of local features from the signal data, enabling the model to effectively capture temporal patterns and variations of essential features for accurate classification. Assuming that the sliding window iterates one element at a time (i.e., with a stride of 1), the operation can be executed based on the following definitions:  
\[(I*K)_{i}=\sum_{u=1}^{s}I(i+u-1)K(u) \tag{1}\]  
\[(I*K)_{i}=\sum_{u=1}^{s}I(i-u-1)K(u) \tag{2}\]  
where \(I\) is the input of length \(n\) and \(K\) is the sliding window of length \(s\).  
By incorporating the sliding window approach in conjunction with the 1-D CNN architecture, we aim to enhance the model's ability to analyze and classify power quality disturbances with a focus on temporal dynamics. This approach contributes significantly to the robustness and efficiency of our classification methodology, allowing for a more nuanced understanding of the complex waveforms associated with various PQ issues. The convolutional layers are utilized to perform convolutional operations on the input data sequence, effectively extracting meaningful features essential for subsequent processing. The proposed model employs multiple convolutional layers with varying kernel sizes, each dedicated to detecting specific patterns or features within the input sequence. With a stride of 1, each filter moves horizontally and vertically across the input data, advancing one position at a time. This configuration enables the convolutional layers to apply filters through element-wise multiplications and summations, leading to the generation of feature maps. A detailed overview of each convolutional layer, alongside its corresponding kernel sizes, is presented in Figure 2 and Table 1.  
The ReLU activation function is utilized by introducing non-linearity into the proposed model. It is defined mathematically as:  
\[f(x)=max(0,x)\]  
\begin{table}
\begin{tabular}{c c c c} \hline
**No.** & **Layer** & **Parameters** & **Activation** \\ \hline
1 & Convolution & Filter size = 32 & Relu \\
2 & & Max pooling & \\
3 & & Batch normalization & \\
4 & Convolution & Filter size = 64 & Relu \\
5 & & Max pooling & \\
6 & & Batch normalization & \\
7 & & Max pooling & \\
8 & Convolution & Filter size = 128 & Relu \\
9 & & Global Max pooling & \\
10 & & Batch normalization & \\
11 & Attention layer & & \\
12 & Fully connected & Size = 128 & Relu \\
13 & Fully connected & Size = 32 & Relu \\
14 & & Batch normalization & \\
15 & Fully connected & Size = 16 & Softmax \\ \hline \end{tabular}
\end{table}
Table 1: Proposed CNN architecture.  
thus, when \(x\) is positive, the output is \(x\). On the other hand, when \(x\) is negative, the output is 0. Introducing non-linearity into our model enables the CNN to learn complex patterns. Moreover, ReLU maintains a gradient of 1 for positive inputs, facilitating faster learning in the deep network.