[108]:
import numpy as np
from matplotlib import pyplot as plt
[109]:
t = np.linspace(0, 1, 10000)
eeg = np.sin(12*t) + 0.1 * np.random.random(size=(16, 10000))
split = np.array(range(0, 10000, 300))
# split = np.cumsum(np.random.randint(250, 350, size=(33)))
[110]:
plt.figure(figsize=(30,5), dpi=90)
plt.plot(eeg[0], '-o')
plt.vlines(split, -1, 1, color='C2', zorder=1)
[110]:
<matplotlib.collections.LineCollection at 0x7fc8b0712c40>

[111]:
c = 600
new_data = np.random.random(size=(16, c))
split = np.roll(split, -c)
eeg = np.roll(eeg, -c, axis=1)
eeg[:, -c:] = new_data
[112]:
plt.figure(figsize=(30,5), dpi=90)
plt.plot(eeg[0], '-o')
plt.vlines(split, -1, 1, color='C2', zorder=1)
[112]:
<matplotlib.collections.LineCollection at 0x7fc8b0bec2b0>

[ ]:
[ ]:
[163]:
fs = 1152
s = 28
f = _get_factor_near_to(fs * np.abs(s), n=1000)
f, fs*s
[163]:
(1008, 32256)
[160]:
np.linspace(0, (fs*s), f+1).astype(int)
[160]:
array([ 0, 32, 64, ..., 32192, 32224, 32256])
[ ]:
[115]:
# ----------------------------------------------------------------------
def _get_factor_near_to(x, n=1000):
"""Get the integer number factor of `x` nearest to `n`.
This factor is used to fast resampling.
Parameters
----------
x
Samples.
n
Near factor
Returns
-------
int
Factor.
"""
a = np.array([(x) / np.arange(max(1, (x // n) - 10), (x // n) + 10)])[0]
a[a % 1 != 0] = 0
return int(a[np.argmin(np.abs(a - n))])
[1]:
import numpy as np
[24]:
x = np.random.randint(0, 100, size=20)
y = np.random.randint(0, 100, size=20)
[47]:
np.cov([x, y, x])
[47]:
array([[ 835.14473684, -134.65789474, 835.14473684],
[-134.65789474, 1132.64210526, -134.65789474],
[ 835.14473684, -134.65789474, 835.14473684]])
[28]:
np.cov(y)
[28]:
array(1132.64210526)
[ ]: