Module: DSP::Autocorrelation
- Defined in:
- lib/dsprb/autocorrelation.rb,
sig/dsprb.rbs
Class Method Summary collapse
Class Method Details
.call(frame, order) ⇒ ::Array[::Float]
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dsprb/autocorrelation.rb', line 8 def call(frame, order) raise ArgumentError, "order must be non-negative, got #{order}" if order.negative? length = frame.length Array.new(order + 1) do |lag| total = 0.0 index = 0 limit = length - lag while index < limit total += frame[index] * frame[index + lag] index += 1 end total end end |