# period of sesonality is 365
# initial parameter of kza 365
# seasonal data
yrs <- 20
t <- seq(0,yrs,length=yrs*365)
q <- 365/2
#noise
set.seed(6); e <- rnorm(n = length(t), sd = 1.0)
trend <- seq(0,-1,length=length(t))
#signal
bkpt <- 3452
brk <- c(rep(0,bkpt),rep(0.2,length(t)-bkpt))
signal <- trend + brk
# y = seasonal + trend + break point + noise
y <- sin(2*pi*t) + signal + e
# kza reconstruction of the signal
z <- kza(y,q)
k.kza <- z[[1]]
# determine adaptive filter
f <- kzf(y,q,rep(0,365*yrs))
k.f <- f[[5]]
# plot of sample variance
s <- kzsv(k.kza,q,k.f)
k.s <- s[[1]]
par(mfrow=c(2,2))
plot(y,type="l", main="Signal + Seasonality(365) + Noise ")
plot(signal,type="l",ylim=c(-2,2), main="Signal and KZA Reconstruction (break=0.2,q=365/2)")
lines(k.kza)
plot(k.s,type="l",main="Sample Variance (break=0.2,q=365/2)")
# example with break = 0.5
brk <- c(rep(0,bkpt),rep(0.5,length(t)-bkpt))
signal <- trend + brk
# y = seasonal + trend + break point + noise
y <- sin(2*pi*t) + signal + e
# kza reconstruction of the signal
z <- kza(y,365)
k.kza <- z[[1]]
plot(signal,type="l",ylim=c(-2,2), main="Signal and KZA Reconstruction (break=0.5,q=365)")
lines(k.kza)
Run the code above in your browser using DataLab