ibllib.dsp.fourier

Low-level functions to work in frequency domain for n-dim arrays

ibllib.dsp.fourier.bp(ts, si, b, axis=None)

Band-pass filter in frequency domain

Parameters:
  • ts – time serie
  • si – sampling interval in seconds
  • b – cutout frequencies: 4 elements vector or list
  • axis – axis along which to perform reduction (last axis by default)
Returns:

filtered time serie

ibllib.dsp.fourier.convolve(x, w, mode='full')

Frequency domain convolution along the last dimension (2d arrays) Will broadcast if a matrix is convolved with a vector :param x: :param w: :return: convolution

ibllib.dsp.fourier.dephas(w, phase, axis=-1)

dephas a signal by a given angle in degrees :param w: :param phase: phase in degrees :param axis: :return:

ibllib.dsp.fourier.dft(x, xscale=None, axis=-1, kscale=None)

1D discrete fourier transform. Vectorized. :param x: 1D numpy array to be transformed :param xscale: time or spatial index of each sample :param axis: for multidimensional arrays, axis along which the ft is computed :param kscale: (optional) fourier coefficient. All if complex input, positive if real :return: 1D complex numpy array

ibllib.dsp.fourier.dft2(x, r, c, nk, nl)

Irregularly sampled 2D dft by projecting into sines/cosines. Vectorized. :param x: vector or 2d matrix of shape (nrc, nt) :param r: vector (nrc) of normalized positions along the k dimension (axis 0) :param c: vector (nrc) of normalized positions along the l dimension (axis 1) :param nk: output size along axis 0 :param nl: output size along axis 1 :return: Matrix X (nk, nl, nt)

ibllib.dsp.fourier.fexpand(x, ns=1, axis=None)

Reconstructs full spectrum from positive frequencies Works on the last dimension (contiguous in c-stored array)

Parameters:
  • x – numpy.ndarray
  • axis – axis along which to perform reduction (last axis by default)
Returns:

numpy.ndarray

ibllib.dsp.fourier.fit_phase(w, si=1, fmin=0, fmax=None, axis=-1)

Performs a linear regression on the unwrapped phase of a wavelet to obtain a time-delay :param w: wavelet (usually a cross-correlation) :param si: sampling interval :param fmin: sampling interval :param fnax: sampling interval :param axis: :return: dt

ibllib.dsp.fourier.freduce(x, axis=None)

Reduces a spectrum to positive frequencies only Works on the last dimension (contiguous in c-stored array)

Parameters:
  • x – numpy.ndarray
  • axis – axis along which to perform reduction (last axis by default)
Returns:

numpy.ndarray

ibllib.dsp.fourier.fscale(ns, si=1, one_sided=False)

numpy.fft.fftfreq returns Nyquist as a negative frequency so we propose this instead

Parameters:
  • ns – number of samples
  • si – sampling interval in seconds
  • one_sided – if True, returns only positive frequencies
Returns:

fscale: numpy vector containing frequencies in Hertz

ibllib.dsp.fourier.hp(ts, si, b, axis=None)

High-pass filter in frequency domain

Parameters:
  • ts – time serie
  • si – sampling interval in seconds
  • b – cutout frequencies: 2 elements vector or list
  • axis – axis along which to perform reduction (last axis by default)
Returns:

filtered time serie

ibllib.dsp.fourier.lp(ts, si, b, axis=None)

Low-pass filter in frequency domain

Parameters:
  • ts – time serie
  • si – sampling interval in seconds
  • b – cutout frequencies: 2 elements vector or list
  • axis – axis along which to perform reduction (last axis by default)
Returns:

filtered time serie

ibllib.dsp.fourier.ns_optim_fft(ns)

Gets the next higher combination of factors of 2 and 3 than ns to compute efficient ffts :param ns: :return: nsoptim

ibllib.dsp.fourier.shift(w, s, axis=-1)

Shifts a signal in frequency domain, to allow for accurate non-integer shifts :param w: input signal :param s: shift in samples, positive shifts forward :param axis: axis along which to shift :return: w