diff --git a/proc/Untitled.ipynb b/proc/Untitled.ipynb index 5215390..834e958 100644 --- a/proc/Untitled.ipynb +++ b/proc/Untitled.ipynb @@ -1,291 +1,361 @@ { "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-02-06T13:42:53.520785Z", - "start_time": "2020-02-06T13:42:52.997099Z" + "end_time": "2020-02-10T16:11:37.736576Z", + "start_time": "2020-02-10T16:11:37.221872Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import os\n", "import pandas as pd \n", "import sys\n", "import matplotlib.pyplot as plt\n", - "from eventBased.descriptor import signalDescriptor, signalDescriptorVector\n", - "from eventBased.EBfilter import FIR\n", + "import eventBased as eb\n", "\n", "dataFolder = '../data'\n", "experiment = 4\n", "sub = 72\n", "dataRwLb = os.path.join(dataFolder, \"dataLabeld\")\n", "dataEBLb = os.path.join(dataFolder, \"dataEB/sub\"+str(sub))\n", "baseFreq = 50\n", "dT = 1/baseFreq\n", "\n", "start = 10000\n", "stop = int(start+baseFreq*2.56)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-02-06T15:23:23.840896Z", - "start_time": "2020-02-06T15:23:23.838748Z" + "end_time": "2020-02-10T16:11:37.739191Z", + "start_time": "2020-02-10T16:11:37.737565Z" } }, "outputs": [], "source": [ "plt.close('all')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-02-06T13:42:53.562846Z", - "start_time": "2020-02-06T13:42:53.525038Z" + "end_time": "2020-02-10T16:11:37.777411Z", + "start_time": "2020-02-10T16:11:37.740526Z" } }, "outputs": [], "source": [ "%matplotlib auto\n", "np.set_printoptions(precision=3)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2020-02-06T13:42:53.565987Z", - "start_time": "2020-02-06T13:42:53.564297Z" - } - }, - "outputs": [], - "source": [ - "import eventBased as eb" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2020-02-06T13:42:53.573045Z", - "start_time": "2020-02-06T13:42:53.567187Z" - } - }, - "outputs": [], - "source": [ - "eb.signalDescriptor" - ] - }, { "cell_type": "markdown", "metadata": {}, "source": [ "## load data " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-02-06T13:42:53.654021Z", - "start_time": "2020-02-06T13:42:53.574079Z" + "start_time": "2020-02-10T16:11:37.216Z" } }, "outputs": [], "source": [ "def getExpNo(s):\n", " idx = 0\n", " for i in range(len(s)):\n", " idx = i\n", " if s[i].isalpha():\n", " break\n", " return int(s[0:idx])\n", "def pik(ls, s):\n", " for e in ls:\n", " if s in e:\n", " return e\n", "def generateFreqScale(dt,N, correctCoeff = None):\n", " if correctCoeff:\n", " dt *= correctCoeff\n", " fs = np.arange(-1/(2*dt),1/(2*dt)-dT/10,1/(dt*N))\n", " return fs \n", "\n", "pathToRwFiles = sorted([os.path.join(dataRwLb,x) for x in os.listdir(dataRwLb) if getExpNo(x) == experiment])\n", "pathToEBFiles = sorted([os.path.join(dataEBLb,x) for x in os.listdir(dataEBLb) if getExpNo(x) == experiment])\n", "\n", "#Original data ---------------------------------------\n", "dataAccRw = pd.read_csv(pik(pathToRwFiles, \"acc\"))\n", "dataGyroRw = pd.read_csv(pik(pathToRwFiles, \"gyro\"))\n", "\n", "#EB data ---------------------------------------\n", "dataAccX = pd.read_csv(pik(pathToEBFiles, \"accx\"), header = None)\n", "dataAccY = pd.read_csv(pik(pathToEBFiles, \"accy\"), header = None)\n", "dataAccZ = pd.read_csv(pik(pathToEBFiles, \"accz\"), header = None)\n", "dataGyroX = pd.read_csv(pik(pathToEBFiles, \"gyrox\"), header = None)\n", "dataGyroY = pd.read_csv(pik(pathToEBFiles, \"gyroy\"), header = None)\n", "dataGyroZ = pd.read_csv(pik(pathToEBFiles, \"gyroz\"), header = None)\n", "\n", "#Some infos:\n", "lengthT = len(dataAccRw)/baseFreq\n", "print(\"Length of the signal, in seconds: {}s\".format(lengthT))\n", "print(\"--------------------------------------------------------------------\")\n", "avgFreqAccX = len(dataAccX)/lengthT\n", "print(\"Average frequency for the x accelerometer: {}Hz\".format(avgFreqAccX))\n", "avgFreqAccY = len(dataAccY)/lengthT\n", "print(\"Average frequency for the y accelerometer: {}Hz\".format(avgFreqAccY))\n", "avgFreqAccZ = len(dataAccZ)/lengthT\n", "print(\"Average frequency for the z accelerometer: {}Hz\".format(avgFreqAccZ))\n", "print(\"--------------------------------------------------------------------\")\n", "avgFreqGyroX = len(dataGyroX)/lengthT\n", "print(\"Average frequency for the x gyroscope: {}Hz\".format(avgFreqGyroX))\n", "avgFreqGyroY = len(dataGyroY)/lengthT\n", "print(\"Average frequency for the y gyroscope: {}Hz\".format(avgFreqGyroY))\n", "avgFreqGyroZ = len(dataGyroZ)/lengthT\n", "print(\"Average frequency for the z gyroscope: {}Hz\".format(avgFreqGyroZ))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-02-06T13:42:53.696208Z", - "start_time": "2020-02-06T13:42:53.655195Z" + "start_time": "2020-02-10T16:11:37.218Z" + } + }, + "outputs": [], + "source": [ + "accx = [list(dataAccX[0]),list(dataAccX[1]),list(dataAccX[2])]\n", + "accy = [list(dataAccY[0]),list(dataAccY[1]),list(dataAccY[2])]\n", + "accz = [list(dataAccZ[0]),list(dataAccZ[1]),list(dataAccZ[2])]\n", + "\n", + "gyrox = [list(dataGyroX[0]),list(dataGyroX[1]),list(dataGyroX[2])]\n", + "gyroy = [list(dataGyroY[0]),list(dataGyroY[1]),list(dataGyroY[2])]\n", + "gyroz = [list(dataGyroZ[0]),list(dataGyroZ[1]),list(dataGyroZ[2])]\n", + "\n", + "dictSigNames = {'accx': 0,'accy': 1,'accz': 2,'gyrox': 3,'gyroy': 4,'gyroz': 5}\n", + "\n", + "stream = eb.VectorStreamer()\n", + "stream.load(dictSigNames.keys(),accx,accy,accz,gyrox,gyroy,gyroz)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-02-10T16:11:37.219Z" + } + }, + "outputs": [], + "source": [ + "f1 = [1,1,1,1]\n", + "f2 = [1,2,3,4,5,6]\n", + "f3 = [-1,-2,-3,-2,-1,0,1,2,3,2,1,0,-1,-2,-3,-2,-1,0]\n", + "a = eb.inertial.inertial(filtersTaps=[f1,f2,f3])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-02-10T16:11:37.221Z" + } + }, + "outputs": [], + "source": [ + "for elem in stream.get():\n", + " a.buildTrain(elem[0],elem[1],elem[2],dictSigNames[elem[3]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-02-10T16:11:37.226Z" } }, "outputs": [], "source": [ "eb = signalDescriptor(dataAccX[0],dataAccX[1])\n", "rw = signalDescriptor(np.arange(len(dataAccRw['x'])),dataAccRw['x'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-02-06T13:42:54.010494Z", - "start_time": "2020-02-06T13:42:53.697294Z" + "start_time": "2020-02-10T16:11:37.227Z" } }, "outputs": [], "source": [ "fEB = eb.nudft(startT = start, endT = stop)\n", "fRW = rw.nudft(startT = start, endT = stop-1)\n", "print(\"Finished nuDft\")\n", "fEBres = eb.resampledDFT(startT = start, endT = stop)\n", "fRWres = rw.resampledDFT(startT = start, endT = stop)\n", "print(\"Finished reDft\")\n", "f = np.fft.fft(dataAccRw['x'][start:stop])\n", "print(\"Finished numpy fft\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-02-06T13:42:54.560252Z", - "start_time": "2020-02-06T13:42:54.011527Z" + "start_time": "2020-02-10T16:11:37.229Z" } }, "outputs": [], "source": [ "fRWScale = generateFreqScale(dT,len(f))\n", "fEBScale = generateFreqScale(dT,len(fEB),len(f)/len(fEB))\n", "#--------------------------------------\n", "plt.figure()\n", "plt.title(\"data Raw\")\n", "plt.plot(dataAccRw['x'][start:stop])\n", "\n", "plt.figure()\n", "plt.title(\"data EB sampled\")\n", "t,v = eb.findInterval(start,stop)\n", "plt.plot(t,v)\n", "#--------------------------------------\n", "plt.figure()\n", "plt.title(\"Non uniform DFT on Event Based\")\n", "plt.plot(fEBScale,np.abs(eb.shift(fEB)))\n", "\n", "plt.figure()\n", "plt.title(\"Non uniform DFT on Raw\")\n", "plt.plot(fRWScale,np.abs(rw.shift(fRW)))\n", "#---------------------------------------\n", "plt.figure()\n", "plt.title(\"uniform DFT on re-sampled Event Based\")\n", "plt.plot(fRWScale,np.abs(eb.shift(fEBres)))\n", "\n", "plt.figure()\n", "plt.title(\"uniform DFT on raw signal\")\n", "plt.plot(fRWScale,np.abs(rw.shift(fRWres)))\n", "#---------------------------------------\n", "plt.figure()\n", "plt.title(\"Numpy FFT on the original signal\")\n", "plt.plot(fRWScale,np.abs(rw.shift(f)))" ] } ], "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.7.1" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }