Changeset 12948 for fact/tools/pyscripts


Ignore:
Timestamp:
02/28/12 17:37:03 (13 years ago)
Author:
neise
Message:
filters use the 1st sample as initial values, instead of zero.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/pyfact/fir_filter.py

    r12947 r12948  
    1717       
    1818        """
    19        
    2019        self.a = a
    2120        self.b = b
     
    2322       
    2423    def __call__(self, data):
    25         return signal.lfilter(self.b, self.a, data)
     24        length = max(len(self.a),len(self.b))-1
     25        initial = np.ones(length)
     26        initial *= data[0]
     27        filtered, zf = signal.lfilter(self.b, self.a, data, zi=initial)
     28        return filtered
    2629
    2730    def __str__(self):
    2831        s = self.name + '\n'
     32        s += 'initial condition for filter: signal@rest = 1st sample\n'
    2933        s += 'filter, coefficients:\n'
    3034        s += 'nominator ' + str(self.b) + '\n'
     
    4246   
    4347        """
    44 
    4548        b = np.ones(length)
    46         a = len(b)
     49        a = np.zeros(length)
     50        a[0] = len(b)
    4751        FirFilter.__init__(self, b, a, 'sliding average')
    4852           
     
    7074       
    7175        b = np.array((-0.5, 1., -0.5))
    72         a = 1.
     76        a = np.zeros(len(b))
     77        a[0] = 1.0
    7378        FirFilter.__init__(self, b, a, 'remove signal')       
    7479
Note: See TracChangeset for help on using the changeset viewer.