# 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 `dephas` dephas a signal by a given angle in degrees `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 `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 `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
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

Parameters
• x

• w

Returns

convolution

ns_optim_fft(ns)[source]

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

Parameters

ns

Returns

nsoptim

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

dephas a signal by a given angle in degrees

Parameters
• w

• phase – phase in degrees

• axis

Returns

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, ns=None)[source]

Shifts a 1D or 2D signal in frequency domain, to allow for accurate non-integer shifts

Parameters
• w – input signal (if complex, need to provide ns too)

• s – shift in samples, positive shifts forward

• axis – axis along which to shift (last axis by default)

• axis – axis along which to shift (last axis by default)

• ns – if a rfft frequency domain array is provided, give a number of samples as there is an ambiguity

Returns

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

Parameters
• w – wavelet (usually a cross-correlation)

• si – sampling interval

• fmin – sampling interval

• fnax – sampling interval

• axis

Returns

dt

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

1D discrete fourier transform. Vectorized.

Parameters
• x – 1D numpy array to be transformed

• xscale – time or spatial index of each sample

• axis – for multidimensional arrays, axis along which the ft is computed

• kscale – (optional) fourier coefficient. All if complex input, positive if real

Returns

1D complex numpy array

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

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

Parameters
• x – vector or 2d matrix of shape (nrc, nt)

• r – vector (nrc) of normalized positions along the k dimension (axis 0)

• c – vector (nrc) of normalized positions along the l dimension (axis 1)

• nk – output size along axis 0

• nl – output size along axis 1

Returns

Matrix X (nk, nl, nt)