Class: SPCore::CombFilter
- Inherits:
-
Object
- Object
- SPCore::CombFilter
- Includes:
- Hashmake::HashMakeable
- Defined in:
- lib/spcore/generation/comb_filter.rb
Constant Summary collapse
- FEED_FORWARD =
:feedForward
- FEED_BACK =
:feedBack
- TYPES =
[ FEED_FORWARD, FEED_BACK ]
- ARG_SPECS =
{ :type => arg_spec(:reqd => true, :type => Symbol, :validator => ->(a){ TYPES.include?(a)}), :frequency => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){ a > 0}), :alpha => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a.between?(0.0,1.0) }) }
Instance Attribute Summary collapse
-
#alpha ⇒ Object
Returns the value of attribute alpha.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #frequency_response(sample_rate, sample_count) ⇒ Object
- #frequency_response_at(x) ⇒ Object
-
#initialize(args) ⇒ CombFilter
constructor
A new instance of CombFilter.
Constructor Details
#initialize(args) ⇒ CombFilter
Returns a new instance of CombFilter.
18 19 20 21 |
# File 'lib/spcore/generation/comb_filter.rb', line 18 def initialize args hash_make args, CombFilter::ARG_SPECS calculate_params end |
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
16 17 18 |
# File 'lib/spcore/generation/comb_filter.rb', line 16 def alpha @alpha end |
#frequency ⇒ Object
Returns the value of attribute frequency.
16 17 18 |
# File 'lib/spcore/generation/comb_filter.rb', line 16 def frequency @frequency end |
#type ⇒ Object
Returns the value of attribute type.
16 17 18 |
# File 'lib/spcore/generation/comb_filter.rb', line 16 def type @type end |
Instance Method Details
#frequency_response(sample_rate, sample_count) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# 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) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# 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 |