# Ch3 R # generate time series with 3 cycles library(ts) t <- 1:128 x1 <- 2*cos(2*pi*t*6/128) + 3*sin(2*pi*t*6/128) x2 <- 4*cos(2*pi*t*10/128) + 5*sin(2*pi*t*10/128) x3 <- 3*cos(2*pi*t*40/128) + 4*sin(2*pi*t*40/128) x <- x1+x2+x3 min(x) max(x) x1 <- ts(x1) win.graph() par(mfrow=c(2,2)) ts.plot(x1,gpars=list(main="nu=6/128, amp^2=13", ylim=c(-16,16))) # in above amp^2=2^2+3^3=13 is the square of the amplitude ts.plot(x2,gpars=list(main="nu=10/128, amp^2=41", ylim=c(-16,16))) ts.plot(x3,gpars=list(main="nu=40/128, amp^2=25", ylim=c(-16,16))) ts.plot(x,gpars=list(main="sum", ylim=c(-16,16))) # the periodogram of x win.graph() par(mfrow=c(1,1)) d <- fft(x)/length(x) per <- abs(d)^2 freq <- (0:64)/128 per <- per[1:65] plot(freq,per,type="l") # try it this way win.graph() spectrum(x, method="pgram", plot=T) # what is that? # ok try this win.graph() spec.pgram(x, detrend=F, demean=F, plot=T) # Note dB=decibel, and the value S in dBs is 10log_10 S