File name
Commit message
Commit date
import pandas as pd
import numpy as np
from scipy import fft
from os import listdir
from os.path import isfile, join
from plotly import express as px
dirs = [f for f in listdir('data') if not isfile(join('data', f))]
rolling_value = 30
window_value = 150
sliding_value = 20
for path in dirs:
df = pd.read_csv(f"data/{path}/Accelerometer.csv")
df_x = df.loc[:, 'x'].rolling(rolling_value).mean().values[rolling_value:]
df_y = df.loc[:, 'y'].rolling(rolling_value).mean().values[rolling_value:]
df_z = df.loc[:, 'z'].rolling(rolling_value).mean().values[rolling_value:]
acc_l2 = np.sqrt(np.power(df_x, 2) + np.power(df_y, 2) + np.power(df_z, 2))
amplitude = []
for i in range(int(np.floor((len(df)-rolling_value)/sliding_value))):
acf = fft.fft(acc_l2[i*sliding_value:(i+1)*sliding_value])
# number of signal points
num = 30
# sample spacing
spacing = 1.0 / 1200.0
freqp = fft.fftfreq(num,spacing)
sample_freq = fft.fftshift(freqp)
freq = fft.fftshift(acf)
freq = np.abs(freq)
amplitude.append(np.max(freq))
# plot = pd.DataFrame(freq)
# graph = px.bar(plot)
# graph.update_layout(
# yaxis_range = [0,500]
# )
fig = px.bar(pd.DataFrame(amplitude))
fig.update_layout(
yaxis_range = [0,100]
)
fig.show()