View Single Post
Old 11-07-07, 06:51 PM   #7
Dr.Sid
The Old Man
 
Join Date: May 2005
Location: Czech Republic
Posts: 1,458
Downloads: 6
Uploads: 0
Default

Bah .. I implemented it .. and there is some error in it I can't find. Well I found many of the errors .. but not.

Just for your info:

Inputs is array of LOBs:
Px,Py - position of listener at the time of observation
Sx,Sy - vector of sight - in my implementation I assume it's length is 1 - this represents the bearing
t - time of observation - in my implementation I use t=0 for the first LOB

if you have 5 lobs, you have 5 these. 5 positons, 5 vectors, 5 times.

I'm looking for these variables:
Ax,Ay - position of the contact at t=0
Vx,Vy - vector of speed of the contact, length is speed

Now my actual formulas look like this:

We must solve this matrix, column represents Ax,Ay,Vx,Vy

+sy.sy -sy.sx +t.sy.sy -t.sy.sx +px.sy.sy-py.sx.sy
-sy.sx +sx.sx -t.sx.sy +t.sx.sx +py.sx.sx-px.sx.sy
+t.sy.sy -t.sx.sy +t.t.sy.sy -t.t.sy.sx +px.t.sy.sy-py.t.sx.sy
-t.sy.sx +t.sx.sx -t.t.sy.sx +t.t.sx.sx +py.t.sx.sx-px.t.sx.sy

All elements must be summed for all the LOBs first, then the matrix is solved. But as I said, there is mistake somewhere.

I used the method like this:

First there is formula for distance of point (B) from line (A+V.u)
dist=(ax.vy-ay.vx-bx.vy+by.vx)/(vx.vx+vy.vy)
The part (vx.vx+vy.vy) is 1 in my case (LOBs vector's length =1 ) so I can omit it.

Now I need to specify the 'wrongness' of my theoretical solution. That is here (using variable names mention on top):

delta = px.sy-py.sx-(ax+vx.t).sy+(ay+vy.t).sx

this is error for particular LOB.

Now I need to sum squares of these errors for each LOB, and look for minimum such sum. That is the trick in the least square method.
The error square looks pretty nasty.

+2.ax.py.sx.sy+2.ax.vx.t.sy.sy+2.ay.px.sx.sy+2.ay. vy.t.sx.sx-2.ay.vx.t.sx.sy+2.vx.t.py.sx.sy+2.vy.t.px.sx.sy
-2.ax.ay.sx.sy-2.ax.px.sy.sy-2.ax.vy.t.sx.sy-2.ay.py.sx.sx-2.px.py.sx.sy-2.vx.t.px.sy.sy-2.vy.t.py.sx.sx
-2.vx.vy.t.t.sx.sy+px.px.sy.sy+py.py.sx.sx+ax.ax.sy .sy+ay.ay.sx.sx+vx.vx.t.t.sy.sy+vy.vy.t.t.sx.sx

But I really went thru this part like 10 times and I think it is correct now.

Then you derivate this by each of variables you are interested in. ax,ay,vx,vy in our case. Why we do the derivation ? We look for minimal error, that's where derivation of the error is equal 0. If we have the derivations, we must solve when they are zero and that is our solution.

Derivates looks like this:

ax:
+2.py.sx.sy
+2.vx.t.sy.sy
-2.ay.sx.sy
-2.px.sy.sy
-2.vy.t.sx.sy
+2.ax.sy.sy

ay:
+2.px.sx.sy
+2.vy.t.sx.sx
-2.vx.t.sx.sy
-2.ax.sx.sy
-2.py.sx.sx
+2.ay.sx.sx

vx:
+2.ax.t.sy.sy
-2.ay.t.sx.sy
+2.t.py.sx.sy
-2.t.px.sy.sy
-2.vy.t.t.sx.sy
+2.vx.t.t.sy.sy

vy:
-2.ax.t.sx.sy
+2.ay.t.sx.sx
+2.t.px.sx.sy
-2.t.py.sx.sx
-2.vx.t.t.sx.sy
+2.vy.t.t.sx.sx

And then you simply put these into the matrix, solve it and that's all. I'm almost sure I have not missed any sign anywhere. I feel like I forget to make some step or something. So I need help from somebody who used least square method to solve problems. Somebody who understands what I'm talking about. If you don't, don't worry, one can easily live without it, but I'm afraid you can't help me.

I have this programmed and it almost works .. in same rare cases it even gives correct data. I'm quite sure I don't have it ALL wrong.

Last edited by Dr.Sid; 11-07-07 at 07:11 PM.
Dr.Sid is offline