(self,
               lowcut=None,
               highcut=None,
               sampling_rate=None,
               order=ACTION_FILTER_ORDER,
               num_joints=None)
Initializes a butterworth filter.

    Either one per joint or same for all joints.

    Args:
      lowcut: list of strings defining the low cutoff frequencies.
        The list must contain either 1 element (same filter for all joints)
        or num_joints elements
        0 for lowpass, > 0 for bandpass. Either all values must be 0
        or all > 0
      highcut: list of strings defining the high cutoff frequencies.
        The list must contain either 1 element (same filter for all joints)
        or num_joints elements
        All must be > 0
      sampling_rate: frequency of samples in Hz
      order: filter order
      num_joints: robot DOF
Initializes a butterworth filter.
Initializes a butterworth filter .
def __init__(self,
               lowcut=None,
               highcut=None,
               sampling_rate=None,
               order=ACTION_FILTER_ORDER,
               num_joints=None):
    """Initializes a butterworth filter.

    Either one per joint or same for all joints.

    Args:
      lowcut: list of strings defining the low cutoff frequencies.
        The list must contain either 1 element (same filter for all joints)
        or num_joints elements
        0 for lowpass, > 0 for bandpass. Either all values must be 0
        or all > 0
      highcut: list of strings defining the high cutoff frequencies.
        The list must contain either 1 element (same filter for all joints)
        or num_joints elements
        All must be > 0
      sampling_rate: frequency of samples in Hz
      order: filter order
      num_joints: robot DOF
    """
    self.lowcut = ([float(x) for x in lowcut]
                   if lowcut is not None else [ACTION_FILTER_LOW_CUT])
    self.highcut = ([float(x) for x in highcut]
                    if highcut is not None else [ACTION_FILTER_HIGH_CUT])
    if len(self.lowcut) != len(self.highcut):
      raise ValueError('Number of lowcut and highcut filter values should '
                       'be the same')

    if sampling_rate is None:
      raise ValueError('sampling_rate should be provided.')

    if num_joints is None:
      raise ValueError('num_joints should be provided.')

    if np.any(self.lowcut):
      if not np.all(self.lowcut):
        raise ValueError('All the filters must be of the same type: '
                         'lowpass or bandpass')
      self.ftype = 'bandpass'
    else:
      self.ftype = 'lowpass'

    a_coeffs = []
    b_coeffs = []
    for i, (l, h) in enumerate(zip(self.lowcut, self.highcut)):
      if h <= 0.0:
        raise ValueError('Highcut must be > 0')

      b, a = self.butter_filter(l, h, sampling_rate, order)
      logging.info(
          'Butterworth filter: joint: %d, lowcut: %f, highcut: %f, '
          'sampling rate: %d, order: %d, num joints: %d', i, l, h,
          sampling_rate, order, num_joints)
      b_coeffs.append(b)
      a_coeffs.append(a)

    super(ActionFilterButter, self).__init__(
        a_coeffs, b_coeffs, order, num_joints, self.ftype)
def __init__ ( self , lowcut = None , highcut = None , sampling_rate = None , order = ACTION_FILTER_ORDER , num_joints = None ) : self . lowcut = ( [ float ( x ) for x in lowcut ] if lowcut is not None else [ ACTION_FILTER_LOW_CUT ] ) self . highcut = ( [ float ( x ) for x in highcut ] if highcut is not None else [ ACTION_FILTER_HIGH_CUT ] ) if len ( self . lowcut ) != len ( self . highcut ) : raise ValueError ( 'Number of lowcut and highcut filter values should ' 'be the same' ) if sampling_rate is None : raise ValueError ( 'sampling_rate should be provided.' ) if num_joints is None : raise ValueError ( 'num_joints should be provided.' ) if np . any ( self . lowcut ) : if not np . all ( self . lowcut ) : raise ValueError ( 'All the filters must be of the same type: ' 'lowpass or bandpass' ) self . ftype = 'bandpass' else : self . ftype = 'lowpass' a_coeffs = [ ] b_coeffs = [ ] for i , ( l , h ) in enumerate ( zip ( self . lowcut , self . highcut ) ) : if h <= 0.0 : raise ValueError ( 'Highcut must be > 0' ) b , a = self . butter_filter ( l , h , sampling_rate , order ) logging . info ( 'Butterworth filter: joint: %d, lowcut: %f, highcut: %f, ' 'sampling rate: %d, order: %d, num joints: %d' , i , l , h , sampling_rate , order , num_joints ) b_coeffs . append ( b ) a_coeffs . append ( a ) super ( ActionFilterButter , self ) . __init__ ( a_coeffs , b_coeffs , order , num_joints , self . ftype )