-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpacket_gen.m
48 lines (43 loc) · 1.34 KB
/
packet_gen.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
function Ta=packet_gen(N,nu,iter,seed,Tslot,traffic,density,segmentationFactor)
% this function returns the arrival time of the packets generated by the
% UEs
flag=0;
Ta=zeros(N,iter);
%arrival time of packets
TiniFixed=rand()*Tslot;
for n=1:N
% arrival time of packets
if traffic==0
% aperiodic
% based on a random distribution
Ta(n,:)=cumsum(nu+randomGen_Exponencial( nu, 1, iter )); % en ms
elseif traffic==1
% periodic arrival
if 0
% all users start at the same time instant
Tini=TiniFixed;
elseif 0
% first packet for user n arrives at a random time instant between
% 0 and nu
Tini=rand()*nu;
else
% este caso lo hacemos aparte
flag=1;
break;
end
Ta(n,:)=cumsum([Tini nu*ones(1,iter-1)]); % en ms
else
disp('traffic not valid.');
return;
end
end
if flag==1
% average vehicle arrival rate to the cell
speed=AvgSpeedAsAFunctionOfDensity(density);
% average vehicle arrival rate to the cell
tasa=density*speed/3600/1000; %veh per millisecond
Tini=cumsum(randomGen_Exponencial( 1/tasa, N, 1 ));
aux=floor(Tini/nu);
Tini=Tini-nu.*aux;
Ta=cumsum([Tini nu*ones(N,iter-1)],2);
end