SetSamplingRate¶
- class torcheeg.transforms.SetSamplingRate(origin_sampling_rate: int, target_sampling_rate: int, apply_to_baseline=False, axis=-1, scale: bool = False, res_type: str = 'soxr_hq')[source][source]¶
Resample a EEG series from orig_sr to target_sr.
from torcheeg import transforms t = SetSamplingRate(origin=500,target_sampling_rate=128) t(eeg=np.random.randn(32, 1000))['eeg'].shape >>> (32, 256)
- Parameters:
origin (int) – Original sampling rate of EEG.
target_sampling_rate (int) – Target sampling rate of EEG.
apply_to_baseline – (bool): Whether to act on the baseline signal at the same time, if the baseline is passed in when calling. (default:
False)axis (int, optional) – The dimension to normalize, when no dimension is specified, the entire data is normalized. (default:
-1)scale (bool, optional) – Whether to scale the resampled signal so that
yandy_hathave approximately equal total energy. (default:False)res_type (str, optional) –
The resampling method to use. (default:
'soxr_hq'), options:- ’soxr_vhq’, ‘soxr_hq’, ‘soxr_mq’ or ‘soxr_lq’
soxr Very high-, High-, Medium-, Low-quality FFT-based bandlimited interpolation.
'soxr_hq'is the default setting of soxr.- ’soxr_qq’
soxr Quick cubic interpolation (very fast, but not bandlimited)
- ’kaiser_best’
resampy high-quality mode
- ’kaiser_fast’
resampy faster method
- ’fft’ or ‘scipy’
scipy.signal.resample Fourier method.
- ’polyphase’
scipy.signal.resample_poly polyphase filtering. (fast)
- ’linear’
samplerate linear interpolation. (very fast, but not bandlimited)
- ’zero_order_hold’
samplerate repeat the last value between samples. (very fast, but not bandlimited)
- ’sinc_best’, ‘sinc_medium’ or ‘sinc_fastest’
samplerate high-, medium-, and low-quality bandlimited sinc interpolation.
Note
Not all options yield a bandlimited interpolator. If you use soxr_qq, polyphase, linear, or zero_order_hold, you need to be aware of possible aliasing effects.
Note
samplerate and resampy are not installed with torcheeg by default. To use samplerate or resampy, they should be installed manually:
$ pip install samplerate $ pip install resampy
Note
When using
res_type='polyphase', only integer sampling rates are supported.