Saturday, June 25, 2011

Generation of Voice traffic [Matlab]


clc;
clear all;
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
voice=64000*n;
% time slot vs bw
d=sum(voice);
figure(1);
bar(d);
xlabel('Timeslot');
ylabel('Bandwidth(bps)');
% time slots 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('Timeslots');
ylabel('Error rate (bps)');
avg=sum(e')/ts;
ber=avg/bm;
buff=0;
disp('Average bit error rate without buffers:');
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('BER with buffer:');
disp(ber);
disp('Optimum buffer size');
disp(buff);

Generation of Video traffic [Matlab]


clc;
clear all;
use=input('Enter The Number Of Users: ');
ts=input('Enter The Number 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;
else
data(i,j)=384000;
end
end
end
end
%Time Slot Vs Bandwidth
d=sum(data);
figure(1);
bar(d);
xlabel('Time Slot');
ylabel('Bandwidth (bps)');
%Time Slots 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('Time Slot');
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);

Stop and Wait Protocol [Matlab]


clc;
clear all;
disp('SAMPLE INPUT AND OUTPUT: ');
n=input('Number of Frames: ');
frame=1;
while frame<=n
fprintf('Transmitting Frame %d\n',frame);
s=randint(1,1,15);
if s<3
fprintf('TIME OUT\n Re-');
elseif s>6
fprintf('PAK of Frame %d Received\n',frame);
frame=frame+1;
else
fprintf('NAK of Frame %d Received\n Re-',frame);
end
end

shortest & Distance Vector Routing [Matlab]


clc;
clear all;
n=input('enter the number of nodes');
conn=input('enter the connected nodes');
delarr=ones(n);
delarr=10000*delarr;
len=length(conn);
delay2=1;

for i=1:2:len;
    delarr(conn(i),conn(i+1))=delay2;
    delarr(conn(i+1),conn(i))=delay2;
  
end
for i=1:n
    delarr(i,i)=0;
end
disp('....Delay time.....');
disp(delarr);
gr=delarr;
v=[1:n];
p=perms(v);
start=input('enter the source node');
dest=input('enter the destination node');

%finding all possible paths and thier delays
paths=zeros(factorial(n-1),n);
index=0;
for i=1:factorial(n);
    if p(i,1)~=start;
        continue;
    end
    de=0;
    temp=p(i,1);
    index=index+1;
    paths(index,1)=temp;
    for j=2:n;
        if(gr(temp,p(i,j))>0 && gr(temp,p(i,j))<1000);
            flag=1;
            de=de+gr(temp,p(i,j));
            temp=p(i,j);
            paths(index,j)=temp;
            if temp == dest
                delay(index)=de;
                break;
            end
        else
            flag=0;
            index=index-1;
            break;
        end;
    end;
end;
%removing the repeated paths
j=1;
delay1(j)= delay(1);
paths1(j,:) = paths(1,:);
for i=2:length(delay);
    if delay(i-1)~=delay(i);
        j=j+1;
        delay1(j)=delay(i);
        paths1(j,:)=paths(i,:);
        shortind=j;
    end;
end;

%displaying all paths and also the delay
for i=1:length(delay1);
    for j=1:n;
        if paths1(1,j)~=0;
            fprintf('%d->',paths1(i,j));
        else
            break;
        end;
    end;
    fprintf('\b\b:delay=%d\n',delay1(i));
end;
%shortest path and its delay
disp('');
disp('the shortest path is');
for j=1:n;
    if paths1(shortind,j)~=0;
        fprintf('%d->',paths1(shortind,j));
    else
        break;
    end;
end;
fprintf('\b\b\t\t delay=%d\n',delay1(shortind));






Google : The top most search engine

Google : MAGIC BOX

nRelate - Posts and Homepage

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Which is the toughest subject ?