{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = np.linspace(0, 1, 10000)\n",
    "eeg = np.sin(12*t) + 0.1 * np.random.random(size=(16, 10000))\n",
    "\n",
    "split = np.array(range(0, 10000, 300))\n",
    "# split = np.cumsum(np.random.randint(250, 350, size=(33)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.LineCollection at 0x7fc8b0712c40>"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 53436 characters]\n",
      "text/plain": [
       "<Figure size 2700x450 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(30,5), dpi=90)\n",
    "\n",
    "plt.plot(eeg[0], '-o')\n",
    "plt.vlines(split, -1, 1, color='C2', zorder=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "c = 600\n",
    "new_data = np.random.random(size=(16, c))\n",
    "\n",
    "split =  np.roll(split, -c)\n",
    "eeg = np.roll(eeg, -c, axis=1)\n",
    "eeg[:, -c:] = new_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.LineCollection at 0x7fc8b0bec2b0>"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 59008 characters]\n",
      "text/plain": [
       "<Figure size 2700x450 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(30,5), dpi=90)\n",
    "\n",
    "plt.plot(eeg[0], '-o')\n",
    "plt.vlines(split, -1, 1, color='C2', zorder=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1008, 32256)"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fs = 1152\n",
    "s = 28\n",
    "f = _get_factor_near_to(fs * np.abs(s), n=1000)\n",
    "f, fs*s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([    0,    32,    64, ..., 32192, 32224, 32256])"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0, (fs*s), f+1).astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ----------------------------------------------------------------------\n",
    "def _get_factor_near_to(x, n=1000):\n",
    "    \"\"\"Get the integer number factor of `x` nearest to `n`.\n",
    "\n",
    "    This factor is used to fast resampling.\n",
    "\n",
    "    Parameters\n",
    "    ----------\n",
    "    x\n",
    "        Samples.\n",
    "    n\n",
    "        Near factor\n",
    "\n",
    "    Returns\n",
    "    -------\n",
    "    int\n",
    "        Factor.\n",
    "    \"\"\"\n",
    "    a = np.array([(x) / np.arange(max(1, (x // n) - 10), (x // n) + 10)])[0]\n",
    "    a[a % 1 != 0] = 0\n",
    "    return int(a[np.argmin(np.abs(a - n))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "x =  np.random.randint(0, 100, size=20)\n",
    "y =  np.random.randint(0, 100, size=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 835.14473684, -134.65789474,  835.14473684],\n",
       "       [-134.65789474, 1132.64210526, -134.65789474],\n",
       "       [ 835.14473684, -134.65789474,  835.14473684]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.cov([x, y, x])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(1132.64210526)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.cov(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
