class Digiproc::DigitalFilter
Parent class to BandpassFilter, HighpassFilter, LowpassFilter, and BandstopFilter
Constants
- PI
Attributes
fft[RW]
size[RW]
weights[RW]
window[RW]
Public Class Methods
Public Instance Methods
calculate_ideal()
click to toggle source
Ensures size is odd, and uses @equation to make a return Array
of ideal filter values. Used by the child class to multiply by the window to the return value of this method for final weights
# File lib/filters/digital_filter.rb, line 21 def calculate_ideal #TODO: allow size to be even @size += 1 if @size.even? n_vals = ((-1 * (@size - 1) / 2)..((@size - 1) / 2)).to_a n_vals.map do |n| @equation.call(n) end end
set_fft_size(size)
click to toggle source
Zero pad @weights to achieve a size of the input value. set @fft to a new Digiproc::FFT
, and calculate with the new padded data.
.set_fft_size(size [Integer])
# File lib/filters/digital_filter.rb, line 35 def set_fft_size(size) if size > @weights.length zeros = Array.new(size - @weights.length, 0) padded = @weights.concat(zeros) @fft = Digiproc::FFT.new(data: padded) @fft.calculate end end
to_ds()
click to toggle source
return a Digiproc::DigitalSignal
whose values are the weights of the filter
# File lib/filters/digital_filter.rb, line 46 def to_ds Digiproc::DigitalSignal.new(data: self.weights) end