diff --git a/Handle_emg_data.py b/Handle_emg_data.py index 437ae9a..2c034fe 100644 --- a/Handle_emg_data.py +++ b/Handle_emg_data.py @@ -447,7 +447,7 @@ class CSV_handler: def get_df_from_data_dict(self, subject_nr, which_arm, round, emg_nr): data_type = self.data_type container = self.data_container_dict.get(subject_nr) - df = container.dict_list[round - 1].get(which_arm)[emg_nr] + df = container.dict_list[round - 1].get(which_arm)[emg_nr - 1] return df diff --git a/Signal_prep.py b/Signal_prep.py index 5186b17..b678861 100644 --- a/Signal_prep.py +++ b/Signal_prep.py @@ -52,8 +52,8 @@ def sure_threshold_filter(cA, cD): ''' # soft filtering of wavelet trans with the 40% lowest removed -def soft_threshold_filter(cA, cD): - cA_filt = pywt.threshold(cA, 0.4 * cA.max()) +def soft_threshold_filter(cA, cD, threshold): + cA_filt = pywt.threshold(cA, threshold * cA.max()) cD_filt = cD return cA_filt, cD_filt @@ -71,16 +71,16 @@ def inverse_wavelet(df, cA_filt, cD_filt): return y_new_values # 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): +def denoice_dataset(handler:Handler.CSV_handler, subject_nr, which_arm, round, emg_nr, threshold): df = handler.get_df_from_data_dict(subject_nr, which_arm, round, emg_nr) N = get_xory_from_df('x', df) N_trans, cA, cD = wavelet_db4_denoising(df) - cA_filt, cD_filt = soft_threshold_filter(cA, cD) + cA_filt, cD_filt = soft_threshold_filter(cA, cD, threshold) y_values = inverse_wavelet(df, cA_filt, cD_filt) df_new = Handler.make_df_from_xandy(N, y_values, emg_nr) - return N, y_values, df_new + return df_new diff --git a/Test_functions.py b/Test_functions.py index e0f997a..dd5ade5 100644 --- a/Test_functions.py +++ b/Test_functions.py @@ -1,3 +1,4 @@ +from matplotlib import lines from numpy import load from Handle_emg_data import * import matplotlib.pyplot as plt @@ -66,11 +67,19 @@ def test_total_denoising(): # Original df: df = handler.get_df_from_data_dict(3, 'left', 3, 3) print(df.head) - plot_df(df) + # Denoised df: - N_trans, y_values, df_denoised = denoice_dataset(handler, 3, 'left', 3, 3) + df_denoised = denoice_dataset(handler, 3, 'left', 3, 3, 0.2) print(df_denoised.head) - plot_df(df_denoised) + + x = get_xory_from_df('x', df) + y1 = get_xory_from_df('y', df) + y2 = get_xory_from_df('y', df_denoised) + + figure, axis = plt.subplots(1, 2) + axis[0].plot(x, y1) + axis[1].plot(x, y2) + plt.show() test_total_denoising() diff --git a/__pycache__/Handle_emg_data.cpython-38.pyc b/__pycache__/Handle_emg_data.cpython-38.pyc index 06146b1..f736d9e 100644 Binary files a/__pycache__/Handle_emg_data.cpython-38.pyc and b/__pycache__/Handle_emg_data.cpython-38.pyc differ diff --git a/__pycache__/Signal_prep.cpython-38.pyc b/__pycache__/Signal_prep.cpython-38.pyc index 0fe993d..4d044dd 100644 Binary files a/__pycache__/Signal_prep.cpython-38.pyc and b/__pycache__/Signal_prep.cpython-38.pyc differ