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
| %%%%%%%%%%%%%%% FINAL CODE %%%%%%%%%%%%%%%
clear all
ct = 10000;
snrdb = 0:20:100;
rn = [5: 5: 20];
% cm = zeros(1,length(snrdb));
% %%%%% RELAY SELECTION %%%%%%%%%
N = 20; %number of relay nodes
M = (N-1); %K-1 relays
for i = 1:length(rn);
N = rn(i);
snr = 10^(20/10);
for k = 1:ct
%Information Forwarding Relay Selection
hsrs = complex(randn(N,2), randn(N,2)); % S— >Inforelays
hsr = abs(hsrs).^2;
[x1,x2] = max(min(hsr));
hrstar = hsr(x2,1);
grstar = hsr(x2,2);
%Jamming Relay 1 Selection
jsrs = complex(randn(N-1,1), randn(N-1,1)); % S— >JammingRelays
jsr = min(abs(jsrs).^2);
J1star = (jsr);
%Jamming Relay 2 Selection
jsrs2 = complex(randn(N-1,2), randn(N-1,2)); % S— >JammingRelay2
jsr2 = abs(jsrs2).^2;
[x3,x4] = min(max(jsr2));
hJ2star = jsr2(x4,1);
gJ2star = jsr2(x4,2);
%EavesDropper Selection
jers = complex(randn(N,1), randn(N,1)); % S— >JammingRelays
jsr = min(abs(jers).^2);
JE1star = (jsr);
hej2s = complex(randn(N,2), randn(N,2)); % S— >Inforelays
hesr = abs(hsrs).^2;
[x1,x2] = max(min(hsr));
hej2 = hsr(x2,1);
gej2 = hsr(x2,2);
hgers = complex(randn(N,2), randn(N,2)); % S— >Inforelays
hgr = abs(hgers).^2;
he = hgr(1);
ge = hgr(2);
%%Outage Probability Calculation
source = ((min(hrstar,grstar))./(J1star)+max(hJ2star,gJ2star));
eaves = 2*(1+((ge+he)./min(JE1star,hej2)));
outageprobab = (eaves-source);
% SINR Calculation
part = ((hrstar)+(grstar)+(J1star)+(1/snr));
part1 = ((hrstar)*(J1star))/ (part);
part2 = ((1/snr)*(hrstar))./ (part);
SINR = (((hrstar)*(grstar))./part)./((part1)+(part2)+(gJ2star)+(1/snr));
capacity(k) = log2(1+SINR);
end
outageprobabcm(i) = mean(outageprobab);
end
plot(rn,outageprobabcm); |