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

vraag 9 goede plot

parent 5a77ce09
Branches
No related tags found
No related merge requests found
......@@ -12,7 +12,6 @@ def load_emg_data(file_path):
emg_data = mat_data['emg_data_walking']
channel_names = emg_data['data_headers'][0][0]
channel_names = [ch[0] for ch in channel_names[0]]
......@@ -26,7 +25,7 @@ def load_emg_data(file_path):
return channel_names
#file_path = "emg_data_walking.mat"
file_path = "emg_data_walking.mat"
#load_emg_data(file_path)
chosen_muscles = {
......@@ -56,12 +55,20 @@ class SignalProcessing:
self.fs = fs
def bandpass_filter(self, data, lowcut, highcut):
#komt nog filters
pass
nyquist = 0.5 * self.fs
low = lowcut / nyquist
high = highcut / nyquist
order = 4
b, a = butter(order, [low, high], btype='band')
filtered_data = filtfilt(b, a, data)
return filtered_data
def power_spectral_analysis(self, data):
#methode
pass
N = len(data)
fft_values = np.fft.fft(data)
fft_magnitude = np.abs(fft_values[:N//2])
freq = np.fft.fftfreq(N, d=1/self.fs)[:N//2]
return freq, fft_magnitude
#print(dir(scipy.signal))
......@@ -70,16 +77,21 @@ def info_emg_data(file_path):
mat_data = scipy.io.loadmat(file_path)
emg_data = mat_data['emg_data_walking']
print("Structuur van emg_data:", emg_data.dtype, emg_data.shape)
print("Beschikbare velden in emg_data:", emg_data.dtype.names)
sampling_rate = emg_data['sampling_rate'][0][0][0]
data = emg_data['data'][0][0]
data = data.T
print("Shape van data:", data.shape)
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)
file_path = "emg_data_walking.mat"
info_emg_data(file_path)
def compute_fft(signal, sampling_rate):
N = len(signal)
......@@ -92,12 +104,15 @@ 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'], :]
num_samples = int(6 * sampling_rate)
num_samples = min(num_samples, data.shape[1])
time_vector = np.linspace(0,6,num_samples)
channel_rectus_femoris = data[chosen_muscles['rectus_fomoris'], :num_samples]
channel_tibialis_anterior = data[chosen_muscles['tibialis_anterior'], :num_samples]
freq_rf, fft_rf = compute_fft(channel_rectus_femoris, sampling_rate)
freq_ta, fft_ta = compute_fft(channel_tibialis_anterior, sampling_rate)
freq_rf, fft_rf = compute_fft(channel_rectus_femoris[:num_samples], sampling_rate)
freq_ta, fft_ta = compute_fft(channel_tibialis_anterior[:num_samples], sampling_rate)
plt.figure(figsize=(10,6))
......@@ -106,14 +121,13 @@ def plot_emg_data(file_path):
plt.title('EMG Data - Rectus femoris')
plt.xlabel('Time [Seconds]')
plt.ylabel('Amplitude')
plt.legend()
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.legend()
plt.tight_layout()
plt.show()
......@@ -133,10 +147,12 @@ def plot_emg_data(file_path):
plt.tight_layout()
plt.show()
file_path = "emg_data_walking"
plot_emg_data(file_path)
print(num_samples)
file_path = "emg_data_walking.mat"
plot_emg_data(file_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment