class_docstr: A `scipy.signal.butter`-based generic filter class.
class_docstr_tok: ["A","`","scipy.signal.butter","`","-based","generic","filter","class","."]
code: def __init__(self, **kwargs):
      assert "p" in kwargs
      assert "min_rolloff" in kwargs
      assert "max_rolloff" in kwargs
      assert "filter_type" in kwargs
      assert "zero_phase" in kwargs
  
      super().__init__(kwargs["p"])
  
      self.filter_type = kwargs["filter_type"]
      self.min_rolloff = kwargs["min_rolloff"]
      self.max_rolloff = kwargs["max_rolloff"]
      self.zero_phase = kwargs["zero_phase"]
  
      if self.zero_phase:
          assert (
              self.min_rolloff % 12 == 0
          ), "Zero phase filters can only have a steepness which is a multiple of 12db/octave"
          assert (
              self.max_rolloff % 12 == 0
          ), "Zero phase filters can only have a steepness which is a multiple of 12db/octave"
      else:
          assert (
              self.min_rolloff % 6 == 0
          ), "Non zero phase filters can only have a steepness which is a multiple of 6db/octave"
          assert (
              self.max_rolloff % 6 == 0
          ), "Non zero phase filters can only have a steepness which is a multiple of 6db/octave"
  
      assert (
          self.filter_type in BaseButterworthFilter.ALLOWED_FILTER_TYPES
      ), "Filter type must be one of: " + ", ".join(
          BaseButterworthFilter.ALLOWED_FILTER_TYPES
      )
  
      assert (
          "min_cutoff_freq" in kwargs and "max_cutoff_freq" in kwargs
      ) or (
          "min_center_freq" in kwargs
          and "max_center_freq" in kwargs
          and "min_bandwidth_fraction" in kwargs
          and "max_bandwidth_fraction" in kwargs
      ), "Arguments for either a one-sided, or a two-sided filter must be given"
  
      if "min_cutoff_freq" in kwargs:
          self.initialize_one_sided_filter(
              min_cutoff_freq=kwargs["min_cutoff_freq"],
              max_cutoff_freq=kwargs["max_cutoff_freq"],
          )
      elif "min_center_freq" in kwargs:
          self.initialize_two_sided_filter(
              min_center_freq=kwargs["min_center_freq"],
              max_center_freq=kwargs["max_center_freq"],
              min_bandwidth_fraction=kwargs["min_bandwidth_fraction"],
              max_bandwidth_fraction=kwargs["max_bandwidth_fraction"],
          )
  
file_path: audiomentations/audiomentations/augmentations/base_butterword_filter.py
imports: import random
  import numpy
  from numpy.typing import NDArray
  from scipy.signal import butter, sosfilt, sosfiltfilt, sosfilt_zi
  from audiomentations.core.transforms_interface import BaseWaveformTransform
  from audiomentations.core.utils import convert_frequency_to_mel, convert_mel_to_frequency
label_desc: Use image node_id 1 to create a new BaseButterworthFilter object from inherited base classes: BaseWaveformTransform with example: obj = BaseButterworthFilter()