Sha256: ad97fd32a4d64b9a12271ace5c32677fd93d2cb218d4b2478f6cd7c67e3e9dbe

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

##
# Hamming Window
# Used to improve digital filters by using a non-retangular frequency domain window 
class Digiproc::HammingWindow < Digiproc::WindowStrategy

    ##
    # == Input Args
    # size (Optional):: Numeric (default: nil), how many datapoings the window should have
    # norm_trans_freq:: Numeric (default: nil), the desired transition frequency
    # If you know what size of the the window that you need, you can input size without norm_trans_freq
    # If you kow the desired transition frequency, the necessary size will be calculated for you based off of 
    # the window type so it is not necessary to enter the size
    def initialize(size: nil , norm_trans_freq: nil)
        super(size: norm_trans_freq.nil? ? size : find_size(norm_trans_freq))
        size = @size + 2
        @equation = lambda { |n| 0.54 - 0.46 * Math.cos(2 * PI * (n + 1) / (size - 1)) }
        calculate
        @values = @values.take(@size)
    end

    # Given a freqency, return the required size of a HammingWindow
    def find_size(freq)
        size = 3.3 / freq
        make_odd(size.ceil)
    end

    # Return the transition width (in rad/s) based off of the size
    def transition_width
        3.3 / @size
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
digiproc-0.2.5 lib/strategies/window/hamming_window.rb
digiproc-0.2.4 lib/strategies/window/hamming_window.rb
digiproc-0.2.3 lib/strategies/window/hamming_window.rb
digiproc-0.2.2 lib/strategies/window/hamming_window.rb
digiproc-0.2.1 lib/strategies/window/hamming_window.rb
digiproc-0.2.0 lib/strategies/window/hamming_window.rb
digiproc-0.1.0 lib/strategies/window/hamming_window.rb