Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
AS_activity_recognition
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Max Nyberg Carlsson
AS_activity_recognition
Commits
460eedc1
Commit
460eedc1
authored
2 years ago
by
Max Nyberg Carlsson
Browse files
Options
Downloads
Patches
Plain Diff
Frequency method
parent
dd48c768
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
frequency_power.jl
+33
-13
33 additions, 13 deletions
frequency_power.jl
with
33 additions
and
13 deletions
frequency_power.jl
+
33
−
13
View file @
460eedc1
using
Pkg
;
Pkg
.
activate
(
"."
);
using
Pkg
;
Pkg
.
activate
(
"."
);
using
FFTW
,
DSP
,
Plots
,
DelimitedFiles
using
FFTW
,
DSP
,
Plots
,
DelimitedFiles
using
REPL
.
TerminalMenus
function
plot_spectrogram
(
s
,
n
=
div
(
length
(
s
),
8
),
noverlap
=
div
(
n
,
2
))
function
plot_spectrogram
(
s
,
n
=
div
(
length
(
s
),
8
),
noverlap
=
div
(
n
,
2
))
n
=
80
noverlap
=
n
-
1
#div(n,2)
spec
=
spectrogram
(
s
,
n
,
noverlap
)
spec
=
spectrogram
(
s
,
n
,
noverlap
)
n
=
300
spec
=
spectrogram
(
s
,
n
,
n
-
1
)
power
=
spec
.
power
./
sum
(
spec
.
power
,
dims
=
1
)
power
=
spec
.
power
./
sum
(
spec
.
power
,
dims
=
1
)
heatmap
(
spec
.
time
,
spec
.
freq
,
power
)
heatmap
(
spec
.
time
,
spec
.
freq
,
power
)
end
end
...
@@ -12,6 +13,13 @@ function plot_periodogram(s)
...
@@ -12,6 +13,13 @@ function plot_periodogram(s)
peri
=
periodogram
(
s
)
peri
=
periodogram
(
s
)
plot
(
peri
.
freq
,
peri
.
power
)
plot
(
peri
.
freq
,
peri
.
power
)
end
end
function
plot_periodogram
(
x
,
y
,
z
)
perix
=
periodogram
(
x
)
periy
=
periodogram
(
y
)
periz
=
periodogram
(
z
)
power
=
max
.
(
perix
.
power
,
periy
.
power
,
periz
.
power
)
plot
(
perix
.
freq
,
power
)
end
function
read_data
(
dataname
,
sensor
)
function
read_data
(
dataname
,
sensor
)
return
readdlm
(
"data/
$(dataname)
_
$(sensor)
.txt"
,
Float64
)
return
readdlm
(
"data/
$(dataname)
_
$(sensor)
.txt"
,
Float64
)
...
@@ -30,20 +38,32 @@ getpitch(data) = data[:,3]
...
@@ -30,20 +38,32 @@ getpitch(data) = data[:,3]
getroll
(
data
)
=
data
[
:
,
4
]
getroll
(
data
)
=
data
[
:
,
4
]
normalize_data
(
A
)
=
sqrt
.
(
sum
(
A
.^
2
,
dims
=
2
))
# TODO squareroot?
normalize_data
(
A
)
=
sqrt
.
(
sum
(
A
.^
2
,
dims
=
2
))
# TODO squareroot?
decimate
(
v
)
=
resample
(
v
,
0.1
)
mean
(
v
)
=
sum
(
v
)
/
length
(
v
)
mean
(
v
)
=
sum
(
v
)
/
length
(
v
)
detrend
(
v
)
=
v
.-
mean
(
v
)
detrend
(
v
)
=
v
.-
mean
(
v
)
acc_data
(
dataname
)
=
read_acc
(
dataname
)
|>
xyz
|>
normalize_data
|>
vec
|>
detrend
acc_data
(
dataname
)
=
read_acc
(
dataname
)
|>
xyz
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
acc_spectogram
(
dataname
)
=
acc_data
(
dataname
)
|>
plot_spectrogram
x_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getx
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
acc_periodogram
(
dataname
)
=
acc_data
(
dataname
)
|>
plot_periodogram
y_data
(
dataname
)
=
read_acc
(
dataname
)
|>
gety
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
x_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getx
|>
normalize_data
|>
vec
|>
detrend
z_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getz
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
y_data
(
dataname
)
=
read_acc
(
dataname
)
|>
gety
|>
normalize_data
|>
vec
|>
detrend
z_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getz
|>
normalize_data
|>
vec
|>
detrend
xyz_data
(
dataname
)
=
(
x_data
(
dataname
),
y_data
(
dataname
),
z_data
(
dataname
))
xyz_data
(
dataname
)
=
(
x_data
(
dataname
),
y_data
(
dataname
),
z_data
(
dataname
))
acc_spectrogram
(
dataname
)
=
acc_data
(
dataname
)
|>
plot_spectrogram
acc_periodogram
(
dataname
)
=
acc_data
(
dataname
)
|>
plot_periodogram
gyr_data
(
dataname
)
=
read_gyr
(
dataname
)
|>
ypr
|>
normalize_data
|>
vec
|>
detrend
gyr_data
(
dataname
)
=
read_gyr
(
dataname
)
|>
ypr
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
gyr_spectogram
(
dataname
)
=
gyr_data
(
dataname
)
|>
plot_spectrogram
pitch_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getpitch
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
yaw_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getyaw
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
roll_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getroll
|>
normalize_data
|>
vec
|>
decimate
|>
detrend
gyr_spectrogram
(
dataname
)
=
gyr_data
(
dataname
)
|>
plot_spectrogram
gyr_periodogram
(
dataname
)
=
gyr_data
(
dataname
)
|>
plot_periodogram
gyr_periodogram
(
dataname
)
=
gyr_data
(
dataname
)
|>
plot_periodogram
pitch_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getpitch
|>
normalize_data
|>
vec
|>
detrend
yaw_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getyaw
|>
normalize_data
|>
vec
|>
detrend
function
menuplot
()
roll_data
(
dataname
)
=
read_acc
(
dataname
)
|>
getroll
|>
normalize_data
|>
vec
|>
detrend
datasets
=
[
"jogging1"
,
"jogging2"
,
"mix1"
,
"standing1"
,
"walking1"
,
"walking2"
]
keybindings
=
[
Char
(
'0'
+
i
)
for
i
in
1
:
length
(
datasets
)]
menu
=
RadioMenu
(
datasets
,
pagesize
=
min
(
length
(
datasets
),
10
),
keybindings
=
keybindings
)
choice
=
request
(
"Please choose a dataset (up/down or 1-9):"
,
menu
)
acc_spectrogram
(
datasets
[
choice
])
end
@show
menuplot
()
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