From e1f3e509b1e0fadead956d6102ab18ed6396a278 Mon Sep 17 00:00:00 2001 From: Skudalen Date: Tue, 29 Jun 2021 11:42:37 +0200 Subject: [PATCH] feat: add func for plotting all emg from one subject --- Handle_emg_data.py | 8 +++ Present_data.py | 63 ++++++++++++++++++++- __pycache__/Handle_emg_data.cpython-38.pyc | Bin 20074 -> 20074 bytes 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Handle_emg_data.py b/Handle_emg_data.py index 31b9b15..f385c6c 100644 --- a/Handle_emg_data.py +++ b/Handle_emg_data.py @@ -449,6 +449,14 @@ class CSV_handler: df = container.dict_list[round - 1].get(which_arm)[emg_nr - 1] return df +''' + def get_keyboard_data(self, filename:str, pres_or_release:str='pressed'): + filepath = self.working_dir + str(filename) + df = pd.read_csv(filepath) + if pres_or_release == 'pressed': + df = df[(df['event'] == 'KeyPressed') and (df['event'] == 'KeyPressed')] + else +''' # HELP FUNCTIONS: ------------------------------------------------------------------------: diff --git a/Present_data.py b/Present_data.py index 06b92f6..c3e5f69 100644 --- a/Present_data.py +++ b/Present_data.py @@ -69,6 +69,34 @@ def plot_3_mfcc(mfcc_data1, data_label1:str, mfcc_data2, data_label2:str, mfcc_d plt.show() +def plot_all_emg_mfcc(data_list:list, label_list:list): + fig, axes = plt.subplots(nrows=4, ncols=2) + plt.subplots_adjust(hspace=1.4, wspace=0.4) + ticks_x = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x * mfcc_stepsize)) + plt.autoscale() + + d_list = np.array([ [data_list[0], data_list[4]], + [data_list[1], data_list[5]], + [data_list[2], data_list[6]], + [data_list[3], data_list[7]] + ]) + l_list = np.array([ [label_list[0], label_list[4]], + [label_list[1], label_list[5]], + [label_list[2], label_list[6]], + [label_list[3], label_list[7]] + ]) + + for col in [0, 1]: + for ax, data, label in zip(axes[:,col], d_list[:,col], l_list[:,col]): + mfcc_data= np.swapaxes(data, 0 ,1) + ax.xaxis.set_major_formatter(ticks_x) + + ax.imshow(mfcc_data, interpolation='nearest', cmap=cm.coolwarm, origin='lower') + ax.set_title('MFCC: ' + str(label)) + ax.set_ylabel('Coefficients') + ax.set_xlabel('Time(s)') + + plt.show() # DATA FUNCTIONS: --------------------------------------------------------------: @@ -168,14 +196,45 @@ def mfcc_3_plots_3_3_4(csv_handler:CSV_handler): plot_3_mfcc(mfcc_feat1, label_1, mfcc_feat2, label_2, mfcc_feat3, label_3) +def mfcc_all_emg_plots(csv_handler:CSV_handler): + df1, samplerate1 = get_data(csv_handler, 1, 'left', 1, 1) + df2, samplerate2 = get_data(csv_handler, 1, 'left', 1, 2) + df3, samplerate3 = get_data(csv_handler, 1, 'left', 1, 3) + df4, samplerate4 = get_data(csv_handler, 1, 'left', 1, 4) + df5, samplerate5 = get_data(csv_handler, 1, 'left', 1, 5) + df6, samplerate6 = get_data(csv_handler, 1, 'left', 1, 6) + df7, samplerate7 = get_data(csv_handler, 1, 'left', 1, 7) + df8, samplerate8 = get_data(csv_handler, 1, 'left', 1, 8) + N1, mfcc_feat1 = mfcc_custom(df1, samplerate1, mfcc_windowsize, mfcc_stepsize) + N2, mfcc_feat2 = mfcc_custom(df2, samplerate2, mfcc_windowsize, mfcc_stepsize) + N3, mfcc_feat3 = mfcc_custom(df3, samplerate3, mfcc_windowsize, mfcc_stepsize) + N4, mfcc_feat4 = mfcc_custom(df4, samplerate4, mfcc_windowsize, mfcc_stepsize) + N5, mfcc_feat5 = mfcc_custom(df5, samplerate5, mfcc_windowsize, mfcc_stepsize) + N6, mfcc_feat6 = mfcc_custom(df6, samplerate6, mfcc_windowsize, mfcc_stepsize) + N7, mfcc_feat7 = mfcc_custom(df7, samplerate7, mfcc_windowsize, mfcc_stepsize) + N8, mfcc_feat8 = mfcc_custom(df8, samplerate8, mfcc_windowsize, mfcc_stepsize) + feat_list = [mfcc_feat1, mfcc_feat2, mfcc_feat3, mfcc_feat4, mfcc_feat5, mfcc_feat6, mfcc_feat7, mfcc_feat8] + label_1 = 'Subject 1, session 1, left arm, emg nr. 1' + label_2 = 'Subject 1, session 1, left arm, emg nr. 2' + label_3 = 'Subject 1, session 1, left arm, emg nr. 3' + label_4 = 'Subject 1, session 1, left arm, emg nr. 4' + label_5 = 'Subject 1, session 1, left arm, emg nr. 5' + label_6 = 'Subject 1, session 1, left arm, emg nr. 6' + label_7 = 'Subject 1, session 1, left arm, emg nr. 7' + label_8 = 'Subject 1, session 1, left arm, emg nr. 8' + label_list = [label_1, label_2, label_3, label_4, label_5, label_6, label_7, label_8] + + plot_all_emg_mfcc(feat_list, label_list) + # MAIN: ------------------------------------------------------------------------: def main(): csv_handler = CSV_handler() load_data(csv_handler, 'soft') - mfcc_3_plots_1_1_2(csv_handler) - mfcc_3_plots_3_3_4(csv_handler) + #mfcc_3_plots_1_1_2(csv_handler) + #mfcc_3_plots_3_3_4(csv_handler) + mfcc_all_emg_plots(csv_handler) main() \ No newline at end of file diff --git a/__pycache__/Handle_emg_data.cpython-38.pyc b/__pycache__/Handle_emg_data.cpython-38.pyc index 4d1b04f489fd063368b0b8b202a8deb210954f7e..d57d8f5c0a5cb8fab78a998deaaf1926033da2ee 100644 GIT binary patch delta 57 zcmaDghw;@MM!ry9UM>b8u(@zD{q(3zKJf?_|6(Iml-wVvoV?X{ N9lIR|3m+Q?I{b8h!wq+5ZAPkuhX0H#N-*?I~mVR4)U4Fcxmz*pA(EXCvWv# N$8N^K!pFwJ4ggP{6f*z-