multilateration 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in multilateration.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Arron Mabrey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Multilateration
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'multilateration'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install multilateration
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ require "matrix"
2
+ require "forwardable"
3
+
4
+ require "multilateration/version"
5
+ require "multilateration/solver"
6
+ require "multilateration/emitter"
7
+ require "multilateration/receiver"
8
+ require "multilateration/time_of_arrival_strategies/source_vector_distance"
9
+
10
+ module Multilateration
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,4 @@
1
+ module Multilateration
2
+ class Emitter
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Multilateration
2
+ class Receiver
3
+ end
4
+ end
@@ -0,0 +1,70 @@
1
+ module Multilateration
2
+ class Solver
3
+ attr_reader :receivers, :wave_speed, :time_of_arrival_strategy
4
+ private :receivers, :wave_speed, :time_of_arrival_strategy
5
+
6
+ def initialize(unsorted_receivers, time_of_arrival_strategy)
7
+ @receivers = unsorted_receivers.sort_by { |r| time_of_arrival_strategy.toa(r) }
8
+ @wave_speed = time_of_arrival_strategy.wave_speed
9
+ @time_of_arrival_strategy = time_of_arrival_strategy
10
+ end
11
+
12
+ def solved_vector
13
+ Vector.elements (ai_matrix * bi_matrix).flat_map.to_a
14
+ end
15
+
16
+ private
17
+
18
+ def ai_matrix
19
+ Matrix.rows(middle_receivers.map { |i| ai(i) }).inverse
20
+ end
21
+
22
+ def bi_matrix
23
+ Matrix.columns([middle_receivers.map { |i| bi(i) }])
24
+ end
25
+
26
+ def ai(i)
27
+ 2*( ( distance(tdoa_between_receivers_first_and_last) * ( i - first_receiver )) \
28
+ - ( distance(tdoa_between_receivers_first_and(i)) * ( last_receiver - first_receiver )) )
29
+ end
30
+
31
+ def bi(i)
32
+ ( distance(tdoa_between_receivers_first_and(i)) * ( distance_sq(tdoa_between_receivers_first_and_last) - inner_product_sq(last_receiver) )) \
33
+ + ( inner_product_sq(first_receiver) * ( distance(tdoa_between_receivers_first_and(i)) - distance(tdoa_between_receivers_first_and_last) )) \
34
+ + ( distance(tdoa_between_receivers_first_and_last) * ( inner_product_sq(i) - distance_sq(tdoa_between_receivers_first_and(i)) ))
35
+ end
36
+
37
+ def middle_receivers
38
+ receivers - [first_receiver, last_receiver]
39
+ end
40
+
41
+ def first_receiver
42
+ receivers.first
43
+ end
44
+
45
+ def last_receiver
46
+ receivers.last
47
+ end
48
+
49
+ def tdoa_between_receivers_first_and_last
50
+ tdoa_between_receivers_first_and(last_receiver)
51
+ end
52
+
53
+ def tdoa_between_receivers_first_and(other_receiver)
54
+ time_of_arrival_strategy.tdoa(other_receiver, first_receiver)
55
+ end
56
+
57
+ def distance(time, exp=1)
58
+ (wave_speed**exp) * (time**exp)
59
+ end
60
+
61
+ def distance_sq(time)
62
+ distance(time, 2)
63
+ end
64
+
65
+ def inner_product_sq(vector)
66
+ vector.inner_product(vector)
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,27 @@
1
+ module Multilateration
2
+ module TimeOfArrivalStrategies
3
+ class SourceVectorDistance
4
+ attr_reader :source_vector, :wave_speed
5
+ private :source_vector
6
+
7
+ def initialize(source_vector, wave_speed=1)
8
+ @source_vector = source_vector
9
+ @wave_speed = wave_speed
10
+ end
11
+
12
+ def tdoa(vector_a, vector_b)
13
+ toa(vector_a) - toa(vector_b)
14
+ end
15
+
16
+ def toa(target_vector)
17
+ distance_between_source_vector_and(target_vector) / wave_speed
18
+ end
19
+
20
+ private
21
+
22
+ def distance_between_source_vector_and(target_vector)
23
+ Math.sqrt((target_vector - source_vector).map { |component| component.abs**2 }.reduce(&:+))
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Multilateration
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'multilateration/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "multilateration"
8
+ spec.version = Multilateration::VERSION
9
+ spec.authors = ["Arron Mabrey"]
10
+ spec.email = ["arron@mabreys.com"]
11
+ spec.description = %q{Solves for the location of an unknown signal emitter by using the signal TDOA between multiple signal receivers with known locations.}
12
+ spec.summary = %q{Solves for the location of an unknown signal emitter by using the signal TDOA between multiple signal receivers with known locations.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Multilateration::Emitter do
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Multilateration::Receiver do
4
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Multilateration::Solver do
4
+ describe "#solved_vector" do
5
+ let(:source_vector) { Vector[-20,5,120.2] }
6
+ let(:reciver_vector_0) { Vector[0,25,1] }
7
+ let(:reciver_vector_1) { Vector[50,20.34,2] }
8
+ let(:reciver_vector_2) { Vector[50,50,33] }
9
+ let(:reciver_vector_3) { Vector[23,75,4] }
10
+ let(:reciver_vector_4) { Vector[100,-100,-5.5] }
11
+ let(:time_of_arrival_strategy) { Multilateration::TimeOfArrivalStrategies::SourceVectorDistance.new(source_vector) }
12
+ let(:recivers) { [reciver_vector_0, reciver_vector_1, reciver_vector_2, reciver_vector_3, reciver_vector_4] }
13
+
14
+ subject(:solved_vector) { described_class.new(recivers, time_of_arrival_strategy).solved_vector }
15
+
16
+ specify { expect( solved_vector.magnitude ).to be_within(0.0000000000001).of(source_vector.magnitude) }
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Multilateration::TimeOfArrivalStrategies::SourceVectorDistance do
4
+ end
@@ -0,0 +1,19 @@
1
+ require 'multilateration'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multilateration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Arron Mabrey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Solves for the location of an unknown signal emitter by using the signal
63
+ TDOA between multiple signal receivers with known locations.
64
+ email:
65
+ - arron@mabreys.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/multilateration.rb
77
+ - lib/multilateration/emitter.rb
78
+ - lib/multilateration/receiver.rb
79
+ - lib/multilateration/solver.rb
80
+ - lib/multilateration/time_of_arrival_strategies/source_vector_distance.rb
81
+ - lib/multilateration/version.rb
82
+ - multilateration.gemspec
83
+ - spec/multilateration/emitter_spec.rb
84
+ - spec/multilateration/receiver_spec.rb
85
+ - spec/multilateration/solver_spec.rb
86
+ - spec/multilateration/time_of_arrival_strategies/source_vector_distance_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.23
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Solves for the location of an unknown signal emitter by using the signal
113
+ TDOA between multiple signal receivers with known locations.
114
+ test_files:
115
+ - spec/multilateration/emitter_spec.rb
116
+ - spec/multilateration/receiver_spec.rb
117
+ - spec/multilateration/solver_spec.rb
118
+ - spec/multilateration/time_of_arrival_strategies/source_vector_distance_spec.rb
119
+ - spec/spec_helper.rb