Class: Cowboy::Frequencies
- Inherits:
-
Object
- Object
- Cowboy::Frequencies
- Defined in:
- lib/cowboy/fft.rb
Instance Attribute Summary collapse
-
#dc ⇒ Object
readonly
Returns the value of attribute dc.
-
#freq ⇒ Object
readonly
Returns the value of attribute freq.
-
#unshifted ⇒ Object
readonly
Returns the value of attribute unshifted.
Instance Method Summary collapse
- #buckets(sample_rate = nil) ⇒ Object
-
#initialize(unshifted_array) ⇒ Frequencies
constructor
A new instance of Frequencies.
Constructor Details
#initialize(unshifted_array) ⇒ Frequencies
Returns a new instance of Frequencies.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/cowboy/fft.rb', line 5 def initialize(unshifted_array) @unshifted = unshifted_array @dc = unshifted_array[0].real n = unshifted_array.size @freq = [] for i in (n/2...n) @freq << unshifted_array[i].abs end for i in (0...n/2) @freq << unshifted_array[i].abs end end |
Instance Attribute Details
#dc ⇒ Object (readonly)
Returns the value of attribute dc.
3 4 5 |
# File 'lib/cowboy/fft.rb', line 3 def dc @dc end |
#freq ⇒ Object (readonly)
Returns the value of attribute freq.
3 4 5 |
# File 'lib/cowboy/fft.rb', line 3 def freq @freq end |
#unshifted ⇒ Object (readonly)
Returns the value of attribute unshifted.
3 4 5 |
# File 'lib/cowboy/fft.rb', line 3 def unshifted @unshifted end |
Instance Method Details
#buckets(sample_rate = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cowboy/fft.rb', line 18 def buckets(sample_rate=nil) return @buckets if @buckets sample_rate ||= @freq.size nyquist = sample_rate/2.0 sum = 0 a = [] n = @freq.size for i in (0...n) a << -nyquist + sum sum += (2 * nyquist/n) end @buckets = a return a end |