# eegfft: Fast Fourier Transform of EEG Data In eegkit: Toolkit for Electroencephalography Data

## Description

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.

## Usage

 `1` ```eegfft(x, Fs, lower, upper) ```

## Arguments

 `x` Vector or matrix (time by channel) of EEG data with `n` time points. `Fs` Sampling rate of `x` in Hz such that `n = s * Fs` where `s` is the number of seconds of input data (some positive integer). `lower` Lower band in Hz. Smallest frequency to keep (defaults to `0`). `upper` Upper band in Hz. Largest frequency to keep (defaults to `Fs/2 - Fs/n`).

## Details

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`).

## Value

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 `F` `strength ` `F` by `J` matrix: strength (amplitude) of signal at each frequency and channel `phase.shift ` `F` by `J` matrix: phase shift of signal at each frequency and channel

## Note

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).

## Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

## References

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.

## Examples

 ``` 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]) ```

eegkit documentation built on May 1, 2019, 8:02 p.m.