ts <- rep(61:65, 10)
approx_entropy(ts, edim = 2) # -0.000936195
sample_entropy(ts, edim = 2) # 0
set.seed(8237)
approx_entropy(rnorm(500), edim = 2) # 1.48944 high, random
approx_entropy(sin(seq(1,100,by=0.2)), edim = 2) # 0.22831 low, deterministic
sample_entropy(sin(seq(1,100,by=0.2)), edim = 2) # 0.2359326
(Careful: This will take several minutes.)
# generate simulated data
N <- 1000; t <- 0.001*(1:N)
sint <- sin(2*pi*10*t); sd1 <- sd(sint) # sine curve
chirpt <- sint + 0.1*whitet; sd2 <- sd(chirpt) # chirp signal
whitet <- rnorm(N); sd3 <- sd(whitet) # white noise
# calculate approximate entropy
rnum <- 30; result <- zeros(3, rnum)
for (i in 1:rnum) {
r <- 0.02 * i
result[1, i] <- approx_entropy(sint, 2, r*sd1)
result[2, i] <- approx_entropy(chirpt, 2, r*sd2)
result[3, i] <- approx_entropy(whitet, 2, r*sd3)
}
# plot curves
r <- 0.02 * (1:rnum)
plot(c(0, 0.6), c(0, 2), type="n",
xlab = "", ylab = "", main = "Approximate Entropy")
points(r, result[1, ], col="red"); lines(r, result[1, ], col="red")
points(r, result[2, ], col="green"); lines(r, result[2, ], col="green")
points(r, result[3, ], col="blue"); lines(r, result[3, ], col="blue")
grid()
Run the code above in your browser using DataLab