Class: Cowboy::Hamming
- Inherits:
-
Object
- Object
- Cowboy::Hamming
- Defined in:
- lib/cowboy/hamming.rb
Instance Method Summary collapse
- #convolve(arr) ⇒ Object
-
#initialize(n) ⇒ Hamming
constructor
A new instance of Hamming.
Constructor Details
#initialize(n) ⇒ Hamming
Returns a new instance of Hamming.
2 3 4 5 |
# File 'lib/cowboy/hamming.rb', line 2 def initialize(n) @n = n create_kernel end |
Instance Method Details
#convolve(arr) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cowboy/hamming.rb', line 7 def convolve(arr) raise "Array smaller than window size" if arr.size < @n a = [] for i in (0...(arr.size - (@n - 1))) n = 0.0 for j in (0...@n) c = @kernel[j] * arr[i+j] n += c end a << n end return a end |