## 3 Methodology
### SDR Module
#### 3.3.2 Detecting Algorithm Using Autoencoders  
This second part involves analyzing the samples obtained in the first block by inputting them into autoencoders to determine if a UAV is present in any of the analyzed frequency bands. Autoencoders are used as anomaly detectors within the frequency bands. When the system is launched for the first time after installation, it begins collecting data from the bands to be analyzed, which will be used to train the autoencoders. These samples correspond to the signal power in the absence of a UAV, allowing the training of a specific autoencoder for each frequency band. This data collection and training process is automatic, and, once it is complete, the detection system starts, along with the camera module. If the system shuts down for any reason, it will resume directly with the detection process upon restarting as the training will already have been completed. Since the training data correspond to the signal power in the absence of a UAV, when inference is performed on the signals constantly received from each band, if the input data do not contain UAV signals, the autoencoders, trained on such data, will reconstruct the signal with low error. However, if the input data contain UAV signals, which were not present during training, the reconstruction error will be high, indicating the possible presence of a UAV. Figure 3 demonstrates this. In the example on the left, the spectrum of the 2.45 MHz band and the reconstruction of the band after passing through the autoencoders are shown. The reconstruction is similar to the input signal, resulting in a low error, as shown in the black spectrum, indicating no UAV in this band. In contrast, in the example on the right, the autoencoder is unable to reconstruct the input signals, resulting in a high reconstruction error, indicating the potential presence of a UAV. The figure was generated in Python 3.8 using the Matplotlib library, employing the power vectors extracted from GNU Radio and the power vectors obtained after processing them through the autoencoders. Based on this, the system continuously analyzes each frequency band for anomalies that could indicate the presence of a UAV. An alert is sent to the camera module only if anomalies are detected in the same section of the frequency band in two consecutive readings. An anomaly is considered to be present when the reconstruction error of the signal in that part of the band exceeds a certain threshold. The requirement of two consecutive readings with anomalies is due to the high likelihood of false positives caused by interfering signals in the frequency bands. An anomaly detected in a single reading could result from a momentary interference and may not necessarily indicate the presence of a UAV. Therefore, by requiring anomalies to be recurrent in two consecutive readings, the possibility of false positives is reduced, improving detection accuracy. The following part explains the steps the algorithm takes to determine if a UAV is present in a frequency band after two consecutive data readings. 1. Sample Reception: \(N\) samples of a specific frequency are received. These samples are fed into the autoencoder, producing \(N\) corresponding reconstructions. 2. Reconstruction Error Calculation: For each sample and its reconstruction, the following takes place: * Both the sample and its reconstruction are divided into \(M\) segments. * The reconstruction error is calculated for each segment individually. * It is checked whether the reconstruction error in any segment exceeds a predefined threshold. * The segments \(m\) in sample \(n\) where the error exceeds the threshold are recorded. 3. Storing Results: This process is repeated for all \(N\) samples, storing the segments where the reconstruction error exceeds the threshold for each sample. 4. Segment Analysis: For each segment, the percentage of samples that have exceeded the initial reconstruction error threshold is calculated. 5.