From 055ad434a3768681b7624f5b28645c1451885c5d Mon Sep 17 00:00:00 2001 From: Skudalen Date: Mon, 28 Jun 2021 20:32:00 +0200 Subject: [PATCH] style: move things :) --- Handle_emg_data.py | 4 +++- Present_data.py | 6 ++++++ Signal_prep.py | 22 ++-------------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Handle_emg_data.py b/Handle_emg_data.py index 54340a8..31b9b15 100644 --- a/Handle_emg_data.py +++ b/Handle_emg_data.py @@ -12,7 +12,7 @@ class Data_container: self.data_dict_round2 = {'left': [None]*8, 'right': [None]*8} self.data_dict_round3 = {'left': [None]*8, 'right': [None]*8} self.data_dict_round4 = {'left': [None]*8, 'right': [None]*8} - self.dict_list = [self.data_dict_round1, + self.dict_list = [self.data_dict_round1, self.data_dict_round2, self.data_dict_round3, self.data_dict_round4 @@ -450,6 +450,8 @@ class CSV_handler: return df +# HELP FUNCTIONS: ------------------------------------------------------------------------: + # Help: gets the str from emg nr def get_emg_str(emg_nr): return 'emg' + str(emg_nr) diff --git a/Present_data.py b/Present_data.py index 9c35da7..dd578c2 100644 --- a/Present_data.py +++ b/Present_data.py @@ -69,6 +69,7 @@ def plot_3_mfcc(mfcc_data1, data_label1:str, mfcc_data2, data_label2:str, mfcc_d plt.show() + # DATA FUNCTIONS: --------------------------------------------------------------: # The CSV_handler takes in data_type, but only for visuals. @@ -115,6 +116,7 @@ def mfcc_custom(df:DataFrame, samplesize, windowsize, stepsize): y = get_xory_from_df('y', df) return N, base.mfcc(y, samplesize, windowsize, stepsize) + # CASE FUNTIONS ----------------------------------------------------------------: # Takes in a df and compares the FFT and the wavelet denoising of the FFT @@ -128,6 +130,9 @@ def compare_with_wavelet_filter(data_frame): plot_compare_two_df(data_frame_freq, 'Original data', data_frame_freq_filt, 'Analyzed data') +# Loads three preset emg datasets, calculates mfcc for each and plots them. +# Input: CSV_handler +# Output: None --> Plot def compare_mfcc_3_plots(csv_handler:CSV_handler): df1, samplerate1 = get_data(csv_handler, 1, 'left', 1, 1) df2, samplerate2 = get_data(csv_handler, 1, 'left', 2, 1) @@ -146,6 +151,7 @@ def compare_mfcc_3_plots(csv_handler:CSV_handler): plot_3_mfcc(mfcc_feat1, label_1, mfcc_feat2, label_2, mfcc_feat3, label_3) + # MAIN: ------------------------------------------------------------------------: def main(): diff --git a/Signal_prep.py b/Signal_prep.py index cf43e36..fae013b 100644 --- a/Signal_prep.py +++ b/Signal_prep.py @@ -2,14 +2,11 @@ import numpy as np from pandas.core.frame import DataFrame from scipy.fft import fft, fftfreq import pywt -#from pyhton_speech_features.base import mfcc import sys +import Handle_emg_data as Handler sys.path.insert(0, '/Users/Markus/Prosjekter git/Slovakia 2021/python_speech_features/python_speech_features') from python_speech_features.python_speech_features import * -import Handle_emg_data as Handler - - # Takes in a df and outputs np arrays for x and y values def get_xory_from_df(x_or_y, df:DataFrame): @@ -42,14 +39,6 @@ def wavelet_db4(df:DataFrame): N_trans = np.array(range(int(np.floor((y_values.size + wavelet.dec_len - 1) / 2)))) return N_trans, cA, cD -# Filters signal accordning to Stein's Unbiased Risk Estimate(SURE) -''' -def sure_threshold_filter(cA, cD): - cA_filt = pyyawt.theselect(cA, 'rigrsure') - cD_filt = cD - return cA_filt, cD_filt -''' - # soft filtering of wavelet trans with the a 1/2 std filter def soft_threshold_filter(cA, cD): cA_filt = pywt.threshold(cA, np.std(cA)/2) @@ -69,16 +58,9 @@ def inverse_wavelet(df, cA_filt, cD_filt): old_len = len(get_xory_from_df('y', df)) return y_new_values +# NOT FINISHED def cepstrum(df:DataFrame): N = get_xory_from_df('x', df) y = get_xory_from_df('y', df) - - return None -def mfcc(df:DataFrame, samplesize, windowsize, stepsize): - N = get_xory_from_df('x', df) - y = get_xory_from_df('y', df) - return N, base.mfcc(y, samplesize, windowsize, stepsize) - -