function [SourceLocation] = TDOALoc(SensorPositions, r, Q),
% SensorPositons: (Dim x M) matrix, each column is a sensor position and
% first column is the reference sensor
% the sensors should not lie in one plane or line
% r: a (M-1) x 1 vector of TDOA measurements times signal propagation speed
% M is the number of sensors and should be at least Dim+2
% Q: the covariance matrix of the r vector
% SourceLocation: estimated source location
%
% Note: W1 is updated 3 times (RptCnt=3) in Stage-1, however in most
% cases updating W1 once (RptCnt=1) is sufficient.
%
% The program can be used for 2D(Dim=2) or 3D(Dim=3) localization
%
%
% Ming Sun, K. C. Ho 08-01-2009
% 10-01-2010, revised
%
% Copyright (C) 2009
% Computational Intelligence Signal Processing Laboratory
% University of Missouri
% Columbia, MO 65211, USA.
% hod@missouri.edu
%
RptCnt = 3; % number of repetitions in Stage-1 to recompute W1
M = length(r) + 1;
if (M