# the program demonstrates that a linear difference equation
#
# y_j = 2 cos(theta) y_{j-1} - y_{j-2}
#
# produces a sine wave with angular frequency (phase increment per sample) t.
# This is true no matter what y_0 and y_1 are.
N = 1024
perlen = 100 # number points to a period
theta = 2*pi/perlen #
y = rep(0,N)
y[1] = rnorm(1); # we chose the first two values randomly
y[2] = rnorm(1); # 1st two sequence values will determine phase and amp
for (j in 3:N)
y[j] = 2*cos(theta)*y[j-1] - y[j-2] # our autoregression
plot(y[1:perlen])
#stopp
r = .995
for (j in 3:N)
y[j] = r*2*cos(theta)*y[j-1] - r*r*y[j-2] # a variation on our equation
# this gives an exponentially decaying
# or increasing sine wave of period perlen
numper = 5;
plot(y[1:numper*perlen])