You are on page 1of 51

SIMULATION OF DISTRIBUTION FUNCTION

% %EXPONENTIAL DISTRIBUTION
clc;
clear all;
close all;
m=2;
% Substituting x Value in pdf Formula
x=0:0.1:10;
pdf=m*(exp(m*x));
figure (1);
subplot(3,1,1);
%Plotting Graph Between X & Pdf
plot(x,pdf);
title('exponential distribution');
xlabel('x');
ylabel('f(x)');

%GAUSSIAN DISTRIBUTION
clc;
m=0;
s=1;
x=-10:0.1:10;
% Substituting x, s and m Value in pdf Formula
p=exp((-0.5)*power(((x-m)/s),2));
pdf=p/(sqrt(2*pi)*s);
figure (1);
subplot(3,1,2);
%Plotting the Graph Between x and pdf
plot(x,pdf);
title('gaussian distribution');
xlabel('x');
ylabel('f(x)');

%GEOMETRIC DISTRIBUTION
clc;
p=0.5;
% Substituting p and x Value in pdf Formula
pdf=p*((1-p).^x);
figure (1);
subplot(3,1,3);
%Bar plot between x and pdf
bar(pdf(1:10));
title('geometric distribution');
xlabel('x');
ylabel('f(x)');

%RAYLEIGH DISTRIBUTION
clc;
s=5;
x=0:0.1:50;
% Substituting x and s Value in pdf Formula
pdf=(x/s^2).*exp((-0.5).*power((x/2),2));
figure (2);
subplot(3,1,1);
%Plot Graph Between x and pdf
plot(x,pdf);
title('rayleigh distribution');
xlabel('x');
ylabel('f(x)')
%GAMMA DISTRIBUTION
clc;
c=1; l=1; m=3;
x=0.1:0.1:10;
% Substituting x and m Value in pdf Formula
pdf1=(l/sqrt(m))*(x*sqrt(m-1)).*exp (-l*x)/sqrt(m);
%Plot Graph Between x and pdf
figure (2);
subplot(3,1,2);
plot(x, pdf1);
title ('gamma distribution');
xlabel ('x');
ylabel ('f(x)');
%POISSON DISTRIBUTION
clc;
m=0.9;
% Substituting x and m Value in pdf Formula
for x=1:100;
pdf(x)=exp(-1*m)*power(m,x)/(factorial(x));
end;
figure(2);
%Plot Stem Graph Between x and pdf
subplot(3,1,3);
stem(pdf(1:20));
title('poisson distribution');
xlabel('x');
ylabel('f(x)');
OUTPUT:
CUMULATIVE DISTRIBUTION

clc;
%Exponential
m=2;
x=0:0.1:10;
cdf=1-(exp(-m*x));
subplot(3,1,1);
plot(x,cdf);
title('cdf of exponential distibution');
xlabel('x');
ylabel('f(x)');
%pause;
%Gaussian
clear all;
m=0;s=1;x=-10:01:10;
cdf=0.5*erfc((-(x-m))/(s*sqrt(2)));
subplot(3,1,2);
plot(x,cdf);
title('cdf of gaussian distribution');
xlabel('x');
ylabel('f(x)');
%pause;
%Geometric
clear all;
p=0.5;x=1:100;
cdf=1-((1-p).^(x+1));
subplot(3,1,3);
stairs(cdf(1:20));
title('cdf of geometric distribution');
xlabel('x');
ylabel('f(x)');
%pause;
%Rayleigh
clear all;
s=5;
x=0:0.1:50;
cdf=1-(exp((-0.5)*power((x/s),2)));
figure (2);
subplot(2,1,1);
plot(x,cdf);

title('cdf of rayleigh distribution');


xlabel('x');
ylabel('f(x)');
%pause;
%Gamma
clear all;
m=3;
p=1;
c=1;
x=0.1:0.001:10;
cdf=gamcdf(x,m,p);
subplot(2,1,2);
plot(x,cdf);
title('cdf of gamma distribution');
xlabel('x');
ylabel('f(x)');
OUTPUT:
GENERATION OF ON-OFF TRAFFIC
PROGRAM

%START
clc;
clear all;
close all;

x=1:10;
t=1:100;
on=input('Enter the Average ON Time: ');
%USERS VS AVERAGE ON TIME
ton=zeros(10,100);
for i=1:10
ton(i,:)=poissrnd((on*10),1,100);
end
a=ton';
b=mean(a);
c=b/1000;
figure(1);
bar(x,c,0.35);
xlabel('Users');
ylabel('Average ON Time');
%TIMESLOTS VS NUMBER OF USERS
n=zeros(10,100);
for i=1:10
for j=1:100
if (ton(i,j)>=4.5)
n(i,j)=1;

end
d=sum(n);
end
end

figure(2);
bar(t,d);
xlabel('Time Slots');
ylabel('Number of Users');
%TIME SLOTS VS BANDWIDTH
bw=64000*n;
for i=1:10
figure(3);
subplot(5,2,i);
bar(t,bw(i,:),0.2)
xlabel('Time Slots');
ylabel('BW Alloted');
end;
SAMPLE INPUT & OUTPUT:

Enter the Average ON Time: .5

USERS VS AVERAGE ON TIME


-3
x 10
6

4
Average ON Time

0
1 2 3 4 5 6 7 8 9 10
Users

TIMESLOTS VS NUMBER OF USERS

6
Number of Users

0
0 20 40 60 80 100 120
Time Slots
TIMESLOTS VS NUMBER OF USERS
PROGRAM:

% START
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 BANDWIDTH
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);
SAMPLE INPUT & OUTPUT:

Enter the no of users: 50

Enter the no. of time slots: 10

Average bit error rate without buffers: 0.0366

BER with buffer:

5.3880e-007

Optimum buffer size:

315990

TIME SLOT VS BANDWIDTH


6
x 10
2

1.8

1.6

1.4
Bandwidth(bps)

1.2

0.8

0.6

0.4

0.2

0
1 2 3 4 5 6 7 8 9 10
Timeslot
TIME SLOTS VS ERROR RATE
5
x 10
3.5

2.5
Error rate (bps)

1.5

0.5

0
1 2 3 4 5 6 7 8 9 10
Timeslots
PROGRAM

%START
clear all;
clc;
use=input('ENTER THE NUMBER OF USERS:');
ts=input('ENTER THE NUMBER OF TIME SLOTS:');
on=0.35;
% CREATING ZERO MATRIX OF SIZE (USE, TS)
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;
%RANDOM DISTRIBUTION OF TRAFFIC
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 SLOTS 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 SLOTS');
ylabel('ERROR RATE(BPS)');
avg=sum(e')/ts;
ber=avg/bm;
buff=0;
disp('AVERAGE BIT ERROR 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);
SAMPLE INPUT & OUTPUT:

ENTER THE NUMBER OF USERS:60

ENTER THE NUMBER OF TIME SLOTS:90

AVERAGE BIT ERROR WITHOUT BUFFERING:

0.3351

BIT ERROR RATE WITH BUFFER:

9.7665e-007

OPTIMUM BUFFER SIZE:

1531730

TIME SLOTS VS BANDWIDTH


6
x 10
2.5

2
BANDWIDTH(BPS)

1.5

0.5

0
0 20 40 60 80 100 120
TIME SLOT
TIME SLOTS VS ERROR RATE

5
x 10
16

14

12
ERROR RATE(BPS)

10

0
0 10 20 30 40 50 60 70 80 90 100
TIME SLOTS
PROGRAM:
clc;
clear all;
close all;
%GETTING NO OF USERS AND TIME SLOTS
use=input('Enter The Number Of Users: ');
ts=input('Enter The Number Of Time Slots: ');
on=0.35;
% CREATING ZERO MATRIX OF SIZE (USE, TS)
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
%RANDOM DISTRIBUTION OF TRAFFIC
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);

SAMPLE INPUT AND OUTPUT:


Enter The Number Of Users: 50
Enter The Number Of Time Slots: 25
Average Bit Error Rate without Buffering: 0.1414
Bit Error Rate with Buffer: 9.6156e-007
Optimum Buffer Size: 955940

TIME SLOT VS BANDWIDTH

6
x 10
2.5

2
Bandwidth (bps)

1.5

0.5

0
0 5 10 15 20 25 30
Time Slot
TIME SLOT VS ERROR RATE

5
x 10
10

7
Error Rate (bps)

0
0 5 10 15 20 25 30
Time Slot
PROGRAM :

% START
clear all;
clc;
%GETTING NO OF USER AND NO OF TIMESLOTS
use=input('Enter the number of user:');
ts=input('Enter the number of timeslots:');
on=0.35;
voiceuser=0;
datauser=0;
voipuser=0;
ton=zeros(use,ts);
n=ton;
%RANDOM DISTRIBUTION OF TRAFFIC ACROSS TIME SLOTS
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
userprob=randint(1,use,[1,10]);
useriden=ones(1,use);
for i=1:use
if userprob(i)>=1 && userprob(i)<=5
useriden(i)=1;
voiceuser=voiceuser+1;
elseif userprob(i)>5&&userprob(i)<=8
useriden(i)=2;
voipuser=voipuser+1;
else
useriden(i)=3;
datauser=datauser+1;
end
end
isdn=64000*n;
test=randint(voipuser,ts,[1,1000]);
for i=voiceuser+1:voipuser+voiceuser
for j=1:ts
if n(i,j)==1
if test(i-voiceuser,j)>=1 && test(i-voiceuser,j)<=800
isdn(i,j)=64000;
else
isdn(i,j)=384000;
end
end
end
end
test1=randint(datauser,ts,[1,1000]);
for i=voiceuser+voipuser+1:use
for j=1:ts
if n(i,j)==1
if test1(i-(voiceuser+voipuser),j)>=1&&test1(i-
(voiceuser+voipuser),j)<=800
isdn(i,j)=64000;
elseif test1(i-(voiceuser+voipuser),j)>800&&test1(i-
(voiceuser+voipuser),j)<=900
isdn(i,j)=128000;
elseif test1(i-(voiceuser+voipuser),j)>900&& test1(i-
(voiceuser+voipuser),j)<=950
isdn(i,j)=256000;
else
isdn(i,j)=512000;
end
end
end
end
%TIMESLOT VS BANDWIDTH
d=sum(isdn);
figure(1);
bar(d);
xlabel('Timeslot'),ylabel('Bandwidth(bps)');
%Time slot vs Error rate
e=zeros(1,ts);
bm=1984000;
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)');
buff=0;
newbw=1984000+buff;
prisdn =isdn(1:voiceuser,:);
voipsort=isdn(voiceuser+1:voiceuser+voipuser,:);
prisdn(voiceuser+1:voiceuser+voipuser,:)=sort(voipsort,1);
datasort=isdn(voiceuser+voipuser+1:use,:);
prisdn(voiceuser+voipuser+1:use,:)=sort(datasort,1);
%To find how many users go unuseverd with /without buffer
unservedvoice=zeros(1,ts);
unservedvoip=zeros(1,ts);
unserveddata=zeros(1,ts);
for i=1:ts
j=0;
bwalloc=0;
while(bwalloc <=newbw &&j<use)
j=j+1;
bwalloc=bwalloc+prisdn(j,i);
end

ch=j;%-1;
if ch<voiceuser
unservedvoice(i)=voiceuser-ch;
unservedvoip(i)=voipuser;
unserveddata(i)=datauser;
else if ch>=(voiceuser)&&ch<(voiceuser+voipuser)
unservedvoip(i)=voiceuser+voipuser-ch;
unserveddata(i)=datauser;
elseif ch>=(voiceuser+voipuser)&&ch<use unservedata(i)=use-ch;
end
end
end
figure(3);
bar(unservedvoice);
xlabel('time slot'),ylabel('Unserved voiceusers');
figure(4);
bar(unservedvoip);
xlabel('Time slot');ylabel('Unserved voipuser');
figure(5);
bar(unserveddata);
xlabel('Time slot'),ylabel('Unserved data user');

SAMPLE INPUT & OUTPUT

Enter the number of user:50

Enter the number of timeslots:80

TIME SLOT VS BANDWIDTH


6
x 10
4.5

3.5

3
Bandwidth(bps)

2.5

1.5

0.5

0
0 10 20 30 40 50 60 70 80 90
Timeslot

TIME SLOT VS ERROR RATE


6
x 10
2.5

1.5
Error rate(bps)

0.5

0
0 10 20 30 40 50 60 70 80 90
Time slot
TIME SLOT VS UNSERVED VOICE USERS
1

0.8

0.6

0.4
Unserved voiceusers

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 10 20 30 40 50 60 70 80 90
time slot

TIME SLOT VS UNSERVED DATA USER

12

10

8
Unserved data user

0
0 10 20 30 40 50 60 70 80 90
Time slot
TIME SLOT VS UNSERVED VOIP USER
1

0.9

0.8

Unserved voipuser 0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 10 20 30 40 50 60 70 80 90
Time slot
GENERATION OF PN SEQUENCE AND VERIFICATION OF RANDOMNESS
PROPERTY
% START
clc;
clear all;
close all;
n=1;
while n==1
% INITIALIZE THE VALUES k,j,g,l,h,x,z,nz,no TO 0
% INITIALIZE THE VALUES y,i,j1,k1 TO 1
k=0;j=0;g=0;l=0;
h=0;x=0;z=0;y=1;
r=0;i=1;
j1=1;k1=1;
nz=0;no=0;
f(1)=1;f(2)=0;
f(3)=1;f(4)=1;
f(5)=0;
% GETTING THE LENGTH OF SEQUENCE
d=input('Enter the length of the sequence (3/7/15//31):');
a=zeros(1,d);
b=zeros(1,d);
c=zeros(1,d);
zr=zeros(1,d);
or=zeros(1,d);
w=zeros(1,d);
% GENERATING THE DATA SEQUENCE
fprintf('\nThe generated sequence:\n');
for i=1:1:d
switch d
case 3
e=xor(f(1),f(2));
case 7
e=xor(f(2),f(3));
case 15
e=xor(f(3),f(4));
case 31
e=xor(f(4),f(5));
end;
a(i)=e;
if e==1
k=k+1;
else
j=j+1;
end;
% VERIFYING BALANCED PROPTERTY
f(5)=f(4);
f(4)=f(3);
f(3)=f(2);
f(2)=f(1);
f(1)=e;
end;
disp(a);
fprintf('\nBalanced property:');
fprintf('\nThe no. of ones:%d',k);
fprintf('\nThe no. of zeros:%d',j);
if (k-j==1)
fprintf('\n Thus the balanced property is satisfied...\n\n');
end;
% VERIFYING AUTOCORRELATION PROPERTY
for i=d:-1:2
b(i)=a(i-1);
end;
b(1)=e;
fprintf('\nAutocorrelation property:');
fprintf('\nThe one bit shift sequence:');
disp(b);
% FINDING AGREEMENTS AND DISAGREEMENTS
for i=1:1:d
if(a(i)==b(i))
z=z+1;
else
x=x+1;
end;
end;
fprintf('\nNo. of agreements:%d',z);
fprintf('\nNo. of disagreements:%d',x);
if x-z==1
fprintf('\nThus the autocorrelation property is satisfied');
end;
fprintf('\n Run property:\n');
i=1;
while(i<d)
% VERIFYING RUN PROPERTY
if(a(i)==0)
nz=nz+1;
i=i+1;
zr(j1)=zr(j1)+1;
while(i<d & a(i)==0)
zr(j1)=zr(j1)+1;
i=i+1;
end;
if(i==d & a(i)==0)
zr(j1)=zr(j1)+1;
end;
j1=j1+1;
end;
if(a(i)==1)
no=no+1;
i=i+1;
or(k)=or(k)+1;
while(i<d & a(i)==0)
or(k1)=or(k1)+1;
i=i+1;
end;
if(i==d & a(i)==1)
or(k1)=or(k1)+1;
end;
k1=k1+1;
end;
end;
r=nz+no;
% CALCULATING TOTAL NO OF ONES
disp('Total no. of runs:');
disp(r);
fprintf('\n');
for j1=1:1:d
switch zr(j1)
case 1
c(1)=c(1)+1;
case 2
c(2)=c(2)+1;
case 3
c(3)=c(3)+1;
case 4
c(4)=c(4)+1;
case 5
c(5)=c(5)+1;
end;
end;
for k1=1:1:d
switch or(k1)
case 1
w(1)=w(1)+1;
case 2
w(2)=w(2)+1;
case 3
w(3)=w(3)+1;
case 4
w(4)=w(4)+1;
case 5
w(5)=w(5)+1;
end;
end;
fprintf('\n');
disp('0 bit runs:');
for j=1:1:d
fprintf('\nNo. of %d bits 0 runs is:%d',j,c(j));
end;
fprintf('\n');
disp('1 bit runs');
for k=1:1:d
fprintf('\nNo.of %d bits 1 runs is:%d',k,w(k));
end;
n=input('\nTo generate the sequence enter 1 else 0:');
fprintf('\n');
end;

SAMPLE INPUT AND OUTPUT:

Enter the length of the sequence (3/7/15//31):7


The generated sequence:
1 1 0 0 1 0 1
Balanced property:
The no. of ones:4
The no. of zeros:3
Thus the balanced property is satisfied...
Autocorrelation property:
The one bit shift sequence: 1 1 1 0 0 1 0
No. of agreements:3
No. of disagreements:4
Thus the autocorrelation property is satisfied
Run property:
Total no. of runs: 3
0 bit runs:
No. of 1 bits 0 runs is:0
No. of 2 bits 0 runs is:0
No. of 3 bits 0 runs is:0
No. of 4 bits 0 runs is:0
No. of 5 bits 0 runs is:0
No. of 6 bits 0 runs is:0
No. of 7 bits 0 runs is:0
1 bit runs
No.of 1 bits 1 runs is:0
No.of 2 bits 1 runs is:2
No.of 3 bits 1 runs is:1
No.of 4 bits 1 runs is:0
No.of 5 bits 1 runs is:0
No.of 6 bits 1 runs is:0
No.of 7 bits 1 runs is:0
To generate the sequence enter 1 else 0: 0
PROGRAM:
%START
clc;
clear all;
arrivalrate=input('ENTER THE ARRIVAL RATE:');
servicerate=input('ENTER THE DATA SERVICE RATE:');
errorrate=input('ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:');
%timeslots=input('ENTER THE NO.OF TIMESLOTS:');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr(1,:)=poissrnd((arrivalrate),1,timeslots);
tser(1,:)=poissrnd((servicerate),1,timeslots);
%TIMESLOT VS PACKETLOSS
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;

xlabel('TIMESLOT'),ylabel('PACKETLOSS');
disp('THE MAXIMUM PACKET LOSS IS:');
disp(max(n));
disp('THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:');
avg=mean(n);
disp(avg);
%BUFFERSIZE VS PACKETLOSS
buff=0;
count=1;
avgloss(1,count)=avg;
buffersize(1,count)=buff;
while(avg>errorrate)
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);
avgloss(1,count)=avg;
buffersize(1,count)=buff;
end;
disp('THE MAX PACKET LOSS AFTER BUFFERING IS:');
disp(max(n));
disp('THE AVERAGE PACKET LOSS AFTER BUFFERING IS:');
disp(avg);
disp('THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:');
disp(buff);
figure (1);
bar(t,n,0.01);
figure(2);
line(buffersize,avgloss);
xlabel('BUFFERSIZE'),ylabel('PACKETLOSS');
SAMPLE INPUT & OUTPUT

ENTER THE ARRIVAL RATE:50

ENTER THE DATA SERVICE RATE:30

ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:2

THE MAXIMUM PACKET LOSS IS:40

THE AVERAGE PACKETLOSS BEFORE BUFFERING IS: 18.9500

THE MAX PACKET LOSS AFTER BUFFERING IS:17

THE AVERAGE PACKET LOSS AFTER BUFFERING IS: 1.9800

THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS: 23

TIMESLOT VS PACKETLOSS

40

35

30

25
PACKETLOSS

20

15

10

0
0 20 40 60 80 100 120
TIMESLOT
BUFFERSIZE VS PACKETLOSS

20

18

16

14
PACKETLOSS

12

10

0
0 5 10 15 20 25
BUFFERSIZE
PROGRAM :

%START
clc;
clear all;
close all;
arrivalrate=input('ENTER THE ARRIVAL RATE:');
servicerate=input('ENTER THE DATA SERVICE RATE:');
errorrate=input('ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:');
%timeslots=input('ENTER THE NO.OF TIMESLOTS');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr(1,:)=poissrnd((arrivalrate),1,timeslots);
tser(1,:)=exprnd((servicerate),1,timeslots);
tser=round(tser);

%TIMESLOT VS PACKETLOSS
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,0.01);
xlabel('TIMESLOT'),ylabel('PACKETLOSS');
disp('THE MAXIMUM PACKET LOSS IS:');
disp(max(n));
disp('THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:');
avg=mean(n);
disp(avg);

%BUFFERSIZE VS PACKETLOSS
buff=0;
count=1;
avgloss(1,count)=avg;
buffersize(1,count)=buff;
while(avg>errorrate)
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);
avgloss(1,count)=avg;
buffersize(1,count)=buff;
end;
disp('THE MAX PACKET LOSS AFTER BUFFERING IS:');
disp(max(n));
disp('THE AVERAGE PACKET LOSS AFTER BUFFERING IS:');
disp(avg);
disp('THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:');
disp(buff);
figure(2);
line(buffersize,avgloss);
xlabel('BUFFERSIZE'),ylabel('PACKETLOSS');

SAMPLE INPUT & OUTPUT

ENTER THE ARRIVAL RATE:50


ENTER THE DATA SERVICE RATE:40
ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:2
THE MAXIMUM PACKET LOSS IS: 59
THE AVERAGE PACKETLOSS BEFORE BUFFERING IS: 23.4200
THE MAX PACKET LOSS AFTER BUFFERING IS: 19
THE AVERAGE PACKET LOSS AFTER BUFFERING IS: 1.7800
THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS: 40

TIMESLOT VS PACKET LOSS

40

35

30

25
PACKETLOSS

20

15

10

0
0 20 40 60 80 100 120
TIMESLOT
BUFFERSIZE VS PACKETLOSS

20

18

16

14
PACKETLOSS

12

10

0
0 5 10 15 20 25
BUFFERSIZE
PROGRAM :

%START
clc;
clear all;
arrivalrate=input('ENTER THE DATAARRIVAL RATE:');
servicerate=input('ENTER THE DATASERVICE RATE:');
errorrate=input('ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:');
%timeslots=input('ENTER THE NO.OF TIMESLOTS:');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr1(1,:)=normrnd((arrivalrate),5,1,timeslots);
tarr=round(tarr1);
tser1(1,:)=exprnd((servicerate),1,timeslots);
tser=round(tser1);
%TIMESLOT VS PACKETLOSS
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,0.01);
xlabel('TIMESLOT'),ylabel('PACKET LOSS');
disp('THE MAXIMUM PACKET LOSS IS:');
disp(max(n));
disp('THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:');
avg=mean(n);
disp(avg);
%BUFFERSIZE VS PACKETLOSS
buff=0;
count=1;
avgloss(1,count)=avg;
buffersize(1,count)=buff;
while(avg>errorrate)
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);
avgloss(1,count)=avg;
buffersize(1,count)=buff;
end;
disp('THE MAX PACKET LOSS AFTER BUFFERING IS:');
disp(max(n));
disp('THE AVERAGE PACKET LOSS AFTER BUFFERING IS:');
disp(avg);
disp('THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:');
disp(buff);
figure(2);
line(buffersize,avgloss);
xlabel('BUFFERSIZE'),ylabel('PACKETLOSS');
SAMPLE INPUT & OUTPUT
ENTER THE DATAARRIVAL RATE:50
ENTER THE DATASERVICE RATE:30
ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:2
THE MAXIMUM PACKET LOSS IS: 57
THE AVERAGE PACKETLOSS BEFORE BUFFERING IS: 25.1700
THE MAX PACKET LOSS AFTER BUFFERING IS: 17
THE AVERAGE PACKET LOSS AFTER BUFFERING IS: 1.7800
THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS: 40

TIMESLOT VS PACKET LOSS


60

50

40
PACKET LOSS

30

20

10

0
0 20 40 60 80 100 120
TIMESLOT

BUFFER SIZE VS PACKET LOSS

30

25

20
PACKETLOSS

15

10

0
0 5 10 15 20 25 30 35 40
BUFFERSIZE
ENCRYPTION AND DECRYPTION USING MONO ALPHABETIC CIPHER
PROGRAM

% START
clc;
clear all;
close all;
% GETTING TEXT TO BE ENCRYPTED & FINDING LENGTH OF THE TEXT
x=input('Enter Input Text =','s');
len=length(x);
Array1=[];
input1=[];
% GETTING THE KEY FOR ENCRYPTION
key = input( 'Enter Key Value:');
for i=1:len
input1(i)=x(i);
end;
% ASCII VALUE OF EACH ALPHABET IS ADDED WITH KEY VALUE
for i=1:len
Array1(i)=input1(i)+key;
%HANDLING SMALL ALPHABETS
if Array1(i)>122 && input1(i)>=97
Array1(i)=Array1(i)-122;
Array1(i)=Array1(i)+96;
end;
%HANDLING CAPITAL ALPHABETS
if Array1(i)>90 && input1(i)<=90
Array1(i)=Array1(i)-90;
Array1(i)=Array1(i)+64;
end;
end
% DISPLAYING ENCRYPTED TEXT
disp('Ecryption Result')
disp(char(Array1));

for i=1:len
Array1(i)=Array1(i)-key;
%HANDLING SMALL ALPHABETS IN DECRYPTION
if Array1(i)<=97 && input1(i)>=97
Array1(i)=97-Array1(i);
Array1(i)=123-Array1(i);
end;
%HANDLING CAPITAL ALPHABETS
if Array1(i)<65 && input1(i)<=90
Array1(i)=65-Array1(i);
Array1(i)=91-Array1(i);
end;
end;
% DISPLAYING DECRYPTED TEXT
disp('Decryption Result');
disp(char(Array1));
SAMPLE INPUT & OUTPUT:

Enter Input Text =mit

Enter Key Value: 5

Ecryption Result

ENCRYPT =rny

Decryption Result

DECRYPT = mit
DATA ENCRYPTION AND DECRYPTION USING RSA ALGORITHM

PROGRAM

% START
clc;
clear all;
% INITIALIZE TWO PRIME NOS ‘p’ AND ‘q’
p=3;
q=11;
n=p*q;
z=(p-1)*(q-1);
d=2;
e=2;
% CALCULATING DECRYPTION KEY
while(gcd(d,z)>1)
d=d+1;
end;
% CALCULATING ENCRYPTION KEY
while(mod(d*e,z)>1)
e=e+1;
end;
disp(e);
disp(sprintf('The encryption key is %d',e));
disp(sprintf('The decryption key is %d',d));
disp(sprintf('1. Message using upper case symbols(^_[])'));
disp(sprintf('2. Message using lower case symbols ({}~/)'));
disp(sprintf('3. Message using numbers and remaining symbols'));
ch=input('\n Enter the choice:');
% GETTING THE MESSAGE TO BE ENCRYPTED
m=input('\n Enter the message to be encrypted:','s');
switch ch
% MESSAGE IS IN LOWER CASE SYMBOLS ( { } ~ / ) ' ) THEN CASE 2
case 2
t=double(m)-96;
t(find(t<1))=0;
for i=1:length(m)
g(i)=mod(t(i)^e,n);
end;
disp(sprintf('\n The encrypted message is:\n'));
disp(g);
for i=1:length(m)
rx(i)=mod(g(i)^d,n);
end;
rx(find(rx<=0))-64;
r=char(rx+96);

% MESSAGE IS IN UPPER CASE SYMBOLS( ^_ [ ] ) ') THEN CASE 1


case 1
t=double(m)-64;
t(find(t<1))=0;
for i=1:length(m)
g(i)=mod(t(i)^e,n);
end;
disp(sprintf('\n The encrypted message is:\n'));
disp(g);
for i=1:length(m)
rx(i)=mod(g(i)^d,n);
end;
rx(find(rx<=0))=-32;
r=char(rx+64);
% MESSAGE IS IN NUMBERS AND REMAINING SYMBOLS
case 3
t=double(m)-32;
for i=1:length(m)
g(i)=mod(t(i)^e,n);
end;
% DISPLAYING ENCRYPTED MESSAGE
disp(sprintf('\n The encrypted message is:\n'));
disp(g);
for i=1:length(m)
rx(i)=mod(g(i)^d,n);
end;
r=char(rx+32);
end;
% DISPLAYING DECRYPTED MESSAGE
disp(sprintf('\n The decrypted message is :\n'));
disp(r);

SAMPLE INPUT & OUTPUT:

CASE I

The encryption key is 7

The decryption key is 3

1. Message using upper case symbols(^_[])

2. Message using lower case symbols ({}~/)

3. Message using numbers and remaining symbols

Enter the choice:1

Enter the message to be encrypted:[COMPUTER]

The encrypted message is:

3 9 27 7 25 21 26 14 6 17

The decrypted message is:[COMPUTER]

CASE II

The encryption key is 7

The decryption key is 3

1. Message using upper case symbols(^_[])


2. Message using lower case symbols ({}~/)

3. Message using numbers and remaining symbols

Enter the choice: 2

Enter the message to be encrypted:{flower}

The encrypted message is:

3 30 12 27 23 14 6 17

The decrypted message is : {flower}

CASE III

The encryption key is 7

The decryption key is 3

1. Message using upper case symbols(^_[])

2. Message using lower case symbols ({}~/)

3. Message using numbers and remaining symbols

Enter the choice:3

Enter the message to be encrypted:#@^&

The encrypted message is:

9 32 17 30

The decrypted message is : #@^&


STOP AND WAIT PROTOCOL

PROGRAM:

clc;
% PROVIDE No OF FRAMES AND LENGTH OF EACH FRAME
m=input('Enter the number of frames to be transmitted:');
n=input('Enter the length of the frame:');
i=1;j=1;l=0;
% RANDOM GENERATION OF FRAMES BITS
d=randint(1,n);
% ADDING PARITY BIT TO THE FRAME SEQUENCE
d(n+1)=rem(sum(d),2);
while((i<=m)&j)
q=randint(1,1);
% FRAME IS TRANSMITTED
disp(sprintf('transmitted frame %d:',i));
disp(d);
% SWITCHING CASE BASED ON Q VALUE
switch q
case 0
disp(sprintf('No Acknowledgement\n'));
disp(sprintf('Retransmitting...'));
l=l+1;
if(l==5)
j=0;
disp(sprintf('Transmission failed\n'));
end;
case 1
p=randint(1,1,[1,n]);
disp(p);
d(p)=randint(1,1);
disp(d(p));
disp(sprintf('Received frame'));
disp(d);
% CHECKING IF RECEIVED FRAME CONTAINS ERROR OR NOT
y=sum(d)-d(n+1);
c=rem(y,2);
if(c==d(n+1))
disp(sprintf('Acknowledgement received\n'));
l=0;
i=i+1;
if(i<=m)
n=input('Enter the length of the frame:');
d=randint(1,1);
d(n+1)=rem(sum(d),2);
end;
else
disp(sprintf('Negative Acknowledgement'));
disp(sprintf('Retransmitting...'));
l=l+1;
% CONTINUOUSLY IF FIVE RETRANSMISSION OCCURS, THEN
TRANSMISSION GETS FAILED
if(l==5)
j=0;
disp(sprintf('Transmission failed\n'));
end;
d(p)=~d(p);
disp(sprintf('\n'));
end;
end;
end;

SAMPLE INPUT & OUTPUT:


% GIVE No OF FRAMES AND LENGTH OF FRAMES
Enter the number of frames to be transmitted:1
Enter the length of the frame:8
Transmitted frame 1:
0 1 0 0 1 0 0 0 0
No Acknowledgement
Retransmitting...
Transmitted frame 1:
0 1 0 0 1 0 0 0 0
3
0
Received frame
0 1 0 0 1 0 0 0 0
Acknowledgement received
GO BACK N PROTOCOL

PROGRAM:

% START
clc;
clear all;
close all;

b=1;
while(b==1)
clc;
% GETTING TOTAL NO OF FRAMES , WINDOW SIZE AND LENGTH OF SEQUENCE
m=input('Enter the total no of frames:');
n=input('Enter the window size:');
t=input('Enter the length of the sequence:');
fprintf('\n');
% CHECKING WHETHER NO OF FRAMES IS LESS THAN WINDOW SIZE
while(m~=0)
if(m<n)
n=m;
end;
for i=1:1:n
% RANDOM GENERATION OF FRAME SEQUENCE BASED ON FRAME LENGTH
d=randint(1,t);
d(t+1)=rem(sum(d),2);
a(i,1:t+1)=d;
% FRAME TRANSMISSION STARTS
fprintf('Transmitting frame%d:',i);
disp(a(i,1:t+1));
end;
% GENERATING RANDOM POSITION AND RANDOM ERROR
p=randint(1,1,[1,n]);
q=randint(1,1,[1,t+1]);
a(p,q)=randint(1,1);
% FRAME IS RECEIVED
for i=1:1:n
fprintf('Receiving frame%d:',i);
disp(a(i,1:t+1));
end;
f=zeros(1,n);
for i=1:1:n
% CHECKING IF RECEIVED FRAME CONTAINS ERROR OR NOT
f(i)=rem(sum(a(i,1:t+1)),2);
if(f(i)==1)
k=i;
end;
end;
if(f==0)
fprintf('Acknowdegement received\n');
else
fprintf('Rejected frames%d\n',k);
disp('Retransmiting....');
% CORRECTING ERROR
a(p,q)=~a(p,q);
for i=k:1:n
fprintf('\nTransmitting frame%d:',i);
disp(a(i,1:t+1));
end;
for i=k:1:n
fprintf('Receivedframe%d',i);
disp(a(i,1:t+1));
end;
fprintf('\nAcknowledgement received\n');
end;
% REDUCING NO OF FRAMES BY WINDOW SIZE
m=m-n;
end;
b=input('\nEnter 1 to continue else 0:');
end;

SAMPLE INPUT & OUTPUT:


% ENTERING NO OF FRAMES, WINDOW SIZE AND LENGTH OF THE
SEQUENCE
Enter the total no of frames:2
Enter the window size:4
Enter the length of the sequence:6
Transmitting frame1: 0 1 0 1 0 0 0
Transmitting frame2: 1 1 0 1 1 0 0
Receiving frame1: 0 1 0 1 0 0 0
Receiving frame2: 1 1 1 1 1 0 0
Rejected frames2
Retransmitting....
Transmitting frame2: 1 1 0 1 1 0 0
Receivedframe2 1 1 0 1 1 0 0
Acknowledgement received
Enter 1 to continue else 0:
SELECTIVE REPEAT PROTOCOL

PROGRAM:

% START
clc;
b=1;
while(b==1)
% GETTING No OF FRAMES, WINDOW SIZE AND LENGTH OF SEQUENCE
m=input('Enter the total no of frames=');
n=input('Enter the window size=');
t=input('Enter the length of sequence=');
fprintf('\n');
% CHECKING WHETHER m VALUE IS 0
while(m~=0)
if(m<n)
n=m;
end;
for i=1:1:n
% RANDOM GENERATION OF FRAME SEQUENCE BASED ON THE FRAME LENGTH
d=randint(1,t);
d(t+1)=rem(sum(d),2);
a(i,1:t+1)=d;
% FRAME IS TRANSMITTED
fprintf('Transmitting frame%d:',i);
disp(a(i,1:t+1));
end;
% RANDOM GENERATION OF ERROR POSITION AND ERROR VALUE
p=randint(1,1,[1,n]);
q=randint(1,1,[1,t+1]);
a(p,q)=randint(1,1);
for i=1:1:n
% RECEIVED FRAME
fprintf('Receiving frame%d:',i);
disp(a(i,1:t+1));
end;
f=zeros(1,n);
% CHECKING RECEIVED FRAME CONTAINS ERROR OR NOT
for i=1:1:n
f(i)=rem(sum(a(i,1:t+1)),2);
if(f(i)==1)
k=i;
end;
end;
if(f==0)
fprintf('Acknowledgement Received\n');
else
fprintf('Rejected frames%d\n\n',k);
disp('Retransmitting....');
% CORRECTING ERROR IF THE FRAME CONTAIN ERROR
a(p,q)=~a(p,q);
fprintf('\nTransmitting frame%d:',k);
disp(a(k,1:t+1));
fprintf('\nReceived frame%d:',k);
disp(a(k,1:t+1));
fprintf('\nAcknowledgement received\n');
end;
% REDUCING NO OF FRAMES BY WINDOW SIZE
m=m-n;
end;
b=input('\nEnter 1 to continue or else 0:');
end;

SAMPLE INPUT & OUTPUT:


% GETTING No OF FRAMES. WINDOW SIZE AND LENGTH OF SEQUENCE
Enter the total no of frames=3
Enter the window size=5
Enter the length of sequence=6
Transmitting frame1: 1 1 0 0 0 0 0
Transmitting frame2: 1 0 1 0 1 0 1
Transmitting frame3: 1 1 1 0 1 1 1
Receiving frame1: 1 1 0 0 0 0 0
Receiving frame2: 1 0 1 0 1 1 1
Receiving frame3: 1 1 1 0 1 1 1
Rejected frames2
Retransmitting....
Transmitting frame2: 1 0 1 0 1 0 1
Received frame2: 1 0 1 0 1 0 1
Acknowledgement received
Enter 1 to continue or else 0:
ERROR DETECTION AND CORRECTION USING CYCLIC REDUNDANCY CODE

PROGRAM

% START
clc;
clear all;
close all;
% GET THE LENGTH OF THE MESSAGE BITS.
n=input('Enter the length of the sequence:');
r(1)=1;
% RANDOM GENERATION OF MESSAGE BITS
r(2:n)=randint(1,n-1);
r(n+1:n+4)=0;
n=n+4;
% INITIALIZE THE DIVISOR BITS- CHOSEN HAS 4 BITS
d=[1 0 0 1];
m=4;
temp=r;
disp(temp);
k=0;
% TRANSMITTER SECTION
% PERFORMING DIVISION OPERATION USING BITXOR OPERATION
disp(sprintf('The division operation is performed as follows'));
for i=1:(n-m+1)
for j=0:(m-1)
if(k==0)
r(j+i)=bitxor(r(j+i),d(j+1));
end;
end;
if(r(i+1)==0)
k=1;
else
k=0;
end;
disp(r);
end;
r=r+temp;
disp(sprintf('The transmitted sequence is'));
disp(r);
% GENERATION OF RANDOM ERRORS
k=randint(1,1,[1,n]);
disp(k);
r(k)=randint(1,1);
disp(r(k));
% RECEIVER SECTION
disp(sprintf('The received sequence is'));
disp(r);
k=0;
for i=1:(n-m+1)
for j=0:(m-1)
if(k==0)
r(j+i)=bitxor(r(j+i),d(j+1));
end;
end;
if(r(i+1)==0)
k=1;
else
k=0;
end;
end;
s=sum(r);
% CHECKING WHETHER ERROR IS PRESENT OR NOT
if(s==0)
disp(sprintf('The sequence is transmitted without error'));
f=(n/n);
sprintf('Without Error Throughput:');
disp(f);
else;
g=((n-1)/n);
sprintf('With Error Throughput:');
disp(g);
disp(sprintf('The sequence is transmitted with error'));
end;

SAMPLE INPUT & OUTPUT:

% ENTERING THE MESSAGE LENGTH


Enter the length of the sequence: 8

1 0 1 1 1 1 0 0 0 0 0 0

The division operation is performed as follows

0 0 1 0 1 1 0 0 0 0 0 0
0 0 1 0 1 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 1 0

The transmitted sequence is


1 0 1 1 1 1 0 0 0 0 1 0

12 % ERROR POSITION
1 % ERROR
2
The received sequence is
1 0 1 1 1 1 0 0 0 0 1 1

The sequence is transmitted with error


With Error Throughput:
0.9167
PROGRAM:

% START
clc;
clear all;
% INITIALIZE THE NODES
a=[inf 2 inf 3 inf 1 4;
2 inf 4 inf 5 inf inf;
inf 4 inf 6 inf 7 inf;
3 inf 6 inf 8 inf 3;
inf 5 inf 8 inf 3 inf;
1 inf 7 inf 3 inf inf;
4 inf inf 3 inf inf inf];
% GETTING TRANSMITTED NODE No AND RECEIVER NODE No
p=input('Enter the transmitter node:');
q=input('Enter the receiver node:');
del(1:10)=0;
j=1;
n=2;
b=1;
for i=1:7
%DISPLAYING THE PATH AND DELAY
if((a(p,i)~=inf)&(i==q))
disp(sprintf('The path is %d \t %d \t %d',b,p,q));
disp(sprintf('The delay is %d\n\t',a(p,q)));
del(b)=a(p,q);
b=b+1;
end;
if((a(p,i)~=inf)&(i~=q))
nxt(j,1,1:2)=p;
nxt(j,2,1:2)=i;
j=j+1;
end;
end;
x=1;
for i=1:(j-1)
for k=1:7
if(a(nxt(i,2),k)~=inf)&(k~=nxt(i,:))
n=n+1;
nxt(i,n,x)=k;
x=x+1;
n=n-1;
end;
end;
x1=x;
x=1;
n=2;
end;
for i1=1:(j-1)
i2=x1;
for i=1:n
if(nxt(i1,i2,i)==q)
disp(sprintf('Path %d',b));
disp(nxt(i1,:,i));
%CALCULATING THE SHORTEST PATH
for k=1:length(nxt)-1
del(b)=del(b)+a(nxt(i1,k,i),nxt(i1,k+1,i));
end;
disp(sprintf('Delay %d\n',del(b)));
b=b+1;
end;
end;
end;
for i=1:10
if del(i)==0;
del(i)=inf;
end;
end;
[o,m]=min(del);
disp(sprintf('Path %d is the shortest path.',m));

SAMPLE INPUT & OUTPUT:

Enter the transmitter node:2

Enter the receiver node:6

Path 1
2 1 6

Delay 3

Path 2
2 3 6

Delay 11

Path 3
2 5 6

Delay 8

Path 1 is the shortest path.

You might also like