diff --git a/ch10.r b/ch10.r index 6763fb3..d83b5db 100644 --- a/ch10.r +++ b/ch10.r @@ -79,3 +79,52 @@ t = seq(-1, 1, len=1000) R = (1/3)*outer(cos(2*pi*t), cos(2*pi*t)) image(t, t, R, col=topo.colors(255), xlab="t_1", ylab="t_2") +## Example 10.12 + +# R code for Example 10.11: Plot the time function +t = seq(-2, 2, len = 1000) +x = matrix(0, 1000, 20) + +for (i in 1:20) { + x[,i] = cos((2*pi*t) + (2*pi*runif(1))) +} + +matplot(t, x, lwd=2, col="gray", type="l", lty="solid", xaxp=c(-2,2, 8)) +grid() +lines(t, 0*cos(2*pi*t), lwd=5, col="darkred") +points(numeric(20), x[501,], lwd=2, col="darkorange") +points(numeric(20) + 0.5, x[626,], lwd=2, col="blue", pch=4) + +# R code for Example 10.12: Plot the autocorrelation function +t = seq(-1, 1, len=1000) +R = toeplitz(0.5*(cos(2*pi*t))) +image(t, t, R, col=topo.colors(255), ylim=c(1,-1), xlab="t_1", ylab="t_2") + +############# +# Chapter 10.3 Wide sense stationary processes + +## Example 10.14 + +# R code to demonstrate autocorrelation + +# Figure 1 +Xa = rnorm(1000) +Xa2 = rnorm(1000) + +plot(Xa, type="l", lwd=2, col="blue") +grid() +lines(Xa2, lwd=2) + +# Figure 2 +N = 1000 +T = 1000 +X = matrix(rnorm(N*T), N, T) +xc = matrix(0, N, 2*T-1) + +for (i in 1:N) { + xc[i,] = ccf(X[i,], X[i,], lag.max=2*T-1)$acf/T +} + +plot(xc[1,], type="l", lwd=2, col="darkblue") +lines(xc[2,], lwd=2) +