Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mask = np.ones(data.size, dtype=bool)
# Bandpass filter
data = filter_data(data, sf, freq_broad[0], freq_broad[1], method='fir',
verbose=0)
# The width of the transition band is set to 1.5 Hz on each side,
# meaning that for freq_sp = (12, 15 Hz), the -6 dB points are located at
# 11.25 and 15.75 Hz.
data_sigma = filter_data(data, sf, freq_sp[0], freq_sp[1],
l_trans_bandwidth=1.5, h_trans_bandwidth=1.5,
method='fir', verbose=0)
# Compute the pointwise relative power using interpolated STFT
# Here we use a step of 200 ms to speed up the computation.
f, t, Sxx = stft_power(data, sf, window=2, step=.2, band=freq_broad,
interp=False, norm=True)
idx_sigma = np.logical_and(f >= freq_sp[0], f <= freq_sp[1])
rel_pow = Sxx[idx_sigma].sum(0)
# Let's interpolate `rel_pow` to get one value per sample
# Note that we could also have use the `interp=True` in the `stft_power`
# function, however 2D interpolation is much slower than
# 1D interpolation.
func = interp1d(t, rel_pow, kind='cubic', bounds_error=False,
fill_value=0)
t = np.arange(data.size) / sf
rel_pow = func(t)
# Now we apply moving RMS and correlation on the sigma-filtered signal
_, mcorr = moving_transform(data_sigma, data, sf, window=.3, step=.1,
method='corr', interp=True)