Files
sleep-detection/plots/straight-data.gnuplot
T
2026-08-13 09:33:00 +02:00

52 lines
1.8 KiB
Gnuplot

# Copyright (C) 2026 Asger Gitz-Johansen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set term qt
set datafile separator " "
set title "Subject 1066528 Sleep"
# Get the magnitude of the derivative-vector.
# We need 3 sets of delta variables, hence we have 3 functions.
# Return NaN for first point, otherwise delta y or (delta y)/(delta x)
d1(y) = ($0 == 0) ? (y11 = y, NaN) : (y21 = y11, y11 = y, y11-y21)
d2(y) = ($0 == 0) ? (y12 = y, NaN) : (y22 = y12, y12 = y, y12-y22)
d3(y) = ($0 == 0) ? (y13 = y, NaN) : (y23 = y13, y13 = y, y13-y23)
mag(x,y,z) = sqrt((x**2) + (y**2) + (z**2))
scale = 1 # 1024 # bma425's default scaling is 1024 (+1g to -1g).
dmag(x,y,z) = mag( \
abs(d1(x)/scale), \
abs(d2(y)/scale), \
abs(d3(z)/scale) \
)
set multiplot
set yrange [-0.1:2 < * < 10] extend
set xrange [-1000:30000] extend
unset ytics
plot "data/motion/1066528_acceleration.txt" using 1:(dmag($2,$3,$4)) w l t "Motion" lw 1 lc "gray"
unset title
unset xtics
unset border
set yrange [-2:8]
set ytics ("Wake" 0, "N1" 1, "N2" 2, "N3" 3, "REM" 5)
plot "data/labels/1066528_labeled_sleep.txt" using 1:2 w l t "Sleep" lw 3 lc "blue"
set y2range [0:200]
set datafile separator ","
plot "data/heart_rate/1066528_heartrate.txt" using 1:2 w l axes x1y2 t "HR" lc "red"