spectrum-analyzer 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGE0ZWFkNjFhMmQ3NmRkZmU4ODRlOGUwNmZlMDIwNzVkYjRlZmEwZg==
4
+ NTU2MDRiMjNmMjlmMWFlZWQ5ZjRlNjU5ODFiMDg0NzlhMjVhZTc2NA==
5
5
  data.tar.gz: !binary |-
6
- ZWIxZTdmZmVhOGM1Yzg2OGE3OTAwNGQyMDAxNTc4MWJjYWY3YjEyMA==
6
+ MTE3YzkxY2FkNmNjNTJhMjI5M2M5ZjM4MmU1MTE1Y2ZhMWUyMjY4Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Yzc4ODFlZDU5YzM3MTg3NzliMzc4MzQ0NzUxYTM5MDRiYTBhMGZkZDlmNDI0
10
- YWJiZmE4NDhhN2MxYjRlNmExZDRmNmIwYTY1NTZhMzdhNzY3NGQzYzE0MjI5
11
- M2VlNWM3ZGI3MzYxMjgxYTA4NjA1ZjAyOGMyN2E2YjcyNDIyNzU=
9
+ NTU3MGY2NjczZmQwNTAyZDQwYjUwZTI0NTdiYTFiZTVjYzQ5NjA2NWIzOWNm
10
+ ZGQ2OWQ0OTFkODFjOGQxMDQ2YzAyYzQzY2NlZDJlMDhiYTI1OWIzZjAyZjE0
11
+ YzE0NzUwYzE4Y2IyMWI5YzllOWJlZGY3NTBlYjJmNzk1YzQzNGE=
12
12
  data.tar.gz: !binary |-
13
- ZmNkNzViYmNiMTk4YmQ1MmIxYTcyNDQ5NjViMzhlN2Y0MmEwMGIwOGQzYjYy
14
- MjdmZWM4NWI0NzNlMDYxZTJkMjFmMjY0YTY3ODM5YTFiYjZjOGE5MGQzMjlk
15
- NjYwNGJkOTFkNGQyMDA3OWZiNDYzZjNlNDEzMGJjYWZmZmIxY2M=
13
+ ZDE5ZjU5NjBhNjJlYTdkOGY5MDc4YjdlZmQyMGUzNTBhOTMyMGI3MzE2NWYx
14
+ MzljNTY3OTg1YzhhNDcxZmNkNjIyMGQ1MjM5ZDFkZTA1OTgzNzBjYjY1Njlh
15
+ NjY3ZjUwMjBkYjM3ZjI0OGViNzgwYjczNjljZTMzOGQ0MGNkMDk=
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Code Climate](https://codeclimate.com/github/jusroberts/spectrum-analyzer.png)](https://codeclimate.com/github/jusroberts/spectrum-analyzer)
1
+ [![Code Climate](https://codeclimate.com/github/jusroberts/spectrum-analyzer.png)](https://codeclimate.com/github/jusroberts/spectrum-analyzer) [![Gem Version](https://badge.fury.io/rb/spectrum-analyzer.png)](http://badge.fury.io/rb/spectrum-analyzer)
2
2
  # Ruby Sound Spectrum Analyzer
3
3
 
4
4
  Have you ever wanted to break apart a sound file and see what frequencies make it up? Well, you're in luck! This program does JUST THAT!!!!
@@ -28,7 +28,7 @@ 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 magnitudes of the complex numbers, and represent the amplitude of each frequency range.
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 the complex numbers themselves. They represent the amplitude of the frequency ranges.
32
32
 
33
33
  Want them to be available as both complex and magnitudes? Let me know, or submit a pull request!
34
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -42,6 +42,13 @@ module SpectrumAnalyzer
42
42
  end
43
43
  end
44
44
 
45
+ def sum_domains
46
+ @spectrum.entire_spectrum = Array.new(@spectrum.domains[0].values.length, 0)
47
+ @spectrum.domains.each do |domain|
48
+ @spectrum.entire_spectrum.map!.with_index{ |x,i| x + domain.values[i]}
49
+ end
50
+ end
51
+
45
52
  def generate_domain(buffer)
46
53
  windowed_array = apply_window(buffer.to_a, windows[@config.window_function])
47
54
  na = NArray.to_na(windowed_array)
@@ -52,11 +59,31 @@ module SpectrumAnalyzer
52
59
  end
53
60
 
54
61
  def analyze_spectrum
55
- #for each FFT window in spectrum class
56
- #determine if window contains hit
57
- #apply hit bool to that fft object
58
- #sum all FFT windows in spectrum to create overall freq spectrum
59
- #return spectrum class
62
+ sum_domains
63
+ find_occurrences
64
+ end
65
+
66
+ def find_occurrences
67
+ ranges = @config.analysis_ranges
68
+ occurrence_count = 0
69
+ @spectrum.domains.each do |domain|
70
+ ranges.each do |range|
71
+ if find_occurrence(range, domain)
72
+ occurrence_count += 1
73
+ domain.contains_frequency_range = true
74
+ end
75
+ end
76
+ end
77
+ @spectrum.num_occurrences = occurrence_count
78
+ end
79
+
80
+ def find_occurrence (range, domain)
81
+ sum_total = 0
82
+ for i in range[:b_index]..range[:t_index]
83
+ sum_total += domain.values[i] if !domain.nil?
84
+ end
85
+ average = sum_total / (range[:t_index] - range[:b_index])
86
+ average > range[:min] and average < range[:max]
60
87
  end
61
88
 
62
89
  def build_file_info
@@ -1,11 +1,11 @@
1
1
  module SpectrumAnalyzer
2
2
  class Config
3
- attr_accessor :file_name, :window_function, :window_size, :analysis_range
3
+ attr_accessor :file_name, :window_function, :window_size, :analysis_ranges
4
4
 
5
5
  def initialize
6
6
  @window_size = 512
7
7
  @window_function = :hanning
8
- @analysis_array = [{ :b_index => 27, :t_index => 47, :min => 1, :max => 2}, #Low area
8
+ @analysis_ranges = [{ :b_index => 27, :t_index => 47, :min => 1, :max => 2}, #Low area
9
9
  { :b_index => 58, :t_index => 64, :min => 2.5, :max => 6.5}, #High peak
10
10
  { :b_index => 70, :t_index => 74, :min => 2.0, :max => 4.2 }, #Mid peak
11
11
  { :b_index => 82, :t_index => 109, :min => 0.8, :max => 2}] #Low area
@@ -5,6 +5,8 @@ module SpectrumAnalyzer
5
5
  def initialize()
6
6
  @values = []
7
7
  @raw_values = []
8
+ @contains_frequency_range = false
8
9
  end
10
+
9
11
  end
10
12
  end
@@ -1,6 +1,6 @@
1
1
  module SpectrumAnalyzer
2
2
  class Spectrum
3
- attr_accessor :domains, :entire_spectrum
3
+ attr_accessor :domains, :entire_spectrum, :num_occurrences
4
4
 
5
5
  def initialize(spectrum = [])
6
6
  @domains = spectrum
@@ -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.3 ruby lib
5
+ # stub: spectrum-analyzer 0.1.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "spectrum-analyzer"
9
- s.version = "0.1.3"
9
+ s.version = "0.1.4"
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"]
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Roberts