Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MCC Flow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
Köllőd Csaba
MCC Flow
Commits
61f77762
Commit
61f77762
authored
2 years ago
by
Köllőd Csaba
Browse files
Options
Downloads
Patches
Plain Diff
Add legacy.py
parent
c220884d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mcc-flow/legacy.py
+156
-0
156 additions, 0 deletions
mcc-flow/legacy.py
with
156 additions
and
0 deletions
mcc-flow/legacy.py
0 → 100644
+
156
−
0
View file @
61f77762
import
argparse
from
struct
import
*
import
matplotlib.pyplot
as
plt
import
numpy
as
np
# import soundfile as sf
from
scipy
import
signal
########################################
########################################
def
notch
(
data
):
# Create/view notch filter
samp_freq
=
250
# Sample frequency (Hz)
notch_freq
=
50.0
# Frequency to be removed from signal (Hz)
quality_factor
=
10.0
# Quality factor
b_notch
,
a_notch
=
signal
.
iirnotch
(
notch_freq
,
quality_factor
,
samp_freq
)
# freq, h = signal.freqz(b_notch, a_notch, fs=samp_freq)
# apply notch filter to signal
return
signal
.
filtfilt
(
b_notch
,
a_notch
,
data
)
######################################
######################################
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
-i
'
,
'
--input_file
'
,
required
=
False
,
type
=
str
,
default
=
"
test.dat
"
,
metavar
=
"
<string>
"
,
help
=
"
Input file to be visualized
"
)
# filename = "test.dat"
args
=
parser
.
parse_args
()
filename
=
args
.
input_file
file
=
open
(
filename
,
"
rb
"
)
# bin_arr = file.read()
no_packets
=
unpack
(
'
>i
'
,
file
.
read
(
4
))[
0
]
great_buffer
=
[]
sound
=
[]
print
(
f
"
Number of packets in file:
{
no_packets
}
"
)
packet_struct_header
=
"
>IIBBBBBBBBBBBHHH
"
packet_struct_header_size
=
4
+
4
+
10
+
1
+
2
+
2
+
2
packet_struct_eeg
=
"
i
"
*
4
*
250
+
3
*
"
h
"
*
50
+
3
*
"
h
"
*
50
packet_struct_eeg_size
=
4
*
4
*
250
+
3
*
2
*
50
+
3
*
2
*
50
packet_struct_emg
=
"
i
"
*
6
*
250
+
3
*
"
h
"
*
50
+
3
*
"
h
"
*
50
+
"
h
"
*
6000
+
"
h
"
*
10
packet_struct_emg_size
=
4
*
6
*
250
+
3
*
2
*
50
+
3
*
2
*
50
+
2
*
6000
+
2
*
10
packet_struct_header_s
=
2
+
10
+
1
+
1
+
1
+
1
packet_struct_eeg_s
=
250
*
4
+
3
*
50
+
3
*
50
packet_struct_emg_s
=
250
*
6
+
3
*
50
+
3
*
50
packet_struct_ss_s
=
6000
+
10
packet_bin
=
packet_struct_header
+
packet_struct_eeg
+
packet_struct_emg
packet_bin_size
=
packet_struct_header_size
+
packet_struct_eeg_size
+
packet_struct_emg_size
# no_packets = 60
for
i
in
range
(
no_packets
):
try
:
packet
=
[
*
unpack
(
packet_bin
,
file
.
read
(
packet_bin_size
))]
except
Exception
as
e
:
print
(
e
)
print
(
"
Got :
"
+
str
(
len
(
file
.
read
(
packet_bin_size
))))
great_buffer
.
append
(
packet
)
print
(
f
"
Packet len:
{
packet_bin_size
}
"
)
print
(
f
"
-- header len:
{
packet_struct_header_size
}
"
)
print
(
f
"
-- arc len:
{
4
*
4
*
250
}
"
)
print
(
f
"
-- imu len:
{
2
*
50
}
"
)
print
(
f
"
Remaining:
{
len
(
file
.
read
())
}
"
)
great_buffer
=
np
.
array
(
great_buffer
)
print
(
f
"
Great buffer shape:
{
great_buffer
.
shape
}
"
)
sound
=
great_buffer
[:,
packet_struct_header_s
+
packet_struct_eeg_s
+
packet_struct_emg_s
:
packet_struct_header_s
+
packet_struct_eeg_s
+
packet_struct_emg_s
+
6000
]
arb_gyro
=
great_buffer
[:,
packet_struct_header_s
+
packet_struct_eeg_s
+
packet_struct_emg_s
-
300
:
packet_struct_header_s
+
packet_struct_eeg_s
+
packet_struct_emg_s
-
150
]
arb_accel
=
great_buffer
[:,
packet_struct_header_s
+
packet_struct_eeg_s
+
packet_struct_emg_s
-
150
:
packet_struct_header_s
+
packet_struct_eeg_s
+
packet_struct_emg_s
]
arc_gyro
=
great_buffer
[:,
packet_struct_header_s
+
packet_struct_eeg_s
-
300
:
packet_struct_header_s
+
packet_struct_eeg_s
-
150
]
arc_accel
=
great_buffer
[:,
packet_struct_header_s
+
packet_struct_eeg_s
-
150
:
packet_struct_header_s
+
packet_struct_eeg_s
]
eeg
=
great_buffer
[:,
packet_struct_header_s
:
packet_struct_header_s
+
250
*
4
]
emg
=
great_buffer
[:,
packet_struct_header_s
+
packet_struct_eeg_s
:
packet_struct_header_s
+
packet_struct_eeg_s
+
250
*
6
]
gsr
=
great_buffer
[:,
-
10
:]
###############
## Plottable
##############
sound_data
=
np
.
reshape
(
sound
,
(
-
1
,))
arc_accel
=
np
.
reshape
(
arc_accel
,
(
-
1
,
3
))
arb_accel
=
np
.
reshape
(
arb_accel
,
(
-
1
,
3
))
arc_gyro
=
np
.
reshape
(
arc_gyro
,
(
-
1
,
3
))
arb_gyro
=
np
.
reshape
(
arb_gyro
,
(
-
1
,
3
))
gsr
=
np
.
reshape
(
gsr
,
(
-
1
,))
eeg
=
np
.
reshape
(
eeg
,
(
-
1
,
4
))
eeg
=
np
.
array
([
notch
(
eeg
[:,
i
])
for
i
in
range
(
4
)])
emg
=
np
.
reshape
(
emg
,
(
-
1
,
6
))
emg
=
np
.
array
([
notch
(
emg
[:,
i
])
for
i
in
range
(
6
)])
# print(f"Plot shape: {sound_data.shape}")
plt
.
title
(
"
GSR
"
)
plt
.
plot
(
gsr
)
plt
.
show
()
plt
.
title
(
"
EMG
"
)
plt
.
plot
(
emg
[
5
])
plt
.
show
()
plt
.
title
(
"
EEG
"
)
plt
.
plot
(
eeg
[
0
])
plt
.
plot
(
eeg
[
1
])
plt
.
plot
(
eeg
[
2
])
plt
.
plot
(
eeg
[
3
])
plt
.
show
()
plt
.
title
(
"
ARB Accel
"
)
plt
.
plot
(
arb_accel
)
plt
.
show
()
plt
.
title
(
"
ARB Gyro
"
)
plt
.
plot
(
arb_gyro
)
plt
.
show
()
plt
.
title
(
"
Sound data
"
)
plt
.
plot
(
sound_data
)
plt
.
show
()
# sound_data = (sound_data - np.mean(sound_data)) / (np.max(sound_data) - np.min(sound_data))
# sf.write("audio_recording.wav", sound_data, 6000)
"""
if __name__ ==
"
__main__
"
:
main(sys.argv[1:])
"""
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