ibllib.dsp.utils

Window generator, front detections, rms

Functions

falls

Detects Falling edges of a voltage signal, returns indices

fcn_cosine

Returns a soft thresholding function with a cosine taper: values <= bounds[0]: values values < bounds[0] < bounds[1] : cosine taper values < bounds[1]: bounds[1] :param bounds: :return: lambda function

fronts

Detects Rising and Falling edges of a voltage signal, returns indices and

parabolic_max

Maximum picking with parabolic interpolation around the maxima :param x: 1d or 2d array :return: interpolated max index, interpolated max

rises

Detect Rising edges of a voltage signal, returns indices

rms

Root mean square of array along axis

sync_timestamps

Sync two arrays of time stamps :param tsa: vector of timestamps :param tsb: vector of timestamps :param tbin: time bin length :param return_indices (bool), if True returns 2 sets of indices for tsa and tsb with identified matches :return: function: interpolation function such as fnc(tsa) = tsb float: drift in ppm numpy array: of indices ia numpy array: of indices ib

Classes

WindowGenerator

wg = WindowGenerator(ns, nswin, overlap)

sync_timestamps(tsa, tsb, tbin=0.1, return_indices=False)[source]

Sync two arrays of time stamps :param tsa: vector of timestamps :param tsb: vector of timestamps :param tbin: time bin length :param return_indices (bool), if True returns 2 sets of indices for tsa and tsb with identified matches :return:

function: interpolation function such as fnc(tsa) = tsb float: drift in ppm numpy array: of indices ia numpy array: of indices ib

parabolic_max(x)[source]

Maximum picking with parabolic interpolation around the maxima :param x: 1d or 2d array :return: interpolated max index, interpolated max

fcn_cosine(bounds)[source]

Returns a soft thresholding function with a cosine taper: values <= bounds[0]: values values < bounds[0] < bounds[1] : cosine taper values < bounds[1]: bounds[1] :param bounds: :return: lambda function

fronts(x, axis=- 1, step=1)[source]

Detects Rising and Falling edges of a voltage signal, returns indices and

Parameters
  • x – array on which to compute RMS

  • axis – (optional, -1) negative value

  • step – (optional, 1) value of the step to detect

Returns

numpy array of indices, numpy array of rises (1) and falls (-1)

falls(x, axis=- 1, step=- 1)[source]

Detects Falling edges of a voltage signal, returns indices

Parameters
  • x – array on which to compute RMS

  • axis – (optional, -1) negative value

  • step – (optional, -1) value of the step to detect

Returns

numpy array

rises(x, axis=- 1, step=1)[source]

Detect Rising edges of a voltage signal, returns indices

Parameters
  • x – array on which to compute RMS

  • axis – (optional, -1)

  • step – (optional, 1) amplitude of the step to detect

Returns

numpy array

rms(x, axis=- 1)[source]

Root mean square of array along axis

Parameters
  • x – array on which to compute RMS

  • axis – (optional, -1)

Returns

numpy array

class WindowGenerator(ns, nswin, overlap)[source]

Bases: object

wg = WindowGenerator(ns, nswin, overlap)

Provide sliding windows indices generator for signal processing applications. For straightforward spectrogram / periodogram implementation, prefer scipy methods !

Example of implementations in test_dsp.py.

property firstlast

Generator that yields first and last index of windows

Returns

tuple of [first_index, last_index] of the window

property slice

Generator that yields slices of windows

Returns

a slice of the window

slice_array(sig, axis=- 1)[source]

Provided an array or sliceable object, generator that yields slices corresponding to windows. Especially useful when working on memmpaps

Parameters
  • sig – array

  • axis – (optional, -1) dimension along which to provide the slice

Returns

array slice Generator

tscale(fs)[source]

Returns the time scale associated with Window slicing (middle of window) :param fs: sampling frequency (Hz) :return: time axis scale

print_progress()[source]

Prints progress using a terminal progress bar