#************************************************************ 
# Spectral Analysis on ARMA type of Data
#------------------------------------------------------------

ARMA_spec <- function(x) {
    par(mfrow=c(2,2))
    ts.plot(x, ylim=c(-12,12))
    acf(x)
#    acf(x, type="partial")
    raw.spec <- spectrum(x)
    plot(raw.spec, log = "no")
}    

# AR to Spectral Analysis
x <- arima.sim(1000, model=list(ar=c(-0.2), order=c(1,0,0)))
ARMA_spec(x)

x <- arima.sim(1000, model=list(ar=c(0.8, -0.5), ma=0.5, order=c(2,0,1)))
ARMA_spec(x)

# MA to Spectral Analysis     
x <- arima.sim(1000, model=list(ma=c(0.8), ma=0.5, order=c(0,0,1)))
ARMA_spec(x)

# MA to Spectral Analysis     
x <- arima.sim(1000, model=list(ma=c(-0.8), ma=1.5, order=c(0,0,1)))
ARMA_spec(x)
