compute_psd: Compute power spectral density

View source: R/frequency_analysis.R

compute_psdR Documentation

Compute power spectral density

Description

compute_psd returns the PSD calculated using Welch's method for every channel in the data. The output is in microvolts ^2 / Hz. If the object has multiple epochs, it will perform Welch's FFT separately for each epoch and then average them afterwards.

Usage

compute_psd(data, ...)

## S3 method for class 'eeg_data'
compute_psd(
  data,
  seg_length = NULL,
  noverlap = NULL,
  n_fft = NULL,
  method = "Welch",
  demean = TRUE,
  verbose = TRUE,
  ...
)

## S3 method for class 'eeg_epochs'
compute_psd(
  data,
  seg_length = NULL,
  noverlap = NULL,
  n_fft = 256,
  method = "Welch",
  keep_trials = TRUE,
  demean = TRUE,
  verbose = TRUE,
  ...
)

## S3 method for class 'eeg_evoked'
compute_psd(
  data,
  seg_length = NULL,
  noverlap = NULL,
  n_fft = 256,
  method = "Welch",
  demean = TRUE,
  verbose = TRUE,
  ...
)

Arguments

data

Data to be plotted. Accepts objects of class eeg_data

...

any further parameters passed to specific methods

seg_length

Length of rolling data segments. Defaults to n_fft. Must be <= n_fft.

noverlap

Number of (sampling) points of overlap between segments. Must be <= seg_length.

n_fft

Length of FFT to be calculated in sampling points. See details.

method

Defaults to "Welch". No other method currently implemented.

demean

Remove channel/epoch means. TRUE by default.

verbose

Print informative messages. TRUE by default.

keep_trials

Include FFT for every trial in output, or average over them if FALSE.

Details

Welch's FFT splits the data into multiple segments, calculates the FFT separately for each segment, and then averages over segments. Each segment is windowed with a Hanning window to counter spectral leakage. For epoched data, Welch's FFT is calculated separately for each trial.

The number of sampling points used for the FFT can be specified using n_fft. n_fft defaults to 256 sampling points for eeg_epochs data, or the minimum of 2048 or the length of the signal for continuous eeg_data.

seg_length defaults to be n_fft, and must be less than or equal to it.

noverlap specifies the amount of overlap between windows in sampling points. If NULL, it defaults to 50\

Value

Currently, a data frame with the PSD for each channel separately.

Methods (by class)

  • eeg_data: Compute PSD for an eeg_data object

  • eeg_epochs: Compute PSD for an eeg_epochs object

  • eeg_evoked: Compute PSD for an eeg_evoked object

Author(s)

Matt Craddock matt@mattcraddock.com

Examples

out <- compute_psd(demo_epochs)

out <- compute_psd(demo_epochs, n_fft = 256, seg_length = 128)


craddm/eegUtils documentation built on March 24, 2022, 9:17 a.m.