Code covered by the BSD License  

Highlights from
distributed radio net

image thumbnail

distributed radio net

by

 

best routs found with dijkstra's algorithm

test1_random_nodes.m
r0=1; % range (activity radius node)
N=1; % noise level
I=r0^2*N; % node power per length^2, SNR~1 => (I/r0^2)/N ~ 1
% node power: I/r^2, r- distance from node

n=8; % number of nodes

pL=64; % packet length, bits

tsz=0.15*sqrt(n)*r0; % typicle size of considered area

% for circle draw:
rc=0.15*tsz; % circle radius
alc=0:pi/32:2*pi;
xc=rc*cos(alc);
yc=rc*sin(alc);

% random coordinaties
x=tsz*randn(1,n);
y=tsz*randn(1,n);

%plot(x,y,'k.');
%axis equal;

% distancies matrix:
D=zeros(n,n);
for nc1=1:n-1
    x1=x(nc1);
    y1=y(nc1);
    for nc2=nc1+1:n
        x2=x(nc2);
        y2=y(nc2);
        dx=x1-x2;
        dy=y1-y2;
        d=sqrt(dx^2+dy^2);
        D(nc1,nc2)=d;
        D(nc2,nc1)=d;
    end
end

ber=0.5*erfc(sqrt(I./(D.^2*N))); % error probability per bit, https://en.wikipedia.org/wiki/Bit_error_rate#Analysis_of_the_BER
q=1-ber; % probability of correct sending of bit
qq=q.^pL; % probability of correct sending of packet
w=1./qq; % weight, proportional to energy of repeated sending

% explanantion of w=1/q:
% w- weight in graph (price) of edge
% q- probability of succes packet sending
% probability sending from 1st time: q
% probability sending from 2nd time: (1-q)q=p*q
% probability sending from 3rd time: (1-q)*(1-q)q=p^2*q
% ...
% probability sending from k-th time: p^(k-1)*q
% E0- energy to send one packet
% E mean energy to send one packet
% E=sum_k(k*E0*q*p^(k-1))=E0/q
% k=1,2,...,Inf
% ie energy is proportional to 1/q, so weight must be proportional to 1/q

% display weights with graycolor:
subplot(3,3,1);
hold on;
for nc1=1:n-1
    x1=x(nc1);
    y1=y(nc1);
    for nc2=nc1+1:n
        x2=x(nc2);
        y2=y(nc2);
        wt=w(nc1,nc2);
        plot([x1 x2],[y1 y2],'-','color',1-[1 1 1]./wt);
    end
end
for nc=1:n
    if nc==1
        plot(x(nc)+xc,y(nc)+yc,'r-');
    else
        plot(x(nc)+xc,y(nc)+yc,'k-');
    end
    text(x(nc),y(nc),num2str(nc),'HorizontalAlignment','center','color',[1 0 0]);
end
axis equal;
title('net graph, wight - graycolor');

% all nodes connected:
C=true(n,n); % connection matrix
C(1:n+1:n^2)=false; % not connected with itself

ptha=dijkstra(C,w,1); % find pathes with dijkstra's algotithm  http://en.wikipedia.org/wiki/Dijkstra's_algorithm

% display pathes:
for nc=2:n
    subplot(3,3,nc);
    hold on;
    for nct=1:n
        if nct==1
            plot(x(nct)+xc,y(nct)+yc,'r-');
        else
            plot(x(nct)+xc,y(nct)+yc,'k-');
        end
    end
    
    
    
    pth=ptha{nc};
    plot(x(pth),y(pth),'k-');
    
    
    

    axis equal;
    title(['route 1-' num2str(nc)]);
end

% last subplot for combined graph:
subplot(3,3,n+1);
hold on;
for nct=1:n
    if nct==1
        plot(x(nct)+xc,y(nct)+yc,'r-');
    else
        plot(x(nct)+xc,y(nct)+yc,'k-');
    end
end
for nc=2:n
        
    
    pth=ptha{nc};
    plot(x(pth),y(pth),'k-');
    
    
    

    axis equal;
end
title('all routes');

Contact us