Saturday 7 September 2013

Generation of M|M|1 model [Matlab]

Generation of M|M|1 model [Matlab]
 
 
clc;

clear all;

arrival_rate = input('Enter the arrival rate : ');

service_rate = input('Enter the service rate : ');

error_rate = input('Enter the max acceptable packet loss : ');

timeslots = input('Enter the number of timeslots : ');

t = 1:timeslots;

tarr = zeros (1,timeslots);

tser = zeros (1,timeslots);

tarr(1,:) = poissrnd( arrival_rate, 1, timeslots);

tser(1,:) = poissrnd( service_rate, 1, timeslots);

%Timeslot vs Packet loss

n = zeros (1,timeslots);

for j = 1:timeslots

if ( tarr(1,j) > tser(1,j) )

n(1,j) = ( tarr(1,j) - tser(1,j) ) ;

end

end

bar (t,n,.01);

xlabel ('Timeslot');

ylabel ('Packet loss');

disp ('The max packet loss is :');

disp (max(n));

disp ('The average packet loss before buffering is :');

avg = mean(n);

disp (avg);

%Buffer size vs Packet loss

buff = 0;

count = 1;

avg_loss(1,count) = avg ;

buffer_size(1,count) = buff;

while (avg > error_rate)

count = count+1;

buff = buff+1;

tser = tser+1;

for j = 1:timeslots

if (n(1,j) > 0)

n(1,j) = (tarr(1,j) - tser(1,j));

end

end

avg = mean(n);

avg_loss (1,count) = avg;

buffer_size (1,count) = buff;

end

disp('The maximum packet loss after buffering is :');

disp(avg);

disp('The maximum buffer size for the given error rate is :');

disp(buff);

figure(2);

line (buffer_size,avg_loss);

xlabel('Buffer size');

ylabel('Packet loss');


No comments:

Post a Comment