-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_script.R
75 lines (75 loc) · 1.73 KB
/
test_script.R
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
source("dft_analysis.R")
library(dplyr)
library(ggplot2)
#
# test only
#
time_units <- 730
#
period_1 <- 90
period_2 <- 10000
period_3 <- 10000
#
granularity <- 10
time <- seq(1, time_units, 1 / granularity)
#
# sinusoid with period "period_1" units
#
X1 <- sin(2 * pi * time / period_1)
#
# sinusoid with period "period_2" units
#
X2 <- sin(2 * pi * time / period_2)
#
# sinusoid with period "period_3" units
# and a phase offset of of "offset time units
#
offset <- 17
X3 <- sin(offset / period_3 + 2 * pi * time / period_3)
#
# linear growth with time
#
X4 <- 0.0 * time
#
# Y is a linear function of the two sinusoids plus the growth term
#
Y <- 2.5 * X1 + X4
my_data <- data.frame(time = time,
X1 = X1,
X2 = X2,
X3 = X3,
X4 = X4,
Y = Y,
stringsAsFactors = FALSE)
#
# plot the first 300 time units
#
my_data %>%
filter(time < 300) %>%
ggplot(aes(x = time, y = Y)) +
geom_line(color = "blue", size = 1)
#
# run the DFT analysis
#
x_var <- "time"
y_var <- "Y"
low_cutoff <- 1000
dc_threshold <- low_cutoff - 0
noise_threshold <- 0.05
significance_threshold <- 1
peak_threshold_ratio <- 0.01
cycles = 3
#
dft_results <-
dft_analysis(data = my_data,
x_var = x_var,
y_var = y_var,
low_cutoff = low_cutoff,
dc_threshold = dc_threshold,
peak_threshold_ratio = peak_threshold_ratio,
cycles = cycles)
#
# dft_results has the periods and the model variable names
#
print(dft_results)