Exemplo n.º 1
0
 def test_filter_lp_hp(self):
     # test 1D time serie: subtracting lp filter removes DC
     ts1 = np.random.rand(500)
     out1 = ft.lp(ts1, 1, [.1, .2])
     self.assertTrue(np.mean(ts1 - out1) < 0.001)
     # test 2D case along the last dimension
     ts = mat.repmat(ts1, 11, 1)
     out = ft.lp(ts, 1, [.1, .2])
     self.assertTrue(np.allclose(out, out1))
     # test 2D case along the first dimension
     ts = mat.repmat(ts1[:, np.newaxis], 1, 11)
     out = ft.lp(ts, 1, [.1, .2], axis=0)
     self.assertTrue(np.allclose(np.transpose(out), out1))
     # test 1D time serie: subtracting lp filter removes DC
     out2 = ft.hp(ts1, 1, [.1, .2])
     self.assertTrue(np.allclose(out1, ts1 - out2))
Exemplo n.º 2
0
def lp(ts, fac, pad=0.2):
    """
    Smooth the data in frequency domain (assumes a uniform sampling rate), using edge padding

    ibllib.dsp.smooth.lp(ts, [.1, .15])
    :param ts: input signal to be smoothed
    :param fac: 2 element vector of the frequency edges relative to Nyquist: [0.15, 0.2] keeps
    everything up to 15% of the full band tapering down to 20%
    :param pad: padding on the edges of the time serie, between 0 and 1 (0.2 means 20% of the size)
    :return: smoothed time series
    """
    # keep at least two periods for the padding
    lpad = np.int(np.ceil(ts.shape[0] * pad))
    ts_ = np.pad(ts, lpad, mode='edge')
    ts_ = ft.lp(ts_, 1, np.array(fac) / 2)
    return ts_[lpad:-lpad]