Class: DSP::Fourier::Radix2
- Inherits:
-
Object
- Object
- DSP::Fourier::Radix2
- Defined in:
- lib/dsprb/fourier.rb,
sig/dsprb.rbs
Instance Attribute Summary collapse
-
#size ⇒ ::Integer
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #call(real, imaginary) ⇒ [::Array[::Float], ::Array[::Float]]
-
#initialize(size) ⇒ Radix2
constructor
A new instance of Radix2.
Constructor Details
#initialize(size) ⇒ Radix2
Returns a new instance of Radix2.
8 9 10 11 12 13 14 |
# File 'lib/dsprb/fourier.rb', line 8 def initialize(size) @size = Integer(size) raise ArgumentError, "FFT size must be a positive power of two, got #{@size}" unless power_of_two?(@size) @stages = build_stages(@size) freeze end |
Instance Attribute Details
#size ⇒ ::Integer (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/dsprb/fourier.rb', line 6 def size @size end |
Instance Method Details
#call(real, imaginary) ⇒ [::Array[::Float], ::Array[::Float]]
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dsprb/fourier.rb', line 16 def call(real, imaginary) assert_size!(real, imaginary) permute(real, imaginary) span = 2 while span <= @size cosines, sines = @stages[span] half = span / 2 block = 0 while block < @size index = 0 while index < half butterfly(real, imaginary, block + index, half, cosines[index], sines[index]) index += 1 end block += span end span <<= 1 end [real, imaginary] end |