neurodsp.spectral.trim_spectrogram¶
- neurodsp.spectral.trim_spectrogram(freqs, times, spg, f_range=None, t_range=None)[source]¶
Extract a frequency or time range of interest from a spectrogram.
- Parameters
- freqs1d array
Frequency values for the spectrogram.
- times1d array
Time values for the spectrogram.
- spg2d array
Spectrogram, or time frequency representation of a signal. Formatted as [n_freqs, n_time_windows].
- f_rangelist of [float, float]
Frequency range to restrict to, as [f_low, f_high].
- t_rangelist of [float, float]
Time range to restrict to, as [t_low, t_high].
- Returns
- freqs_ext1d array
Extracted frequency values for the power spectrum.
- times_ext1d array
Extracted segment time values
- spg_ext2d array
Extracted spectrogram values.
Notes
This function extracts frequency ranges >= f_low and <= f_high, and time ranges >= t_low and <= t_high. It does not round to below or above f_low and f_high, or t_low and t_high, respectively.
Examples
Trim the spectrogram of a simulated time series:
>>> from neurodsp.sim import sim_combined >>> from neurodsp.timefrequency import compute_wavelet_transform >>> from neurodsp.utils.data import create_times, create_freqs >>> fs = 500 >>> n_seconds = 10 >>> times = create_times(n_seconds, fs) >>> sig = sim_combined(n_seconds, fs, ... components={'sim_powerlaw': {}, 'sim_oscillation' : {'freq': 10}}) >>> freqs = create_freqs(1, 15) >>> mwt = compute_wavelet_transform(sig, fs, freqs) >>> spg = abs(mwt)**2 >>> freqs_ext, times_ext, spg_ext = trim_spectrogram(freqs, times, spg, ... f_range=[8, 12], t_range=[0, 5])