-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathBlockageSimFn.m
140 lines (119 loc) · 5.42 KB
/
BlockageSimFn.m
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
function output = BlockageSimFn(s_mobility,BS_input)
% Written by Ish Jain
% NYU Tandon School of Engineering
% Date: June 2018
%
% Input:
% s_mobility: contains parameters corresponding to blockers mobility
% BS_input: contains infromation related to BS-UE topology and simulation
% parameters. See SimulationLOS.m for the usage.
% Description:
% We use random way point mobility model for the blockers. The UE is at the
% origin and the BSs are located in a circle around the UE. A random
% blocker will block the BS-UE LOS path is it crosses the line joining
% between BS and the UE. We use find_blockage_distance.m function to fine
% intersection of two such lines. Finally, we repeat the process for all
% the blockers, for all the BSs and for the whole simulation duration. We
% collect this data as sequences (binary_seq) of 0 and 1 (0=blockage, 1=not blocked) for
% the entire duration for each BS-UE pair. Bitwise and of these sequences
% for all the APs gives a sequence (allBl) indicating simultaneous blockage of all BSs.
%
% Output: output file contains:
% avgFreq: Average frequency of simultaneous blockage of all BS.
% avgDur: Average duration of simultaneous blockage of all BS.
% probAllBl: probability of simultaneous blockage of all BS.
% nTorig: original number of BS (can be blocked by self-blockage)
% nT: number of BS not blocked by self-blockage
%----Play-with-values-here--------------------------------------
wannaplot = BS_input.WANNAPLOT; %1;
nB = BS_input.NUM_BL; %number of blokers
nTorig = BS_input.Original_NUM_AP; %Original APs without considering self blockage
rT =BS_input.LOC_AP_DISTANCE; %location of APs
alphaTorig = BS_input.LOC_AP_ANGLE;%location of APs
frac = BS_input.FRACTION;
omega = BS_input.SELF_BL_ANGLE_OMEGA;
%%Implementing self-blockage
tempInd = find(alphaTorig>=omega); %These BSs are not blocked by self-blockage
xT = rT(tempInd).*cos(alphaTorig(tempInd));%location of APs (distance)
yT = rT(tempInd).*sin(alphaTorig(tempInd));%location of APs (angle)
nT = length(tempInd); % number of BS not blocked by self-blockage
% nT=0
if(nT==0)
output=[0,0,0,nTorig,nT];
return;
end % Dealing zero APs
xTfrac = frac*xT; %blockage zone around UE for each APs
yTfrac = frac*yT;
locT = [xTfrac';yTfrac']; %2 rows for x and y, nT columns
alphaT = alphaTorig(tempInd); %angle from x-axis for BS not blocked by self-bl
simTime = BS_input.SIMULATION_TIME; %sec Total Simulation time
tstep = BS_input.TIME_STEP; %(sec) time step
mu = BS_input.MU; %Expected bloc dur =1/mu
dataBS = cell(nT,1);
%dataBS contain array of timestamps of blocker arrival for all BSs,
%independent of which blocker is blocking
for indB = 1:nB %for every blocker
for iter =1:(length(s_mobility.VS_NODE(indB).V_POSITION_X)-1)
% for every time blocker changes direction
loc0 = [s_mobility.VS_NODE(indB).V_POSITION_X(iter);...
s_mobility.VS_NODE(indB).V_POSITION_Y(iter)];
loc1 = [s_mobility.VS_NODE(indB).V_POSITION_X(iter+1);...
s_mobility.VS_NODE(indB).V_POSITION_Y(iter+1)];
start_time = s_mobility.VS_NODE(indB).V_TIME(iter);
velocity = sqrt((s_mobility.VS_NODE(indB).V_SPEED_X(iter))^2+ ...
(s_mobility.VS_NODE(indB).V_SPEED_Y(iter))^2);
for indT = 1:nT %for every BS around the UE (outside self-bl zone)
%The find_blockage_distance() function is written by Ish Jain
distance_travelled = find_blockage_distance([loc0,loc1],locT(:,indT),alphaT(indT));
timeToBl = distance_travelled/velocity; %time to blocking event
timestampBl = start_time+timeToBl; %timestamp of blockage event
if(distance_travelled>=0 && timestampBl<=simTime)
% data{indB,indT} = [data{indB,indT},start_time+blockage_time];
dataBS{indT} = [dataBS{indT}, timestampBl];
end
end
end
end
totaltime = (simTime)/tstep;
binary_seq = zeros(nT,totaltime); %time sequence for every BS
allBl = ones(1,totaltime); %binary seq of all blocked
Tval = tstep:tstep:totaltime*tstep; %run simulation till tdur with step of tstep
if(wannaplot),figure; hold on; end
for indT = 1:nT
len =length(dataBS{indT});
dataBS{indT}(2,:) = exprnd(1/mu,1,len);
end
for indT = 1:nT
% blDur = exprnd(1/mu);
for timestamp = 1:size(dataBS{indT},2)
blDur = ceil(dataBS{indT}(2,timestamp)/tstep);
blTime = ceil(dataBS{indT}(1,timestamp)/tstep);
if(blTime+blDur<=simTime/tstep)%avoid excess duration
binary_seq(indT, blTime+1:1:(blTime+blDur))=binary_seq(indT, blTime+1:1:(blTime+blDur))+1;
end
end
allBl = allBl & binary_seq(indT,:);
if(wannaplot)
subplot(nT+1,1,indT)
plot(binary_seq(indT,1:10/tstep), 'lineWidth',4)
set(gca,'xtick',[])
set(gca,'xticklabel',[])
set(gca,'ytick',[])
set(gca,'yticklabel',[])
end
end
if(wannaplot)
subplot(nT+1,1,nT+1)
plot(Tval(1:10/tstep),allBl(1:10/tstep),'r-', 'lineWidth',4)
xlabel('Time (sec)')
end
% plot(binary_seq(1,:), 'lineWidth',4)
%%Evaluate frequency and average duration of blockage
%%frequency = (per sec)count transitions from 0 to 1 devided by simTime
%%duration: (sec) count total # of 1's multiplied by tstep/blockageCount
avgFreq = sum(diff(allBl)>0)/simTime;
avgDur = sum(allBl)*tstep/sum(diff(allBl)>0);
probAllBl = sum(allBl)*tstep/simTime;
%%Return now
output=[avgFreq,avgDur,probAllBl,nTorig,nT];
end