feat: add mfcc func
This commit is contained in:
parent
452a591837
commit
2563a4bb33
@ -20,10 +20,10 @@ class Data_container:
|
|||||||
|
|
||||||
class CSV_handler:
|
class CSV_handler:
|
||||||
|
|
||||||
def __init__(self, data_type):
|
def __init__(self):
|
||||||
self.working_dir = str(Path.cwd())
|
self.working_dir = str(Path.cwd())
|
||||||
self.data_container_dict = {} # Dict with keys equal subject numbers and values equal the relvant datacontainer
|
self.data_container_dict = {} # Dict with keys equal subject numbers and values equal the relvant datacontainer
|
||||||
self.data_type = data_type
|
self.data_type = None
|
||||||
|
|
||||||
# Makes dataframe from the csv files in the working directory
|
# Makes dataframe from the csv files in the working directory
|
||||||
def make_df(self, filename):
|
def make_df(self, filename):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from logging import error
|
||||||
from Handle_emg_data import *
|
from Handle_emg_data import *
|
||||||
from Signal_prep import *
|
from Signal_prep import *
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -41,13 +42,16 @@ def plot_mfcc(mfcc_data):
|
|||||||
|
|
||||||
# Loads in data. Choose data_type: hard, hardPP, soft og softPP as str. Returns None
|
# Loads in data. Choose data_type: hard, hardPP, soft og softPP as str. Returns None
|
||||||
def load_data(csv_handler:CSV_handler, data_type):
|
def load_data(csv_handler:CSV_handler, data_type):
|
||||||
switcher = {
|
if data_type == 'hard':
|
||||||
'hard': csv_handler.load_hard_original_emg_data(),
|
csv_handler.load_hard_original_emg_data()
|
||||||
'hardPP':csv_handler.load_hard_PP_emg_data(),
|
elif data_type == 'hardPP':
|
||||||
'soft':csv_handler.load_soft_original_emg_data(),
|
csv_handler.load_hard_PP_emg_data()
|
||||||
'softPP':csv_handler.load_soft_PP_emg_data(),
|
elif data_type == 'soft':
|
||||||
}
|
csv_handler.load_soft_original_emg_data()
|
||||||
return switcher.get(data_type)
|
elif data_type == 'softPP':
|
||||||
|
csv_handler.load_soft_PP_emg_data()
|
||||||
|
else:
|
||||||
|
raise Exception('Wrong input')
|
||||||
|
|
||||||
# Retrieved data. Send in loaded csv_handler and data detailes you want. Returns DataFrame
|
# Retrieved data. Send in loaded csv_handler and data detailes you want. Returns DataFrame
|
||||||
def get_data(csv_handler:CSV_handler, subject_nr, which_arm, session, emg_nr):
|
def get_data(csv_handler:CSV_handler, subject_nr, which_arm, session, emg_nr):
|
||||||
@ -83,13 +87,15 @@ def compare_with_wavelet(data_frame):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
csv_handler = CSV_handler('hard')
|
csv_handler = CSV_handler()
|
||||||
load_data(csv_handler, 'hard')
|
load_data(csv_handler, 'hard')
|
||||||
|
print(csv_handler.data_type)
|
||||||
data_frame = get_data(csv_handler, 1, 'left', 1, 1)
|
data_frame = get_data(csv_handler, 1, 'left', 1, 1)
|
||||||
|
|
||||||
N, y_mfcc = mfcc(data_frame)
|
print(data_frame.head)
|
||||||
plt.plot(y_mfcc)
|
|
||||||
plt.show()
|
N, y_mfcc = mfcc(data_frame, 0.1)
|
||||||
|
plot_mfcc(y_mfcc)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -77,9 +77,9 @@ def cepstrum(df:DataFrame):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def mfcc(df:DataFrame):
|
def mfcc(df:DataFrame, window_lenth):
|
||||||
N = get_xory_from_df('x', df)
|
N = get_xory_from_df('x', df)
|
||||||
y = get_xory_from_df('y', df)
|
y = get_xory_from_df('y', df)
|
||||||
return N, base.mfcc(y, SAMPLE_RATE)
|
return N, base.mfcc(y, SAMPLE_RATE, window_lenth)
|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user