spectrum-analyzer 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +3 -1
- data/VERSION +1 -1
- data/lib/spectrum-analyzer/clients/generator.rb +7 -31
- data/lib/spectrum-analyzer/clients/window_functions.rb +19 -0
- data/lib/spectrum-analyzer/criteria/domain.rb +4 -3
- data/spectrum-analyzer.gemspec +3 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGE0ZWFkNjFhMmQ3NmRkZmU4ODRlOGUwNmZlMDIwNzVkYjRlZmEwZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWIxZTdmZmVhOGM1Yzg2OGE3OTAwNGQyMDAxNTc4MWJjYWY3YjEyMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Yzc4ODFlZDU5YzM3MTg3NzliMzc4MzQ0NzUxYTM5MDRiYTBhMGZkZDlmNDI0
|
10
|
+
YWJiZmE4NDhhN2MxYjRlNmExZDRmNmIwYTY1NTZhMzdhNzY3NGQzYzE0MjI5
|
11
|
+
M2VlNWM3ZGI3MzYxMjgxYTA4NjA1ZjAyOGMyN2E2YjcyNDIyNzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmNkNzViYmNiMTk4YmQ1MmIxYTcyNDQ5NjViMzhlN2Y0MmEwMGIwOGQzYjYy
|
14
|
+
MjdmZWM4NWI0NzNlMDYxZTJkMjFmMjY0YTY3ODM5YTFiYjZjOGE5MGQzMjlk
|
15
|
+
NjYwNGJkOTFkNGQyMDA3OWZiNDYzZjNlNDEzMGJjYWZmZmIxY2M=
|
data/README.md
CHANGED
@@ -28,7 +28,9 @@ You now have a bunch of "domains" held in the spectrum (SpectrumAnalyzer.spectru
|
|
28
28
|
s = SpectrumAnalyzer.spectrum
|
29
29
|
s.domains
|
30
30
|
```
|
31
|
-
These domains are an array of frequencies that occur over the time slice defined by the window_size. The values are currently complex numbers,
|
31
|
+
These domains are an array of frequencies that occur over the time slice defined by the window_size. The values are currently magnitudes of the complex numbers, and represent the amplitude of each frequency range.
|
32
|
+
|
33
|
+
Want them to be available as both complex and magnitudes? Let me know, or submit a pull request!
|
32
34
|
|
33
35
|
More to come.
|
34
36
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
@@ -4,6 +4,7 @@ module SpectrumAnalyzer
|
|
4
4
|
@config = SpectrumAnalyzer.configuration
|
5
5
|
@file = build_file_info
|
6
6
|
@spectrum = SpectrumAnalyzer.spectrum
|
7
|
+
@window_functions = SpectrumAnalyzer::WindowFunctions.new(@config.window_size)
|
7
8
|
end
|
8
9
|
|
9
10
|
def set_file(file)
|
@@ -26,25 +27,12 @@ module SpectrumAnalyzer
|
|
26
27
|
|
27
28
|
|
28
29
|
def generate_spectrum
|
29
|
-
#For each FFT window built
|
30
|
-
#add FFT window to spectrum class
|
31
30
|
begin
|
32
31
|
buffer = RubyAudio::Buffer.float(@config.window_size)
|
33
32
|
RubyAudio::Sound.open(@config.file_name) do |snd|
|
34
33
|
while snd.read(buffer) != 0
|
35
|
-
|
36
|
-
@spectrum.domains.push (
|
37
|
-
#i=0
|
38
|
-
#fft_slice.each { |x| spectrum[i] += x.magnitude; i+=1}
|
39
|
-
#
|
40
|
-
#spectrum_array[iterations] = fft_slice
|
41
|
-
#i = 0
|
42
|
-
#spectrum_array[iterations].each { |x| spectrum_array[iterations][i] = x.magnitude; i+=1}
|
43
|
-
#iterations += 1
|
44
|
-
#
|
45
|
-
#ping = analyze_for_hit(fft_slice, iterations - 1)
|
46
|
-
#return ping if ping
|
47
|
-
#hits += 1 if ping
|
34
|
+
domain = generate_domain(buffer)
|
35
|
+
@spectrum.domains.push (domain)
|
48
36
|
end
|
49
37
|
end
|
50
38
|
|
@@ -58,8 +46,8 @@ module SpectrumAnalyzer
|
|
58
46
|
windowed_array = apply_window(buffer.to_a, windows[@config.window_function])
|
59
47
|
na = NArray.to_na(windowed_array)
|
60
48
|
fft_array = FFTW3.fft(na).to_a[0, @config.window_size/2]
|
61
|
-
domain =
|
62
|
-
fft_array.each { |x| domain.push(x.magnitude)}
|
49
|
+
domain = SpectrumAnalyzer::Domain.new()
|
50
|
+
fft_array.each { |x| domain.raw_values.push(x); domain.values.push(x.magnitude)}
|
63
51
|
domain
|
64
52
|
end
|
65
53
|
|
@@ -79,8 +67,8 @@ module SpectrumAnalyzer
|
|
79
67
|
|
80
68
|
def windows
|
81
69
|
{
|
82
|
-
:hanning => hanning(
|
83
|
-
:rectangle => rectangle(
|
70
|
+
:hanning => @window_functions.hanning(),
|
71
|
+
:rectangle => @window_functions.rectangle()
|
84
72
|
}
|
85
73
|
end
|
86
74
|
|
@@ -99,18 +87,6 @@ module SpectrumAnalyzer
|
|
99
87
|
buffer.each { |x| windowed_array[i] = x * window_type[i]; i+=1}
|
100
88
|
end
|
101
89
|
|
102
|
-
def hanning (window_size)
|
103
|
-
hannified_array = Array.new
|
104
|
-
i=0
|
105
|
-
(0..window_size).each { |x| hannified_array[i] = 0.5 - 0.5 * Math.cos(2 * Math::PI * i / window_size) ; i+=1}
|
106
|
-
|
107
|
-
hannified_array
|
108
|
-
end
|
109
|
-
|
110
|
-
def rectangle (window_size)
|
111
|
-
Array.new(window_size, 1)
|
112
|
-
end
|
113
|
-
|
114
90
|
def analysis_array
|
115
91
|
@config.analysis_array
|
116
92
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SpectrumAnalyzer
|
2
|
+
class WindowFunctions
|
3
|
+
def initialize(window_size)
|
4
|
+
@window_size = window_size
|
5
|
+
end
|
6
|
+
def hanning
|
7
|
+
hannified_array = Array.new
|
8
|
+
i=0
|
9
|
+
(0..@window_size).each { |x| hannified_array[i] = 0.5 - 0.5 * Math.cos(2 * Math::PI * i / @window_size) ; i+=1}
|
10
|
+
|
11
|
+
hannified_array
|
12
|
+
end
|
13
|
+
|
14
|
+
def rectangle
|
15
|
+
Array.new(@window_size, 1)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module SpectrumAnalyzer
|
2
2
|
class Domain
|
3
|
-
attr_accessor :values, :contains_frequency_range
|
3
|
+
attr_accessor :values, :raw_values, :contains_frequency_range
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@values =
|
5
|
+
def initialize()
|
6
|
+
@values = []
|
7
|
+
@raw_values = []
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
data/spectrum-analyzer.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: spectrum-analyzer 0.1.
|
5
|
+
# stub: spectrum-analyzer 0.1.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "spectrum-analyzer"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Justin Roberts"]
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/spectrum-analyzer.rb",
|
30
30
|
"lib/spectrum-analyzer/clients/analyze.rb",
|
31
31
|
"lib/spectrum-analyzer/clients/generator.rb",
|
32
|
+
"lib/spectrum-analyzer/clients/window_functions.rb",
|
32
33
|
"lib/spectrum-analyzer/config.rb",
|
33
34
|
"lib/spectrum-analyzer/criteria/domain.rb",
|
34
35
|
"lib/spectrum-analyzer/criteria/file.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectrum-analyzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Roberts
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/spectrum-analyzer.rb
|
128
128
|
- lib/spectrum-analyzer/clients/analyze.rb
|
129
129
|
- lib/spectrum-analyzer/clients/generator.rb
|
130
|
+
- lib/spectrum-analyzer/clients/window_functions.rb
|
130
131
|
- lib/spectrum-analyzer/config.rb
|
131
132
|
- lib/spectrum-analyzer/criteria/domain.rb
|
132
133
|
- lib/spectrum-analyzer/criteria/file.rb
|