diff --git a/.gitignore b/.gitignore index df5ee50..efb7fcd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ Exp20201205_2myo_hard** Exp20201205_2myo_soft** Documents +python_speech_features \ No newline at end of file diff --git a/Present_data.py b/Present_data.py index 0d6c888..09b0bcb 100644 --- a/Present_data.py +++ b/Present_data.py @@ -9,20 +9,20 @@ def plot_df(df:DataFrame): plt.show() # Plots ndarrays after transformations -def plot_arrays(N, y): +def plot_arrays(N, N_name, y, y_name): plt.plot(N, np.abs(y)) plt.show() -def plot_compare_two_df(df_old, df_new): +def plot_compare_two_df(df_old, old_name, df_new, new_name): x = get_xory_from_df('x', df_old) y1 = get_xory_from_df('y', df_old) y2 = get_xory_from_df('y', df_new) figure, axis = plt.subplots(1, 2) axis[0].plot(x, y1) - axis[0].set_title('Original data') + axis[0].set_title(old_name) axis[1].plot(x, y2) - axis[1].set_title('Analyzed data') + axis[1].set_title(new_name) plt.show() @@ -46,6 +46,19 @@ 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 +#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): + 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(df) + cA_filt, cD_filt = soft_threshold_filter(cA, cD) + y_values = inverse_wavelet(df, cA_filt, cD_filt) + + df_new = Handler.make_df_from_xandy(N, y_values, emg_nr) + return df_new + + # MAIN: @@ -55,13 +68,13 @@ def main(): load_data(csv_handler, 'hard') data_frame = get_data(csv_handler, 1, 'left', 1, 1) - N_trans, cA, cD = wavelet_db4_denoising(data_frame) + N_trans, cA, cD = wavelet_db4(data_frame) data_frame_freq = make_df_from_xandy(N_trans, cA, 1) - cA_filt, cD_filt = soft_threshold_filter(cA, cD, 0.6) - data_frame_freq_filt = make_df_from_xandy(N_trans, cA_filt, 1) + cA_filt, cD_filt = soft_threshold_filter(cA, cD) + data_frame_freq_filt = make_df_from_xandy(N_trans, cD_filt, 1) - plot_compare_two_df(data_frame_freq, data_frame_freq_filt) + plot_compare_two_df(data_frame_freq, 'Original data', data_frame_freq_filt, 'Analyzed data') return None diff --git a/Signal_prep.py b/Signal_prep.py index 3285084..032eda7 100644 --- a/Signal_prep.py +++ b/Signal_prep.py @@ -4,6 +4,7 @@ import pandas from pandas.core.frame import DataFrame from scipy.fft import fft, fftfreq import pywt +import pyhton_speech_features as psf #from scipy.signal import wavelets #import pyyawt @@ -35,7 +36,7 @@ def fft_of_df(df:DataFrame): return N_trans, y_f # Removes noise with db4 wavelet function -def wavelet_db4_denoising(df:DataFrame): +def wavelet_db4(df:DataFrame): y_values = get_xory_from_df('y', df) #y_values = normalize_wave(y_values) wavelet = pywt.Wavelet('db4') @@ -51,10 +52,10 @@ def sure_threshold_filter(cA, cD): return cA_filt, cD_filt ''' -# soft filtering of wavelet trans with the 40% lowest removed -def soft_threshold_filter(cA, cD, threshold): - cA_filt = pywt.threshold(cA, threshold * cA.max()) - cD_filt = cD +# 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) + cD_filt = pywt.threshold(cD, np.std(cD)/2) return cA_filt, cD_filt # Inverse dwt for brining denoise signal back to the time domainfi @@ -70,16 +71,16 @@ def inverse_wavelet(df, cA_filt, cD_filt): old_len = len(get_xory_from_df('y', df)) 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, threshold): - df = handler.get_df_from_data_dict(subject_nr, which_arm, round, emg_nr) - +def cepstrum(df:DataFrame): N = get_xory_from_df('x', df) - N_trans, cA, cD = wavelet_db4_denoising(df) - 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 df_new - + y = get_xory_from_df('y', df) + + + return None +''' +def mfcc(df:DataFrame): + N = get_xory_from_df('x', df) + y = get_xory_from_df('y', df) + spf.mfcc(y, ) +''' diff --git a/__pycache__/Signal_prep.cpython-38.pyc b/__pycache__/Signal_prep.cpython-38.pyc index 79537c9..519d559 100644 Binary files a/__pycache__/Signal_prep.cpython-38.pyc and b/__pycache__/Signal_prep.cpython-38.pyc differ diff --git a/python_speech_features.egg-info/PKG-INFO b/python_speech_features.egg-info/PKG-INFO new file mode 100644 index 0000000..7ae6330 --- /dev/null +++ b/python_speech_features.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: python-speech-features +Version: 0.6.1 +Summary: Python Speech Feature extraction +Home-page: https://github.com/jameslyons/python_speech_features +Author: James Lyons +Author-email: james.lyons0@gmail.com +License: MIT +Description: UNKNOWN +Platform: UNKNOWN diff --git a/python_speech_features.egg-info/SOURCES.txt b/python_speech_features.egg-info/SOURCES.txt new file mode 100644 index 0000000..b33bcb8 --- /dev/null +++ b/python_speech_features.egg-info/SOURCES.txt @@ -0,0 +1,7 @@ +python_speech_features/example.py +python_speech_features/setup.py +python_speech_features.egg-info/PKG-INFO +python_speech_features.egg-info/SOURCES.txt +python_speech_features.egg-info/dependency_links.txt +python_speech_features.egg-info/requires.txt +python_speech_features.egg-info/top_level.txt \ No newline at end of file diff --git a/python_speech_features.egg-info/dependency_links.txt b/python_speech_features.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/python_speech_features.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/python_speech_features.egg-info/requires.txt b/python_speech_features.egg-info/requires.txt new file mode 100644 index 0000000..6bad103 --- /dev/null +++ b/python_speech_features.egg-info/requires.txt @@ -0,0 +1,2 @@ +numpy +scipy diff --git a/python_speech_features.egg-info/top_level.txt b/python_speech_features.egg-info/top_level.txt new file mode 100644 index 0000000..42c4020 --- /dev/null +++ b/python_speech_features.egg-info/top_level.txt @@ -0,0 +1 @@ +python_speech_features