예제 #1
0
def resample_rec(d, factor, max_marker_delay=0):
  '''Resample a recording to length d.ninstances * factor'''
  new_len = int(d.ninstances * factor)
  labels = resample_markers(d.labels.flatten(), new_len, 
    max_delay=max_marker_delay)

  # calculate data and ids
  data, ids = signal.resample(d.data, new_len, t=d.ids.ravel(), axis=1)
  data = data.astype(d.data.dtype) # keep old dtype

  # construct new DataSet
  return DataSet(data=data, labels=labels, ids=ids, default=d)
예제 #2
0
def resample_rec(d, factor, max_marker_delay=0):
  '''Resample a recording to length d.ninstances * factor'''
  new_len = int(d.ninstances * factor)
  ys = resample_markers(d.ys.flatten(), new_len, 
    max_delay=max_marker_delay).reshape(-1, 1)

  # calculate xs and ids
  xs, ids = signal.resample(d.xs, new_len, t=d.ids)
  xs = xs.astype(d.xs.dtype) # keep old dtype

  # construct new DataSet
  extra = d.extra.copy()
  return DataSet(xs=xs, ys=ys, ids=ids.reshape(-1, 1), extra=extra, default=d)
예제 #3
0
def decimate_rec(d, factor, max_marker_delay=0):
  '''Decimate a recording using an anti-aliasing filter.'''
  assert isinstance(factor, int), 'Decimation factor should be an int'

  # anti-aliasing filter
  (b, a) = signal.iirfilter(8, .8 / factor, btype='lowpass', rp=0.05, 
    ftype='cheby1')
  data = d.data.copy()
  data = signal.filtfilt(b, a, data, axis=1)

  data = np.ascontiguousarray(data[:, ::factor]).astype(d.data.dtype)
  labels = resample_markers(d.labels.flatten(), data.shape[1],
    max_delay=max_marker_delay)
  ids = np.ascontiguousarray(d.ids[:, ::factor]).astype(d.ids.dtype)

  # construct new DataSet
  return DataSet(data=data, labels=labels, ids=ids, default=d)
예제 #4
0
def decimate_rec(d, factor, max_marker_delay=0):
  '''Decimate a recording using an anti-aliasing filter.'''
  assert isinstance(factor, int), 'Decimation factor should be an int'

  # anti-aliasing filter
  (b, a) = signal.iirfilter(8, .8 / factor, btype='lowpass', rp=0.05, 
    ftype='cheby1')
  xs = d.xs.copy()
  for i in range(d.nfeatures):
    xs[:,i] = signal.filtfilt(b, a, xs[:, i])

  xs = np.ascontiguousarray(xs[::factor,:]).astype(d.xs.dtype)
  ys = resample_markers(d.ys.flatten(), xs.shape[0],
    max_delay=max_marker_delay).reshape(-1, 1)
  ids = np.ascontiguousarray(d.ids[::factor,:]).astype(d.ids.dtype)

  # construct new DataSet
  return DataSet(xs=xs, ys=ys, ids=ids.reshape(-1, 1), default=d)