feat: add the samplerate as an output the get_data
This commit is contained in:
parent
9d3919c4f9
commit
c5d2e48771
@ -7,12 +7,12 @@ import matplotlib.pyplot as plt
|
|||||||
from matplotlib import cm
|
from matplotlib import cm
|
||||||
import matplotlib.ticker as ticker
|
import matplotlib.ticker as ticker
|
||||||
|
|
||||||
|
# Global variables for MFCC
|
||||||
SAMPLE_RATE = 200
|
|
||||||
mfcc_stepsize = 0.5
|
mfcc_stepsize = 0.5
|
||||||
mfcc_windowsize = 2
|
mfcc_windowsize = 2
|
||||||
|
|
||||||
# PLOT FUNCTIONS:
|
|
||||||
|
# PLOT FUNCTIONS --------------------------------------------------------------:
|
||||||
|
|
||||||
# Plots DataFrame objects
|
# Plots DataFrame objects
|
||||||
def plot_df(df:DataFrame):
|
def plot_df(df:DataFrame):
|
||||||
@ -36,19 +36,20 @@ 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):
|
def plot_mfcc(mfcc_data, data_label:str):
|
||||||
#plt.rcParams["figure.figsize"] = [7.50, 15]
|
|
||||||
#plt.rcParams["figure.autolayout"] = True
|
|
||||||
|
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
mfcc_data= np.swapaxes(mfcc_data, 0 ,1)
|
mfcc_data= np.swapaxes(mfcc_data, 0 ,1)
|
||||||
#ax.axis([0, mfcc_stepsize * len(mfcc_data[0]), 0, len(mfcc_data[:,0])])
|
|
||||||
#ax.set_xticks(range(int(len(mfcc_data) * 1 / mfcc_stepsize)))
|
ticks_x = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x * mfcc_stepsize))
|
||||||
|
ax.xaxis.set_major_formatter(ticks_x)
|
||||||
|
|
||||||
ax.imshow(mfcc_data, interpolation='nearest', cmap=cm.coolwarm, origin='lower')
|
ax.imshow(mfcc_data, interpolation='nearest', cmap=cm.coolwarm, origin='lower')
|
||||||
ax.set_title('MFCC')
|
ax.set_title('MFCC:' + data_label)
|
||||||
|
ax.set_ylabel('Cepstral coefficients')
|
||||||
|
ax.set_xlabel('Time(s)')
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
# DATA FUNCTIONS:
|
# DATA FUNCTIONS: --------------------------------------------------------------:
|
||||||
|
|
||||||
# The CSV_handler takes in data_type, but only for visuals.
|
# The CSV_handler takes in data_type, but only for visuals.
|
||||||
# E.g. handler = CSV_handler('soft')
|
# E.g. handler = CSV_handler('soft')
|
||||||
@ -66,10 +67,11 @@ def load_data(csv_handler:CSV_handler, data_type):
|
|||||||
else:
|
else:
|
||||||
raise Exception('Wrong input')
|
raise Exception('Wrong input')
|
||||||
|
|
||||||
# Retrieved data. Send in loaded csv_handler and data detailes you want. Returns DataFrame
|
# Retrieved data. Send in loaded csv_handler and data detailes you want. Returns DataFrame and samplerate
|
||||||
def get_data(csv_handler:CSV_handler, subject_nr, which_arm, session, emg_nr):
|
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)
|
data_frame = csv_handler.get_df_from_data_dict(subject_nr, which_arm, session, emg_nr)
|
||||||
return data_frame
|
samplerate = get_samplerate(data_frame)
|
||||||
|
return data_frame, samplerate
|
||||||
|
|
||||||
#Takes in handler and detailes to denoise. Returns arrays and df
|
#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):
|
||||||
@ -88,9 +90,9 @@ def mfcc_custom(df:DataFrame, samplesize, windowsize, stepsize):
|
|||||||
y = get_xory_from_df('y', df)
|
y = get_xory_from_df('y', df)
|
||||||
return N, base.mfcc(y, samplesize, windowsize, stepsize)
|
return N, base.mfcc(y, samplesize, windowsize, stepsize)
|
||||||
|
|
||||||
# CASE FUNTIONS
|
# CASE FUNTIONS ----------------------------------------------------------------:
|
||||||
|
|
||||||
def compare_with_wavelet(data_frame):
|
def compare_with_wavelet_filter(data_frame):
|
||||||
N_trans, cA, cD = wavelet_db4(data_frame)
|
N_trans, cA, cD = wavelet_db4(data_frame)
|
||||||
data_frame_freq = make_df_from_xandy(N_trans, cA, 1)
|
data_frame_freq = make_df_from_xandy(N_trans, cA, 1)
|
||||||
|
|
||||||
@ -100,19 +102,18 @@ def compare_with_wavelet(data_frame):
|
|||||||
plot_compare_two_df(data_frame_freq, 'Original data', data_frame_freq_filt, 'Analyzed data')
|
plot_compare_two_df(data_frame_freq, 'Original data', data_frame_freq_filt, 'Analyzed data')
|
||||||
|
|
||||||
|
|
||||||
# MAIN:
|
# MAIN: ------------------------------------------------------------------------:
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
csv_handler = CSV_handler()
|
csv_handler = CSV_handler()
|
||||||
load_data(csv_handler, 'hard')
|
load_data(csv_handler, 'hard')
|
||||||
data_frame = get_data(csv_handler, 2, 'left', 1, 1)
|
data_frame, samplerate = get_data(csv_handler, 2, 'left', 1, 1)
|
||||||
|
|
||||||
print(get_samplerate(data_frame))
|
N, mfcc_feat = mfcc_custom(data_frame[:5000], samplerate, mfcc_windowsize, mfcc_stepsize)
|
||||||
|
|
||||||
N, mfcc_feat = mfcc_custom(data_frame[:5000], SAMPLE_RATE, mfcc_windowsize, mfcc_stepsize)
|
|
||||||
plot_mfcc(mfcc_feat)
|
plot_mfcc(mfcc_feat)
|
||||||
print(get_sample_data)
|
#print(mfcc_feat)
|
||||||
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ from python_speech_features.python_speech_features import *
|
|||||||
|
|
||||||
import Handle_emg_data as Handler
|
import Handle_emg_data as Handler
|
||||||
|
|
||||||
SAMPLE_RATE = 200
|
|
||||||
|
|
||||||
|
|
||||||
# Takes in a df and outputs np arrays for x and y values
|
# Takes in a df and outputs np arrays for x and y values
|
||||||
@ -30,7 +29,7 @@ def fft_of_df(df:DataFrame):
|
|||||||
y_values = get_xory_from_df('y', df)
|
y_values = get_xory_from_df('y', df)
|
||||||
N = y_values.size
|
N = y_values.size
|
||||||
norm = normalize_wave(y_values)
|
norm = normalize_wave(y_values)
|
||||||
N_trans = fftfreq(N, 1 / SAMPLE_RATE)
|
N_trans = fftfreq(N, 1 / Handler.get_samplerate(df))
|
||||||
y_f = fft(norm)
|
y_f = fft(norm)
|
||||||
return N_trans, y_f
|
return N_trans, y_f
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user