image thumbnail

Single target Localization

by

 

16 Nov 2011 (Updated )

distance based localization of a single target

SimpleLocalization.m
%% Abstract
% Localization is one the most important task of the future wireless sensor
% networks (WSNs). There are lots of algorithm for localization and tracking of a
% mobile node in the network which can categorized into following groups:
% 1. distance based localization: which assumes that the distances between
%    the nodes of the WSN are measured. 
% 2. angle based localization: which assumes the mobile nodes can measure
%    the angles to the anchor nodes with respect to some origin.
% 3. received signal strenght: In this type, it is assumed that the mobile 
%    can only measure the signal power from the base stations at its
%    location
% 4. Hybrid
%
% Here, we consider only the distance based localization of a single
% target. There are N anchor nodes in the system and one mobile node, we
% use the measured distances and we find the location of the mobile through
% multilateration. 

%% Setting Parameters
    N = 4;  % number of anchors
    M = 1;  % number of mobile nodes
    
    noisePow = 20;  % it means that the accuracy of distance measurement is 90 %
                    % for instance the inaccuracy of a 1m measured distance
                    % is around .1 meter.

    networkSize = 100;  % we consider a 100by100 area that the mobile can wander
    
    anchorLoc   = [0                     0; % set the anchor at 4 vertices of the region
                   networkSize           0;
                   0           networkSize;
                   networkSize networkSize];

    % building a random location for the mobile node
    mobileLoc  = networkSize*rand(M,2);
    
    % Computing the Euclidian distances    
        % very fast computation :)
        % distance   = sqrt(sum( (anchorLoc - repmat(mobileLoc,N,1)).^2 , 2));
        
        % easy to understand computation
        distance = zeros(N,1);
        for n = 1 : N
                distance(n) = sqrt( (anchorLoc(n,1)-mobileLoc(m,1)).^2 + ...
                                            (anchorLoc(n,2)-mobileLoc(m,2)).^2  );
        end
    % Plot the scenario
    f1 = figure(1);
    clf
    plot(anchorLoc(:,1),anchorLoc(:,2),'ko','MarkerSize',12,'lineWidth',2);
    grid on
    hold on
    plot(mobileLoc(:,1),mobileLoc(:,2),'b+','MarkerSize',12,'lineWidth',2);
    
    % noisy measurements
    distanceNoisy = distance + distance.*noisePow./100.*(rand(N,1)-1/2);
    
    % using gussian newton to solve the problem
    % (http://en.wikipedia.org/wiki/Gauss%E2%80%93Newton_algorithm)
    
    numOfIteration = 5;
    
    % Initial guess (random locatio)
    mobileLocEst = networkSize*rand(1,2);
    % repeatation
    for i = 1 : numOfIteration
        % computing the esimated distances
        distanceEst   = sqrt(sum( (anchorLoc - repmat(mobileLocEst,N,1)).^2 , 2));
        % computing the derivatives
            % d0 = sqrt( (x-x0)^2 + (y-y0)^2 )
            % derivatives -> d(d0)/dx = (x-x0)/d0
            % derivatives -> d(d0)/dy = (y-y0)/d0
        distanceDrv   = [(mobileLocEst(1)-anchorLoc(:,1))./distanceEst ... % x-coordinate
                         (mobileLocEst(2)-anchorLoc(:,2))./distanceEst];   % y-coordinate
        % delta 
        delta = - (distanceDrv.'*distanceDrv)^-1*distanceDrv.' * (distanceEst - distanceNoisy);
        % Updating the estimation
        mobileLocEst = mobileLocEst + delta.';
    end
    
    plot(mobileLocEst(:,1),mobileLocEst(:,2),'ro','MarkerSize',12,'lineWidth',2);
    legend('Anchor locations','Mobile true location','Mobile estimated location',...
           'Location','Best')
    
    % Compute the Root Mean Squred Error
    Err = sqrt(sum((mobileLocEst-mobileLoc).^2));
    title(['Estimation error is ',num2str(Err),'meter'])

Contact us