{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib\nimport matplotlib.pyplot as plt\nfrom scipy.signal import find_peaks","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-26T14:20:44.087498Z","iopub.execute_input":"2023-03-26T14:20:44.088139Z","iopub.status.idle":"2023-03-26T14:20:44.568177Z","shell.execute_reply.started":"2023-03-26T14:20:44.088103Z","shell.execute_reply":"2023-03-26T14:20:44.567030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/06414383cf.csv')\ndata","metadata":{"execution":{"iopub.status.busy":"2023-03-26T14:20:45.897404Z","iopub.execute_input":"2023-03-26T14:20:45.897934Z","iopub.status.idle":"2023-03-26T14:20:46.311912Z","shell.execute_reply.started":"2023-03-26T14:20:45.897888Z","shell.execute_reply":"2023-03-26T14:20:46.310146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['raiz']=np.sqrt(data['AccV']*data['AccV']+data['AccML']*data['AccML']+data['AccAP']*data['AccAP'])\ndata","metadata":{"execution":{"iopub.status.busy":"2023-03-26T14:20:48.929625Z","iopub.execute_input":"2023-03-26T14:20:48.930056Z","iopub.status.idle":"2023-03-26T14:20:48.960503Z","shell.execute_reply.started":"2023-03-26T14:20:48.930021Z","shell.execute_reply":"2023-03-26T14:20:48.959107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"turn=data.query(\"Turn==1 and Valid==True\")\nturn","metadata":{"execution":{"iopub.status.busy":"2023-03-26T14:22:24.191715Z","iopub.execute_input":"2023-03-26T14:22:24.192211Z","iopub.status.idle":"2023-03-26T14:22:24.223122Z","shell.execute_reply.started":"2023-03-26T14:22:24.192169Z","shell.execute_reply":"2023-03-26T14:22:24.221625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[83800:83850]\n#43368-43530 ====162\n#83809-89016 ===5207","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(data['AccV'][43000:44000],'b-')\nplt.plot(data['AccML'][43000:44000],'r-')\nplt.plot(data['AccAP'][43000:44000],'y-')\nplt.show","metadata":{"execution":{"iopub.status.busy":"2023-03-26T14:48:34.823309Z","iopub.execute_input":"2023-03-26T14:48:34.823795Z","iopub.status.idle":"2023-03-26T14:48:35.098514Z","shell.execute_reply.started":"2023-03-26T14:48:34.823740Z","shell.execute_reply":"2023-03-26T14:48:35.097391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(data['AccV'][83000:84000],'b-')\nplt.plot(data['AccML'][83000:84000],'r-')\nplt.plot(data['AccAP'][83000:84000],'y-')\nplt.show","metadata":{"execution":{"iopub.status.busy":"2023-03-26T14:50:58.087342Z","iopub.execute_input":"2023-03-26T14:50:58.087771Z","iopub.status.idle":"2023-03-26T14:50:58.338653Z","shell.execute_reply.started":"2023-03-26T14:50:58.087734Z","shell.execute_reply":"2023-03-26T14:50:58.336764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#43368---43530","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plt.plot(data['AccV'][:1000],'b-')\nplt.plot(data['AccV'][:50000],'r-')\nplt.plot(data['AccML'][:50000],'g-')\nplt.plot(data['AccAP'][:50000],'y-')\nplt.show","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:08:36.833356Z","iopub.execute_input":"2023-03-26T03:08:36.833779Z","iopub.status.idle":"2023-03-26T03:08:37.233682Z","shell.execute_reply.started":"2023-03-26T03:08:36.833744Z","shell.execute_reply":"2023-03-26T03:08:37.232065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_peaks(data):\n    peaks_x = []\n    \n    for i in range(1, len(data)-1):\n        \n        if ( data[i]>data[i-1] and data[i]>data[i+1]):\n            if (data[i]>-0.8 ):\n                peaks_x.append(i)\n        if ( data[i]<data[i-1] and data[i]<data[i+1]):\n            if (data[i]<-1.2 ):\n                peaks_x.append(i)       \n    return peaks_x\n","metadata":{"execution":{"iopub.status.busy":"2023-03-26T14:55:31.410879Z","iopub.execute_input":"2023-03-26T14:55:31.411337Z","iopub.status.idle":"2023-03-26T14:55:31.420267Z","shell.execute_reply.started":"2023-03-26T14:55:31.411301Z","shell.execute_reply":"2023-03-26T14:55:31.418828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datt=data['AccV'][:2000]\npeaks_x=get_peaks(datt)","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:08:49.235133Z","iopub.execute_input":"2023-03-26T03:08:49.235580Z","iopub.status.idle":"2023-03-26T03:08:49.290985Z","shell.execute_reply.started":"2023-03-26T03:08:49.235542Z","shell.execute_reply":"2023-03-26T03:08:49.289523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"peaks_y=[data['AccV'][index] for index in peaks_x]","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:08:52.332623Z","iopub.execute_input":"2023-03-26T03:08:52.333256Z","iopub.status.idle":"2023-03-26T03:08:52.340864Z","shell.execute_reply.started":"2023-03-26T03:08:52.333200Z","shell.execute_reply":"2023-03-26T03:08:52.339437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(datt,'b-')\nplt.plot(peaks_x, peaks_y, 'ro')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:10:18.280312Z","iopub.execute_input":"2023-03-26T03:10:18.280886Z","iopub.status.idle":"2023-03-26T03:10:18.514401Z","shell.execute_reply.started":"2023-03-26T03:10:18.280838Z","shell.execute_reply":"2023-03-26T03:10:18.513020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Funcion find_peaks","metadata":{}},{"cell_type":"code","source":"from scipy import constants\nfrom scipy.signal import spectrogram, find_peaks","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:10:20.810858Z","iopub.execute_input":"2023-03-26T03:10:20.811351Z","iopub.status.idle":"2023-03-26T03:10:20.818054Z","shell.execute_reply.started":"2023-03-26T03:10:20.811310Z","shell.execute_reply":"2023-03-26T03:10:20.816407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"arr_dat=np.asarray(datt)","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:10:22.976144Z","iopub.execute_input":"2023-03-26T03:10:22.976570Z","iopub.status.idle":"2023-03-26T03:10:22.985075Z","shell.execute_reply.started":"2023-03-26T03:10:22.976533Z","shell.execute_reply":"2023-03-26T03:10:22.983143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"peaks, _ = find_peaks(arr_dat)\npeaks_y=[data['AccV'][index] for index in peaks]\npeaks","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:10:25.207020Z","iopub.execute_input":"2023-03-26T03:10:25.208222Z","iopub.status.idle":"2023-03-26T03:10:25.222712Z","shell.execute_reply.started":"2023-03-26T03:10:25.208141Z","shell.execute_reply":"2023-03-26T03:10:25.220942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(arr_dat)\nplt.plot(peaks, arr_dat[peaks], \"x\")\n#plt.plot(-1, \"--\", color=\"gray\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:10:29.127973Z","iopub.execute_input":"2023-03-26T03:10:29.128394Z","iopub.status.idle":"2023-03-26T03:10:29.363557Z","shell.execute_reply.started":"2023-03-26T03:10:29.128352Z","shell.execute_reply":"2023-03-26T03:10:29.362184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"peaks, _ = find_peaks(arr_dat, distance=10)\nnp.diff(peaks)\n\nplt.plot(arr_dat)\nplt.plot(peaks, arr_dat[peaks], \"x\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:10:32.497795Z","iopub.execute_input":"2023-03-26T03:10:32.498258Z","iopub.status.idle":"2023-03-26T03:10:32.743148Z","shell.execute_reply.started":"2023-03-26T03:10:32.498222Z","shell.execute_reply":"2023-03-26T03:10:32.741560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"peaks, properties = find_peaks(arr_dat, prominence=(None, 0.6))\nproperties[\"prominences\"].max()\n\nplt.plot(arr_dat)\nplt.plot(peaks, arr_dat[peaks], \"x\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:13:40.997610Z","iopub.execute_input":"2023-03-26T03:13:40.998064Z","iopub.status.idle":"2023-03-26T03:13:41.246227Z","shell.execute_reply.started":"2023-03-26T03:13:40.998027Z","shell.execute_reply":"2023-03-26T03:13:41.244823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"peaks, properties = find_peaks(arr_dat, prominence=0.9, width=2)\nproperties[\"prominences\"], properties[\"widths\"]\nplt.plot(arr_dat)\nplt.plot(peaks, arr_dat[peaks], \"x\")\nplt.vlines(x=peaks, ymin=arr_dat[peaks] - properties[\"prominences\"],\n           ymax = arr_dat[peaks], color = \"C1\")\nplt.hlines(y=properties[\"width_heights\"], xmin=properties[\"left_ips\"],\n           xmax=properties[\"right_ips\"], color = \"C1\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:14:53.762990Z","iopub.execute_input":"2023-03-26T03:14:53.763489Z","iopub.status.idle":"2023-03-26T03:14:54.007082Z","shell.execute_reply.started":"2023-03-26T03:14:53.763447Z","shell.execute_reply":"2023-03-26T03:14:54.005781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nfrom scipy import signal\n\npeakind = signal.find_peaks_cwt(arr_dat, np.arange(1,10))\npeakind, arr_dat[peakind]","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:14:49.401730Z","iopub.execute_input":"2023-03-26T03:14:49.402724Z","iopub.status.idle":"2023-03-26T03:14:49.479552Z","shell.execute_reply.started":"2023-03-26T03:14:49.402665Z","shell.execute_reply":"2023-03-26T03:14:49.477893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from scipy.signal import find_peaks, peak_prominences\nimport matplotlib.pyplot as plt\npeaks, _ = find_peaks(arr_dat)\nprominences = peak_prominences(arr_dat, peaks)[0]\nprominences","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:13:51.575736Z","iopub.execute_input":"2023-03-26T03:13:51.577161Z","iopub.status.idle":"2023-03-26T03:13:51.592635Z","shell.execute_reply.started":"2023-03-26T03:13:51.577102Z","shell.execute_reply":"2023-03-26T03:13:51.591183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"contour_heights = arr_dat[peaks] - prominences\nplt.plot(arr_dat)\nplt.plot(peaks, arr_dat[peaks], \"x\")\nplt.vlines(x=peaks, ymin=contour_heights, ymax=arr_dat[peaks])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:13:55.669432Z","iopub.execute_input":"2023-03-26T03:13:55.670174Z","iopub.status.idle":"2023-03-26T03:13:55.929328Z","shell.execute_reply.started":"2023-03-26T03:13:55.670133Z","shell.execute_reply":"2023-03-26T03:13:55.928059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install sensormotion","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:14:05.589151Z","iopub.execute_input":"2023-03-26T03:14:05.589609Z","iopub.status.idle":"2023-03-26T03:14:21.764995Z","shell.execute_reply.started":"2023-03-26T03:14:05.589572Z","shell.execute_reply":"2023-03-26T03:14:21.762805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sensormotion as sm","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:14:32.190172Z","iopub.execute_input":"2023-03-26T03:14:32.190611Z","iopub.status.idle":"2023-03-26T03:14:32.196660Z","shell.execute_reply.started":"2023-03-26T03:14:32.190575Z","shell.execute_reply":"2023-03-26T03:14:32.195394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"help(sm.gait)","metadata":{"execution":{"iopub.status.busy":"2023-03-26T03:14:33.716510Z","iopub.execute_input":"2023-03-26T03:14:33.717016Z","iopub.status.idle":"2023-03-26T03:14:33.726447Z","shell.execute_reply.started":"2023-03-26T03:14:33.716974Z","shell.execute_reply":"2023-03-26T03:14:33.724750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}