From c5d2e48771c555250fc897482b75384777a92b3c Mon Sep 17 00:00:00 2001 From: Skudalen Date: Mon, 28 Jun 2021 19:24:17 +0200 Subject: [PATCH] feat: add the samplerate as an output the get_data --- Present_data.py | 43 +++++++++++---------- Signal_prep.py | 3 +- __pycache__/Handle_emg_data.cpython-38.pyc | Bin 20113 -> 20074 bytes __pycache__/Signal_prep.cpython-38.pyc | Bin 2402 -> 2400 bytes 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Present_data.py b/Present_data.py index 199d39b..e8d24d2 100644 --- a/Present_data.py +++ b/Present_data.py @@ -7,12 +7,12 @@ import matplotlib.pyplot as plt from matplotlib import cm import matplotlib.ticker as ticker - -SAMPLE_RATE = 200 +# Global variables for MFCC mfcc_stepsize = 0.5 mfcc_windowsize = 2 -# PLOT FUNCTIONS: + +# PLOT FUNCTIONS --------------------------------------------------------------: # Plots DataFrame objects def plot_df(df:DataFrame): @@ -36,19 +36,20 @@ def plot_compare_two_df(df_old, old_name, df_new, new_name): axis[1].set_title(new_name) plt.show() -def plot_mfcc(mfcc_data): - #plt.rcParams["figure.figsize"] = [7.50, 15] - #plt.rcParams["figure.autolayout"] = True - +def plot_mfcc(mfcc_data, data_label:str): fig, ax = plt.subplots() mfcc_data= np.swapaxes(mfcc_data, 0 ,1) - #ax.axis([0, mfcc_stepsize * len(mfcc_data[0]), 0, len(mfcc_data[:,0])]) - #ax.set_xticks(range(int(len(mfcc_data) * 1 / mfcc_stepsize))) + + ticks_x = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x * mfcc_stepsize)) + ax.xaxis.set_major_formatter(ticks_x) + ax.imshow(mfcc_data, interpolation='nearest', cmap=cm.coolwarm, origin='lower') - ax.set_title('MFCC') + ax.set_title('MFCC:' + data_label) + ax.set_ylabel('Cepstral coefficients') + ax.set_xlabel('Time(s)') plt.show() -# DATA FUNCTIONS: +# DATA FUNCTIONS: --------------------------------------------------------------: # The CSV_handler takes in data_type, but only for visuals. # E.g. handler = CSV_handler('soft') @@ -66,10 +67,11 @@ def load_data(csv_handler:CSV_handler, data_type): 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 and samplerate def get_data(csv_handler:CSV_handler, subject_nr, which_arm, session, emg_nr): data_frame = csv_handler.get_df_from_data_dict(subject_nr, which_arm, session, emg_nr) - return data_frame + samplerate = get_samplerate(data_frame) + return data_frame, samplerate #Takes in handler and detailes to denoise. Returns arrays and df def denoice_dataset(handler:Handler.CSV_handler, subject_nr, which_arm, round, emg_nr): @@ -88,9 +90,9 @@ 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 +# CASE FUNTIONS ----------------------------------------------------------------: -def compare_with_wavelet(data_frame): +def compare_with_wavelet_filter(data_frame): N_trans, cA, cD = wavelet_db4(data_frame) data_frame_freq = make_df_from_xandy(N_trans, cA, 1) @@ -100,19 +102,18 @@ def compare_with_wavelet(data_frame): plot_compare_two_df(data_frame_freq, 'Original data', data_frame_freq_filt, 'Analyzed data') -# MAIN: +# MAIN: ------------------------------------------------------------------------: def main(): csv_handler = CSV_handler() load_data(csv_handler, 'hard') - data_frame = get_data(csv_handler, 2, 'left', 1, 1) + data_frame, samplerate = get_data(csv_handler, 2, 'left', 1, 1) - print(get_samplerate(data_frame)) - - N, mfcc_feat = mfcc_custom(data_frame[:5000], SAMPLE_RATE, mfcc_windowsize, mfcc_stepsize) + N, mfcc_feat = mfcc_custom(data_frame[:5000], samplerate, mfcc_windowsize, mfcc_stepsize) plot_mfcc(mfcc_feat) - print(get_sample_data) + #print(mfcc_feat) + return None diff --git a/Signal_prep.py b/Signal_prep.py index 3017104..cf43e36 100644 --- a/Signal_prep.py +++ b/Signal_prep.py @@ -9,7 +9,6 @@ from python_speech_features.python_speech_features import * import Handle_emg_data as Handler -SAMPLE_RATE = 200 # Takes in a df and outputs np arrays for x and y values @@ -30,7 +29,7 @@ def fft_of_df(df:DataFrame): y_values = get_xory_from_df('y', df) N = y_values.size norm = normalize_wave(y_values) - N_trans = fftfreq(N, 1 / SAMPLE_RATE) + N_trans = fftfreq(N, 1 / Handler.get_samplerate(df)) y_f = fft(norm) return N_trans, y_f diff --git a/__pycache__/Handle_emg_data.cpython-38.pyc b/__pycache__/Handle_emg_data.cpython-38.pyc index 84ed5602da228ebe37bff00ec2612034b3ed299f..d4d90d8ec876bd2c1906269cee46ee5314318e78 100644 GIT binary patch delta 104 zcmbO@m+{pcM!ry9UM>b8cz@<*0%OxgK5kzP10c7Ap@yNEF@~v@v6iWZDTPsjp$3R+ xnM)XJ7*d!dfpWDhlcRm5*qDmEfXXK~`D!rUn!MUqp9gFjBM%b@PJZLN6aYYT7-9eb delta 143 zcmaDghjHRuM!ry9UM>b8*mCA(!oS9ieB8cHUO;XMLk&YSV+>O*V=Yq&V+~^sQ!^7I zLk&|3qXa_@5Z5vTMVXr!85v5LY8XNt)e!ZIYt36h$Q#y!ZiP5kZBXq9DD*!@9}Ln!si^%xoGfDG^)r zTn52|LOpu-XXwp~dlFCe=D7#)olX28(1Ce(pLgDw=b7i7@0D*Ad&{=-3XIO@ua9pZ z*k{nkgY_*!HDbO+#3FcKZ#yJM^7~4=IL|JT0%S{bWD^HanG{J0YAU2mD)6n&SF6N@ zRdJCV)VLh0(;xy<9^bk?1RE=z{fX)jn>6Ib*)+i$T0*(b&>na z)LBtHRXY!IkjZLi!2y^$QOpK@*ndX7vA<0lkmEW81=SIA;oC(L&4(nG^A1eDAueg> zriaEvd5=yjd+M&9m=kRe?HUt(VgxEE)>%2MYE zO+4-oh5-D8GEHtWndDe*$Wo0lna8yivy1YE3k_fASfu0 zOoWjuj;L>) zlCFgy9F99LRAV1bcx7C?uuxXxF^EcfjPhO_5-;e7aKr23i*bl@Vq~si=?z$9ig)If zwT0cqezZ*)pS1|cHpEZ!(M{Rm%-$x-oNa0|ua^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