Module: Digiproc::FourierTransformable
- Included in:
- DigitalSignal, Probability::GaussianDistribution
- Defined in:
- lib/concerns/fourier_transformable.rb
Overview
Module for Classes which have a property ‘data` which we can take the Discrete Fourier Transform of. A class which wants to use methods outside of GenricMethods will also include Digiproc::Initializable, and you have to use the appropriate methods in your class constructor if you want the Digiproc::FFT class to be set up automatically You could manually set it up if your class sets up its own @fft property which is an instance of Digiproc::FFT with the class’ ‘data` passed in. See an example of this in action in Digiproc::DigitalSignal initializer method.
Defined Under Namespace
Modules: GenericMethods
Instance Attribute Summary collapse
-
#fft(size = @fft.data.size) ⇒ Object
fft(size [optional Integer]) #=> returns Digiproc::FFT instance Will calculate the FFT if it has not yet been calculated size is an optional parameter which allows you to delegate the size of the FFT to be calculated..
-
#fft_strategy ⇒ Object
Returns the value of attribute fft_strategy.
Class Method Summary collapse
-
.included(base) ⇒ Object
Include Digiproc::RequiresData when an instance is instantiated that includes Digiproc::FourierTransformable because methods require ‘data` (an array of Fourier Transformable data) to exist in the class.
Instance Method Summary collapse
-
#fft_angle ⇒ Object
fft_data # => Array of angle vals (radians) Calculate the fft if not yet calculated, and returns Arra of the angle data in radians.
-
#fft_data ⇒ Object
fft_data # => Array of FFT vals (complex Numeric) Calculates the fft if not yet calculated, and returns the calculation.
-
#fft_db ⇒ Object
fft_db #=> Array of decible values of the magnitude of the FFT (Float, not complex) Ensures the fft is calculated, and then returns the dB vals.
-
#fft_imaginary ⇒ Object
fft_imaginary # => Array of imaginary vals Calculate the fft if not yet calculated, and retun an Array of the imaginary values.
-
#fft_magnitude ⇒ Object
fft_db #=> Array of values of the magnitude of the FFT (numeric, not complex) Ensures the fft is calculated, and then returns the magnitude.
-
#fft_real ⇒ Object
fft_real # => Array of real vals Calculate the fft if not yet calculated, and retun an Array of the real values.
-
#initialize(time_data:, fft_strategy: Digiproc::Strategies::Radix2Strategy) ⇒ Object
Initialize with (time_data: [Array(Numeric)], fft_strategy: [optional, defaults to Digiproc::Strategies::Radix2Strategy]) Upon instantiation, a new Digiproc::FFT class is made with the data passed in as time_data.
Instance Attribute Details
#fft(size = @fft.data.size) ⇒ Object
fft(size [optional Integer]) #=> returns Digiproc::FFT instance Will calculate the FFT if it has not yet been calculated size is an optional parameter which allows you to delegate the size of the FFT to be calculated.. This is useful if you want a particular resolution of the frequency domain, or if you are trying to match FFT sizes for calculation purposes.
126 127 128 129 130 131 |
# File 'lib/concerns/fourier_transformable.rb', line 126 def fft(size = @fft.data.size) if @fft.data.size != size @fft.calculate_at_size(size) end @fft end |
#fft_strategy ⇒ Object
Returns the value of attribute fft_strategy.
80 81 82 |
# File 'lib/concerns/fourier_transformable.rb', line 80 def fft_strategy @fft_strategy end |
Class Method Details
.included(base) ⇒ Object
Include Digiproc::RequiresData when an instance is instantiated that includes Digiproc::FourierTransformable because methods require ‘data` (an array of Fourier Transformable data) to exist in the class
73 74 75 76 77 |
# File 'lib/concerns/fourier_transformable.rb', line 73 def self.included(base) base.class_eval do include Digiproc::RequiresData, Digiproc::Initializable end end |
Instance Method Details
#fft_angle ⇒ Object
fft_data # => Array of angle vals (radians) Calculate the fft if not yet calculated, and returns Arra of the angle data in radians
150 151 152 153 |
# File 'lib/concerns/fourier_transformable.rb', line 150 def fft_angle setup_fft @fft.angle end |
#fft_data ⇒ Object
fft_data # => Array of FFT vals (complex Numeric) Calculates the fft if not yet calculated, and returns the calculation
142 143 144 145 |
# File 'lib/concerns/fourier_transformable.rb', line 142 def fft_data setup_fft @fft.fft end |
#fft_db ⇒ Object
fft_db #=> Array of decible values of the magnitude of the FFT (Float, not complex) Ensures the fft is calculated, and then returns the dB vals
108 109 110 111 |
# File 'lib/concerns/fourier_transformable.rb', line 108 def fft_db setup_fft @fft.fft.db end |
#fft_imaginary ⇒ Object
fft_imaginary # => Array of imaginary vals Calculate the fft if not yet calculated, and retun an Array of the imaginary values
166 167 168 169 |
# File 'lib/concerns/fourier_transformable.rb', line 166 def fft_imaginary setup_fft @fft.fft.imaginary end |
#fft_magnitude ⇒ Object
fft_db #=> Array of values of the magnitude of the FFT (numeric, not complex) Ensures the fft is calculated, and then returns the magnitude
115 116 117 118 |
# File 'lib/concerns/fourier_transformable.rb', line 115 def fft_magnitude setup_fft @fft.magnitude end |
#fft_real ⇒ Object
fft_real # => Array of real vals Calculate the fft if not yet calculated, and retun an Array of the real values
158 159 160 161 |
# File 'lib/concerns/fourier_transformable.rb', line 158 def fft_real setup_fft @fft.real end |
#initialize(time_data:, fft_strategy: Digiproc::Strategies::Radix2Strategy) ⇒ Object
Initialize with (time_data: [Array(Numeric)], fft_strategy: [optional, defaults to Digiproc::Strategies::Radix2Strategy]) Upon instantiation, a new Digiproc::FFT class is made with the data passed in as time_data. NOTE this does not happen automatically upon instantiation of the class which includes this module. The class including this module will also include Digiproc::Initializable, so you can initialize this module in the class’ #initialize method as follows: class TestClass
include Digiproc::FourierTransformable
attr_accessor :data
def initialize(data: )
@data = data
initialize_modules(Digiproc::FourierTransformable => {time_data: data})
end
end
Note that the calculation of the FFT itself is lazy and will not be calculated unless there is an attempt to access it or #calculate is called on @fft
100 101 102 103 |
# File 'lib/concerns/fourier_transformable.rb', line 100 def initialize(time_data: , fft_strategy: Digiproc::Strategies::Radix2Strategy) @fft_strategy = fft_strategy @fft = Digiproc::FFT.new(time_data: time_data.dup, strategy: fft_strategy) end |