# Detecting Jamming in Smart Grid Communications via Deep Learning
## 5 Theoretical Framework and Methodology
### Theoretical Framework
Then, we compute the bi-variate histogram of the \(I-Q\) samples and translate it into RGB images. At last, we create two datasets of images with labels of non-jammed and jammed samples. jammed signals. In fact, we consider two datasets, \(X_{J}\) and \(X_{NJ}\), representing the jammed and non-jammed datasets, respectively. Each \(X_{y}\) (where \(y\in J,NJ\)) is divided into three subsets, namely \(\mathcal{T}\), \(\mathcal{V}\), and \(\mathcal{S}\), each of which constitutes (\(60\%\approx 450\times 2(\text{classes})\approx 900\)), (\(20\%\approx 150\times 2\approx 300\)), and (\(20\%\approx 150\times 2\approx 300\)) of the original dataset, respectively. We employ state-of-the-art CNN classifiers, specifically a CNN based on Residual Network (Resnet-18 and Resnet-50) and Inception-v3, implemented in MatLab2023b. Neural network models are pre-trained using the ImageNet database [62]. The input layers are adjusted to accommodate the output of the bi-variate histogram (image size), set at \(224\times 224\), while the output layer is modified to match the two classes of our problem, namely _jammed_ and _non-jammed_. **Jamming Detection. ** In this case, we consider Scenario 2, where we assume that the receiver has never been jammed before and has to detect the presence of the jammer by only considering a dataset consisting of images generated from non-jammed signals. Under this assumption, we address the problem of jamming detection by considering _sparse autoencoders_. The typical architecture of _autoencoders_ is shown in Figure 8. The encoder processes input images of size \(N\times M\times 3\). The input is compressed into its corresponding latent space representation via multiple hidden units. In the latter stage, compressed features (latent representation) are decoded into \(N\times M\times 3\) neurons with the help of a decoder. We stress that, since we assume Scenario 2 during the training process, only \(X_{NJ}\) (images generated from non-jammed signals) are considered and passed to the autoencoders. The training phase of the autoencoder is shown in Figure 9, where we highlight that only \(X_{NJ}\) is fed to the model. To fine-tune the configuration of the key parameters in the autoencoder for Scenario 2, we use a subset of the data not used during the training process, namely the _validation set_. We use the reconstruction MSE of the training and validation sets to calculate a threshold value \(\tau\). If a sample image has a reconstruction MSE greater than \(\tau\), it is classified as an anomaly; otherwise, it is considered a legitimate sample. The threshold value should be chosen taking into account the sensitivity to minimal anomalies and false positives, i.e., wrong classification of legitimate events on the channel as jamming. If the threshold is too large, anomalies whose MSE value is close to the model cannot be detected. If the threshold is too small, legitimate channel samples could be mistaken for anomalies. We opted for an empirical selection of the threshold computation technique defined in [63] and formalized in Equation (8). \[\tau=mean(MSE_{train})+3\times std(MSE_{train}), \tag{8}\]  
Figure 8: Autoencoder architecture. where \(MSE_{train}\) is the MSE of the training set, _mean_ is the statistical average, and \(std\) is the standard deviation. As demonstrated by the authors in [63], this choice increases the chances of detecting anomalous channel conditions due to jamming. As an example, Figure 10 shows the threshold calculation for three scenarios, with the receiver located at 65 m, 70 m, and 75 m from the jammer (the jammer uses the same transmission power of the transmitter, i.e., RJP = 1). In Figure 10a,b, the jammed samples (test dataset) are characterized by MSE values that are distinct from the non-jammed ones (training and validation sets). In fact, the distribution of the samples collected in the presence of the jammer exhibits higher MSE values than those collected without the presence of the jammer.