From e7087b04c77be8e4e081044aaee4fcb22f4105ac Mon Sep 17 00:00:00 2001 From: Skudalen Date: Mon, 28 Jun 2021 09:59:01 +0200 Subject: [PATCH] fix: add minor changes --- .gitignore | 1 + Present_data.py | 29 ++++++++++----- Signal_prep.py | 33 +++++++++--------- __pycache__/Signal_prep.cpython-38.pyc | Bin 2290 -> 2298 bytes python_speech_features.egg-info/PKG-INFO | 10 ++++++ python_speech_features.egg-info/SOURCES.txt | 7 ++++ .../dependency_links.txt | 1 + python_speech_features.egg-info/requires.txt | 2 ++ python_speech_features.egg-info/top_level.txt | 1 + 9 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 python_speech_features.egg-info/PKG-INFO create mode 100644 python_speech_features.egg-info/SOURCES.txt create mode 100644 python_speech_features.egg-info/dependency_links.txt create mode 100644 python_speech_features.egg-info/requires.txt create mode 100644 python_speech_features.egg-info/top_level.txt 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 79537c929868eb3f1595866f1a6e3f06fb75ea88..519d5594fc6a60b7499ec3bdef1e1fce44aa78c5 100644 GIT binary patch delta 498 zcmX|7J!>055Z&3m-CLb>hYpO1uw@8Q5}yr5!43o)+_*6W()gni=<5_z2pjemtJy_` zDwkmmZlyj&LhAeh`wtkk{snetSD8~}&oDbPk2kY#_c4Bs!;>%!2-@wS8dF_4Qg-qf>PqkO~1)Cx^8LxWl0N?Xv(NK+Wo2DO1LYR_;JnBth(lI9a( zgel=Xv!MxH;BSddT&?PE-+#*@^~rVo4fn&ZylDO9*DGIzp-l<}t{^b(Cg?Ybx5 n!nPaA>YM*tkTNSC9Gx~74?@aM`8np2dR`f}{@j1B! zX!&382|E4*{|VhMr{Wg0Z@xQuTaHTGFHRr!i*h^}R>Sd|yZ)o>OhxEkSwvBh?~_-z z2`rlfGUUkSe8JY)f;)lWBnp)0{E+2vkPFi#=CWo7rmO~&QDJUSokwPig1HmmULeG0 zPy6S?k)`C>Rbmo)_IuH0_L!0?EM~9{5=_reqVMWH)h745>N)KB_o_SHriUDs@!(`! zj7oEM)e*YL*2w=!Kca#pGX#=OQWw%G3k9H>aTi-o5srn^uIB1iU=8aS&BQTx4cD|1 z6*jOr6E3mQTw#m}O%N{SnEH17K=o+4+4e8vO|fQn{3Pyeg#%4kZ`uJi0{lOJb;!4P zXX6F^R4D<27Oz7JEokx-%o7jV!LFa`Zs&SFQI?JU!=wJ{TB3Z_k20ybl&RKHT1zvn Gbn+L#q-xFp 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