[R] power spectrum of eeg
David Scott
d.scott at auckland.ac.nz
Mon Nov 22 04:04:18 CET 2010
On 21/11/10 21:18, Az Ha wrote:
> Hi,
> I need to find the power spectrum of an eeg and display frequency in hz. I
> found two functions, spectrum or auspec but they give me frequency from 0.0
> - 0.5. How do i get frequency in Hz or KHz?
> Also, is it possible to plot two overlapping spectra in order to compare
> their peaks etc?
>
> Thanks for any help.
Well you you have the spectrum already, you just need to change the
scale on the x-axis. The change that needs to be made is not really an
R question, though how to do it is an R question.
The scale used by R is cycles per unit time, where the time unit is the
sampling interval of your time series. Thus the value at 0.25 say is the
spectral density at 0.25 cycles per time interval, or for a period of 4
time units. To convert to Hertz, you need to know the size of your time
unit in seconds. If your time unit (sampling interval) is say 1/1000
seconds (0.001 of a second), then 0.25 cycles per time interval
corresponds to 1000*0.25 cycles per second, or 250 Hertz. Since kHz
denotes the number of thousands of cycles per second, 250 Hz is
205/1000=0.25 Khz.
Here is an example:
par(mfrow = c(1,2))
w0 <- 0.2
n <- 100
x <- cos(2*pi*w0*(0:(n-1)))
specx <- spec.pgram(x, plot = FALSE)
spec.pgram(x)
spec.pgram(x, xaxt = "n", xlab = "frequency (Hz)",
sub = paste("bandwidth = ", round(1000*specx$bandwidth,2)))
axis(side = 1, at = (0:5)/10, labels = 1000*(0:5)/10)
David Scott
--
_________________________________________________________________
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142, NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email: d.scott at auckland.ac.nz, Fax: +64 9 373 7018
Director of Consulting, Department of Statistics
More information about the R-help
mailing list