-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstress_analysis.R
More file actions
54 lines (40 loc) · 1.84 KB
/
stress_analysis.R
File metadata and controls
54 lines (40 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Documentation -----------------------------------------------------------
# Title: "Stress prediction using IBI"
# Author: "Deepak Sharma"
# Date: "March 20, 2017"
# Import libraries --------------------------------------------------------
library(xlsx)
# Import data -------------------------------------------------------------
di <- read.xlsx("~/AIIMS work/Stress_analysis/Datasets/dr. bhola 8-5-15(E).xlsx",sheetIndex = 1,header = TRUE)
# Filter parameters -------------------------------------------------------
min_ibi <- 400
max_ibi <- 1200
margin <- 50
# Subsetting --------------------------------------------------------------
first <- margin
di_ibi <- as.numeric(di$IBI)
times <- di$LocalTime
lasttime <- tail(times[!is.na(times)], 1)
last <- which(times == lasttime)
last <- last - margin
di_ibi <- di_ibi[first:last]
s_set <- as.numeric(subset(di_ibi, di_ibi >= min_ibi & di_ibi < max_ibi ))
cat("Range of IBI (Min, Max) : ", range(di_ibi))
cat("Standard deviation of complete dataset: ", sd(di_ibi))
cat("Standard deviation of subset : ", sd(s_set))
y <- fft(as.numeric(s_set))
# Process -----------------------------------------------------------------
freq_frame = as.data.frame(table(s_set))
colnames(freq_frame) <- c("Inter Beat Interval", "Frequency")
freq_frame
x = as.numeric(as.vector(freq_frame[,1]))
y = freq_frame[,2]
freq_codes <- list("Very low frequency","LOw frequency","High frequency","Very high frequency")
# Visualization -----------------------------------------------------------
plot(x,y,main = "Frequency spectrum of Inter Beat Interval",
xlab="Inter Beat Interval", ylab="Frequency",
xlim=c(min(x),max(x)), ylim=c(min(y),max(y)),pch=15, col="blue")
text(x, y, row.names(freq_frame$Frequency), cex=1, pos=1, col="blue",labels = freq_codes)
plot(1:last,fft(di_ibi),type = 'l')
plot(s_set,type='l')
hist(s_set,breaks = 800)