Saturday, 7 September 2013

Data Traffic [matlab code]

Data Traffic [matlab code]
 
clear all;

clc;

use=input('Enter the no. of users: ');

ts=input('Enter the no. of time slots: ');

on=0.35;

ton=zeros(use,ts);

n=ton;

for i=1:use

for j=1:ts

ton(i,:)=poissrnd((on*10),1,ts);

if (ton(i,j)>=3.5)

n(i,j)=1;

end

end

end

test=randint(use,ts,[1,1000]);

data=n;

for i=1:use

for j=1:ts

if n(i,j)==1

if test(i,j)>=1 & test(i,j)<=980

data(i,j)=64000;

elseif test(i,j)>980 & test(i,j)<=990

data(i,j)=128000;

elseif test(i,j)>990 & test(i,j)<=998

data(i,j)=256000;

else

data(i,j)=512000;

end

end

end

end

%timeslot vs bandwidth

d= sum(data);

figure(1);

bar(d);

xlabel('Time slot');

ylabel('Bandwidth(bps)');

%timeslot vs error rate

e=zeros(1,ts);

bm=1540000;

for i=1:ts

if d(i)>bm

e(i)=d(i)-bm;

end

end

figure(2);

bar(e);

xlabel('Timeslot');

ylabel('Error rate (bps)');

avg=sum(e')/ts;

ber=avg/bm;

buff=0;

disp('Average bit error rate without buffering');

disp(ber);

while (ber)>1e-6

buff=buff+10;

bm=bm+10;

for i=1:ts

if e(i)>0

e(i)=d(i)-bm;

end

end

s=sum(e');

ber=s/(ts*bm);

end

disp('Bit error rate with buffer');

disp(ber);

disp('Optimum buffer size');

disp(buff);

No comments:

Post a Comment