brain_sense_spectrogram {LeadSense}R Documentation

Plot BrainSense Spectrograms and Return Data (with Optional Band Filtering)

Description

This function generates spectrograms for Medtronic BrainSense time-domain signals across one or more data passes. Optionally, the user can select specific passes to plot, filter by frequency band, save the plots, and extract the underlying spectrogram data.

Usage

brain_sense_spectrogram(
  dataset = NULL,
  wl = 512,
  ovlp = 75,
  collevels = seq(-80, 0, by = 0.2),
  save_as = NULL,
  output_dir = getwd(),
  passes = NULL,
  band = NULL
)

Arguments

dataset

A JSON-like object (e.g., parsed with jsonlite::fromJSON()) containing Medtronic BrainSense data. If NULL, attempts to load the default dataset from the LeadSense package.

wl

Integer. Window length for FFT. Default is 512.

ovlp

Numeric. Overlap percentage between successive windows. Default is 75.

collevels

Numeric. A sequence of color levels for the spectrogram image (in dB). Default is seq(-80, 0, by = 0.2).

save_as

Character. File format to save plots ("png", "pdf", or "jpeg"). If NULL (default), plots are not saved.

output_dir

Character. Path to the directory where plots will be saved. Default is current working directory.

passes

Integer vector. Indices of passes to plot (e.g., c(1,3)). Default is NULL, which plots all available passes.

band

Character. One of "Delta", "Theta", "Alpha", "Beta", "Gamma". If provided, filters signal to this frequency band before generating the spectrogram.

Details

WARNING: This function may be computationally intensive and take significant time to execute. Please wait until all plots are rendered.

Value

A list of data frames (invisible). Each data frame corresponds to one spectrogram and contains:

time

Time in seconds

frequency

Frequency in Hz

magnitude

Spectral power in dB

channel

Channel label

pass

Pass index (i)

Examples

brain_sense_spectrogram(dataset, passes = c(2), band = "Beta")

[Package LeadSense version 0.0.2.0 Index]