ibllib.dsp.fourier¶
Lowlevel functions to work in frequency domain for ndim arrays
Functions
Bandpass filter in frequency domain 

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 a signal by a given angle in degrees :param w: :param phase: phase in degrees :param axis: :return: 

1D discrete fourier transform. 

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

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

Performs a linear regression on the unwrapped phase of a wavelet to obtain a timedelay :param w: wavelet (usually a crosscorrelation) :param si: sampling interval :param fmin: sampling interval :param fnax: sampling interval :param axis: :return: dt 

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

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

Shifts a 1D or 2D signal in frequency domain, to allow for accurate noninteger 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 

Highpass filter in frequency domain 

Lowpass filter in frequency domain 

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 cstored 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 cstored 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]¶ Bandpass 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]¶ Lowpass 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]¶ Highpass 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 noninteger 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 timedelay :param w: wavelet (usually a crosscorrelation) :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)