feat: clone and import python_speech_features

and add a mfcc func
This commit is contained in:
Skudalen 2021-06-28 10:57:08 +02:00
parent e7087b04c7
commit 452a591837
7 changed files with 31 additions and 18 deletions

BIN
.DS_Store vendored

Binary file not shown.

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
Exp20201205_2myo_hard** Exp20201205_2myo_hard**
Exp20201205_2myo_soft** Exp20201205_2myo_soft**
Documents Documents
python_speech_features python_speech_features**

View File

@ -1,7 +1,6 @@
import pandas as pd import pandas as pd
from pathlib import Path from pathlib import Path
import numpy as np import numpy as np
from pandas.core.frame import DataFrame from pandas.core.frame import DataFrame
class Data_container: class Data_container:

View File

@ -1,5 +1,7 @@
from Handle_emg_data import * from Handle_emg_data import *
from Signal_prep import * from Signal_prep import *
import matplotlib.pyplot as plt
from matplotlib import cm
# PLOT FUNCTIONS: # PLOT FUNCTIONS:
@ -9,7 +11,7 @@ def plot_df(df:DataFrame):
plt.show() plt.show()
# Plots ndarrays after transformations # Plots ndarrays after transformations
def plot_arrays(N, N_name, y, y_name): def plot_array(N, y):
plt.plot(N, np.abs(y)) plt.plot(N, np.abs(y))
plt.show() plt.show()
@ -25,6 +27,12 @@ def plot_compare_two_df(df_old, old_name, df_new, new_name):
axis[1].set_title(new_name) axis[1].set_title(new_name)
plt.show() plt.show()
def plot_mfcc(mfcc_data):
fig, ax = plt.subplots()
mfcc_data= np.swapaxes(mfcc_data, 0 ,1)
cax = ax.imshow(mfcc_data, interpolation='nearest', cmap=cm.coolwarm, origin='lower')
ax.set_title('MFCC')
plt.show()
# DATA FUNCTIONS: # DATA FUNCTIONS:
@ -59,6 +67,17 @@ def denoice_dataset(handler:Handler.CSV_handler, subject_nr, which_arm, round, e
return df_new return df_new
# CASE FUNTIONS
def compare_with_wavelet(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)
data_frame_freq_filt = make_df_from_xandy(N_trans, cD_filt, 1)
plot_compare_two_df(data_frame_freq, 'Original data', data_frame_freq_filt, 'Analyzed data')
# MAIN: # MAIN:
@ -68,13 +87,9 @@ def main():
load_data(csv_handler, 'hard') load_data(csv_handler, 'hard')
data_frame = get_data(csv_handler, 1, 'left', 1, 1) data_frame = get_data(csv_handler, 1, 'left', 1, 1)
N_trans, cA, cD = wavelet_db4(data_frame) N, y_mfcc = mfcc(data_frame)
data_frame_freq = make_df_from_xandy(N_trans, cA, 1) plt.plot(y_mfcc)
plt.show()
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, 'Original data', data_frame_freq_filt, 'Analyzed data')
return None return None

View File

@ -1,12 +1,11 @@
import numpy as np import numpy as np
import matplotlib.pyplot as plt
import pandas
from pandas.core.frame import DataFrame from pandas.core.frame import DataFrame
from scipy.fft import fft, fftfreq from scipy.fft import fft, fftfreq
import pywt import pywt
import pyhton_speech_features as psf #from pyhton_speech_features.base import mfcc
#from scipy.signal import wavelets import sys
#import pyyawt sys.path.insert(0, '/Users/Markus/Prosjekter git/Slovakia 2021/python_speech_features/python_speech_features')
from python_speech_features.python_speech_features import *
import Handle_emg_data as Handler import Handle_emg_data as Handler
@ -78,9 +77,9 @@ def cepstrum(df:DataFrame):
return None return None
'''
def mfcc(df:DataFrame): def mfcc(df:DataFrame):
N = get_xory_from_df('x', df) N = get_xory_from_df('x', df)
y = get_xory_from_df('y', df) y = get_xory_from_df('y', df)
spf.mfcc(y, ) return N, base.mfcc(y, SAMPLE_RATE)
'''