class SPCore::TukeyWindow
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 en.wikipedia.org/wiki/Window_function#Tukey_window.
Attributes
data[R]
Public Class Methods
new(size, alpha = 0.5)
click to toggle source
# File lib/spcore/windows/tukey_window.rb, line 9 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