ts <- rep(61:65, 10)
ApEn(ts, edim = 2) # -0.000936195
set.seed(8237)
ApEn(rnorm(500), edim = 2) # 1.48944 high, random
ApEn(sin(seq(1,100,by=0.2)), edim = 2) # 0.22831 low, deterministic
(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] <- ApEn(sint, 2, r*sd1)
result[2, i] <- ApEn(chirpt, 2, r*sd2)
result[3, i] <- ApEn(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