head gestures, maybe??

This commit is contained in:
Kavish Devar
2024-12-03 03:15:24 +05:30
parent f12cf0c16f
commit 3fe268eb15
19 changed files with 750 additions and 436 deletions

View File

@@ -1,5 +1,6 @@
import os
import matplotlib.pyplot as plt
import mplcursors
def hex_to_base10(hex_string):
hex_values = hex_string.split()
@@ -14,36 +15,25 @@ def convert_file(input_filepath):
data.append(base10_line)
return data
def plot_data(data, title, save_path):
# Transpose the data to get columns
columns = list(zip(*data))
# Filter out columns that stay the same across all rows
filtered_columns = [column for column in columns if len(set(column)) > 1]
# Generate time values for the x-axis
time_values = [i * 35 for i in range(len(data))]
def plot_data(data, title, directory):
plt.figure()
plt.title(title)
# columns_to_remove = [0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 32, 35, 36, 37, 38, 43, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 59, 46, 61, 63, 64, 65, 67, 68, 70, 71, 73, 74, 75, 77]
columns_to_remove = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
for i in range(len(data[0])):
if i in columns_to_remove:
continue
plt.plot([row[i] for row in data], label=f'Column {i}', alpha=1, linewidth=1.2)
# Plot in sets of 4 columns
for start in range(0, len(filtered_columns), 4):
end = start + 4
subset_columns = filtered_columns[start:end]
num_columns = len(subset_columns)
fig, axs = plt.subplots(num_columns, 1, figsize=(10, 2 * num_columns), sharex=True)
if num_columns == 1:
axs = [axs] # Ensure axs is iterable when there's only one subplot
for i, column in enumerate(subset_columns):
axs[i].plot(time_values, column, label=f'Column {start + i + 1}')
axs[i].set_ylabel('Value')
axs[i].legend()
plt.xlabel('Time (ms)')
plt.suptitle(f'{title} (Columns {start + 1} to {end})')
# Save the plot as a PNG file
plot_filename = f'{title.replace(".txt","")} - {start + 1} to {end}.png'
plt.savefig(os.path.join(save_path, plot_filename))
plt.close()
plt.legend()
plt.xlabel('Time')
plt.ylabel('Value')
# Add interactive cursor
mplcursors.cursor(hover=True)
plt.show()
plt.close()
def process_files(directory):
for filename in os.listdir(directory):
@@ -53,7 +43,7 @@ def process_files(directory):
plot_data(data, f'{filename}', directory)
# Directory containing the files
directory = '/Users/kavish/AirPodsLikeNormal/training data/Extracted Data/'
directory = 'yes'
# Process each file in the directory
process_files(directory)