Description Usage Arguments Details Value Note Author(s) References Examples
Finds the strength (amplitude) and phase shift of the input signal(s) at a particular range of frequencies via a Discrete Fast Fourier Transform (FFT). Can input single or multi-channel data.
1 | eegfft(x, Fs, lower, upper)
|
x |
Vector or matrix (time by channel) of EEG data with |
Fs |
Sampling rate of |
lower |
Lower band in Hz. Smallest frequency to keep (defaults to |
upper |
Upper band in Hz. Largest frequency to keep (defaults to |
The fft
function (or mvfft
function) is used to implement the FFT (or multivatiate FFT). Given the FFT, the strength of the signal is the modulus (Mod
), and the phase.shift is the angle (Arg
).
If x
is a vector, returns a data frame with variables:
frequency |
vector of frequencies |
strength |
strength (amplitude) of signal at each frequency |
phase.shift |
phase shift of signal at each frequency |
If x
is a matrix with J
channels, returns a list with elements:
frequency |
vector of frequencies of length |
strength |
|
phase.shift |
|
The strength of the signal has the same unit as the input (typically microvolts), and the phase shift is measured in radians (range -pi to pi).
Nathaniel E. Helwig <helwig@umn.edu>
Cooley, James W., and Tukey, John W. (1965) An algorithm for the machine calculation of complex Fourier series, Math. Comput. 19(90), 297-301.
Singleton, R. C. (1979) Mixed Radix Fast Fourier Transforms, in Programs for Digital Signal Processing, IEEE Digital Signal Processing Committee eds. IEEE Press.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | ########## EXAMPLE ##########
### Data Generation ###
# parameters for signal
Fs <- 1000 # 1000 Hz signal
s <- 3 # 3 seconds of data
t <- seq(0, s - 1/Fs, by = 1/Fs) # time sequence
n <- length(t) # number of data points
freqs <- c(1, 5, 10, 20) # frequencies
amp <- c(2, 1.5, 3, 1.75) # strengths (amplitudes)
phs <- c(0, pi/6, pi/4, pi/2) # phase shifts
# create data generating signals
mu <- rep(0, n)
for(j in 1:length(freqs)){
mu <- mu + amp[j] * sin(2*pi*t*freqs[j] + phs[j])
}
set.seed(1) # set random seed
e <- rnorm(n) # Gaussian error
y <- mu + e # data = mean + error
### FFT of Noise-Free Data ###
# fft of noise-free data
ef <- eegfft(mu, Fs = Fs, upper = 40)
head(ef)
ef[ef$strength > 0.25,]
# plot frequency strength
par(mfrow = c(1,2))
plot(x = ef$frequency, y = ef$strength, t = "b",
xlab = "Frequency (Hz)",
ylab = expression("Strength (" * mu * "V)"),
main = "FFT of Noise-Free Data")
# compare to data generating parameters
cbind(amp, ef$strength[ef$strength > 0.25])
cbind(phs - pi/2, ef$phase[ef$strength > 0.25])
### FFT of Noisy Data ###
# fft of noisy data
ef <- eegfft(y, Fs = Fs, upper = 40)
head(ef)
ef[ef$strength > 0.25,]
# plot frequency strength
plot(x = ef$frequency, y = ef$strength, t = "b",
xlab = "Frequency (Hz)",
ylab = expression("Strength (" * mu * "V)"),
main = "FFT of Noisy Data")
# compare to data generating parameters
cbind(amp, ef$strength[ef$strength > 0.25])
cbind(phs - pi/2, ef$phase[ef$strength > 0.25])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.