fix: add minor changes
This commit is contained in:
parent
f1ba1e93a8
commit
e7087b04c7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
Exp20201205_2myo_hard**
|
||||
Exp20201205_2myo_soft**
|
||||
Documents
|
||||
python_speech_features
|
@ -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
|
||||
|
||||
|
@ -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, )
|
||||
'''
|
||||
|
Binary file not shown.
10
python_speech_features.egg-info/PKG-INFO
Normal file
10
python_speech_features.egg-info/PKG-INFO
Normal file
@ -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
|
7
python_speech_features.egg-info/SOURCES.txt
Normal file
7
python_speech_features.egg-info/SOURCES.txt
Normal file
@ -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
|
1
python_speech_features.egg-info/dependency_links.txt
Normal file
1
python_speech_features.egg-info/dependency_links.txt
Normal file
@ -0,0 +1 @@
|
||||
|
2
python_speech_features.egg-info/requires.txt
Normal file
2
python_speech_features.egg-info/requires.txt
Normal file
@ -0,0 +1,2 @@
|
||||
numpy
|
||||
scipy
|
1
python_speech_features.egg-info/top_level.txt
Normal file
1
python_speech_features.egg-info/top_level.txt
Normal file
@ -0,0 +1 @@
|
||||
python_speech_features
|
Loading…
Reference in New Issue
Block a user