ksppgram<- function(n,np,nv,a,b){ # n=number of observations # np=number of periods of cyclical component # nv=noise variance # a=coefficient of cosine term # b=coefficient of sine term kt<-seq(1,n) f<-2*pi*np*(kt-1)/n # look at cosine term z<-a*cos(f) par(mfrow=c(2,2)) tsplot(z) # add in sin term z<-z+b*sin(f) tsplot(z) # add noise z<-z+rnorm(n,0,nv) tsplot(z) # plot periodogram spec.pgram(z,spans=1,detrend=F,plot=T) } ksppgram(128,4,1,1,1) ksppgram(128,4,1,0,0) ksppgram(128,4,.25,1,1)