Info
This question is closed. Reopen it to edit or answer.
Please explain me this code, this code is related to DV-Hop Algo, but I m unable to understand it..plz help me and i want to modify this code.
1 view (last 30 days)
Show older comments
function test1 % h=nodeAmount; % Sxy= BeaconAmount; % x= UNAmount; clear, close all; BorderLength=100; NodeAmount=250; BeaconAmount=50; UNAmount=NodeAmount-BeaconAmount; R=60; Dall=zeros(NodeAmount,NodeAmount);%Unknown electricity saving to beacon node distance initial matrix; Beacon Amount line of Node Amount rows h=zeros(NodeAmount,NodeAmount);%Initial jumps the number zero; BeaconAmount line of Node Amount rows x=zeros(2,UNAmount);%Node estimate coordinate initial matrix
%~~~Has Uniform Distribution in the square region the random topology~~~~ C=BorderLength.*rand(2,NodeAmount);% Has the logical number node coordinate Sxy=[[1:NodeAmount];C]; Beacon=[Sxy(2,1:BeaconAmount);Sxy(3,1:BeaconAmount)];%Beacon node coordinate UN=[Sxy(2,(BeaconAmount+1):NodeAmount);Sxy(3,(BeaconAmount+1):NodeAmount)];%Beacon node coordinate %~~~~Draws the Node Distribution map~~~~ plot(Sxy(2,1:BeaconAmount),Sxy(3,1:BeaconAmount),'r*',Sxy(2,(BeaconAmount+1):NodeAmount),Sxy(3,(BeaconAmount+1):NodeAmount),'k.') xlim([0,BorderLength]); ylim([0,BorderLength]); title('*Random Deployment of Node*')
%Among the initialization nodes is away from and jumps the number matrix %(Node Ammount) for i=1:NodeAmount for j=1:NodeAmount Dall(i,j)=((Sxy(2,i)-Sxy(2,j))^2+(Sxy(3,i)-Sxy(3,j))^2)^0.5; %Among all nodes is away from mutually if (Dall(i,j)<=R)&(Dall(i,j)>0) h(i,j)=1;%initial jumps the number matrix elseif i==j h(i,j)=0; else h(i,j)=inf; end end end
%It jumps number among the algorithm computation nodes for k=1:NodeAmount for i=1:NodeAmount for j=1:NodeAmount if h(i,k)+h(k,j)<h(i,j) %min(h(i,j),h(i,k)+h(k,j) h(i,j)=h(i,k)+h(k,j); end end end end
h %Sought each beacon node correct value h1=h(1:BeaconAmount,1:BeaconAmount); D1=Dall(1:BeaconAmount,1:BeaconAmount); for i=1:BeaconAmount dhop(i,1)=sum(D1(i,:))/sum(h1(i,:)) %each beacon node jumps the distance on average every time end D2=Dall(1:BeaconAmount,(BeaconAmount+1):NodeAmount); %Beacon Amount line of Unamount rows for i=1:BeaconAmount for j=1:UNAmount if min(D2(:,j))==D2(i,j) Dhop(1,j)=D2(i,j); end end end Dhop
hop1=h(1:BeaconAmount,(BeaconAmount+1):NodeAmount);%jumps the number the unknown node to the beacon, the beacon amount line of unamount rows for i=1:UNAmount hop=Dhop(1,i);%hop is the correct value of the recent beacon obtaining Distance(:,i)=hop*hop1(:,i); end
% The method of least square sought the unknown point coordinate~~~ d=Distance; for i=1:2 for j=1:(BeaconAmount-1) a(i,j)=Beacon(i,j)-Beacon(i,BeaconAmount); end end A=-2*(a'); %d=d1 for m=1:UNAmount for i=1:(BeaconAmount-1) B(i,1)=d(i,m)^2-d(BeaconAmount,m)^2-Beacon(1,i)^2+Beacon(1,BeaconAmount)^2-Beacon(2,i)^2+Beacon(2,BeaconAmount)^2; end X1=inv(A'*A)*A'*B; X(2,m)=X1(1,1); X(3,m)=X1(2,1); end UN X for i=1:UNAmount error(1,i)=(((X(1,i)-UN(1,i))^2+(X(2,i)-UN(2,i))^2)^0.5); end figure;plot(error,'-o') title('Localization Error') error=sum(error)/UNAmount Accuracy=error/R
3 Comments
Walter Roberson
on 6 Mar 2013
Please indicate portions of it you are having difficulty understanding, and please indicate the kind of modification you are wishing to do.
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!