elephant.signal_processing.wavelet_transform

elephant.signal_processing.wavelet_transform(signal, frequency, n_cycles=6.0, sampling_frequency=1.0, zero_padding=True)[source]

Compute the wavelet transform of a given signal with Morlet mother wavelet. The parametrization of the wavelet is based on (Le Van Quyen et al., 2001).

Parameters:
signal(Nt, Nch) neo.AnalogSignal or np.ndarray or list

Time series data to be wavelet-transformed. When multi-dimensional np.ndarray or list is given, the time axis must be the last dimension. If neo.AnalogSignal, Nt is the number of time points and Nch is the number of channels.

frequencyfloat or list of float

Center frequency of the Morlet wavelet in Hz. Multiple center frequencies can be given as a list, in which case the function computes the wavelet transforms for all the given frequencies at once.

n_cyclesfloat, optional

Size of the mother wavelet (approximate number of oscillation cycles within a wavelet). Corresponds to \(nco\) in (Le Van Quyen et al., 2001). A larger n_cycles value leads to a higher frequency resolution and a lower temporal resolution, and vice versa. Typically used values are in a range of 3–8, but one should be cautious when using a value smaller than ~ 6, in which case the admissibility of the wavelet is not ensured (Farge, 1992). Default: 6.0

sampling_frequencyfloat, optional

Sampling rate of the input data in Hz. When signal is given as a neo.AnalogSignal, the sampling frequency is taken from its attribute and this parameter is ignored. Default: 1.0

zero_paddingbool, optional

Specifies whether the data length is extended to the least power of 2 greater than the original length, by padding zeros to the tail, for speeding up the computation. If True, the extended part is cut out from the final result before returned, so that the output has the same length as the input. Default: True

Returns:
signal_wtnp.ndarray

Wavelet transform of the input data. When frequency was given as a list, the way how the wavelet transforms for different frequencies are returned depends on the input type:

  • when the input was a neo.AnalogSignal, the returned array has shape (Nt, Nch, Nf), where Nf = len(freq), such that the last dimension indexes the frequencies;

  • when the input was a np.ndarray or list of shape (a, b, …, c, Nt), the returned array has a shape (a, b, …, c, Nf, Nt), such that the second last dimension indexes the frequencies.

To summarize, signal_wt.ndim = signal.ndim + 1, with the additional dimension in the last axis (for neo.AnalogSignal input) or the second last axis (np.ndarray or list input) indexing the frequencies.

Raises:
ValueError

If frequency (or one of the values in frequency when it is a list) is greater than the half of sampling_frequency.

If n_cycles is not positive.

Notes

n_cycles is related to the wavelet number \(w\) as \(w \sim 2 \pi \frac{n_{\text{cycles}}}{6}\) as defined in (Le Van Quyen et al., 2001).

Examples

>>> import neo
>>> import numpy as np
>>> import quantities as pq
>>> from elephant.signal_processing import wavelet_transform
>>> noise = neo.AnalogSignal(np.random.normal(size=7),
...     sampling_rate=11 * pq.Hz, units='mV')

The wavelet frequency must be less than the half of the sampling rate; picking at 5 Hz.

>>> wavelet_transform(noise, frequency=5) 
array([[-1.00890049+3.003473j  ],
   [-1.43664254-2.8389273j ],
   [ 3.02499511+0.96534578j],
   [-2.79543976+1.4581079j ],
   [ 0.94387304-2.98159518j],
   [ 1.41476471+2.77389985j],
   [-2.95996766-0.9872236j ]])