Sha256: db667c28f150a4f2cac3bac8f7305bfee527e9f00d078c1845f4fb65cb335f91
Contents?: true
Size: 1009 Bytes
Versions: 3
Compression:
Stored size: 1009 Bytes
Contents
module SPCore # Produces a Tukey window of a given size (number of samples). # The Tukey window, also known as tapered cosine, can be regarded as a cosine # lobe of width alpha * N / 2 that is convolved with a rectangular window. At # alpha = 0 it becomes rectangular, and at alpha = 1 it becomes a Hann window. # For more info, see https://en.wikipedia.org/wiki/Window_function#Tukey_window. class TukeyWindow attr_reader :data def initialize size, alpha = 0.5 @data = Array.new(size) left = (alpha * (size - 1) / 2.0).to_i right = ((size - 1) * (1.0 - (alpha / 2.0))).to_i size_min_1 = size - 1 for n in 0...left x = Math::PI * (((2.0 * n) / (alpha * size_min_1)) - 1.0) @data[n] = 0.5 * (1.0 + Math::cos(x)) end for n in left..right @data[n] = 1.0 end for n in (right + 1)...size x = Math::PI * (((2 * n) / (alpha * size_min_1)) - (2.0 / alpha) + 1.0) @data[n] = 0.5 * (1.0 + Math::cos(x)) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
spcore-0.2.1 | lib/spcore/windows/tukey_window.rb |
spcore-0.2.0 | lib/spcore/windows/tukey_window.rb |
spcore-0.1.9 | lib/spcore/windows/tukey_window.rb |