Lab: The Spectrum


Getting Started

Start R

R functions: spectrum, spec.pgram, spec.ar, plot.spec

> help(spectrum)

If you are interested in how the spectrum is estimated you can read:

> help(spec.pgram)


Plotting the Spectrum

Before we use the R function spectrum. Let's plot some of the spectrums from the Examples in Chapter 11, Example 11.2 (nonperiodic sequence) and Example 11.3 (symmetric ocillating seqence).

Plot: f(w) = 3/(2*pi*(5-4*cos(w))), -pi <= w <= pi
and f(w) = 3/(2*pi*(5+4*cos(w))), -pi <= w <= pi

First, generate a sequence of numbers between -pi and pi and plot the spectrum!

> w <- seq(-pi,pi,length=100)
> f1 <- 3/(2*pi*(5-4*cos(w)))
> f2 <- 3/(2*pi*(5+4*cos(w)))

Now make two plots, one for (w, f1) and one for (w, f2).
Describe each plot. What are the difference in these plots?


Example 1: Spectrum of AR(1)

Let's look at the sample code in spec1.r

Which process has a high frequency component, so that there is a lot of power concentrated at high frequencies of the spectrum?

Which process has a low frequency component, so that there is a lot of power concentrated at low frequencies of the spectrum?


Example 2: Lynx Data

> help(lynx)

Let's look at the sample code in lynx1.r

To estimate the spectrum for this series, let's look at the sample code in lynx2.r

What is in the object lynx.pgram1? What does the fast=T option do?

> help(plot.spec)

What is a dB? Ans: decibels = 10 x log_10(I(omega))


Example 3: Luteinizing Hormone Data

> help(lh)

Plot the data and plot the spectrum, raw, and spans=c(5,5), spans=c(13,13) and spans=c(21,21)