├── .gitignore ├── LICENSE ├── README.md └── main.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | __pycache__ 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .coverage 27 | .tox 28 | nosetests.xml 29 | 30 | # Translations 31 | *.mo 32 | 33 | # Mr Developer 34 | .mr.developer.cfg 35 | .project 36 | .pydevproject 37 | 38 | octave-workspace 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Paul Hayes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Multilateration Example 2 | ====================== 3 | 4 | Python rewrite of multilateration technique by André Andersen in his [blog post](http://blog.andersen.im/2012/07/signal-emitter-positioning-using-multilateration). -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | ########################### 2 | # 3 | # Python rewrite of multilateration technique by André Andersen in his [blog post](http://blog.andersen.im/2012/07/signal-emitter-positioning-using-multilateration). 4 | # 5 | ############################ 6 | 7 | from numpy import * 8 | from numpy.linalg import * 9 | import json 10 | #speed of sound in medium 11 | v = 3450 12 | numOfDimensions = 3 13 | nSensors = 5 14 | region = 3 15 | sensorRegion = 2 16 | 17 | #choose a random sensor location 18 | emitterLocation = region * ( random.random_sample(numOfDimensions) - 0.5 ) 19 | sensorLocations = [ sensorRegion * ( random.random_sample(numOfDimensions)-0.5 ) for n in range(nSensors) ] 20 | p = matrix( sensorLocations ).T 21 | 22 | #Time from emitter to each sensor 23 | sensorTimes = [ sqrt( dot(location-emitterLocation,location-emitterLocation) ) / v for location in sensorLocations ] 24 | 25 | c = argmin(sensorTimes) 26 | cTime = sensorTimes[c] 27 | 28 | #sensors delta time relative to sensor c 29 | t = sensorDeltaTimes = [ sensorTime - cTime for sensorTime in sensorTimes ] 30 | 31 | ijs = range(nSensors) 32 | del ijs[c] 33 | 34 | A = zeros([nSensors-1,numOfDimensions]) 35 | b = zeros([nSensors-1,1]) 36 | iRow = 0 37 | rankA = 0 38 | 39 | for i in ijs: 40 | for j in ijs: 41 | A[iRow,:] = 2*( v*(t[j])*(p[:,i]-p[:,c]).T - v*(t[i])*(p[:,j]-p[:,c]).T ) 42 | b[iRow] = v*(t[i])*(v*v*(t[j])**2-p[:,j].T*p[:,j]) + \ 43 | (v*(t[i])-v*(t[j]))*p[:,c].T*p[:,c] + \ 44 | v*(t[j])*(p[:,i].T*p[:,i]-v*v*(t[i])**2) 45 | rankA = matrix_rank(A) 46 | if rankA >= numOfDimensions : 47 | break 48 | iRow += 1 49 | if rankA >= numOfDimensions: 50 | break 51 | 52 | calculatedLocation = asarray( lstsq(A,b)[0] )[:,0] 53 | 54 | print "Emitter location: %s " % emitterLocation 55 | print "Calculated position of emitter: %s " % calculatedLocation 56 | --------------------------------------------------------------------------------