From bd0ca8d46671fb5637454b073bf8b8bc80971b25 Mon Sep 17 00:00:00 2001 From: LexvanGastel <l.vangastel@studen.utwente.nl> Date: Tue, 1 Apr 2025 17:59:27 +0200 Subject: [PATCH] vraag 13 --- main.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 7afa614..035bb00 100644 --- a/main.py +++ b/main.py @@ -62,6 +62,14 @@ class SignalProcessing: b, a = butter(order, [low, high], btype='band') filtered_data = filtfilt(b, a, data) return filtered_data + + def lowpass_filter(self, data, cutoff): + nyquist = 0.5 * self.fs + normal_cutoff = cutoff / nyquist + order = 4 + b, a = butter(order, normal_cutoff, btype='low') + filtered_data = filtfilt(b, a, data) + return filtered_data def power_spectral_analysis(self, data): N = len(data) @@ -113,21 +121,25 @@ def plot_emg_data(file_path): filtered_ta = signal_processor.bandpass_filter(channel_tibialis_anterior, 25, 300) rectified_rf = np.abs(filtered_rf) - recitfied_ta = np.abs(filtered_ta) + rectified_ta = np.abs(filtered_ta) + + envelope_rf = signal_processor.lowpass_filter(rectified_rf,5) + envelope_ta = signal_processor.lowpass_filter(rectified_ta,5) + - freq_rf, fft_rf = compute_fft(rectified_rf, sampling_rate) - freq_ta, fft_ta = compute_fft(recitfied_ta, sampling_rate) + freq_rf, fft_rf = compute_fft(envelope_rf, sampling_rate) + freq_ta, fft_ta = compute_fft(envelope_ta, sampling_rate) plt.figure(figsize=(13,8)) plt.subplot(2, 2, 1) - plt.plot(time_vector, filtered_rf) + plt.plot(time_vector, envelope_rf) plt.title('EMG Data - Rectus femoris') plt.xlabel('Time [Seconds]') plt.ylabel('Amplitude') plt.subplot(2, 2, 2) - plt.plot(time_vector, filtered_ta) + plt.plot(time_vector, envelope_ta) plt.title('EMG Data - Tibialis Anterior') plt.xlabel('Time [seconds]') plt.ylabel('Amplitude') -- GitLab