Skip to content
Snippets Groups Projects
Commit c7cf0c1c authored by LexvanGastel's avatar LexvanGastel
Browse files

vraag9

parent 9ceb0184
Branches
No related tags found
No related merge requests found
import scipy.io import scipy.io
import numpy as np
from scipy.signal import butter, filtfilt from scipy.signal import butter, filtfilt
import scipy.signal import matplotlib.pyplot as plt
def load_emg_data(file_path): def load_emg_data(file_path):
...@@ -25,8 +26,8 @@ def load_emg_data(file_path): ...@@ -25,8 +26,8 @@ def load_emg_data(file_path):
return channel_names return channel_names
file_path = "emg_data_walking.mat" #file_path = "emg_data_walking.mat"
load_emg_data(file_path) #load_emg_data(file_path)
chosen_muscles = { chosen_muscles = {
'rectus_fomoris': 0, 'rectus_fomoris': 0,
...@@ -43,7 +44,7 @@ class DataRetrieval: ...@@ -43,7 +44,7 @@ class DataRetrieval:
def load_data(self): def load_data(self):
mat_data = scipy.io.loadmat(self.file_path) mat_data = scipy.io.loadmat(self.file_path)
self.emg_data = mat_data['emg_data_walking'] self.emg_data = mat_data['emg_data_walking']
self.channel_names = emg_data['data_headers'][0][0] self.channel_names = self.emg_data['data_headers'][0][0]
self.channel_names = [ch[0] for ch in self.channel_names[0]] self.channel_names = [ch[0] for ch in self.channel_names[0]]
def get_channel_names(self): def get_channel_names(self):
...@@ -63,15 +64,50 @@ class SignalProcessing: ...@@ -63,15 +64,50 @@ class SignalProcessing:
pass pass
#print(dir(scipy.signal)) #print(dir(scipy.signal))
mat_data = scipy.io.loadmat('emg_data_walking.mat')
emg_data = mat_data['emg_data_walking']
sampling_rate = emg_data['sampling_rate'][0][0][0]
data = emg_data['data'][0][0] def info_emg_data(file_path):
num_samples = data.shape[1] mat_data = scipy.io.loadmat(file_path)
emg_data = mat_data['emg_data_walking']
sampling_rate = emg_data['sampling_rate'][0][0][0]
data = emg_data['data'][0][0]
num_samples = data.shape[1]
duration = num_samples / sampling_rate
return sampling_rate, data, num_samples, duration
#file_path = "emg_data_walking.mat"
#info_emg_data(file_path)
def plot_emg_data(file_path):
sampling_rate, data, num_samples, duration = info_emg_data(file_path)
sampling_time = float(1/sampling_rate)
time_vector = np.arange(0,duration,sampling_time)
channel_rectus_femoris = data[chosen_muscles['rectus_fomoris'], :]
channel_tibialis_anterior = data[chosen_muscles['tibialis_anterior'], :]
plt.figure(figsize=(10,6))
plt.subplot(2, 1, 1)
plt.plot(time_vector, channel_rectus_femoris)
plt.title('EMG Data - Rectus femoris')
plt.xlabel('Time [Seconds]')
plt.ylabel('Amplitude')
plt.subplot(2, 1, 2)
plt.plot(time_vector, channel_tibialis_anterior)
plt.title('EMG Data - Tibialis Anterior')
plt.xlabel('Time [seconds]')
plt.ylabel('Amplitude')
plt.tight_layout()
plt.show()
file_path = "emg_data_walking"
plot_emg_data(file_path)
duration = num_samples / sampling_rate
print(f"Sampling frequentie: {sampling_rate} Hz")
print(f"Aantal samples: {num_samples}")
print(f"Lengte van de data: {duration}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment