module SignalTools
Public Class Methods
average(array)
click to toggle source
# File lib/signal_tools.rb, line 16 def self.average(array) return nil if !array || array.size == 0 sum(array).to_f / array.size end
sum(array)
click to toggle source
# File lib/signal_tools.rb, line 12 def self.sum(array) array.inject(0) {|accum, c| accum + c.to_f } end
truncate_to_shortest!(*arrays)
click to toggle source
Truncates all arrays to the size of the shortest array by cutting off the front of the longer arrays.
# File lib/signal_tools.rb, line 23 def self.truncate_to_shortest!(*arrays) shortest_size = arrays.inject(arrays.first.size) { |size, array| array.size < size ? array.size : size } arrays.each { |array| array.slice!(0...(array.size - shortest_size)) } end