Sha256: 290a755fb23bb1f31feae9041f80fc26d4a53520a6ef63fa2d42debb5ee52055

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

##
# Creates a Bandpass Filter via the Windowing method. 
class Digiproc::BandpassFilter < Digiproc::DigitalFilter
    attr_accessor :equation

    ##
    # == Inputs
    # size:: [Integer] number of datapoints window should be 
    # window:: [Digiproc::WindowStrategy] desired window strategy
    # wo:: [Float] center frequency in radians
    # bw:: [Float] bandwidth in radians
    # wcl:: [Float] lower cutoff frequency in radians
    # wch:: [Float] higher cutoff frequency in radians
    # correct:: [Boolean] perform frequency corrections to make frequency points more accurate. Defaults to true
    #
    # Must have either `wo` and `bw` or `wcl` and `wch`
    #
    ## Digiproc::BandpassFilter.new(size: 1000, wo: Math::PI / 4, bw: Math::PI / 10) 

    def initialize(size:, window: Digiproc::RectangularWindow, wo: nil, bw: nil, wcl: nil , wch: nil, correct: true )

        super(size: size, window: window)

        if !!wo && !!bw
            bw += @window.transition_width * 2 * PI if correct
            wcl = wo - bw / 2.0
            wch = wo + bw / 2.0
        else
            raise ArgumentError.new("You must provide either bandwidth and center freq or frequency bands") if wcl.nil? or wch.nil? 
            wcl -= @window.transition_width * PI if correct
            wch += @window.transition_width * PI if correct
            bw = wch - wcl
            wo = (wch + wcl) / 2.0
        end
        @equation = ->(n){ 
            n == 0 ?  bw / PI : ((Math.sin(bw * n / 2.0)) / (PI * n)) * (2.0 * Math.cos(n * wo))
        }
        ideal_filter = calculate_ideal
        @weights = self.window.values.times ideal_filter
        @fft = Digiproc::FFT.new(time_data: self.weights)
        @fft.calculate
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
digiproc-0.2.5 lib/filters/bandpass_filter.rb
digiproc-0.2.4 lib/filters/bandpass_filter.rb
digiproc-0.2.3 lib/filters/bandpass_filter.rb
digiproc-0.2.2 lib/filters/bandpass_filter.rb
digiproc-0.2.1 lib/filters/bandpass_filter.rb
digiproc-0.2.0 lib/filters/bandpass_filter.rb
digiproc-0.1.0 lib/filters/bandpass_filter.rb