feat: add mfcc func

This commit is contained in:
Skudalen 2021-06-28 11:28:53 +02:00
parent 452a591837
commit 2563a4bb33
6 changed files with 21 additions and 15 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -20,10 +20,10 @@ class Data_container:
class CSV_handler:
def __init__(self, data_type):
def __init__(self):
self.working_dir = str(Path.cwd())
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
def make_df(self, filename):

View File

@ -1,3 +1,4 @@
from logging import error
from Handle_emg_data import *
from Signal_prep import *
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
def load_data(csv_handler:CSV_handler, data_type):
switcher = {
'hard': csv_handler.load_hard_original_emg_data(),
'hardPP':csv_handler.load_hard_PP_emg_data(),
'soft':csv_handler.load_soft_original_emg_data(),
'softPP':csv_handler.load_soft_PP_emg_data(),
}
return switcher.get(data_type)
if data_type == 'hard':
csv_handler.load_hard_original_emg_data()
elif data_type == 'hardPP':
csv_handler.load_hard_PP_emg_data()
elif data_type == 'soft':
csv_handler.load_soft_original_emg_data()
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
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():
csv_handler = CSV_handler('hard')
csv_handler = CSV_handler()
load_data(csv_handler, 'hard')
print(csv_handler.data_type)
data_frame = get_data(csv_handler, 1, 'left', 1, 1)
N, y_mfcc = mfcc(data_frame)
plt.plot(y_mfcc)
plt.show()
print(data_frame.head)
N, y_mfcc = mfcc(data_frame, 0.1)
plot_mfcc(y_mfcc)
return None

View File

@ -77,9 +77,9 @@ def cepstrum(df:DataFrame):
return None
def mfcc(df:DataFrame):
def mfcc(df:DataFrame, window_lenth):
N = get_xory_from_df('x', df)
y = get_xory_from_df('y', df)
return N, base.mfcc(y, SAMPLE_RATE)
return N, base.mfcc(y, SAMPLE_RATE, window_lenth)