Multitaper spectral analysis (spynal.spectra.multitaper)

Multitaper spectral analysis

multitaper_spectrum(data, smp_rate, axis=0, data_type='lfp', spec_type='complex', freq_range=None, removeDC=True, freq_width=4, n_tapers=None, keep_tapers=False, tapers=None, pad=True, **kwargs)

Multitaper Fourier spectrum computation for continuous (eg LFP) or point process (spike) data

Multitaper methods project the data onto orthogonal Slepian (DPSS) “taper” functions, which increases the data’s effective signal-to-noise. It allows a principled tradeoff btwn time resolution (data.shape[axis]), frequency resolution (freq_width), and the number of taper functions (n_tapers), which determines the signal-to-noise boost.

Note: By default, data is zero-padded to the next power of 2 greater than its input length. This will change the frequency sampling (number of freqs and exact freqs sampled) from what would be obtained from the original raw data, but can be skipped by inputtng pad=False.

Only parameters differing from spectrum() are described here.

Parameters:
  • freq_range (array-like, shape=(2,) or scalar, default: all frequencies from FFT (0-smp_rate/2)) – Range of frequencies to keep in output, either given as an explicit [low,high] range or just a scalar giving the highest frequency to return.

  • freq_width (scalar, default: 4 Hz) – Frequency bandwidth ‘W’ (Hz).

  • n_tapers (scalar, default: (2TW-1)) – Number of tapers to compute. Must be <= 2TW-1, as this is the max number of spectrally delimited tapers (and is set as default based on set T,W values). Note: Time bandwidth ‘T’ is set to full length of data.

  • tapers (ndarray, shape=(n_win_samples,n_tapers), default: (computed from t/f_range,ntapers)) –

    Precomputed tapers (as computed by compute_tapers()).

    Alternative method for explictly setting taper functions. Input either time_width/freq_width/n_tapers OR tapers. If tapers not explicitly input, we compute them from time_width/freq_width/n_tapers. If tapers are explicitly input, time_width/freq_width/n_tapers are ignored.

  • keep_tapers (bool, default: False) – If True, tapers axis is retained in output, between frequency axis and time axis. If False, output is averaged over tapers, and taper axis is removed

  • pad (bool, default: True) – If True, zero-pads data to next power of 2 length

Returns:

  • spec (ndarray, shape=(…,n_freqs,[n_tapers,]…), dtype=complex or float) – Multitaper spectrum of given type of data. Sampling (time) axis is replaced by frequency and taper axes (if keep_tapers is True), but shape is otherwise preserved. dtype is complex if spec_type is ‘complex’, float otherwise.

  • freqs (ndarray, dtype=(n_freqs,)) – List of frequencies in spec (in Hz)

References

multitaper_spectrogram(data, smp_rate, axis=0, data_type='lfp', spec_type='complex', freq_range=None, removeDC=True, time_width=0.5, freq_width=4, n_tapers=None, spacing=None, tapers=None, keep_tapers=False, pad=True, **kwargs)

Compute multitaper time-frequency spectrogram for continuous (eg LFP) or point process (eg spike) data

Multitaper methods project the data onto orthogonal Slepian (DPSS) “taper” functions, which increases the data’s effective signal-to-noise. It allows a principled tradeoff btwn time resolution (data.shape[axis]), frequency resolution (freq_width), and the number of taper functions (n_tapers), which determines the signal-to-noise increase.

Note: By default, data is zero-padded to the next power of 2 greater than its input length. This will change the frequency sampling (number of freqs and exact freqs sampled) from what would be obtained from the original raw data, but can be skipped by inputtng pad=False.

Only parameters differing from spectrogram() are described here.

Parameters:
  • freq_range (array-like, shape=(2,) or scalar, default: all frequencies from FFT (0-smp_rate/2)) – Range of frequencies to keep in output, either given as an explicit [low,high] range or just a scalar giving the highest frequency to return.

  • time_width (scalar, default: 0.5 (500 ms)) – Time bandwidth ‘T’ (s). Width of sliding time window is set equal to this.

  • freq_width (scalar, default: 4 Hz) – Frequency bandwidth ‘W’ (Hz).

  • n_tapers (scalar, default: (2TW-1)) – Number of tapers to compute. Must be <= 2TW-1, as this is the max number of spectrally delimited tapers (and is set as default based on set T,W values).

  • spacing (scalar, default: time_width (so each window exactly non-overlapping)) – Spacing between successive sliding time windows (s)

  • tapers (ndarray, shape=(n_win_samples,n_tapers), default: (computed from t/f_range,ntapers)) –

    Precomputed tapers (as computed by compute_tapers()).

    Alternative method for explicitly setting taper functions. Input either time_width/freq_width/n_tapers OR tapers. If tapers not explicitly input, we compute them from time_width/freq_width/n_tapers. If tapers are explicitly input, time_width/freq_width/n_tapers are ignored.

  • keep_tapers (bool, default: False) – If True, tapers axis is retained in output, between frequency axis and time axis. If False, output is averaged over tapers, and taper axis is removed

  • pad (bool, default: True) – If True, zero-pads data to next power of 2 length

Returns:

  • spec (ndarray, shape=(…,n_freqs[,n_tapers],n_timewins,…), dtype=complex or float) – Multitaper time-frequency spectrogram of data. Sampling (time) axis is replaced by frequency, taper (if keep_tapers=True), and time window axes but shape is otherwise preserved. dtype is complex if spec_type is ‘complex’, float otherwise.

  • freqs (ndarray, shape=(n_freqs,)) – List of frequencies in spec (in Hz)

  • timepts (ndarray, shape=(n_timewins,…)) – List of timepoints in spec (in s, referenced to start of data). Timepoints here are centers of each time window.

References

compute_tapers(smp_rate, time_width=0.5, freq_width=4, n_tapers=None)

Compute Discrete Prolate Spheroidal Sequence (DPSS) tapers for use in multitaper spectral analysis.

Uses scipy.signal.windows.dpss, but arguments are different here

Parameters:
  • smp_rate (scalar) – Data sampling rate (Hz)

  • time_width (scalar, default: 0.5 (500 ms)) – Time bandwidth ‘T’ (s). Should match data window length.

  • freq_width (scalar, default: 4 Hz) – Frequency bandwidth ‘W’ (Hz)

  • n_tapers (scalar, default: (2TW-1)) – Number of tapers to compute. Must be <= 2TW-1, as this is the max number of spectrally delimited tapers.

Returns:

tapers – Computed dpss taper functions (n_samples = T*smp_rate)

Return type:

ndarray, shape=(n_samples,n_tapers)