Skip to content
Igor Kagan edited this page Jul 12, 2022 · 49 revisions

LFP time frequency analysis

Welcome to the LFP_timefrequency_analysis wiki!


This document walks through the procedure for running the time frequency analysis pipeline for LFP. Two steps are required for running the LFP time frequency analysis:

  1. Create a settings file as a matlab script (.m file) as described below.
  2. Run the lfp_tfa_mainscript.m by setting the variable settings_filepath as the absolute path to the created settings file.

Creating a settings file

This section explains the settings to be configured for running the LFP time frequency analysis. All settings which can be configured are saved inside a structure called lfp_tfa_cfg which is set by the function lfp_tfa_define_settings.

Settings for data folders


lfp_tfa_cfg.results_folder - absolute path to the folder where the results of analysis should be stored.

Example:

    lfp_tfa_cfg.results_folder = 'Y:\Personal\Sarath\Results\LFP_TFA_Results';

lfp_tfa_cfg.version - a version to be defined for the analysis. This can be a user defined string to indicate the version of the analysis. The analysis results will be stored in different folders for different versions. Therefore, if same settings has to be applied for two analyses, a different value can be set as lfp_tfa_cfg.version.

Example:

    lfp_tfa_cfg.version = 'Linus_inactivation';

The results of the analyses will be stored under a sub folder [lfp_tfa_cfg.results_folder/lfp_tfa_cfg.version]. For example, if lfp_tfa_cfg.results_folder = 'Y:\Personal\Sarath\Results\LFP_TFA_Results' and lfp_tfa_cfg.version = 'Linus_inactivation' then results will be stored under 'Y:\Personal\Sarath\Results\LFP_TFA_Results\Linus_inactivation'


lfp_tfa_cfg.process_LFP - whether to calculate the LFP time frequency spectrograms and noise trial detection. If the time frequency spectrograms for the given sessions were already calculated, it can be reused by setting 'lfp_tfa_cfg.proc_lfp_folder' as the folder where the results are stored. In this case, set this variable to false. If this variable is set to false, but the LFP time frequency spectrograms are not available in the specified folder in 'lfp_tfa_cfg.proc_lfp_folder', the time frequency spectrograms will be calculated and stored in lfp_tfa_cfg.results_folder. If the time frequency spectrograms should be computed newly, set this variable to true.

Examples (use any one):

    lfp_tfa_cfg.process_LFP = false; %do not compute time frequency histograms, noise detection and baseline power calculation
    lfp_tfa_cfg.process_LFP = true; %compute time frequency histograms, noise detection and baseline power calculation

lfp_tfa_cfg.proc_lfp_folder - folder where the results of LFP time frequency spectrograms are stored. This need to be filled in if lfp_tfa_cfg.process_LFP = false.

Example:

    lfp_tfa_cfg.proc_lfp_folder = [];
    if ~lfp_tfa_cfg.process_LFP
        lfp_tfa_cfg.proc_lfp_folder = ...
            'Y:\Personal\Sarath\Results\LFP_TFA_Results\Linus_inactivation\Processed LFP';
    end

lfp_tfa_cfg.compute_site_average - flag indicating whether to calculate the site-wise averages. If the site-wise averages for the given sessions were already calculated, it can be reused by setting 'lfp_tfa_cfg.analyse_lfp_folder' as the folder where the results are stored. In this case, set this variable to false. If this variable is set to false, but the LFP site-wise averages are not available in the specified folder, the site-wise averages will be calculated and stored in lfp_tfa_cfg.results_folder. If the site-wise averages should be computed, set this variable to true. Please note that this variable should be set to false only when one wants to recompute the averages for same analysis settings, while, for example, excluding a session from previous analysis. If the analysis settings changes, set to true to recalculate the site averages.

Examples (use any one):

    lfp_tfa_cfg.compute_site_average = false; %reuse computed site averages of tfr, evoked, spectra, and sync
    lfp_tfa_cfg.compute_site_average = true; %compute time site averages of tfr, evoked, spectra, and sync

lfp_tfa_cfg.analyse_lfp_folder - folder where the computed site averages for tfr, evoked, spectra, and sync are stored. Please note that this should be a folder containing the analysed site averages created previously by the same pipeline, when lfp_tfa_cfg.compute_site_average was set to true. If the site averages were not computed previously, set lfp_tfa_cfg.compute_site_average to true and leave this folder empty.

Example:

    lfp_tfa_cfg.analyse_lfp_folder = [];
    if ~lfp_tfa_cfg.compute_site_average
        lfp_tfa_cfg.analyse_lfp_folder = ...
            'Y:\Personal\Sarath\Results\LFP_TFA_Results\Linus_inactivation\LFP Analysis';
    end

lfp_tfa_cfg.info_filepath - absolute path to the sorted neurons excel file, from which information about sessions and individual sites can be obtained (for future use, ignore now)

Example:

    lfp_tfa_cfg.info_filepath = 'Y:\Projects\PPC_pulv_body_signals\ephys\MIP_inactivation_20190314\Mag_sorted_neurons.xls';

lfp_tfa_cfg.use_datasets - dataset to be used for analysis, see entry Set in the sorted neurons excel file only those sessions belonging to Set = lfp_tfa_cfg.use_datasets will be used for analysis (for future use, ignore now)

Example:

    lfp_tfa_cfg.use_datasets = [31];

lfp_tfa_cfg.session_info - info about sessions to be analysed should be a 1 x N struct, N = number of sessions to analyse. Each struct element the struct should contain the following fields:

  • Monkey: name of monkey (string)
  • Date: recording date (string of format YYYYMMDD)
  • Input_file: Absolute path to the file containing LFP data for the session
  • Preinj_blocks: Blocks to be considered for pre-injection, typically 0
  • Postinj_blocks: Blocks to be considered for post-injection, can be integer, array of integers, 'all' or 'allbutfirst'
    • 'all' - all post-injection blocks will be combined
    • 'allbutfirst' - all blocks from the second post-injection block will be combined
    • integer - only one block (whose block number is specified by the given integer) is considered for post-injection
    • integer array - all blocks from integer array are considered as post-injection

Example:

    lfp_tfa_cfg.session_info(1) = ...
        struct('Monkey',        'Lin', ...
               'Date',          '20170622', ...
               'Input', 'Y:\Projects\PPC_pulv_eye_hand\ephys\MIP_dPul_inj_working_post_sfn\sites_Linus_20170622.mat',...
               'Preinj_blocks',  0, ...
               'Postinj_blocks', 'allbutfirst');
    lfp_tfa_cfg.session_info(2) = ...
        struct('Monkey',        'Lin', ...
               'Date',          '20170629', ...
               'Input',         'Y:\Projects\PPC_pulv_eye_hand\ephys\MIP_dPul_inj_working_post_sfn\sites_Linus_20170629.mat', ...
               'Preinj_blocks',  0, ...
               'Postinj_blocks', 'allbutfirst');
    lfp_tfa_cfg.session_info(3) = ...
        struct('Monkey',        'Lin', ...
               'Date',          '20170707', ...
               'Input',         'Y:\Projects\PPC_pulv_eye_hand\ephys\MIP_dPul_inj_working_post_sfn\sites_Linus_20170707.mat', ...
               'Preinj_blocks',  0, ...
               'Postinj_blocks', 'allbutfirst');
    
    % To add a new session to analyse, increment the counter by 1 and add a new
    % value into the lfp_tfa_cfg.session_info struct
    % Example: 
    % lfp_tfa_cfg.session_info(3) = ...
    %     struct('Monkey',        'Magnus', ...
    %            'Date',          '20190208', ...
    %            'Input',         'Y:\Projects\PPC_pulv_body_signals\ephys\MIP_inactivation_20190208\sites_Magnus_20190208.mat', ...
    %            'Preinj_blocks',  0, ...
    %            'Postinj_blocks', 'allbutfirst');

Settings relevant for analysis


lfp_tfa_cfg.analyses - what kind of analyses should be performed on LFP data This field should be a cell array of strings. Currently supported analyses are 'tfs', 'evoked', 'pow', 'sync', and 'syncsp'.

  • 'tfs' - LFP time frequency spectrogram average for given conditions and time windows
  • 'evoked' - LFP evoked response average for given conditions and time windows
  • 'pow' - LFP power spectrum average for given conditions and epochs
  • 'sync' - LFP-LFP phase synchronization spectrogram (sync vs. time-freq) for given conditions and time windows
  • 'syncsp' - LFP-LFP phase synchronization spectra (sync vs. freq) measure for given conditions and time windows

Example:

   lfp_tfa_cfg.analyses = {'tfs', 'evoked', 'pow', 'sync', 'syncsp'};

lfp_tfa_cfg.compare.targets - targets to be included in the analysis. This field should be a cell array of strings which indicate the target names. The target names should be same as the target field in the LFP data structure. Those targets which are not in the analysed sessions will be ignored

Example:

    lfp_tfa_cfg.compare.targets = {'MIP_R', 'MIP_L'}; 

lfp_tfa_cfg.compare.target_pairs - target pairs to be included for LFP-LFP sychronization. This field is only required if lfp_tfa_cfg.analyses contains 'sync' or 'syncsp'. This field should be a 1xN cell array of 1x2 cell array of strings which indicate the target pairs between which the LFP-LFP phase synchronization should be calculated

Example:

    if any(strcmp(lfp_tfa_cfg.analyses, 'sync') | strcmp(lfp_tfa_cfg.analyses, 'syncsp'))
        lfp_tfa_cfg.compare.target_pairs = {{'MIP_R', 'MIP_R'}, {'MIP_R', 'MIP_L'}, ...
            {'MIP_L', 'MIP_L'}}; 
    end

lfp_tfa_cfg.ref_hemisphere - reference hemisphere for hand-space labelling. This field can take values 'R' (for right hemisphere) or 'L' (for left hemisphere). lfp_tfa_cfg.ref_hemisphere is used for labeling contra- and ipsi- hand and space. Set lfp_tfa_cfg.ref_hemisphere to lesioned hemisphere for ipsilesional and contralesional labeling. Set lfp_tfa_cfg.ref_hemisphere to recorded hemisphere for ipsi lateral and contra lateral labeling. For example, if right hemisphere is lesioned and lfp_tfa_cfg.ref_hemisphere = 'R', right hand and right space are ipsi-lesional and left hand and left space are contra-lesional.

Example:

    lfp_tfa_cfg.ref_hemisphere = 'R'; 

lfp_tfa_cfg.random_seed - random seed for random number generator for reproducibility (for future use, ignore now)

Example:

    lfp_tfa_cfg.random_seed = rng; %random number generator used to set random seed

lfp_tfa_cfg.analyse_states - define the time windows arounds the state onsets to analyse for LFP time frequency spectrograms, evoked LFP response and LFP-LFP phase synchronization

This field must be a Nx5 cell array, N = number of windows to analyse. Each row corresponds to one state and contain following elements

  • type of windows to be analysed: always set to 'single' indicating that for each trial, a single window is considered with respect to one event onset
  • ID of state around whose onset the window is referenced, see lfp_tfa_global_states, Example: lfp_tfa_states.CUE_ON
  • Name of the reference state (window) - string (used for labeling purposes in plots) eg: 'Cue'
  • Start time offset - offset in seconds from reference state onset for the start of time window. i.e., start time = Reference state onset time + Start time offset
  • End time offset - offset in seconds from ref. state onset for end of time window. i.e., end time = Ref. state onset time + end time offset

Example usage:

    lfp_tfa_cfg.analyse_states = {'single', lfp_tfa_states.CUE_ON,    'Cue',      -0.5,   0.9; ...
                                  'single', lfp_tfa_states.REA_INI,   'Reach',    -0.3,   0.5};

lfp_tfa_cfg.analyse_epochs - define the epochs to analyse for LFP power spectrum. Must be a Nx4 cell array, N = number of epochs to analyse

Each row corresponds to one epoch and contain following elements:

  • Identifier of state whose onset to which the epoch is referred, see lfp_tfa_global_states, Example:
    lfp_tfa_states.CUE_ON
  • Name of the epoch - string (used for labeling purposes in plots) eg: 'FHol'
  • Start time offset - offset in seconds from reference state onset for the epoch start. i.e., Epoch start time = Reference state onset time + Start time offset
  • End time offset - offset in seconds from ref. state onset for epoch end Epoch end time = Ref. state onset time + end time offset

Example usage:

    lfp_tfa_cfg.analyse_epochs = {lfp_tfa_states.CUE_ON,     'FHol',    -0.3 ,    0  ;
                                  lfp_tfa_states.CUE_ON,     'Cue' ,    0.05 ,    0.2 ; 
                                  lfp_tfa_states.DEL_PER,    'EDel',    0.3 ,     0.6 ; 
                                  lfp_tfa_states.TAR_ACQ,    'Del',     -0.3 ,    0  ; 
                                  lfp_tfa_states.REA_INI,    'PreR',    -0.3 ,    -0.05 ; 
                                  lfp_tfa_states.REA_END,    'PeriR',   -0.2 ,    0.2 ;
                                  lfp_tfa_states.SUCCESS,    'THol',    -0.3 ,    0    };

lfp_tfa_cfg.epoch_colors - The color scheme to be used for plotting the power spectra and ppc spectra curve for each epoch. This should be a Kx3 array, where K is the number of epochs to be analysed i.e. K=length(lfp_tfa_cfg.analyse_epochs). The three columns represent R, G, and B values normalized to 1. A standard or user-defined colormap with K colors can also be used to generate the required colors.

Examples:

lfp_tfa_cfg.epoch_colors = flip(othercolor('Cat_12', ...
    length(lfp_tfa_cfg.analyse_epochs)));
lfp_tfa_cfg.epoch_colors = jet(length(lfp_tfa_cfg.analyse_epochs));

lfp_tfa_cfg.error_measure - the error measure to be plotted for evoked LFP response. This can be 'stddev', 'stderr' or 'bootci'

  • 'stddev' - plots one standard deviation around the mean
  • 'stderr' - plots one standard error around the mean
  • 'bootci' - plots 95% confidence interval around the mean by bootstrapping, see bootci function in MATLAB

Example:

    lfp_tfa_cfg.error_measure = 'bootci';

Settings for trial conditions

Note: By condition, we mean a combination of choice/instruscted, pre/post-injection, type and effector, and hand-space


lfp_tfa_cfg.compare.types - trial types to be included in the analysis This field should be a vector of integers specifying the types to be analysed. Entries should be same as one of the values available in the 'type' field in the input LFP data

Examples (use any one):

   lfp_tfa_cfg.compare.types = [4]; % only analyse trials with type = 4
   lfp_tfa_cfg.compare.types = [4, 2]; % analyse trials with type = 4 and type = 2 separately
   lfp_tfa_cfg.compare.types = inf; % Ignore trial type (trials with any type value are combined)

lfp_tfa_cfg.compare.effectors - effectors to be included in the analysis This field should be a vector of integers specifying the effectors to be included in analysis. Entries should be same as one of the type specified in the 'effector' field in the input LFP data

Examples (use any one):

    lfp_tfa_cfg.compare.effectors = [4]; % analyse only trials with effector = 4 
    lfp_tfa_cfg.compare.effectors = [4, 6]; % analyse trials with effector = 4 and effector = 6 separately  
    lfp_tfa_cfg.compare.effectors = inf; % Ignore effector (trials with any effector value are combined)

lfp_tfa_cfg.compare.choice_trials - which type of choice trials are to be included in the analysis

Examples (use any one):

    lfp_tfa_cfg.compare.choice_trials = 0;  % analyse only instructed trials
    lfp_tfa_cfg.compare.choice_trials = 1;  %analyse only choice trials
    lfp_tfa_cfg.compare.choice_trials = [0, 1]; %analyse choice and instructed trials separately
    lfp_tfa_cfg.compare.choice_trials = inf; %ignore choice (both choice and instructed trials are combined)

lfp_tfa_cfg.compare.reach_hands - reach hands to be included for analysis. This field can contain only values 'R', 'L' or inf.

Examples (use any one):

    lfp_tfa_cfg.compare.reach_hands = {'L'}; %include only those trials in which reach hand is left  
    lfp_tfa_cfg.compare.reach_hands = {'R'}; %include only those trials in which reach hand is right
    lfp_tfa_cfg.compare.reach_hands = {'L', 'R'}; %analyse the trials in which reach hand is left and right separately
    lfp_tfa_cfg.compare.reach_hands = inf; %ignore hand label (trial with any hand label is combined)

lfp_tfa_cfg.compare.reach_spaces - reach space to be included for analysis. This field should be inf or a cell array that contain only values 'R', 'L'.

Examples:

    lfp_tfa_cfg.compare.reach_spaces = {'L'}; %include only those trials in which acquired target is on left  
    lfp_tfa_cfg.compare.reach_spaces = {'R'}; %include only those trials in which acquired target is on right  
    lfp_tfa_cfg.compare.reach_spaces = {'L', 'R'}; %analyse the trials in which acquired target is on left and on right separately 
    lfp_tfa_cfg.compare.reach_spaces = inf; %ignore space label (trial with any acquired target position is combined)

lfp_tfa_cfg.compare.exclude_handspace - hand space combinations to be excluded from analysis. This field should be a cell array with each element containing the hand and space label to be excluded. If no hand-space conditions are to be excluded, leave empty

Examples (use any one):

    lfp_tfa_cfg.compare.exclude_handspace = {'LR', 'RL'}; %exclude left hand right space and right hand left space trials
    lfp_tfa_cfg.compare.exclude_handspace = {'LL', 'RR'}; %exclude left hand left space and right hand right space trials
    lfp_tfa_cfg.compare.exclude_handspace = {'RL', 'RR'}; %exclude right hand left space and right hand right space trials
    lfp_tfa_cfg.compare.exclude_handspace = {}; %no hand-space labels excluded from analysis

lfp_tfa_cfg.compare.perturbations - perturbations to be included in the analysis. This field should be inf, 0, 1 or [0, 1]

Examples (use any one):

    lfp_tfa_cfg.compare.perturbations = 0; % analyse only pre-injection trials
    lfp_tfa_cfg.compare.perturbations = 1; % analyse only post-injection trials
    lfp_tfa_cfg.compare.perturbations = [0, 1]; % consider the pre-injection and post-injection trials separately
    lfp_tfa_cfg.compare.perturbations = inf; % combine the trials with any perturbation value 

lfp_tfa_cfg.diff_condition - differences in conditions to be analysed for LFP time frequency spectrogram and LFP-LFP phase synchronization measures. Currently differences can be calculated between choices, perturbations, and type/effector pairs.

This field should be a cell array, with each entry being another cell array. Each entry should specify the condition to be compared and the respective values. For example, lfp_tfa_cfg.diff_condition(1) = {{'perturbation', {0, 1}}}; would compute difference between each of the hand-space conditions of post- and pre-injection trials.

Two comparisons can be nested. For example, lfp_tfa_cfg.diff_condition(2) = {{'perturbation', {0, 1}, 'choice', {0, 1}}}; computes the difference between post and pre-injection trials among instructed trials and choice trials separately and then compute a difference between these. i.e., Choice(Post - Pre) - Instructed(Post - Pre).

Examples (use any one):

  % Single parameter comparison
  % Compute difference of TFS between all pre- and all post-injection trials
  lfp_tfa_cfg.diff_condition(1) = {{'perturbation', {0, 1}}};
  
  % Single parameter comparison
  % Compute difference of TFS between all choice and all instructed trials
  lfp_tfa_cfg.diff_condition(1) = {{'choice', {0, 1}}};

  % Single parameter comparison
  % Compute difference of TFS between all trials of two kinds of type-effector
  lfp_tfa_cfg.diff_condition(1) = {{'type_eff', {[4 6], [1 0]}}};

  % Multiple comparisons
  % Compute difference of TFS between pre- and post-injection, choice and instructed trials, and two kinds of type-effector
  lfp_tfa_cfg.diff_condition(1) = {{'perturbation', {0, 1}}};
  lfp_tfa_cfg.diff_condition(2) = {{'choice', {0, 1}}};     
  lfp_tfa_cfg.diff_condition(3) = {{'type_eff', {[4 6], [1 0]}}};

  % Muliple and nested comparison
  % Compute difference of TFS between pre- and post-injection, choice and instructed trials
  lfp_tfa_cfg.diff_condition(1) = {{'perturbation', {0, 1}}};
  lfp_tfa_cfg.diff_condition(2) = {{'choice', {0, 1}}};
  % nested difference of Instructed(Post - Pre) - Choice(Post - Pre) 
  lfp_tfa_cfg.diff_condition(3) = {{'perturbation', {0, 1}, 'choice', {0, 1}}};

lfp_tfa_cfg.mintrials_percondition - minimum number of trials per condition to be satisfied to consider a site for averaging. If for a site, for any condition, the number of valid (non-noisy) trials is less than mintrials_percondition, the site is not considered for averaging. Set lfp_tfa_cfg.mintrials_percondition = 1 to consider a site if at least one valid trial is obtained (keep minimum value of 1)

Example:

    lfp_tfa_cfg.mintrials_percondition = 5; %consider those sites with atleast 5 trials for each condition

Settings for defining trial start and end


lfp_tfa_cfg.trialinfo.start_state - ID of the reference state which indicates start of a trial.

Example:

    lfp_tfa_cfg.trialinfo.start_state = lfp_tfa_states.FIX_ACQ; %reference for  trial start is the onset of fixation acquisition

lfp_tfa_cfg.trialinfo.ref_tstart - offset to be considered from the onset of trial start reference state for calculating the trial start time. i.e., trial start time = onset of trial start state + start offset

Examples:

    lfp_tfa_cfg.trialinfo.ref_tstart = -0.5; % trial start time = onset time of lfp_tfa_cfg.trialinfo.start_state - 0.5
    lfp_tfa_cfg.trialinfo.ref_tstart = 0.5; % trial start time = onset time of lfp_tfa_cfg.trialinfo.start_state + 0.5

lfp_tfa_cfg.trialinfo.end_state - ID of the reference state which indicates start of a trial

Example:

    lfp_tfa_cfg.trialinfo.end_state = lfp_tfa_states.TAR_HOL; %reference state for trial start is the onset of target hold

lfp_tfa_cfg.trialinfo.ref_tend - offset to be considered from the onset of trial end reference state for calculating the trial end time. i.e., trial end time = onset of trial end state + end offset

Examples:

    lfp_tfa_cfg.trialinfo.ref_tend = 0.5; %trial end time = onset time of lfp_tfa_cfg.trialinfo.end_state + 0.5;
    lfp_tfa_cfg.trialinfo.ref_tend = -0.5; %trial end time = onset time of lfp_tfa_cfg.trialinfo.end_state - 0.5

Settings for power spectrogram calculations

Following settings are used for ft_freqanalysis in FieldTrip toolbox, see ft_freqanalysis for more details


lfp_tfa_cfg.tfr.method - method for calculating the LFP power spectra This can be 'mtmconvol' or 'wavelet'. This field will be used as cfg.method for ft_freqanalysis

Examples (use any one):

    lfp_tfa_cfg.tfr.method = 'wavelet'; %implements wavelet time frequency transformation (using Morlet wavelets) based on multiplication in the frequency domain.
    lfp_tfa_cfg.tfr.method = 'mtmconvol'; %implements multitaper time-frequency transformation based on multiplication in the frequency domain

lfp_tfa_cfg.tfr.foi - frequencies of interest (in Hz). This will be used as cfg.foi for ft_freqanalysis

Examples:

    lfp_tfa_cfg.tfr.foi = logspace(log10(2), log10(120), 60); %60 log-spaced frequencies from 2Hz to 120 Hz
    lfp_tfa_cfg.tfr.foi = 2:2:100; %Frequencies from 2HZ to 100Hz in a step of 2Hz

lfp_tfa_cfg.tfr.timestep - number of lfp samples to step for the sliding time window. This field will be used to define the cfg.toi for ft_freqanalysis. For example, if a time window of -0.5s to +0.5s from an event onset has to be analysed and lfp_tfa_cfg.tfr.timestep = 25, then cfg.toi = -0.5:25*ts:0.5, where ts is the sampling time of LFP signal.

Example:

    lfp_tfa_cfg.tfr.timestep  = 25; % the sliding time window steps by an amount equal to 25 lfp samples.
    lfp_tfa_cfg.tfr.timestep  = 50; % the sliding time window steps by an amount equal to 50 lfp samples. 

lfp_tfa_cfg.tfr.width - width of the wavelets in number of cycles. (For method = 'wavelet', Ignored for 'mtmconvol')

Making the value smaller will increase the temporal resolution at the expense of frequency resolution and vice versa. Wavelet duration = width / F / pi (F = frequency), i.e., wavelet duration decreases with frequency For example, if width = 6, and considered frequency F = 30 Hz, wavelet duration = 6/30/pi = 0.0637 s

Example:

    lfp_tfa_cfg.tfr.width = [];
    if strcmp(lfp_tfa_cfg.tfr.method, 'wavelet')
        lfp_tfa_cfg.tfr.width       = 6; %wavelet of width 6 cycles 
    end 

lfp_tfa_cfg.tfr.taper - taper (single or multiple) to be used. This field will be used as cfg.taper when cfg.method = 'mtmconvol for ft_freqanalysis. (To be used only when lfp_tfa_cfg.tfr.method = 'mtmconvol';, leave empty for 'wavelet')

Taper can be 'dpss', 'hanning' or many others

  • 'hanning' - conventional single taper
  • 'dpss' - multiple tapers based on discrete prolate spheroidal sequences (DPSS), also known as the Slepian sequence

Example:

    lfp_tfa_cfg.tfr.taper           = [];
    if strcmp(lfp_tfa_cfg.tfr.method, 'mtmconvol')
        lfp_tfa_cfg.tfr.width       = 'hanning'; % use a conventional single taper
    end

lfp_tfa_cfg.tfr.tapsmofrq - the width of frequency smoothing in Hz (= fw). Note that 4 Hz smoothing means plus-minus 4 Hz, i.e. a 8 Hz smoothing box. This field should be a vector of size 1 x numfoi.

(Used only when lfp_tfa_cfg.tfr.method = 'mtmconvol', Leave empty for lfp_tfa_cfg.tfr.method= 'wavelet')

Example:

    lfp_tfa_cfg.tfr.tapsmofrq       = [];
    if strcmp(lfp_tfa_cfg.tfr.method, 'mtmconvol')
        lfp_tfa_cfg.tfr.tapsmofrq  = 0.4 *cfg.foi; % the smoothing will increase with frequency.
    end

lfp_tfa_cfg.tfr.t_ftimwin - length of the sliding time-window in seconds (= tw). Should be vector of size (1, numel(lfp_tfa_cfg.tfr.foi)). Following relation must hold:

K = 2twfw-1, where K is required to be larger than 0, K is the number of tapers applied

(Used only when lfp_tfa_cfg.tfr.method = 'mtmconvol', Leave empty for lfp_tfa_cfg.tfr.method= 'wavelet')

Example usage:

    lfp_tfa_cfg.tfr.t_ftimwin       = [];
    if strcmp(lfp_tfa_cfg.tfr.method, 'mtmconvol')
        lfp_tfa_cfg.tfr.tapsmofrq  = 5./cfg.foi; % 5 cycles per window. window length decreases with frequency
    end

Settings for LFP-LFP phase synchronization measure


lfp_tfa_cfg.sync.measure - measure of LFP-LFP phase synchronization. Can be only 'ppc' currently. This entry will be used as cfg.method for performing ft_connectivityanalysis. See ft_connectivityanalysis for more details.

Example:

    lfp_tfa_cfg.sync.measure = 'ppc'; %calculates pairwise phase consistency. 

Settings for detection of noisy trials


Noise detection based on LFP raw amplitude thresholding

A trial is rejected if N consecutive LFP sample amplitudes are beyond a specified threshold. Threshold is defined as and K standard deviations from mean LFP amplitude across a whole session, i.e., T_amp = mean(LFP) + K.std(LFP), where N and K are specified in the settings as lfp_tfa_cfg.noise.amp_N and lfp_tfa_cfg.noise.amp_thr respectively.

Noise detection based on LFP trial standard deviation thresholding

A trial is rejected if the LFP amplitude standard deviation for that trial is greater than or equal to K times the LFP standard deviation for the whole session, where K is specified in the settings as lfp_tfa_cfg.noise.std_thr.

Noise detection based on LFP differential amplitude thresholding

A trial is rejected if N consecutive samples of LFP differential amplitude are beyond a specified threshold. Threshold is defined by the mean and standard deviation of LFP differential amplitude across a whole session as T_diff = mean(diff_LFP) + K.std(diff_LFP), where N and K are specified in settings as lfp_tfa_cfg.noise.diff_N and lfp_tfa_cfg.noise.diff_thr respectively.

Noise detection based on LFP spectral power thresholding

A trial is rejected if in the LFP time frequency spectrogram, at least half of the frequency bins have spectral power greater than a threshold for any time bin of that trial. The threshold is defined by the mean and standard deviation of LFP spctral power across different frequency bins for the whole session. i.e., T_pow(f) = mean(LFP_pow(f)) + K.std(LFP_pow(f)), where K is specified in the settings as lfp_tfa_cfg.noise.pow_thr.


lfp_tfa_cfg.noise.detect - whether or not to apply noise rejection. Set to zero to accept all completed trials. Set to 1 to run the noise trial detection methods.

Examples (use any one):

    lfp_tfa_cfg.noise.detect = 1; % detect noisy trials and reject them from analysis
    lfp_tfa_cfg.noise.detect = 0; % use all completed trials for analysis

lfp_tfa_cfg.noise.methods - methods to be used for noisy trial detection (for future use). Can be 'amp', 'std', 'diff', 'pow'. Currently all methods are applied, so ignore.

  • 'amp' - Noise detection based on LFP raw amplitude thresholding
  • 'std' - Noise detection based on LFP trial standard deviation thresholding
  • 'diff' - Noise detection based on LFP differential amplitude thresholding
  • 'pow' - Noise detection based on LFP spectral power thresholding

Example:

    lfp_tfa_cfg.noise.methods = {'amp', 'std', 'diff', 'pow'};

lfp_tfa_cfg.noise.amp_thr - number of standard deviations from LFP amplitude mean to be considered for LFP amplitude thresholding

Example:

    lfp_tfa_cfg.noise.amp_thr = 6;

lfp_tfa_cfg.noise.amp_N - number of consecutive LFP amplitude samples beyond threshold to be considered for detecting a noisy trial

Example:

    lfp_tfa_cfg.noise.amp_N = 10;

lfp_tfa_cfg.noise.std_thr - number of standard deviations of a trial LFP w.r.t LFP std of all trials to consider a trial to be noisy

Example:

    lfp_tfa_cfg.noise.std_thr = 4;

lfp_tfa_cfg.noise.diff_thr - number of standard deviations from LFP differential amplitude mean to be considered for LFP differential amplitude thresholding

Example:

    lfp_tfa_cfg.noise.diff_thr = 6;

lfp_tfa_cfg.noise.diff_N - number of consecutive LFP differential amplitude samples beyond threshold to be considered for marking a noisy trial

Example:

    lfp_tfa_cfg.noise.diff_N = 10;

lfp_tfa_cfg.noise.pow_thr - number of standard deviations from mean LFP spectral power to be considered for LFP spectral power thresholding

Example:

    lfp_tfa_cfg.noise.pow_thr = 4;

lfp_tfa_cfg.noise.plottrials - whether to plot single trial LFP amplitude, differential amplitude and time frequency spectrogram. Set to 0 for not plotting the single trials and 1 otherwise (consumes a lot of time if single trials are plotted).

Example:

    lfp_tfa_cfg.noise.plottrials = 0;

Settings used for baseline power normalization


lfp_tfa_cfg.baseline_ref_state - ID of the reference state around which baseline should be considered, see lfp_tfa_global_define_states

Examples:

   lfp_tfa_cfg.baseline_ref_state = lfp_tfa_states.CUE_ON; %considers cue onset as the reference state for baseline period
   lfp_tfa_cfg.baseline_ref_state = ''; %consider the whole trial period for baseline

lfp_tfa_cfg.baseline_ref_period - time period of interest relative to onset of baseline_ref_state for baseline power calculation. If lfp_tfa_cfg.baseline_ref_state = '', lfp_tfa_cfg.baseline_ref_period is set to 'trial' indicating that the complete trial period will be used for baseline power calculation. Otherwise, the user needs to set a time period to be considered relative to onset of baseline_ref_state

Example usage:

    if isempty(lfp_tfa_cfg.baseline_ref_state)
        % complete trial period starting from the onset of 
        % lfp_tfa_cfg.trialinfo.start_state + lfp_tfa_cfg.trialinfo.ref_tstart to the onset of 
        % lfp_tfa_cfg.trialinfo.end_state + lfp_tfa_cfg.trialinfo.ref_tend will be used for baseline power calculation
        lfp_tfa_cfg.baseline_ref_period = 'trial';
    else
        % Consider the time period -0.5 s to -0.1 s from the onset of 
        % baseline_ref_state (i.e., if lfp_tfa_cfg.baseline_ref_state = lfp_tfa_states.CUE_ON, time period from -0.5 s 
        % to -0.1s from the cue onset is considered as baseline period)
        lfp_tfa_cfg.baseline_ref_period = [-0.5 -0.1]; 
    end

lfp_tfa_cfg.baseline_perturbation - which perturbation blocks to be considered for baseline power calculation. If only pre-injection or only post-injection block are analysed, baseline power is calculated from the analysed perturbation block. If both pre- and post-injection blocks are analysed, the perturbation block(s) to be used for baseline power calculation should be set in this field.

Example:

      lfp_tfa_cfg.baseline_perturbation = 0; %only perturbation block 0 (pre-injection) is used for baseline power calculation    
      lfp_tfa_cfg.baseline_perturbation = [0, 2]; %combines perturbation blocks 0 (pre-injection) and 2 (post-injection), but is not recommended since it does not help in comparing the pre- and post-injection effects
      lfp_tfa_cfg.baseline_perturbation = [2, 3]; %combines perturbation blocks 2 and 3 (post-injection)

lfp_tfa_cfg.baseline_use_choice_trial - whether to consider choice (1) or instructed trials (0) in baseline power calculation. If only instructed or only choice trials are analysed, the analysed choice will be used for baseline power. If both instructed and choice trials are analysed, which choice(s) of trials to be used for baseline power should be specified in this field.

Example usage: lfp_tfa_cfg.baseline_use_choice_trial = 0; consider only instructed trials lfp_tfa_cfg.baseline_use_choice_trial = 1; consider only choice trials
lfp_tfa_cfg.baseline_use_choice_trial = [0, 1]; consider both instructed and choice trials


lfp_tfa_cfg.baseline_method - method to be used for baseline normalization. This field can take values 'zscore', 'relchange', 'subtraction', or 'division'

  • 'zscore' - computes Z-score for each time freq bin

    • Z(t,f) = (P(t, f) - mu_P(f)) / (sigma_P(f))
  • 'relchange' - relative power change w.r.t. the baseline power

    • P_norm(t,f) = (P(t, f) - mu_P(f)) / (mu_P(f))
  • 'subtraction' - absolute increase in power w.r.t. the baseline

    • P_norm(t,f) = (P(t, f) - mu_P(f))
  • 'division' - relative increase in power w.r.t. the baseline

    • P_norm(t,f) = (P(t, f)) / (mu_P(f))

Example:

    lfp_tfa_cfg.baseline_method = 'zscore';

Settings for grand averaging


lfp_tfa_cfg.compute_avg_across - how to average data across multiple sessions/sites. This field can take values 'sessions' and/or 'sites'.

  • 'sessions' - average the session averages (a session average is the average of site averages within a session)
  • 'sites' - average across sites, regardless of which session they come from.

Example usage:

   lfp_tfa_cfg.compute_avg_across = {'sessions', 'sites'}; %compute both averages across session averages and across site averages

Settings for statistical test for significance of difference between TFR average across sites


lfp_tfa_cfg.fd_rate - Desired false discovery rate for multiple comparison correction for statistical significance tests. See https://de.mathworks.com/matlabcentral/fileexchange/27418-fdr_bh?focused=5807896&tab=function for details

Example:

    lfp_tfa_cfg.fd_rate = 0.005; %set false discovery rate to 0.5%

lfp_tfa_cfg.fdr_method - FDR procedure to be used. This can be 'pdep' or 'dep'

  • 'pdep' - executes the original Bejnamini & Hochberg FDR procedure is used, which is guaranteed to be accurate if the individual tests are independent or positively dependent
  • 'dep' - the FDR procedure described in Benjamini & Yekutieli (2001) that is guaranteed to be accurate for any test dependency structure

Example:

    lfp_tfa_cfg.fdr_method = 'pdep';

lfp_tfa_cfg.plot_significant - Flag to indicate whether only the significantly different time bins should be plotted. Set to true (1) to plot only the significant difference bins (non-significant bins will be shown as white), set to false (0) to plot all difference bins.

Example:

    lfp_tfa_cfg.plot_significant = 1;  

lfp_tfa_cfg.save_fig_format - Format(s) to save the resulting figures. This should be a cell array containing one or multiple formats in which figure should be saved. The valid formats are 'pdf', 'eps', 'svg', 'png', 'tif', 'jpg' and 'bmp' (if no format is given, figures will be saved in 'png' format).

Examples:

    lfp_tfa_cfg.save_fig_format = {'png'}; % save figure as png only
    lfp_tfa_cfg.save_fig_format = {'png', 'pdf'}; % save figure as png and pdf