# Here we generate a causal AR(2) where the roots are complex, thus giving rise to # pseudo periods # Since it is causal, lambda must be less than one (this ensures the roots of the characteristic function lie # outside the unit circle). # omega must lie between 0 and pi ar2complex = function(lambda,omega,n1){ n = (n1+200) gen = rnorm(n) x = rep(0,n) for(j in c(3:n)){ x[j] = (2*lambda*cos(omega)*x[j-1] - (lambda**2)*x[j-2] + gen[j]) } x1 = x[-c(1:200)] return(x1) } # Experiment with keeping omega fixed but letting lambda get closer to one. # test test = ar2complex(lambda=0.8,omega = pi/3,n1=200) acf(test) # To plot the periodogram and corresponding spectral density Periodogram <- abs(fft(test)/200)**2 frequency = c(0:199)/200 plot(frequency, Periodogram,type="o") library("astsa") lambda = 0.8 omega = pi/3 # note that on the plot below 0.5 corresponds to pi par(mfrow=c(2,1)) arma.spec( ar = c(2*lambda*cos(omega), -lambda**2), log = "no", main = "Autoregressive") plot(frequency[c(1:100)], Periodogram[c(1:100)],type="o")