-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asv
116 lines (97 loc) · 5.06 KB
/
main.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function main()
% MAIN - Main script for Pilot Spoofing Attack (PSA) simulation and analysis
%
% This script runs a comprehensive simulation of a massive MIMO system
% with potential pilot spoofing attacks. It generates data, trains neural
% network models, performs attack detection and localization, and
% visualizes the results using the Wireless Security Simulation Toolkit (WSST).
%
% The script progresses through the following steps:
% 1. Set up simulation parameters
% 2. Generate dataset
% 3. Train neural network models
% 4. Perform attack detection
% 5. Perform attacker localization
% 6. Calculate and visualize performance metrics
%
% Note: Ensure all required functions are in the MATLAB path before running.
% Simulation Parameters
M = 100; % Number of base station antennas
K = 8; % Number of legitimate users
tau = 16; % Length of pilot sequence
gridSize = 400; % Simulation area size (m x m)
nbLoc = 50; % Number of different location realizations
nbChanReal = 100;% Number of channel realizations per location
P_ED_dBm = 0:5:30; % Eavesdropper power range (dBm)
P_ED = 1e-3 * 10.^(P_ED_dBm/10); % Convert eavesdropper power to Watts
n_attackers = 3; % Number of attackers for multiple attacker scenario
% Generate Dataset
disp('Generating dataset...');
[X_feature_PPR, X_feature_Eig, y_label] = generateDataset(M, K, tau, gridSize, nbLoc, nbChanReal, P_ED);
% Print dataset sizes for debugging
disp(['X_feature_PPR size: ', num2str(size(X_feature_PPR))]);
disp(['X_feature_Eig size: ', num2str(size(X_feature_Eig))]);
disp(['y_label size: ', num2str(size(y_label))]);
% Remove extremely low variance features
[X_feature_PPR, X_feature_Eig] = removeExtremelyLowVarianceFeatures(X_feature_PPR, X_feature_Eig);
% Train Neural Network Models
disp('Training neural network models...');
tic;
trainAndSaveNNModels(X_feature_PPR, X_feature_Eig, y_label);
timeTrain = toc;
disp(['Training time: ', num2str(timeTrain), ' seconds']);
% Perform Attack Detection
disp('Performing attack detection...');
tic;
[detAcc_PPR, detAcc_MDL, detAcc_PPR_NN, detAcc_Eig_NN, predictions_PPR_NN, predictions_Eig_NN, y_true] = ...
detectMultipleAttackers(X_feature_PPR, X_feature_Eig, y_label, P_ED, P_ED_dBm, nbLoc, nbChanReal);
timeDetect = toc;
disp(['Detection time: ', num2str(timeDetect), ' seconds']);
% Perform Single Attacker Localization
disp('Performing single attacker localization...');
tic;
attackerTarget = locateSingleAttacker(X_feature_PPR, K, P_ED, nbLoc, nbChanReal);
timeLocateSingle = toc;
disp(['Single attacker localization time: ', num2str(timeLocateSingle), ' seconds']);
% Perform Multiple Attacker Localization
disp('Performing multiple attacker localization...');
tic;
attackerTargets = locateMultipleAttackers(X_feature_PPR, n_attackers, K, P_ED, nbLoc, nbChanReal);
timeLocateMultiple = toc;
disp(['Multiple attacker localization time: ', num2str(timeLocateMultiple), ' seconds']);
% Visualize Execution Times
executionTimes = [timeTrain, timeDetect, timeLocateSingle, timeLocateMultiple];
plotExecutionTime(executionTimes);
% Calculate Error Rates
disp('Calculating error rates...');
[FPR_PPR_NN, FNR_PPR_NN] = calculateErrorRates(predictions_PPR_NN, y_true);
[FPR_Eig_NN, FNR_Eig_NN] = calculateErrorRates(predictions_Eig_NN, y_true);
% Visualize Results
disp('Generating visualization plots...');
% Plot Error Rates vs. Eavesdropper Power
plotErrorRates(P_ED_dBm, FPR_PPR_NN, FNR_PPR_NN, FPR_Eig_NN, FNR_Eig_NN);
% Plot Detection Accuracy
plotDetectionAccuracy(P_ED_dBm, detAcc_PPR, detAcc_MDL, detAcc_PPR_NN, detAcc_Eig_NN);
% Plot Localization Accuracy
plotLocalizationAccuracy(attackerTargets, attackerTarget, n_attackers);
% Plot Accuracy vs Complexity
complexityLevels = [50, 100, 150, 200]; % Assumed antenna numbers for complexity
accuracyLevels = [mean(detAcc_PPR), mean(detAcc_MDL), mean(detAcc_PPR_NN), mean(detAcc_Eig_NN)];
plotAccuracyVsComplexity(complexityLevels, accuracyLevels);
% Generate and plot heatmap
heatmapData = reshape(detAcc_PPR_NN, [], K);
plotHeatmap(heatmapData);
% Select best algorithm and plot results
bestAlgoIdx = selectBestAlgorithm(detAcc_PPR, detAcc_MDL, detAcc_PPR_NN, detAcc_Eig_NN);
plotBestAlgorithm(P_ED_dBm, bestAlgoIdx);
% Display summary
disp('Simulation complete. Results summary:');
disp(['Average PPR-NN Detection Accuracy: ', num2str(mean(detAcc_PPR_NN))]);
disp(['Average Eig-NN Detection Accuracy: ', num2str(mean(detAcc_Eig_NN))]);
disp(['PPR-NN False Positive Rate: ', num2str(mean(FPR_PPR_NN))]);
disp(['PPR-NN False Negative Rate: ', num2str(mean(FNR_PPR_NN))]);
disp(['Eig-NN False Positive Rate: ', num2str(mean(FPR_Eig_NN))]);
disp(['Eig-NN False Negative Rate: ', num2str(mean(FNR_Eig_NN))]);
disp(['Total Execution Time: ', num2str(sum(executionTimes)), ' seconds']);
disp('All results have been plotted and saved.');
end