class SPCore::CombFilter
Constants
- ARG_SPECS
- FEED_BACK
- FEED_FORWARD
- TYPES
Attributes
alpha[R]
frequency[R]
type[R]
Public Class Methods
new(args)
click to toggle source
# File lib/spcore/generation/comb_filter.rb, line 18 def initialize args hash_make args, CombFilter::ARG_SPECS calculate_params end
Public Instance Methods
alpha=(alpha)
click to toggle source
# File lib/spcore/generation/comb_filter.rb, line 34 def alpha= alpha ARG_SPECS[:alpha].validate_value alpha @alpha = alpha end
frequency=(frequency)
click to toggle source
# File lib/spcore/generation/comb_filter.rb, line 28 def frequency= frequency ARG_SPECS[:frequency].validate_value frequency @frequency = frequency calculate_params end
frequency_response(sample_rate, sample_count)
click to toggle source
# File lib/spcore/generation/comb_filter.rb, line 49 def frequency_response sample_rate, sample_count output = [] sample_period = 1.0 / sample_rate sample_count.times do |n| x = sample_period * n output.push frequency_response_at(x) end return output end
frequency_response_at(x)
click to toggle source
# File lib/spcore/generation/comb_filter.rb, line 39 def frequency_response_at x output = 0 if @type == FEED_FORWARD output = Math.sqrt((1.0 + @alpha**2) + 2.0 * @alpha * Math.cos(@k * x)) elsif @type == FEED_BACK output = 1.0 / Math.sqrt((1.0 + alpha**2) - 2.0 * @alpha * Math.cos(@k * x)) end return output end
type=(type)
click to toggle source
# File lib/spcore/generation/comb_filter.rb, line 23 def type= type ARG_SPECS[:type].validate_value type @type = type end
Private Instance Methods
calculate_params()
click to toggle source
# File lib/spcore/generation/comb_filter.rb, line 61 def calculate_params @k = (Math::PI * 2) * @frequency end