ibllib.dsp.fourier

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

Functions

bp

Band-pass filter in frequency domain

convolve

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

dephas

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

dft

1D discrete fourier transform.

dft2

Irregularly sampled 2D dft by projecting into sines/cosines.

fexpand

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

fit_phase

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

freduce

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

fscale

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

fshift

Shifts a 1D or 2D 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 (last axis by default) :return: w

hp

High-pass filter in frequency domain

lp

Low-pass filter in frequency domain

ns_optim_fft

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

convolve(x, w, mode='full')[source]

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

ns_optim_fft(ns)[source]

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

dephas(w, phase, axis=- 1)[source]

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

fscale(ns, si=1, one_sided=False)[source]

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

freduce(x, axis=None)[source]

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

fexpand(x, ns=1, axis=None)[source]

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

bp(ts, si, b, axis=None)[source]

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

lp(ts, si, b, axis=None)[source]

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

hp(ts, si, b, axis=None)[source]

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

fshift(w, s, axis=- 1)[source]

Shifts a 1D or 2D 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 (last axis by default) :return: w

fit_phase(w, si=1, fmin=0, fmax=None, axis=- 1)[source]

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

dft(x, xscale=None, axis=- 1, kscale=None)[source]

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

dft2(x, r, c, nk, nl)[source]

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)