neurodsp.rhythm.sliding_window_matching

neurodsp.rhythm.sliding_window_matching(sig, fs, win_len, win_spacing, max_iterations=500, temperature=1, window_starts_custom=None)[source]

Find recurring patterns in a time series using the sliding window matching algorithm.

Parameters
sig1d array

Time series.

fsfloat

Sampling rate, in Hz.

win_lenfloat

Window length, in seconds.

win_spacingfloat

Minimum window spacing, in seconds.

max_iterationsint

Maximum number of iterations of potential changes in window placement.

temperaturefloat

Temperature parameter. Controls probability of accepting a new window.

window_starts_custom1d array, optional

Custom pre-set locations of initial windows.

Returns
avg_window1d array

The average waveform in ‘sig’ in the frequency ‘f_range’ triggered on ‘trigger’.

window_starts1d array

Indices at which each window begins for the final set of windows.

costs1d array

Cost function value at each iteration.

Notes

  • Apply a highpass filter if looking at high frequency activity, so that it does not converge on a low frequency motif.

  • Parameters win_len and win_spacing should be chosen to be about the size of the motif of interest, and the N derived should be about the number of occurrences.

References

1

Gips, B., Bahramisharif, A., Lowet, E., Roberts, M. J., de Weerd, P., Jensen, O., & van der Eerden, J. (2017). Discovering recurring patterns in electrophysiological recordings. Journal of Neuroscience Methods, 275, 66-79. DOI: 10.1016/j.jneumeth.2016.11.001 Matlab Code: https://github.com/bartgips/SWM

Examples

Search for reoccuring patterns using sliding window matching in a simulated beta signal:

>>> from neurodsp.sim import sim_combined
>>> sig = sim_combined(n_seconds=10, fs=500,
...                    components={'sim_powerlaw': {'f_range': (2, None)},
...                                'sim_bursty_oscillation': {'freq': 20,
...                                                           'enter_burst': .25,
...                                                           'leave_burst': .25}})
>>> avg_window, window_starts, costs = sliding_window_matching(sig, fs=500, win_len=0.05,
...                                                            win_spacing=0.20)

Examples using neurodsp.rhythm.sliding_window_matching