# R functions to perform symmetric extension and # periodization of a vector x, evaluated at index i e11s <- function(x, i) { n<- length(x); period<- 2*n-2; # WSS at 0 and WSS at n-1 if(i<0) { i<- -i; } i<- i %% period; if(i>n-1) { i<- period-i; } return(x[i+1]); # +1 accommodates index range 0,...,n-1. } e22s <- function(x, i) { n<- length(x); period<- 2*n-1; # HSS at -1/2 and HSS at n-1/2 if(i<0) { i<- -1-i; } i<- i %% period; if(i>n-1) { i<- period-i; } return(x[i+1]); # +1 accommodates index range 0,...,n-1. } # example plots indices <- 1:60; shift <- 18; # evaluate at -17,-16, ..., 42 u11s<-indices; u22s<-indices; # initialize output vectors u<-sin(2*pi*(1:9)/13); # input: 9-sample vector for(i in indices) { u11s[i] <- e11s(u,i-shift) u22s[i] <- e22s(u,i-shift) } matplot(cbind(u11s,u22s))