Saturday, November 7, 2015

optimization in Cognitive radio network (spectrum sensing, total error rate)

clc; 
close all;
clear all;
%This program is for optimization of spectrum sensing in 
%Cognitive radio network.
N=20;
j=1;
tt=[];
err2=[];
Pmi=[];
Pdc=[];
error=[];
err1=[];
K=10;
snr=10;
Qd=0;
Qf=0;
tt=10:0.5:60;
vec=['-+','-o','-v','-d','->','-x','-s','-<','-*','-^'];

for n=1:1:10
    
s=ones(1,N);
w=randn(1,N); 

u=N/2;                    %Time-delay bandwidth product

for t=10:0.5:60 
  
Qd=0;
Qf=0;
SNR=10^(snr/10);   %for linear scale 

a=sqrt(2*SNR);
b=sqrt(t);



Pd = marcumq(a,b,u );         % AVG. PROB OF DETECTION(computes the generalized Marcum Q)
                 
Pf = gammainc((t/2),u,'upper');% AVG. PROB OF FALSE ALARM(compute incompelete gamma function)

Pm=1-Pd;                %AVG. PROB OF MISSED DETECTION OVER AWGN
for l=n:1:K
Qd=Qd+(factorial(K)*(Pd^l)*((1-Pd)^(K-l))/(factorial(l)*factorial(K-l)));
Qf=Qf+(factorial(K)*(Pf^l)*((1-Pf)^(K-l))/(factorial(l)*factorial(K-l)));
end

Qm=1-Qd;
err=Qf+Qm;
err1=[err1 err];
end

end
l=1;
i=1;
for j=1:1:10
semilogy(tt,err1(i:i+100),vec(l:l+1),'LineWidth',1.5)
i=i+101;
l=l+2;
hold on;
end
grid on;
ylabel('Total Error rate');
xlabel('Threshold');


%----------------------Energy Detection----------------------------------------
n=5;
rel=10000;
tt1=10:0.5:60;
er1=[];
for t=10:0.5:60
Pdc=0;
Pfc=0;
Qd=0;
Qf=0;
Qm=0;

for i=1:1:rel
SNR=10;

snr=10^(SNR/10);

    
s=ones(1,N);
w=randn(1,N); 
vari=var(w);               %variance of noise

Es=sum(s.^2);

N02=(Es)/(2*snr);   

x1=s+w; 
x2=w;
W=1;                    %Time-delay bandwidth product

E0=(sum(x2.^2))/((W*N02));

E1=(sum(x1.^2))/((W*N02));


if E1>t
    Pdc=Pdc+1;
else
end
if E0>t
    Pfc=Pfc+1;
else
end
end
Pd=Pdc/rel;
Pf=Pfc/rel;
   
  
for l=n:1:K
Qd=Qd+(factorial(K)*(Pd^l)*((1-Pd)^(K-l))/(factorial(l)*factorial(K-l)));
Qf=Qf+(factorial(K)*(Pf^l)*((1-Pf)^(K-l))/(factorial(l)*factorial(K-l)));
end
Qm=1-Qd;
er=Qf+Qm;
er1=[er1 er];
end
hold on;
semilogy(tt1,er1,'*r')
grid on;

ylabel('Total Error rate');
xlabel('Threshold');
legend('n=1','n=2','n=3','n=4','n=5','n=6','n=7','n=8','n=9','n=10','n=5 by modelling');

Low Energy Adaptive Clustering Hierarchy protocol (LEACH) in WSN & path_delay_calculation in Wireless Sensor Networks GUI

LEACH is a hierarchical protocol in which most nodes transmit to cluster heads, and the cluster heads aggregate and compress the data and forward it to the base station(sink). Each node uses a stochastic algorithm at each round to determine whether it will become a cluster head in this round. LEACH assumes that each node has a radio powerful enough to directly reach the base station or the nearest cluster head, but that using this radio at full power all the time would waste energy. 
Nodes that have been cluster heads cannot become cluster heads again for P rounds, where P is the desired percentage of cluster heads. Thereafter, each node has a 1/P probability of becoming a cluster head in each round. At the end of each round, each node that is not a cluster head selects the closest cluster head and joins that cluster. The cluster head then creates a schedule for each node in its cluster to transmit its data. 
All nodes that are not cluster heads only communicate with the cluster head in a TDMA fashion, according to the schedule created by the cluster head. They do so using the minimum energy needed to reach the cluster head, and only need to keep their radios on during their time slot. 
LEACH also uses CDMA so that each cluster uses a different set of CDMA codes, to minimize interference between clusters.


 MATLAB release MATLAB 8.0 (R2012b)
Other requirements Windows x64


clear;
%%%%%%%%%%%%%%%%%%%%%%%%% PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Field Dimensions - x and y maximum (in meters)/ Tarife Size mohite shabake(m)
xm=100;
ym=100;
%x and y Coordinates of the Sink  / 
sink.x=0.5*xm;
sink.y=0.5*ym;

%Number of Nodes in the field  / Tedade Node haye shabake
n=100

%Optimal Election Probability of a node to become cluster head/ Ehtemale Entekhab Node be onvane Cluster Head
p=0.1;
%Energy Model (all values in Joules)/ Energy ha bar hasbe Joule
%Initial Energy / Energy Avaliye
Eo=0.5;
%Eelec=Etx=Erx 
ETX=50*0.000000001;
ERX=50*0.000000001;
%Transmit Amplifier types / Ghodrate Ersal
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
%Data Aggregation Energy/ Energy Masrafi Tajmie Dade
EDA=5*0.000000001;
%Values for Hetereogeneity 
%Percentage of nodes than are advanced 
m=0.1;
%\alpha
a=1;
%maximum number of rounds/ Max tedade round ha
rmax=200
%%%%%%%%%%%%%%%%%%%%%%%%% END OF PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%
%Computation of do/ 
do=sqrt(Efs/Emp);
%Creation of the random Sensor Network/ Tolide Randome shabake
figure(1);
for i=1:1:n
    S(i).xd=rand(1,1)*xm;
    XR(i)=S(i).xd;
    S(i).yd=rand(1,1)*ym;
    YR(i)=S(i).yd;
    S(i).G=0;
    %initially there are no cluster heads only nodes/ Dar ebteda hich Cluster Head i mojud nist
    S(i).type='N';
   
    temp_rnd0=i;
    %Random Election of Normal Nodes/ Entekhabe Tasadofi Node ha 
    if (temp_rnd0>=m*n+1) 
        S(i).E=Eo;
        S(i).ENERGY=0;
        plot(S(i).xd,S(i).yd,'o');
        hold on;
    end
    %Random Election of Advanced Nodes/ Entekhab Tasadofie CH ha
    if (temp_rnd0<m*n+1)  
        S(i).E=Eo*(1+a)
        S(i).ENERGY=1;
        plot(S(i).xd,S(i).yd,'+');
        hold on;
    end
end
S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
plot(S(n+1).xd,S(n+1).yd,'x');
  
      
%First Iteration
figure(1);

%counter for CHs/ Tedade Cluster Head ha 
countCHs=0;
%counter for CHs per round/ Tedade CH haye har Round
rcountCHs=0;
cluster=1;

countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;

for r=0:1:rmax
    r

  %Operation for epoch/ Formule entekhabe CH
  if(mod(r, round(1/p) )==0)
    for i=1:1:n
        S(i).G=0;
        S(i).cl=0;
    end
  end

hold off;

%Number of dead nodes/ Tedade Node haye morde dar kol
dead=0;
%Number of dead Advanced Nodes/ Tedade Node haye CH morde
dead_a=0;
%Number of dead Normal Nodes/ Tedade Node haye morde mamuli
dead_n=0;

%counter for bit transmitted to Bases Station and to Cluster Heads/ Tedade packet haye ersali be BS 
packets_TO_BS=0;
packets_TO_CH=0;
%counter for bit transmitted to Bases Station and to Cluster Heads /Tedade packet haye Ersali be BS dar har round
%per round
PACKETS_TO_CH(r+1)=0;
PACKETS_TO_BS(r+1)=0;

figure(1);

for i=1:1:n
    %checking if there is a dead node/ Check kardane zende budane Node ha 
    if (S(i).E<=0)
        plot(S(i).xd,S(i).yd,'red .');
        dead=dead+1;
        if(S(i).ENERGY==1)
            dead_a=dead_a+1;
        end
        if(S(i).ENERGY==0)
            dead_n=dead_n+1;
        end
        hold on;    
    end
    if S(i).E>0
        S(i).type='N';
        if (S(i).ENERGY==0)  
        plot(S(i).xd,S(i).yd,'o');
        end
        if (S(i).ENERGY==1)  
        plot(S(i).xd,S(i).yd,'+');
        end
        hold on;
    end
end
plot(S(n+1).xd,S(n+1).yd,'x');


STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;
DEAD_N(r+1)=dead_n;
DEAD_A(r+1)=dead_a;

%When the first node dies/ Pas az marge avalin Node
if (dead==1)
    if(flag_first_dead==0)
        first_dead=r
        flag_first_dead=1;
    end
end

countCHs=0;
cluster=1;
for i=1:1:n
   if(S(i).E>0)
   temp_rand=rand;     
   if ( (S(i).G)<=0)

 %Election of Cluster Heads/ Entekhabe CH
 if(temp_rand<= (p/(1-p*mod(r,round(1/p)))))
            countCHs=countCHs+1;
            packets_TO_BS=packets_TO_BS+1;
            PACKETS_TO_BS(r+1)=packets_TO_BS;
            
            S(i).type='C';
            S(i).G=round(1/p)-1;
            C(cluster).xd=S(i).xd;
            C(cluster).yd=S(i).yd;
            plot(S(i).xd,S(i).yd,'k*');
            
            distance=sqrt( (S(i).xd-(S(n+1).xd) )^2 + (S(i).yd-(S(n+1).yd) )^2 );
            C(cluster).distance=distance;
            C(cluster).id=i;
            X(cluster)=S(i).xd;
            Y(cluster)=S(i).yd;
            cluster=cluster+1;
            
            %Calculation of Energy dissipated/  Mohasebe energy masrafi
            distance;
            if (distance>do)
                S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance )); 
            end
            if (distance<=do)
                S(i).E=S(i).E- ( (ETX+EDA)*(4000)  + Efs*4000*( distance * distance )); 
            end
        end     
    
    end
  end 
end

STATISTICS(r+1).CLUSTERHEADS=cluster-1;
CLUSTERHS(r+1)=cluster-1;

%Election of Associated Cluster Head for Normal Nodes/ Entekhabe CH marbute baraye Node haye mamuli
for i=1:1:n
   if ( S(i).type=='N' && S(i).E>0 )
     if(cluster-1>=1)
       min_dis=sqrt( (S(i).xd-S(n+1).xd)^2 + (S(i).yd-S(n+1).yd)^2 );
       min_dis_cluster=1;
       for c=1:1:cluster-1
           temp=min(min_dis,sqrt( (S(i).xd-C(c).xd)^2 + (S(i).yd-C(c).yd)^2 ) );
           if ( temp<min_dis )
               min_dis=temp;
               min_dis_cluster=c;
           end
       end
       
       %Energy dissipated by associated Cluster Head/ Mohasebe energy masrafi CH ha 
            min_dis;
            if (min_dis>do)
                S(i).E=S(i).E- ( ETX*(4000) + Emp*4000*( min_dis * min_dis * min_dis * min_dis)); 
            end
            if (min_dis<=do)
                S(i).E=S(i).E- ( ETX*(4000) + Efs*4000*( min_dis * min_dis)); 
            end
        %Energy dissipated/ Masrafe energy kol
        if(min_dis>0)
          S(C(min_dis_cluster).id).E = S(C(min_dis_cluster).id).E- ( (ERX + EDA)*4000 ); 
         PACKETS_TO_CH(r+1)=n-dead-cluster+1; 
        end

       S(i).min_dis=min_dis;
       S(i).min_dis_cluster=min_dis_cluster;
           
   end
 end
end
hold on;

countCHs;
rcountCHs=rcountCHs+countCHs;
end

%  DEAD  : a rmax x 1 array of number of dead nodes/round          %
%  DEAD_A : a rmax x 1 array of number of dead Advanced nodes/round       %
%  DEAD_N : a rmax x 1 array of number of dead Normal nodes/round                     %
%  CLUSTERHS : a rmax x 1 array of number of Cluster Heads/round                      %
%  PACKETS_TO_BS : a rmax x 1 array of number packets send to Base Station/round      %
%  PACKETS_TO_CH : a rmax x 1 array of number of packets send to ClusterHeads/round   %
%  first_dead: the round where the first node died  

WSN protocol implementation leach program GUI

close all;
clear;
clc;
%-------------------------------
%Number of Nodes in the field
 n=200;
%n=input('Enter the number of nodes in the space : '); 
%Energy Model (all values in Joules)
%Initial Energy 
Eo=0.1;
%Eo=input('Enter the initial energy of sensor nJ : ');
%Field Dimensions - x and y maximum (in meters)
% xm=input('Enter x value for area plot : ');
% ym=input('Enter y value for area plot : ');  
xm=100;
ym=100;

%x and y Coordinates of the Sink
sink.x=1.5*xm;
sink.y=0.5*ym;

%Optimal Election Probability of a node
%to become cluster head
p=0.2;

%Eelec=Etx=Erx
ETX=50*0.000000001;
ERX=50*0.000000001;
%Transmit Amplifier types
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
%Data Aggregation Energy
EDA=5*0.000000001;

%Values for Hetereogeneity
%Percentage of nodes than are advanced
m=0.5;
%\alpha
a=1;

%maximum number of rounds
%rmax=input('enter the number of iterations you want to run : '); 
rmax=50;
%------------------

%Computation of do
do=sqrt(Efs/Emp);

%Creation of the random Sensor Network
figure(1);
hold off;
for i=1:1:n
    S(i).xd=rand(1,1)*xm;
    XR(i)=S(i).xd;
    S(i).yd=rand(1,1)*ym;
    YR(i)=S(i).yd;
    S(i).G=0;
    %initially there are no cluster heads only nodes
    S(i).type='N';
   
    temp_rnd0=i;
    %Random Election of Normal Nodes
    if (temp_rnd0>=m*n+1) 
        S(i).E=Eo;
        S(i).ENERGY=0;
       plot(S(i).xd,S(i).yd,'o-r');
        hold on;
    end
    %Random Election of Advanced Nodes
    if (temp_rnd0<m*n+1)  
        S(i).E=Eo*(1+a);
        S(i).ENERGY=1;
       plot(S(i).xd,S(i).yd,'+');
        hold on;
    end
end

S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
plot(S(n+1).xd,S(n+1).yd,'o', 'MarkerSize', 12, 'MarkerFaceColor', 'r');
figure(1);  
% figure(1)
%  plot(o1,o2,'^','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','y', 'MarkerSize',12);
%    hold on
%First Iteration
%counter for CHs
countCHs=0;
%counter for CHs per round
rcountCHs=0;
cluster=1;

countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;

for r=0:1:rmax
    r;

  %Operation for epoch
  if(mod(r, round(1/p) )==0)
    for i=1:1:n
        S(i).G=0;
        S(i).cl=0;
    end
  end

hold off;

%Number of dead nodes
dead=0;
%Number of dead Advanced Nodes
dead_a=0;
%Number of dead Normal Nodes
dead_n=0;

%counter for bit transmitted to Bases Station and to Cluster Heads
packets_TO_BS=0;
packets_TO_CH=0;
%counter for bit transmitted to Bases Station and to Cluster Heads 
%per round
PACKETS_TO_CH(r+1)=0;
PACKETS_TO_BS(r+1)=0;

figure(1);

for i=1:1:n
    %checking if there is a dead node
    if (S(i).E<=0)
       plot(S(i).xd,S(i).yd,'^','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','y', 'MarkerSize',8);
        dead=dead+1;
        if(S(i).ENERGY==1)
            dead_a=dead_a+1;
        end
        if(S(i).ENERGY==0)
            dead_n=dead_n+1;
        end
        hold on;    
    end
    if S(i).E>0
        S(i).type='N';
        if (S(i).ENERGY==0)  
     plot(S(i).xd,S(i).yd,'o','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','g', 'MarkerSize',8);
        end
        if (S(i).ENERGY==1)  
        plot(S(i).xd,S(i).yd,'+','LineWidth',3, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);
        end
        hold on;
    end
end
plot(S(n+1).xd,S(n+1).yd,'x','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8); 


STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;
DEAD_N(r+1)=dead_n;
DEAD_A(r+1)=dead_a;
%          plot(S(n+1).xd,S(n+1).yd,'o', 'MarkerSize', 12, 'MarkerFaceColor', 'r');
%          plot(S(n+1).xd,S(n+1).yd,'x','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);  
%When the first node dies
if (dead==1)
    if(flag_first_dead==0)
        first_dead=r;
        flag_first_dead=1;
    end
end

countCHs=0;
cluster=1;
for i=1:1:n
   if(S(i).E>0)
   temp_rand=rand;     
   if ( (S(i).G)<=0)

 %Election of Cluster Heads
 if(temp_rand<= (p/(1-p*mod(r,round(1/p)))))
            countCHs=countCHs+1;
            packets_TO_BS=packets_TO_BS+1;
            PACKETS_TO_BS(r+1)=packets_TO_BS;
            
            S(i).type='C';
            S(i).G=round(1/p)-1;
            C(cluster).xd=S(i).xd;
            C(cluster).yd=S(i).yd;
             plot(S(i).xd,S(i).yd,'k*');
            
            distance=sqrt( (S(i).xd-(S(n+1).xd) )^2 + (S(i).yd-(S(n+1).yd) )^2 );
            C(cluster).distance=distance;
            C(cluster).id=i;
            X(cluster)=S(i).xd;
            Y(cluster)=S(i).yd;
            cluster=cluster+1;
            
            %Calculation of Energy dissipated
            distance;
            if (distance>do)
                S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance )); 
            %S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance )); 
            end
            if (distance<=do)
                S(i).E=S(i).E- ( (ETX+EDA)*(4000)  + Efs*4000*( distance * distance )); 
            %S(i).E=S(i).E- ( (ETX+EDA)*(4000)  + Efs*4000*( distance * distance )); 
            end
            Energy_disp(r+1) =  S(i).E;
        end     
    
    end
  end 
end

STATISTICS(r+1).CLUSTERHEADS=cluster-1;
CLUSTERHS(r+1)=cluster-1;

%Election of Associated Cluster Head for Normal Nodes
for i=1:1:n
   if ( S(i).type=='N' && S(i).E>0 )
     if(cluster-1>=1)
       min_dis=sqrt( (S(i).xd-S(n+1).xd)^2 + (S(i).yd-S(n+1).yd)^2 );
       min_dis_cluster=1;
       for c=1:1:cluster-1
           temp=min(min_dis,sqrt( (S(i).xd-C(c).xd)^2 + (S(i).yd-C(c).yd)^2 ) );
           if ( temp<min_dis )
               min_dis=temp;
               min_dis_cluster=c;
           end
       end
       
       %Energy dissipated by associated Cluster Head
            min_dis;
            if (min_dis>do)
                S(i).E=S(i).E- ( ETX*(4000) + Emp*4000*( min_dis * min_dis * min_dis * min_dis)); 
            end
            if (min_dis<=do)
                S(i).E=S(i).E- ( ETX*(4000) + Efs*4000*( min_dis * min_dis)); 
            end
        %Energy dissipated
        if(min_dis>0)
         distance=sqrt( (S(C(min_dis_cluster).id).xd-(S(n+1).xd) )^2 + (S(C(min_dis_cluster).id).yd-(S(n+1).yd) )^2 );
          S(C(min_dis_cluster).id).E = S(C(min_dis_cluster).id).E- ( (ERX + EDA)*4000 ); 
if (distance>do)
                S(C(min_dis_cluster).id).E=S(C(min_dis_cluster).id).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance )); 
            end
            if (distance<=do)
                S(C(min_dis_cluster).id).E=S(C(min_dis_cluster).id).E- ( (ETX+EDA)*(4000)  + Efs*4000*( distance * distance )); 
            end
          PACKETS_TO_CH(r+1)=n-dead-cluster+1; 
        end

       S(i).min_dis=min_dis;
       S(i).min_dis_cluster=min_dis_cluster;
           
   end
 end
end
hold on;

countCHs;
rcountCHs=rcountCHs+countCHs;
sum=0;
for i=1:1:n
if(S(i).E>0)
    sum=sum+S(i).E;
end
end
avg=sum/n;
STATISTICS(r+1).AVG=avg;
sum;


%Code for Voronoi Cells
%Unfortynately if there is a small
%number of cells, Matlab's voronoi
%procedure has some problems
warning('OFF');
[vx,vy]=voronoi(X(:),Y(:));
plot(X,Y,'g+',vx,vy,'m-');
hold on;
voronoi(X,Y);
axis([10 xm 0 ym]);

end
% figure1 = figure11;
% % Create axes
% axes1 = axes('Parent',figure1,'YGrid','on','XGrid','on','GridLineStyle','--');
% box(axes1,'on');
% hold(axes1,'all');
figure(2);
for r=0:1:24
    ylabel('Average Energy of Each Node');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
    hold on;
end
figure(3);
for r=0:1:49
    ylabel('Average Energy of Each Node');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
    hold on;
end
figure(4);
for r=0:1:74
    ylabel('Average Energy of Each Node');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
    hold on;
end
figure(5);
for r=0:1:99
    ylabel('Average Energy of Each Node');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
    hold on;
end
figure(6);
for r=0:1:24
    ylabel('Number of Dead Nodes');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
    hold on;
end
figure(7);
for r=0:1:49
        ylabel('Number of Dead Nodes');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
    hold on;
end
figure(8);
for r=0:1:74
        ylabel('Number of Dead Nodes');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
    hold on;
end
figure(9);
for r=0:1:99
        ylabel('Number of Dead Nodes');
    xlabel('Round Number');
    plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
    hold on;
end

Wednesday, October 28, 2015

Easy step by step procedure for beginners in NS-3.24 installation in UBUNTU 12.04 LTS or UBUNTU 14.04LTS

Easy step by step procedure for beginners in NS-3.24 installation in UBUNTU 12.04 LTS or UBUNTU 14.04LTS

D.VINAYAGAM M.Tech

vinotd@gmail.com

+918681954006

NS3 Installation in Ubuntu 12.04 version

Ubuntu 2012(12) april(04) RELEASE


Installation of Dependencies


vina@ubuntu:~/workspace/bake$ sudo apt-get update

vina@ubuntu:~/workspace$ sudo apt-get install gcc g++ python python-dev qt4-dev-tools mercurial bzr cmake libc6-dev g++-multilib gdb valgrind gsl-bin libgsl0-dev libgsl0ldbl flex bison libfl-dev tcpdump sqlite sqlite3 libsqlite3-dev libxml2 libxml2-dev libgtk2.0-0 libgtk2.0-dev uncrustify python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev

vina@ubuntu:~/workspace$ sudo apt-get install vtun lxc bridge-utils uml-utilities

vina@ubuntu:~/workspace$ sudo apt-get install doxygen graphviz imagemagick texlive texlive-extra-utils texlive-latex-extra python-sphinx dia

vina@ubuntu:~/workspace$ sudo apt-get install python-pygccxml

vina@ubuntu:~/workspace$ sudo apt-get install libxml2-dev

vina@ubuntu:~/workspace$ sudo apt-get install python-setuptools

vina@ubuntu:~/workspace$ sudo apt-get install gnuplot plotdrop

vina@ubuntu:~/workspace$ sudo apt-get install wireshark

----------------------------------------end package updation------------------------------------
know your location/directory at present
vina@ubuntu$ pwd

make a directory
vina@ubuntu$ mkdir workspace

download ns-3 package
vina@ubuntu:~/workspace$ sudo apt-get install wget
vina@ubuntu:~/workspace$ wget http://www.nsnam.org/release/ns-allinone-3.23.tar.bz2


unrar the ns-3-allinone package
vina@ubuntu:~/workspace$ tar -xvjf ns-allinone-3.24.tar.bz2
vina@ubuntu:~/workspace$ cd ns-allinone-3.24/

Compilation, installation, building
vina@ubuntu:~/workspace$ chmod +x build.py
vina@ubuntu:~/workspace$ ./build.py --enable-examples --enable-tests

vina@ubuntu:~/workspace$ cd ns-3.24/
vina@ubuntu:~/workspace$ ./waf --enable-examples --enable-tests configure
vina@ubuntu:~/workspace$ ./waf

run command the file
vina@ubuntu:~/workspace$ ./waf --run scratch/scratch-simulator
vina@ubuntu:~/workspace$ ./waf --run scratch/first


------------------------------------------------------------------------------------------------------
If anyone require workshop (hand on training for beginners) can contact me for further details and i had mentioned the details below (contact no. and email id)
-------------------------------------------------------------------------------------------------------

Aim : to promote the research in NS-3 open source simulation software with free GPL license) with Advanced features to visualize, trace the logging, animate the networks virtually and emulate the test network in NS-3 before hardware implementation. 

Objective : Providing Practical and Theoretical training related to NS-3 simulator.

Content: 

Introduction of use of NS-3 simulator and features

NS-3 Installation, 
Bake installation with all modules & development package for research
Tarball installation with all modules 

Basic programming console (python and C++), how to use the simulator,

Develop the NS-3 code with explanation from basic step

Basic programs execution (build, compile, run) in NS-3

Simulate all wireless scenarios and also examples programs for easy understanding  

Verifying and tracing output using real world software (graphically, visually, Animated, logging).

optional : Basic procedures for including modules, 
Adding protocols/modules in specific, testing the protocol.

Requirements for Ns-3 installation

1. Vmware version 9 or Version 8 or higher with ubuntu 12.04 Operating system.

Specification in ubuntu 12.04 installation:

  • (20GB HDD for comfortable usage os ubuntu in future use)

  • (miminum 1.5GB ram guest OS (ubuntu 12.-04) allocated out 3GB ram mother OS(windows10 or 8 or 7)

2. INTERNET facilities with interruption or minimum 512kps link

or

1. Dual OS ubuntu 12.04 (updated)

(40GB HDD and minimum 2GB ram)

2. Internet connection for 2 to 6 hours

Requirements for Ns-3 installation

1. Vmware version 9 or Version 8 or higher with ubuntu 12.04 Operating system.

Specification in ubuntu 12.04 installation:

  • (20GB HDD for comfortable usage os ubuntu in future use)

  • (miminum 1.5GB ram guest OS (ubuntu 12.-04) allocated out 3GB ram mother OS(windows10 or 8 or 7)

2. INTERNET facilities with interruption or minimum 512kps link

or

1. Dual OS ubuntu 12.04 (updated) (40GB HDD and minimum 2GB ram)

2. Internet connection for 2 to 6 hours

Documents and ubuntu 12.04 module Given to students:

A VMWARE Module (ubuntu.vmx) with Ns-2.34-allinone package preinstalled in ubuntu 12.04 LTS

A VMWARE Module (ubuntu.vmx) with Ns-2.34-allinone & Ns-3-development (NS 2.24 package late 2015 release) package preinstalled in ubuntu 12.04 lts

Benefits: NS-3 workshop Manuals (Installation, NS-3 programs with output simulation, and prequites for Ns-3 Softwares installation will be provided.





Contact: Vinotd@gmail.com                                       Contact no.   +918681954006
Location: Pondicherry

Classes will be handled in their colleges (located within India)
Give the details of college/institutions for conducting the workshop.
Minimum 1 day for hand on training for full  NS-3 installation.

installing ns3.16 in opensuse 12 using vmware

Install and configure Eclipse IDE on ns-3

In this article, I want to review my video about install and configure Eclipse for ns-3.
In articles install ns-3 on OpenSuse Part 1, Part 2 and Part 3, we sow that how we can install ns-3. So I already have installed ns-3.17 on OpenSuse 12.2.

You can find my videos about installing ns-3 on OpenSuse Linux in: 
Part1: Install OpenSuse 12.2 On VM-Ware
Part2: Install Pre-requirements Package for ns-3 (ns3.16)
Part3: Install ns-3 and Run Example (ns-3.16)
And now we want to install and configure Eclipse IDE on ns-3.



Please notice that I installed ns-3.17 on OpenSuse Linux from ns-allinone-3.17.tar.bz2 in Documentspath in OpenSuse Linux. We need this path later. (/home/ns3user/ Documents/ns-allinone-3.17/)

I suppose, you already have Mercurial installed on your machine. You can find how to install Mercurialat "Part2: Install Pre-requirements Package for ns-3"

What we need:
1. Eclipse IDE for C/C++ Developers. You can download it from http://www.eclipse.org/downloads/
Depend on your CPU which is 32-bit or 64-bit, you can download eclipse-cpp-juno-SR2-linux-gtk-x86_64.tar.gz or eclipse-cpp-juno-SR2-linux-gtk.tar.gz. In this video, I downloaded "eclipse-cpp-juno-SR2-linux-gtk-x86_64.tar.gz".
Eclipse IDE for C/C++ Developers version in this video is: Version: Juno Service Release 2 - Build id: 20130225-0426

2. An Internet Connection.

In this tutorial, we have 4 parts:
• Part A: Install Eclipse and Configure Mercurial
• Part B: Configure Waf Builder
• Part C: Configure Debugger
• Part D: Create new source code, and run it.
   o D-1: Use Eclipse for running source code
   o D-2: Use Eclipse for creating new source code, but use ns-3 for running it (I Recommend)


Part A: Install Eclipse and Configure Mercurial 

1. Open Terminal and go to Eclipse path by cd command. Then use tar command to extract Eclipse
 tar -xvf eclipse-cpp-juno-SR2-linux-gtk-x86_64.tar.gz

2. Open Eclipse and choose a path for your projects.
You can choose whatever you want but it is advised to use a directory just for the Eclipse projects.

3. Be sure your Internet is connected.

4. In Eclipse, go to Help → Install New Software.
You should insert http://cbes.javaforge.com/update and mercurialeclipse in the form. It is simple, just follow the video. (After this step, the Internet is no longer needed)

 5. Create new C++ Project and with your preferred name. (I choose NS-3 Projects as project name)
You should choose the installed ns-3 path for the project. As I told you before, I installed ns-3 in Documents. The path is:  /home/ns3user/Documents/ns-allinone-3.17/ns-3.17/

6. Right Click on the project and go to Team→ Share Project. Then click on Next and select local Mercurial.


B: Configure Waf Builder 

1. Right Click on the project and click on Properties. Then, click on C/C++ build. After that uncheck the boxes: "Use default build command" and "Generate make file automatically"

2. Insert this path as Build command: /home/ns3user/Documents/ns-allinone-3.17/ns-3.17/waf

3. Insert this path as Build directory: /home/ns3user/Documents/ns-allinone-3.17/ns-3.17/build

4. Click on the Behaviour tab and remove the `all` option in front of the Build (Incremental build) check-box and then write build


Part C: Configure Debugger

1. Go to Run → Debug Configurations and create a new configuration and choose a name for it.
2. Click on the "Browse" button under the "Project" section and select your project.
3. Click on the "Search Project" button under the "C/C++ Application" section and type scratch-simulator
4. Go to Environment tab and click on New button to create a new variable. You will need these:LD_LIBRARY_PATH  and /home/ns3user/Documents/ns-allinone-3.17/ns-3.17/build
5. Be sure the "Append environment to native environment" is selected. Now, let run an example


Part D: Create new source code, and run it.
There are two different ways for compiling source codes:
 • D-1: Use Eclipse for running source codes
 • D-2: Use Eclipse for creating new source code, but use waf for running it (I recommend this one)

D-1: Use Eclipse for running source code

1. Create your source code, in scratch directory. As you will watch in the video, I create reza.cc file and copy the third.cc content into reza.cc. (The third.cc is one of the ns-3.17 example.) You can suppose it is a new code. The path is:  /home/ns3user/Documents/ns-allinone-3.17/ns-3.17/scratch/
2. Click on Run button to compile all the source codes in scratch directory. So your source code is compiled too.
3. Go to Run Configurations and in Search Project option, select your project. Then click again on Run button and wait until compile complete. You will see your source code output

D-2: Use Eclipse for creating new source code, but use waf for running it (I Recommend) 

 1. Create your source code, in scratch directory. As you will watch in the video, I create reza.cc file and copy the third.cc content into reza.cc. (The third.cc is one of the ns-3.17 example.) You can suppose it is a new code. The path is: • /home/ns3user/Documents/ns-allinone-3.17/ns-3.17/scratch/
2. Open terminal, go to ns-3 path by cd command, and run the source code by waf command.:   ./waf  or ./waf --run scratch/reza

You see D-1 and D-2 ways have same output. but when you use way D-2 you can use --visualize for visualizing.for example: ./waf --run scratch/reza --visualize


References:
http://www.nsnam.org
http://www.nsnam.org/documentation/videos/
http://www.nsnam.org/documentation/presentations/
http://www.nsnam.org/wiki/index.php/HOWTO_configure_Eclipse_with_ns-3

Saturday, October 6, 2012

MATLAB to automatically create a wireless network GUI graphical user interface

This is a sample of creating a node manuly using GUI
BeconX=500;
BeconY=500;
axes(handles.axes1);
gca;
hold on;
hbecon=plot(BeconX,BeconY,'s')
set(hbecon,'color','red','LineWidth',8);

Basic part of my code is to randomly place the sensor nodes in the given space then connecting each two nodes if the distance between them less than or equal to the communication radius. Please check Matlab code below.

clear;
noOfNodes = 50;
rand('state', 0);
figure(1);
clf;
hold on;
L = 1000;
R = 200; % maximum range;
netXloc = rand(1,noOfNodes)*L;
netYloc = rand(1,noOfNodes)*L;
for i = 1:noOfNodes
plot(netXloc(i), netYloc(i), '.');
text(netXloc(i), netYloc(i), num2str(i));
for j = 1:noOfNodes
distance = sqrt((netXloc(i) - netXloc(j))^2 + (netYloc(i) - netYloc(j))^2);
if distance <= R
matrix(i, j) = 1; % there is a link;
line([netXloc(i) netXloc(j)], [netYloc(i) netYloc(j)], 'LineStyle', ':');
else
matrix(i, j) = inf;
end;
end;
end;

how to simulate wireless sensor network using matlab

Wireless Sensor Network Localization Measurement Repository

Measurement Environment Photo  
This page provides electronic access to data collected in the measurement campaign reported in [1].  Please see the reference for a detailed description of the measurement experiments.  This page describes only the files which contain the data.

Files

The data is contained within a Matlab file (binary file) that can be opened in Matlab with the `load' command. 

Description

There are three channel measurement experiments presented in [1], the first in Section IV, and the next two in Section V.  This data corresponds to the measurement campaign in Section IV.  This campaign measured both TOA and RSS between sensors in a 44-sensor network in an office environment.   The variables contained in the Matlab file are as follows:
  • P_dB_RSS:  Measured received power between sensors in dBm (a 44 by 44 matrix).  The (i,j) element is the dB average of 10 measurements, 5 with the transmitter at i and receiver at j, and 5 with the transmitter at j and receiver at i.  (The diagonal elements are not used, and the matrix is symmetric.)
  • n_p_RSS:  The estimated path loss exponent
  • P_0_RSS:  The received power at the reference distance of 1m, in dBm.
  • tilde_d_RSS:  The ML distance estimate from P_dB_RSS, n_p_RSS, and P_0_RSS, as given in Equation (7) in reference [1].
  • Device Location MapdeviceLocs:  Actual coordinates of the 44 devices, in units of meters as shown in the plot on this page.
  • T_TOA:  Time delay between sensors, in seconds (a 44 by 44 matrix).  The (i,j) element is the Ti,j reported in Section IV of [1], i.e., the average of 10 measured time delays, 5 with the transmitter at i and receiver at j, and 5 with the transmitter at j and receiver at i. (The diagonal elements are not used, and the matrix is symmetric.)
  • mu_T_TOA:  mean time delay error.  This, as described in Section IV of [1], has already been subtracted out of T_TOA.  If you want the original TOA measurements you should add it back in to each element.
  • v_p_TOA:  Speed of propagation (speed of light) in m/s.

Further Information

Please contact Neal Patwari by email:  npatwari _at_ umich.edu, or visit the Sensing and Processing Across Networks (SPAN) web site.

References

[1]  Neal Patwari, Alfred O. Hero III, Matt Perkins, Neiyer Correal, and Robert J. O'Dea,"Relative Location Estimation in Wireless Sensor Networks", IEEE Transactions on Signal Processing, vol. 51, no. 8, Aug. 2003, pages 2137-2148.  Available: [pdf].

New!  Matlab Localization Code

We now make a set of Matlab localization code freely available.  This code encompasses two main components:
  • simMLE.m:  Simulation script and accompanying functions which run simulation trials for sensor localization when measurements are RSS and TOA.  The simulation generates a sensor network geometry, selects reference devices, generates measurements based on the statistical models presented in [1], and then estimates sensor coordinates by maximizing the likelihood function.  Many trials are run, and afterwards, the 1-standard deviation uncertainty ellipse of the simulations is ouput.  The Cramér-Rao bound (CRB) is also calculated and displayed.
  • calcLocalizationCRB.m:  Function for calculation of the CRB on unbiased location estimators.  This code calculates the bound when measurements are either RSS, Quantized RSS, Proximity (Connectivity), TOA, or AOA.  This function is based on the work presented in several papers (see publications page).   Arbitrary sensor geometries, channel measurement parameters, and sets of measurements can be set.
Download Matlab localization simulation and Cramer-Rao Bound calculation code.