Created
November 19, 2021 15:21
-
-
Save CnrLwlss/5cd83de5529d0eda74fe64781e7dbd6e to your computer and use it in GitHub Desktop.
Simulating two schemes for irregular sampling from regular timeseries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulating two schemes for irregular sampling from regular timeseries | |
deltasim = 0.1 | |
deltarec = 1/3 | |
tmax = 10.0 | |
simtimes = seq(0,tmax,0.1) | |
rectargets = seq(0,tmax,deltarec) | |
recindex = 1 | |
nextrec = rectimes[1] | |
actualrecs = c() | |
actualrecs_index = c() | |
for (st in simtimes){ | |
# Jordan method | |
if(st>=nextrec){ | |
actualrecs = c(actualrecs,st) | |
nextrec = st + deltarec | |
} | |
# Conor method (better) | |
if(st>=rectargets[recindex]){ | |
actualrecs_index = c(actualrecs_index,st) | |
recindex = recindex+1 | |
} | |
} | |
# These points should all lie on the red line, but... | |
trim = min(c(length(actualrecs),length(rectargets),length(actualrecs_index))) | |
plot(rectargets[1:trim],actualrecs[1:trim],xlim=c(0,tmax),ylim=c(0,tmax),cex=1.5,pch=16) | |
points(rectargets[1:trim],actualrecs_index[1:trim],col="blue",cex=1.5,pch=16) | |
abline(a=0,b=1,col="red",lwd=3) | |
legend("topleft",c("Jordan","Conor","Perfection"),col=c("black","blue","red"),pch=16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment