[R] power spectrum of eeg
master.rstat at yahoo.com
Mon Nov 22 07:02:15 CET 2010
David Scott-6 wrote:
> On 21/11/10 21:18, Az Ha wrote:
>> I need to find the power spectrum of an eeg and display frequency in hz.
>> found two functions, spectrum or auspec but they give me frequency from
>> - 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, 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
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Thanks David for explaining this, I got it to work the way i wanted.
Meantime i found another function meanspec (package seewave), in which I can
directly input the sampling frequency (in my case 4800Hz), which is lot
easier to work with. But it gives me Y-axis in amplitude. Can someone
explain me how amplitude in "meanspec" compares to spectrum in "spectrum"?
My aim in doing all this is to compare two different eeg signal peaks to see
which has greater power.
View this message in context: http://r.789695.n4.nabble.com/power-spectrum-of-eeg-tp3052195p3053104.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help