API
Scitex dsp module.
- scitex_dsp.band_powers(self, psd)[source]
Calculate the average power for specified frequency bands.
- scitex_dsp.crop(sig_2d, window_length, overlap_factor=0.0, axis=-1, time=None)[source]
Crops the input signal into overlapping windows of a specified length, allowing for an arbitrary axis and considering a time vector.
Parameters: - sig_2d (numpy.ndarray): The input sig_2d array to be cropped. Can be multi-dimensional. - window_length (int): The length of each window to crop the sig_2d into. - overlap_factor (float): The fraction of the window that consecutive windows overlap. For example, an overlap_factor of 0.5 means 50% overlap. - axis (int): The time axis along which to crop the sig_2d.
time (numpy.ndarray): The time vector associated with the signal. Its length should match the signal’s length along the cropping axis.
Returns: - cropped_windows (numpy.ndarray): The cropped signal windows. The shape depends on the input shape and the specified axis.
- scitex_dsp.demo_sig(sig_type='periodic', batch_size=8, n_chs=19, n_segments=20, t_sec=4, fs=512, freqs_hz=None, verbose=False)[source]
Generate demo signals for various signal types.
- Parameters:
sig_type (str, optional) – Type of signal to generate. Options are “uniform”, “gauss”, “periodic”, “chirp”, “ripple”, “meg”, “tensorpac”, “pac”. Default is “periodic”.
batch_size (int, optional) – Number of batches to generate. Default is 8.
n_chs (int, optional) – Number of channels. Default is 19.
n_segments (int, optional) – Number of segments for tensorpac and pac signals. Default is 20.
t_sec (float, optional) – Duration of the signal in seconds. Default is 4.
fs (int, optional) – Sampling frequency in Hz. Default is 512.
freqs_hz (list or None, optional) – List of frequencies in Hz for periodic signals. If None, random frequencies will be used.
verbose (bool, optional) – If True, print additional information. Default is False.
- Returns:
A tuple containing: - np.ndarray: Generated signal(s) with shape (batch_size, n_chs, time_samples) or (batch_size, n_chs, n_segments, time_samples) for tensorpac and pac signals. - np.ndarray: Time array. - int: Sampling frequency.
- Return type:
- scitex_dsp.detect_ripples(xx, fs, low_hz, high_hz, sd=2.0, smoothing_sigma_ms=4, min_duration_ms=10, return_preprocessed_signal=False)[source]
xx: 2-dimensional (n_chs, seq_len) or 3-dimensional (batch_size, n_chs, seq_len) wide-band signal.
- scitex_dsp.get_eeg_pos(channel_names=['FP1', 'F3', 'C3', 'P3', 'O1', 'FP2', 'F4', 'C4', 'P4', 'O2', 'F7', 'T7', 'P7', 'F8', 'T8', 'P8', 'FZ', 'CZ', 'PZ'])[source]
- scitex_dsp.modulation_index(pha, amp, n_bins=18, amp_prob=False)[source]
pha: (batch_size, n_chs, n_freqs_pha, n_segments, seq_len) amp: (batch_size, n_chs, n_freqs_amp, n_segments, seq_len)
- scitex_dsp.pac(x, fs, pha_start_hz=2, pha_end_hz=20, pha_n_bands=100, amp_start_hz=60, amp_end_hz=160, amp_n_bands=100, device='cuda', batch_size=1, batch_size_ch=-1, fp16=False, trainable=False, n_perm=None, amp_prob=False)[source]
Compute the phase-amplitude coupling (PAC) for signals. This function automatically handles inputs as PyTorch tensors, NumPy arrays, or pandas DataFrames.
Arguments: - x (torch.Tensor | np.ndarray | pd.DataFrame): Input signal. Shape can be either (batch_size, n_chs, seq_len) or - fs (float): Sampling frequency of the input signal. - pha_start_hz (float, optional): Start frequency for phase bands. Default is 2 Hz. - pha_end_hz (float, optional): End frequency for phase bands. Default is 20 Hz. - pha_n_bands (int, optional): Number of phase bands. Default is 100. - amp_start_hz (float, optional): Start frequency for amplitude bands. Default is 60 Hz. - amp_end_hz (float, optional): End frequency for amplitude bands. Default is 160 Hz. - amp_n_bands (int, optional): Number of amplitude bands. Default is 100.
Returns: - torch.Tensor: PAC values. Shape: (batch_size, n_chs, pha_n_bands, amp_n_bands) - numpy.ndarray: Phase bands used for the computation. - numpy.ndarray: Amplitude bands used for the computation.
Example
FS = 512 T_SEC = 4 xx, tt, fs = scitex.dsp.demo_sig(
batch_size=1, n_chs=1, fs=FS, t_sec=T_SEC, sig_type=”tensorpac”
) pac, pha_mids_hz, amp_mids_hz = scitex.dsp.pac(xx, fs)
- scitex_dsp.psd(x, fs, prob=False, dim=-1)[source]
import matplotlib.pyplot as plt
x, t, fs = scitex.dsp.demo_sig() # (batch_size, n_chs, seq_len) pp, ff = psd(x, fs)
# Plots plt, CC = scitex.plt.configure_mpl(plt) fig, ax = scitex.plt.subplots() ax.plot(fs, pp[0, 0]) ax.xlabel(“Frequency [Hz]”) ax.ylabel(“log(Power [uV^2 / Hz]) [a.u.]”) plt.show()
- scitex_dsp.time(start_sec, end_sec, fs)[source]
Linearly spaced time samples between [start_sec, end_sec) at sample rate fs.
Replaces the prior
scitex.gen.float_linspacecall so this module doesn’t pull the umbrellascitexdistribution at import time. The behaviour matches np.linspace(endpoint=False) which is also what the legacy float_linspace returned.