Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
assignment Programming 2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gastel, L. van (Lex, Student B-BMT)
assignment Programming 2
Commits
d0de7d16
Commit
d0de7d16
authored
3 weeks ago
by
LexvanGastel
Browse files
Options
Downloads
Patches
Plain Diff
vraag 9 goede plot
parent
5a77ce09
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+34
-18
34 additions, 18 deletions
main.py
with
34 additions
and
18 deletions
main.py
+
34
−
18
View file @
d0de7d16
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment