MATLAB Answers

Can any one find whats problem in this code

6 views (last 30 days)
jawad
jawad on 4 Aug 2013
%=============================================================================%
results = zeros(); % Final arrays initialization
report = zeros();
t = 1; m = 1; tt = 1; %counters
U = 0.4; % Portion of voice traffic
D = 0.4; % Portion of data traffic
%============================================================================%
% General Parameters
sfrange = 4000; % Signal frequency range in Hz (4000 - 8000 range)
cduration = 30000; % Calls duration in (ms)
pr_delay = 100; % Network delay in (ms)
Capacity = 5000/8; % Outgoing link capacity in kilobytes per second
source_number = 10; % Number of sources of data traffic
burst_rate = 2*(Capacity*8*D)/source_number;
MaxQsize = Capacity*0.1*1000; % Router Queue size in bytes, 100 ms of queuing delay
IMPORT = 0; % 1 - Import data traffic pattern from file
ALGORITHM = 1; % 0 - do not use; 1 - use
jitter_buffer = 1; % 0 - fixed; 1 - variable (existing)
Qsize = 0; % Router queue size initialization
Lost = 0; % Initialization of lost packet indicator
count = 0;
min_JB = 40; % Minimum jitter buffer size in (ms)
dmin = 0;
Talkspurt = 300; % Talkspurt duration (active speech)
Qmatrix = zeros();
TS_change = 1; % Last talkspurt when encoding parameters were changes
TS_array = zeros(); % Initialization
data_loss = 0; % Lost data traffic
change = 0; W = 0; Product = 0;
%============================================================================%
% Modeling of data traffic
if (IMPORT == 0) % generate traffic, not to use a previous pattern
psize1 = 40; % 40 bytes packets
psize2 = 550; % 550 bytes packets
psize3 = 1500; % 1500 bytes packets
pport1 = 0.6; % 60% of packets
pport2 = 0.25; % 25% of packets
pport3 = 0.15; % 15% of packets
Pareto_a = 1.5; % parameter of pareto distribution
Pareto_b = 50; % minimum burst length in milliseconds
RU = 0; % average link utilization (calculated)
dtraffic = zeros(); % data traffic array initialization
while (abs(RU-D)) > 0.03 % difference between average and real utilization
dtraffic = zeros(); % data traffic array utilization
tnumber = 0; % sequence number in the mixed data stream
i = 1;
for i = 1:1:source_number
timer = 30000; % starting time of data traffic generation
pnumber = 0; % packet sequence number in a given data stream
state = randsrc(1,1,[0,1; 0.5,0.5]); % initial state (1 - burst, 0 - ideal)
while (timer < cduration)
if state == 1 % generate traffic
burst_length = min(Pareto_b/(rand()^Pareto_a), 1000); % burst length in ms
if (burst_length < cduration-timer)
burst_length = cduration-timer;
end
end_burst = timer + burst_length; % end of burst time
while (timer < end_burst) && (timer < cduration)
gp_size = randsrc(1,1,[psize1, psize2, psize3; pport1, pport2, pport3]);
gp_duration = gp_size*8/burst_rate;
pnumber = pnumber + 1;
tnumber = tnumber + 1;
dtraffic(tnumber,1) = timer;
dtraffic(tnumber,2) = gp_size;
dtraffic(tnumber,3) = 0;
timer = timer + gp_duration;
end
state = 0;
else
% adjust timer
idle_length = min(Pareto_b/rand()^Pareto_a, 1000);
% idle state length in ms
if (idle_length < cduration-timer)
idle_length = cduration-timer;
end
end_idle = timer + idle_length;
state = 1;
end
end
end
RU = sum(dtraffic(:,2))/1000/Capacity/(cduration/1000);
end
dtraffic = sortrows(dtraffic,1);
end
This is the code for modeling of data traffic
when during run it made matlab busy for infinite time.
can any one check it for me.what possibly may be the problem
Regards
  1 Comment
Cedric Wannaz
Cedric Wannaz on 4 Aug 2013
You should print/disp some information that will tell you roughly what it is doing (e.g. in which of the three WHILE loops it is stuck), and then refine the analysis using the debugger.
What is randsrc by the way?

Sign in to comment.

Answers (1)

dpb
dpb on 4 Aug 2013
while (abs(RU-D)) > 0.03
...
while (timer < cduration)
...
while (timer < end_burst) && (timer < cduration)
...
timer = timer + gp_duration;
end
RU = sum(dtraffic(:,2))/1000/Capacity/(cduration/1000);
end
...
end
You've got three WHILE constructs any one (or more) of which could be the culprit. Use the debugger and/or some well-placed diagnostics to determine which it is and why.
Of the three, just superficially it would seem the one on the timer would likely be the least problematical so can probably eliminate it pretty quickly (but do that before going to the next just to be certain--it's very tricky to ensure just by reading code)
  2 Comments
Cedric Wannaz
Cedric Wannaz on 5 Aug 2013
Then display gp_size (or gp_duration, but if burst_rate is positive, the problem will be on gp_size) in that loop, because if, for any reason, it is stuck on a 0 or a negative value, conditions in the definition of the WHILE statement will never be wrong.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!