Class: Digiproc::BandstopFilter

Inherits:
DigitalFilter show all
Defined in:
lib/filters/bandstop_filter.rb

Overview

Creates a bandstop filter via the Windowing Method

Constant Summary

Constants inherited from DigitalFilter

DigitalFilter::PI

Instance Attribute Summary collapse

Attributes inherited from DigitalFilter

#fft, #size, #weights, #window

Instance Method Summary collapse

Methods inherited from DigitalFilter

#calculate_ideal, #set_fft_size, #to_ds

Constructor Details

#initialize(size:, window: RectangularWindow, wo: nil, bw: nil, wlp_upper: nil, whp_lower: nil, correct: true) ⇒ BandstopFilter

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

wlp_upper
Float

Upper frequency limit (radians) of the lowpass passband

whp_lower
Float

Lower frequency limit (radians) of the highpass passband

correct
Boolean

perform frequency corrections to make frequency points more accurate. Defaults to true

Must have either wo and bw or wlp_upper and whp_lower For wo and bw, include the “don’t care” areas in the bandstop area

Digiproc::BandpassFilter.new(size: 1000, wo: Math::PI / 4, bw: Math::PI / 10)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/filters/bandstop_filter.rb', line 22

def initialize(size:, window: RectangularWindow, wo: nil, bw: nil, wlp_upper: nil , whp_lower: nil, correct: true )

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

Instance Attribute Details

#equationObject

Returns the value of attribute equation.



6
7
8
# File 'lib/filters/bandstop_filter.rb', line 6

def equation
  @equation
end