{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":41880,"databundleVersionId":5677426,"sourceType":"competition"}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Dataframes and data processing\nimport pandas as pd\n\n# Linear algebra and math\nimport numpy as np \nfrom scipy.integrate import cumtrapz\nfrom scipy.signal import hilbert\n\n# Visualization\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline\n\n# For random choices within a list\nimport random\n\n# Accesing files in a folder\nimport os\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-25T16:34:31.668975Z","iopub.execute_input":"2024-01-25T16:34:31.669372Z","iopub.status.idle":"2024-01-25T16:34:32.77889Z","shell.execute_reply.started":"2024-01-25T16:34:31.669339Z","shell.execute_reply":"2024-01-25T16:34:32.777698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Iterate through each CSV file and check for the presence of targets\nfiles_with_one_target = []\n\nfor csv_file in csv_files:\n    file_path = os.path.join(folder_path, csv_file)\n    df = pd.read_csv(file_path)\n\n    # Check if any of the target columns has at least one episode (value of 1)\n    has_targets = any(df[['Turn', 'Walking', 'StartHesitation']].any(axis=1))\n\n    if has_targets:\n        files_with_one_target.append(csv_file)","metadata":{"execution":{"iopub.status.busy":"2024-01-23T18:22:22.77627Z","iopub.execute_input":"2024-01-23T18:22:22.776711Z","iopub.status.idle":"2024-01-23T18:22:34.901106Z","shell.execute_reply.started":"2024-01-23T18:22:22.776668Z","shell.execute_reply":"2024-01-23T18:22:34.900202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'The number of files with at least one of the three FOG events in the tdcsgfog dataset is: {len(files_with_one_target)}/833')","metadata":{"execution":{"iopub.status.busy":"2024-01-23T18:23:13.194436Z","iopub.execute_input":"2024-01-23T18:23:13.194866Z","iopub.status.idle":"2024-01-23T18:23:13.200249Z","shell.execute_reply.started":"2024-01-23T18:23:13.194833Z","shell.execute_reply":"2024-01-23T18:23:13.199228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Adjust the folder path to match the Kaggle dataset structure\nfolder_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog'\n\n# List all CSV files in the folder\ncsv_files = [file for file in os.listdir(folder_path) if file.endswith('.csv')]\n\n# Iterate through each CSV file and check for the presence of all three targets\nfiles_with_targets = []\n\nfor csv_file in csv_files:\n    file_path = os.path.join(folder_path, csv_file)\n    df = pd.read_csv(file_path)\n\n    # Check if the file has at least one episode for each target\n    if any(df['Turn'].eq(1)) and any(df['Walking'].eq(1)) and any(df['StartHesitation'].eq(1)):\n        files_with_targets.append(csv_file)","metadata":{"execution":{"iopub.status.busy":"2024-01-23T18:12:52.792867Z","iopub.execute_input":"2024-01-23T18:12:52.79396Z","iopub.status.idle":"2024-01-23T18:13:06.059645Z","shell.execute_reply.started":"2024-01-23T18:12:52.793918Z","shell.execute_reply":"2024-01-23T18:13:06.058559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'The number of files with the three FOG events in the tdcsgfog dataset is: {len(files_with_targets)}/833')","metadata":{"execution":{"iopub.status.busy":"2024-01-23T18:14:35.18171Z","iopub.execute_input":"2024-01-23T18:14:35.182161Z","iopub.status.idle":"2024-01-23T18:14:35.187994Z","shell.execute_reply.started":"2024-01-23T18:14:35.182124Z","shell.execute_reply":"2024-01-23T18:14:35.186745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if files_with_targets:\n    random_file = random.choice(files_with_targets)\n    print(\"Randomly selected file with targets:\", random_file)","metadata":{"execution":{"iopub.status.busy":"2024-01-23T18:10:49.695325Z","iopub.execute_input":"2024-01-23T18:10:49.695738Z","iopub.status.idle":"2024-01-23T18:10:49.701508Z","shell.execute_reply.started":"2024-01-23T18:10:49.695707Z","shell.execute_reply":"2024-01-23T18:10:49.70057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/692e9e05ef.csv') # sample_subject\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:39.499647Z","iopub.execute_input":"2024-01-25T16:34:39.500169Z","iopub.status.idle":"2024-01-25T16:34:39.561813Z","shell.execute_reply.started":"2024-01-25T16:34:39.500127Z","shell.execute_reply":"2024-01-25T16:34:39.560752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Time-series plot</font>\n","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['AccV'], label='AccV')\n\ntime = data['Time']\nacc_v = data['AccV']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], acc_v[mask], label=f'{label} Event', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Acceleration')\nplt.title('Vertical accerleration over time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:42.99227Z","iopub.execute_input":"2024-01-25T16:34:42.992666Z","iopub.status.idle":"2024-01-25T16:34:43.420491Z","shell.execute_reply.started":"2024-01-25T16:34:42.992633Z","shell.execute_reply":"2024-01-25T16:34:43.419498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Magnitude of acceleration or radial distance</font>","metadata":{}},{"cell_type":"code","source":"data['Acc_Mag'] = np.sqrt(data['AccV']**2+data['AccML']**2+data['AccAP']**2)","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:43.422511Z","iopub.execute_input":"2024-01-25T16:34:43.423194Z","iopub.status.idle":"2024-01-25T16:34:43.431102Z","shell.execute_reply.started":"2024-01-25T16:34:43.423148Z","shell.execute_reply":"2024-01-25T16:34:43.430041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['Acc_Mag'], label='Acc_Mag')\n\ntime = data['Time']\nAcc_Mag = data['Acc_Mag']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], Acc_Mag[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Acceleration')\nplt.title('Magnitude of Acceleration over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:43.573808Z","iopub.execute_input":"2024-01-25T16:34:43.574465Z","iopub.status.idle":"2024-01-25T16:34:43.987112Z","shell.execute_reply.started":"2024-01-25T16:34:43.574433Z","shell.execute_reply":"2024-01-25T16:34:43.985911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Inclination angle (theta)</font>","metadata":{}},{"cell_type":"code","source":"data['Theta'] = np.arccos(data['AccV']/data['Acc_Mag'])","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:43.988912Z","iopub.execute_input":"2024-01-25T16:34:43.989255Z","iopub.status.idle":"2024-01-25T16:34:43.998756Z","shell.execute_reply.started":"2024-01-25T16:34:43.989225Z","shell.execute_reply":"2024-01-25T16:34:43.997715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['Theta'], label='Theta')\n\ntime = data['Time']\ntheta = data['Theta']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], theta[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Acceleration')\nplt.title('Inclination angle over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:44.178074Z","iopub.execute_input":"2024-01-25T16:34:44.178733Z","iopub.status.idle":"2024-01-25T16:34:44.571453Z","shell.execute_reply.started":"2024-01-25T16:34:44.178698Z","shell.execute_reply":"2024-01-25T16:34:44.570324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Azimuth angle (phi)</font>","metadata":{}},{"cell_type":"code","source":"data['Phi'] = np.arctan2(data['AccAP'],data['AccML'])","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:44.573235Z","iopub.execute_input":"2024-01-25T16:34:44.573598Z","iopub.status.idle":"2024-01-25T16:34:44.58012Z","shell.execute_reply.started":"2024-01-25T16:34:44.573569Z","shell.execute_reply":"2024-01-25T16:34:44.578919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['Phi'], label='Phi')\n\ntime = data['Time']\nphi = data['Phi']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], phi[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Acceleration')\nplt.title('Azimuth angle over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:44.731443Z","iopub.execute_input":"2024-01-25T16:34:44.731821Z","iopub.status.idle":"2024-01-25T16:34:45.16005Z","shell.execute_reply.started":"2024-01-25T16:34:44.73179Z","shell.execute_reply":"2024-01-25T16:34:45.158907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Jolt (Derivative of acceleration)</font>","metadata":{}},{"cell_type":"code","source":"data['JoltAP'] = np.gradient(data['AccAP'],data['Time'], edge_order = 2)\ndata['JoltML'] = np.gradient(data['AccML'],data['Time'], edge_order = 2)\ndata['JoltV'] = np.gradient(data['AccV'],data['Time'], edge_order = 2)","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:45.162296Z","iopub.execute_input":"2024-01-25T16:34:45.162753Z","iopub.status.idle":"2024-01-25T16:34:45.173317Z","shell.execute_reply.started":"2024-01-25T16:34:45.162712Z","shell.execute_reply":"2024-01-25T16:34:45.17206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['JoltAP'], label='JoltAP')\n\ntime = data['Time']\njoltAP = data['JoltAP']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], joltAP[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Jolt')\nplt.title('Anteroposterior jolt over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:45.297971Z","iopub.execute_input":"2024-01-25T16:34:45.298696Z","iopub.status.idle":"2024-01-25T16:34:45.687068Z","shell.execute_reply.started":"2024-01-25T16:34:45.298662Z","shell.execute_reply":"2024-01-25T16:34:45.685987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['JoltML'], label='JoltML')\n\ntime = data['Time']\njoltML = data['JoltML']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], joltML[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Jolt')\nplt.title('Mediolateral jolt over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:45.689023Z","iopub.execute_input":"2024-01-25T16:34:45.689382Z","iopub.status.idle":"2024-01-25T16:34:46.058071Z","shell.execute_reply.started":"2024-01-25T16:34:45.689352Z","shell.execute_reply":"2024-01-25T16:34:46.057016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['JoltV'], label='JoltV')\n\ntime = data['Time']\njoltV = data['JoltV']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], joltV[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Jolt')\nplt.title('Vertical jolt over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:46.059338Z","iopub.execute_input":"2024-01-25T16:34:46.059909Z","iopub.status.idle":"2024-01-25T16:34:46.442541Z","shell.execute_reply.started":"2024-01-25T16:34:46.059853Z","shell.execute_reply":"2024-01-25T16:34:46.441355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Velocity (Integral of acceleration)</font>","metadata":{}},{"cell_type":"code","source":"time_diff = np.diff(data['Time'])\ntime_diff = np.concatenate(([0],time_diff))\ndata['Time_diff'] = time_diff","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:46.445276Z","iopub.execute_input":"2024-01-25T16:34:46.445801Z","iopub.status.idle":"2024-01-25T16:34:46.45352Z","shell.execute_reply.started":"2024-01-25T16:34:46.445761Z","shell.execute_reply":"2024-01-25T16:34:46.452323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['VelAP'] = np.cumsum(data['AccAP']*data['Time_diff'])\ndata['VelML'] = np.cumsum(data['AccML'])*data['Time_diff']\ndata['VelV'] = np.cumsum(data['AccV'])*data['Time_diff']","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:46.454778Z","iopub.execute_input":"2024-01-25T16:34:46.455102Z","iopub.status.idle":"2024-01-25T16:34:46.466721Z","shell.execute_reply.started":"2024-01-25T16:34:46.455076Z","shell.execute_reply":"2024-01-25T16:34:46.465818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['VelV'], label='VelV')\n\ntime = data['Time']\nvelV = data['VelV']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], velV[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Velocity')\nplt.title('Vertical velocity over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:46.775337Z","iopub.execute_input":"2024-01-25T16:34:46.776225Z","iopub.status.idle":"2024-01-25T16:34:47.127019Z","shell.execute_reply.started":"2024-01-25T16:34:46.77619Z","shell.execute_reply":"2024-01-25T16:34:47.125913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['VelML'], label='VelML')\n\ntime = data['Time']\nvelML = data['VelML']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], velML[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Velocity')\nplt.title('Mediolateral velocity over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:47.129343Z","iopub.execute_input":"2024-01-25T16:34:47.129705Z","iopub.status.idle":"2024-01-25T16:34:47.515485Z","shell.execute_reply.started":"2024-01-25T16:34:47.129674Z","shell.execute_reply":"2024-01-25T16:34:47.514329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['VelAP'], label='VelAP')\n\ntime = data['Time']\nvelAP = data['VelAP']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], velAP[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Velocity')\nplt.title('Anteroposterior velocity over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:47.516707Z","iopub.execute_input":"2024-01-25T16:34:47.517063Z","iopub.status.idle":"2024-01-25T16:34:47.902497Z","shell.execute_reply.started":"2024-01-25T16:34:47.517034Z","shell.execute_reply":"2024-01-25T16:34:47.901544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['VelAP'] = cumtrapz(data['AccAP'], dx=np.diff(data['Time']), initial=0)","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:47.903684Z","iopub.execute_input":"2024-01-25T16:34:47.904005Z","iopub.status.idle":"2024-01-25T16:34:47.910221Z","shell.execute_reply.started":"2024-01-25T16:34:47.90398Z","shell.execute_reply":"2024-01-25T16:34:47.909276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"time = data['Time']\nvelAP = data['VelAP']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], velAP[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Velocity')\nplt.title('Anteroposterior velocity over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:47.91341Z","iopub.execute_input":"2024-01-25T16:34:47.914Z","iopub.status.idle":"2024-01-25T16:34:48.348927Z","shell.execute_reply.started":"2024-01-25T16:34:47.913961Z","shell.execute_reply":"2024-01-25T16:34:48.347841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['HilAP'] = hilbert(data['AccAP'])\ndata['HilML'] = hilbert(data['AccML'])\ndata['HilV'] = hilbert(data['AccV'])","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:48.350229Z","iopub.execute_input":"2024-01-25T16:34:48.350616Z","iopub.status.idle":"2024-01-25T16:34:48.368425Z","shell.execute_reply.started":"2024-01-25T16:34:48.350586Z","shell.execute_reply":"2024-01-25T16:34:48.367578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['HilAP'], label='HilAP')\n\ntime = data['Time']\nHilAP = data['HilAP']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], HilAP[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('Anteroposterior Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:48.36982Z","iopub.execute_input":"2024-01-25T16:34:48.370467Z","iopub.status.idle":"2024-01-25T16:34:48.7548Z","shell.execute_reply.started":"2024-01-25T16:34:48.370429Z","shell.execute_reply":"2024-01-25T16:34:48.753806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['HilV'], label='HilV')\n\ntime = data['Time']\nHilV = data['HilV']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], HilV[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('Vertical Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:48.756171Z","iopub.execute_input":"2024-01-25T16:34:48.756496Z","iopub.status.idle":"2024-01-25T16:34:49.144779Z","shell.execute_reply.started":"2024-01-25T16:34:48.756469Z","shell.execute_reply":"2024-01-25T16:34:49.143925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['HilML'], label='HilML')\n\ntime = data['Time']\nHilML = data['HilML']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], HilML[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('Mediolateral Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:49.14724Z","iopub.execute_input":"2024-01-25T16:34:49.147908Z","iopub.status.idle":"2024-01-25T16:34:49.574594Z","shell.execute_reply.started":"2024-01-25T16:34:49.147875Z","shell.execute_reply":"2024-01-25T16:34:49.573542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:49.575991Z","iopub.execute_input":"2024-01-25T16:34:49.576599Z","iopub.status.idle":"2024-01-25T16:34:49.603914Z","shell.execute_reply.started":"2024-01-25T16:34:49.576555Z","shell.execute_reply":"2024-01-25T16:34:49.602922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Magnitude (abs value) in Hilbert phase</font>","metadata":{}},{"cell_type":"code","source":"data['absHilAP'] = abs(data['HilAP'])\ndata['absHilML'] = abs(data['HilML'])\ndata['absHilV'] = abs(data['HilV'])","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:49.605473Z","iopub.execute_input":"2024-01-25T16:34:49.606249Z","iopub.status.idle":"2024-01-25T16:34:49.614703Z","shell.execute_reply.started":"2024-01-25T16:34:49.606209Z","shell.execute_reply":"2024-01-25T16:34:49.613829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['absHilML'], label='absHilML')\n\ntime = data['Time']\nabsHilML = data['absHilML']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], absHilML[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('abs Mediolateral Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:49.616168Z","iopub.execute_input":"2024-01-25T16:34:49.616495Z","iopub.status.idle":"2024-01-25T16:34:50.00276Z","shell.execute_reply.started":"2024-01-25T16:34:49.616468Z","shell.execute_reply":"2024-01-25T16:34:50.001581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['absHilV'], label='absHilV')\n\ntime = data['Time']\nabsHilV = data['absHilV']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], absHilV[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('abs Vertical Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:50.005528Z","iopub.execute_input":"2024-01-25T16:34:50.00598Z","iopub.status.idle":"2024-01-25T16:34:50.38728Z","shell.execute_reply.started":"2024-01-25T16:34:50.00594Z","shell.execute_reply":"2024-01-25T16:34:50.386186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['absHilAP'], label='absHilAP')\n\ntime = data['Time']\nabsHilAP = data['absHilAP']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], absHilAP[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('abs Anteroposterior Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:50.388692Z","iopub.execute_input":"2024-01-25T16:34:50.389033Z","iopub.status.idle":"2024-01-25T16:34:50.745487Z","shell.execute_reply.started":"2024-01-25T16:34:50.389002Z","shell.execute_reply":"2024-01-25T16:34:50.744406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <font color='orange'>Angle (phase) of Hilbert phase</font>","metadata":{}},{"cell_type":"code","source":"data['angleHilAP'] = np.angle(data['HilAP'])\ndata['angleHilML'] = np.angle(data['HilML'])\ndata['angleHilV'] = np.angle(data['HilV'])","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:50.747408Z","iopub.execute_input":"2024-01-25T16:34:50.747695Z","iopub.status.idle":"2024-01-25T16:34:50.754823Z","shell.execute_reply.started":"2024-01-25T16:34:50.74767Z","shell.execute_reply":"2024-01-25T16:34:50.753983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['angleHilML'], label='angleHilML')\n\ntime = data['Time']\nangleHilML = data['angleHilML']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], angleHilML[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('angle Mediolateral Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:51.003676Z","iopub.execute_input":"2024-01-25T16:34:51.004054Z","iopub.status.idle":"2024-01-25T16:34:51.490231Z","shell.execute_reply.started":"2024-01-25T16:34:51.004023Z","shell.execute_reply":"2024-01-25T16:34:51.489111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['angleHilV'], label='angleHilV')\n\ntime = data['Time']\nangleHilV = data['angleHilV']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], angleHilV[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('angle Vertical Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:51.560575Z","iopub.execute_input":"2024-01-25T16:34:51.560973Z","iopub.status.idle":"2024-01-25T16:34:52.032786Z","shell.execute_reply.started":"2024-01-25T16:34:51.560939Z","shell.execute_reply":"2024-01-25T16:34:52.031799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nplt.plot(data['Time'], data['angleHilAP'], label='angleHilAP')\n\ntime = data['Time']\nangleHilAP = data['angleHilAP']\nwalking = data['Walking']\nturning = data['Turn']\nstarthesitation = data['StartHesitation']\n\n# Create a colormap for the events\ncolormap = {'Walking': 'orange', 'Turn': 'green', 'StartHesitation': 'red'}\n\n# Iterate over each event and plot the corresponding segment with a different color\nfor label, color in colormap.items():\n    mask = data[label] == 1\n    plt.plot(time[mask], angleHilAP[mask], label=f'{label}', color=color)\n\n# Show the plot\nplt.xlabel('Time')\nplt.ylabel('Hilbert')\nplt.title('angle Anteroposterior Hilbert Transform over Time')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:52.055937Z","iopub.execute_input":"2024-01-25T16:34:52.056898Z","iopub.status.idle":"2024-01-25T16:34:52.438132Z","shell.execute_reply.started":"2024-01-25T16:34:52.056863Z","shell.execute_reply":"2024-01-25T16:34:52.43675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:34:52.468439Z","iopub.execute_input":"2024-01-25T16:34:52.469375Z","iopub.status.idle":"2024-01-25T16:34:52.483399Z","shell.execute_reply.started":"2024-01-25T16:34:52.469341Z","shell.execute_reply":"2024-01-25T16:34:52.482336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.pairplot(data[['AccV','AccML','AccAP','Acc_Mag','Theta','Phi','JoltAP','JoltML','JoltV','VelML','absHilAP', 'absHilML','absHilV', 'angleHilAP', 'angleHilML','angleHilV']])","metadata":{"execution":{"iopub.status.busy":"2024-01-25T16:35:39.369823Z","iopub.execute_input":"2024-01-25T16:35:39.370257Z","iopub.status.idle":"2024-01-25T16:37:41.558689Z","shell.execute_reply.started":"2024-01-25T16:35:39.370222Z","shell.execute_reply":"2024-01-25T16:37:41.557127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}