Skip to content

Instantly share code, notes, and snippets.

@nassimhaddad
Created September 4, 2014 10:12
Show Gist options
  • Save nassimhaddad/c2a7cb549c1ccb3d5a5a to your computer and use it in GitHub Desktop.
Save nassimhaddad/c2a7cb549c1ccb3d5a5a to your computer and use it in GitHub Desktop.
to create a distortion in a time series
#' function that distorts
distort <- function(y, from, to){
before <- seq(from=1, to=from,length.out = to)
after <- seq(from=from+1, to=length(y), length.out = length(y)-to)
out <- approx(seq(y),y, xout = c(before, after))
return(out$y)
}
# example
x <- seq(1,120, by = 1)
y <- seq(x)*sin(x/2)
plot(x, y, type="l")
lines(x, distort(y, 60, 20), col = "red")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment