Path: news.mathworks.com!not-for-mail
From: "Miroslav Balda" <miroslav.nospam@balda.cz>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Solving equations
Date: Wed, 20 Aug 2008 20:49:01 +0000 (UTC)
Organization: Miroslav Balda
Lines: 125
Message-ID: <g8hvvt$r50$1@fred.mathworks.com>
References: <g8bugl$e7c$1@fred.mathworks.com> <g8dp5i$509$1@fred.mathworks.com> <g8hni0$klf$1@fred.mathworks.com>
Reply-To: "Miroslav Balda" <miroslav.nospam@balda.cz>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1219265341 27808 172.30.248.35 (20 Aug 2008 20:49:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 20 Aug 2008 20:49:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 360709
Xref: news.mathworks.com comp.soft-sys.matlab:486565



"Mazahir " <maz_p5@hotmail.com> wrote in message
<g8hni0$klf$1@fred.mathworks.com>...
:
SNIP
:
> Hi Mira,
> 
> Sorry but I could not understand your solution well. I know
> that solving by least square method might be the best option
> but can you please describe the solution and the variables
> used like d,a,b,z, res, etc.. dxy is the approx. distance
> from corners, but distance of what? Also are the values
> randomly taken by you?
> 
> 
> Also below I am explaining you the problem again in detail,
> so that you can get a clear picture.
> 
> I have to find the location of a sound source on a 2d plane.
> (I am not considering z axis). I have 4 mics the
> co-ordinates of which are m1(0,0), m2(0,6), m3(4,6), m4(4,0). 
> del12 is the difference between the distance from mic 1 to
> the source and from mic 2 to the source. 
> del12=((time taken to reach 1st mic-time taken to reach 2nd
> mic) x v sound i.e. 340m/s)/fs i.e. 44000. Therefore, for a
> particular set of readings, the calculated del12 = 0.0848.
> Similarly, del13 = 0.9098 and del14 = 0.5937
> 
> Now solving the equations below simultaneously using least
> square method will give me the point. 
> 
> del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)
> del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)
> del14=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x4-x)^2+(y4-y)^2)
> 
> Now this is the exact problem which I cant get hang of. 
> 
> I think 1st solving with just 3 mics and 2 equations will be
> good enough to predict the output before going to the 4th
mic. 
> 
> Also what I know is that such systems can also be solved by
> techniques such as multilateration. If yes, would that be
> easier?
> 
> Please do reply soon.
> 
> Thank you,
> Mazahir 

Hi Mazahir,

Since that you have changed your descriptiom of the problem,
I will not return to the previous example, which was set by
my by random distances, which I chose. The solution of your
problem is as follows:

x  = [0,0,4,4];
y  = [0,6,6,0];
xy = [x;y];
dij = [0.0848,0.99098,0.5937];

del = @(d) sqrt(d'*d);
res = @(z) [del(xy(:,1)-z) - del(xy(:,2)-z) - dij(1)
            del(xy(:,1)-z) - del(xy(:,3)-z) - dij(2)
            del(xy(:,1)-z) - del(xy(:,4)-z) - dij(3)];

[XY,ssq,cnt] = LMFnlsq(res,[2;3],'display',1)

>> test080820
***************************************************************************
  itr  nfJ   SUM(r^2)        x           dx           l    
      lc
***************************************************************************
   0    1  1.3417e+000  2.0000e+000  0.0000e+000           
                                                         
0.0000e+000  1.0000e+000 
                        3.0000e+000  0.0000e+000 
   1    2  2.6097e-002  2.6290e+000 -6.2904e-001 
0.0000e+000  1.0000e+000 
                        3.1136e+000 -1.1355e-001 
   2    3  2.4987e-002  2.6390e+000 -9.9365e-003 
0.0000e+000  1.0000e+000 
                        3.1240e+000 -1.0411e-002 
   3    4  2.4987e-002  2.6392e+000 -1.9470e-004 
0.0000e+000  1.0000e+000 
                        3.1240e+000 -3.6993e-005 
 
   4    5  2.4987e-002  2.6392e+000  6.9462e-007 
0.0000e+000  1.0000e+000 
                        3.1240e+000 -1.9698e-006 
XY =
    2.6392
    3.1240
ssq =
    0.0250
cnt =
     4

* xy  are coordinates of microphones,
* dij are your calculated differences,
* del is the handle of anonymous function for calculation of
yours sqrt((x1-x)^2 + ....),
* res is the handle to anonymous function that declares
residuals (errors of your equations)
* XY are coordinates of the sound source,
* ssq is a sum of squares of residuals,
* cnt number of calls to res and Jacobian matrix.

You see that ssq is only by approx. 10^2 lower then for the
initial guess. It means that yours delijs are inexact.
Better way would be in taking times of wave approach to
microphones. More over having reading from 4 microphones
could set 6 equations -> residuals and by least squares get
much more accurate coordinates of the source.

I think, that it is all what to say to it.
Hope it helps.

Mira

PS: The time shift makes the communication difficult. Now is
almost 23 o'clock at Pilsen (CZ).