Hippocampal ripples initiate cortical dimensionality expansion for memory retrieval.
The 6 matches
- [1] § Methods › Theta-gamma phase-amplitude coupling ↔ ripple_stage_05b_PAC_across_time_shuffled_final.m, lines 650–709 · score 0.72 · theta frequency, 140 Hz, hippocampal channels, wavelet, Hanning, taper
- [2] § Methods › Theta-gamma phase-amplitude coupling ↔ ripple_stage_05a_PAC_final.m, lines 607–664 · score 0.71 · theta frequency, 140 Hz, hippocampal channels, wavelet, Hanning, taper
- [3] § Methods › Method details › Dimensionality transformation ↔ ripple_stage_04c_dimensionality_LME_final.m, lines 603–718 · score 0.61 · elbow point, explained variance, eigenvalues, threshold, PCA, component
- [4] § Methods › Method details › Dimensionality transformation ↔ ripple_stage_04a_dimensionality_final.m, lines 531–662 · score 0.59 · elbow point, explained variance, eigenvalues, PCA, component, transformation
- [5] § Results › Hippocampal ripple-induced dimensionality expansion increases the separability of cortical representations ↔ ripple_stage_04a_dimensionality_final.m, lines 531–662 · score 0.51 · sliding windows, latent, elbow, eigenvalue, variance, overlap
- [6] § Results › Hippocampal ripple-induced dimensionality expansion increases the separability of cortical representations ↔ ripple_stage_04a_dimensionality_shuffled_final.m, lines 530–647 · score 0.51 · sliding windows, latent, elbow, eigenvalue, variance, overlap
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
MATLAB · 1,223 lines · 43 KB · no license · 2 matches
- %%
- % [ripple_stage_04a_dimensionality] find ripples in hippocampal channels,
- % extract and realign data based on ripple events.
- % Do PCA to estimate dimensionality of correct and incorrect.
- % Bernhard Staresina [[email hidden]]
- % Casper Kerren [[email hidden]]
- clear
- restoredefaultpath
- addpath('/Users/kerrenadmin/Desktop/Postdoc/Project_1/Analyses_matlab/general_scripts_matlab/fieldtrip-20230422')
- ft_defaults
- % [~,ftpath]=ft_version;
- %% path settings
- settings = [];
- settings.base_path_castle = '/Users/kerrenadmin/Desktop/Other_projects/Dimensionality_ripples_Casper_and_Bernhard/'; % '/castles/nr/projects/w/wimberm-ieeg-compute/';
- settings.subjects = char('CF', 'JM', 'SO', 'AH','FC', 'HW', 'AM', 'MH','FS', 'AS', 'CB', 'KK');
- settings.SubjectIDs = char('01_CF', '02_JM', '03_SO', '06_AH','07_FC', '08_HW', '09_AM', '10_MH','11_FS', '12_AS', '13_CB', '14_KK');
- load("colour_scheme.mat")
- settings.colour_scheme = colour_scheme;
- settings.data_dir = [settings.base_path_castle,'preprocessing/artifact_rejected_data/'];
- settings.save_dir = [settings.base_path_castle,'output_data/decoding/'];
- settings.data_dir_channels = [settings.base_path_castle,'ripple_project_publication_for_replication/templates'];
- settings.anatomy_dir = [settings.base_path_castle,'ripple_project_publication_for_replication/additional_analyses/visualisation/'];
- settings.AAL_dir = fullfile(settings.base_path_castle,'ripple_project_publication_for_replication/subfunctions/AAL3');
- settings.SPM_dir = fullfile(settings.base_path_castle,'/ripple_project_publication_for_replication/subfunctions/spm12');
- settings.scalp_channels = {'C3' 'C4' 'Cz' 'T3' 'T4' 'T5' 'T6' 'O1' 'O2' 'Oz' 'F3' 'F4' 'Fz' 'Cb1' 'Cb2'};
- subjects = {'CF', 'JM', 'SO', 'AH','FC', 'HW', 'AM', 'MH','FS', 'AS', 'CB', 'KK'};
- SubjectIDs = {'01_CF', '02_JM', '03_SO', '06_AH','07_FC', '08_HW', '09_AM', '10_MH','11_FS', '12_AS', '13_CB', '14_KK'};
- settings.nu_rep = [1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1];
- settings.healthyhemi = {'R' 'LR' 'R' 'L' 'L' 'R' 'R' 'R' 'R' 'R' 'R' 'LR'};
- addpath(genpath('/Users/kerrenadmin/Desktop/Postdoc/Project_1/Analyses_matlab/general_scripts_matlab/MVPA-Light-master'))
- addpath(genpath([settings.base_path_castle,'ripple_project_publication_for_replication/main_analyses/Slythm']))
- addpath([settings.base_path_castle,'ripple_project_publication_for_replication/subfunctions'])
- addpath(genpath('/Users/kerrenadmin/Desktop/Postdoc/Project_1/Analyses_matlab/help_functions'))
- addpath(genpath('/Users/kerrenadmin/Desktop/Postdoc/Project_1/Analyses_matlab/general_scripts_matlab/plotting'))
- %% pre-decoding settings
- % ripple extraction
- settings.remove_falsepositives = 1; % decide whether or not to exclude ripples deemed false positives based on spectral peak detection
- settings.full_enc_trial = 1; % set to 0 if you want encoding trial to end with RT and to 1 if it should end at 3 sec
- settings.remove_ripple_duplicates = 1; % remove co-occuring ripples
- settings.time_to_excl_RT = .25; % exclude last 250 ms of trials, to make sure ripple event was in trial
- settings.solo_ripple = 1; % pick one (maxEnv) ripple per trial if multiple ripple events are found
- settings.ripple_latency = [.25 5]; % define time window at retrieval in which the ripple events need to occur
- settings.do_surrogates = 0; % switch time of ripples between trials, 1 == for all trials, 2 == for correct trials only
- %% decoding settings
- % data preprocessing
- settings.ori_fsample = 1000; % original sample frequency
- settings.do_resample = 100; % [] or sample frequency
- % baseline and zscoring settings
- settings.zscore_data4class = 1;
- settings.bs_correct = 1;
- settings.bs_period = [-.2 0]; % [-.5 -.1]
- settings.bs_trim = 0; % can be 0. amount of % to trim away when calculating the baseling
- % smoothing options
- settings.do_smoothdata = 1; % use matlabs smoothdata function for running average
- settings.smooth_win = .200; % .100, [] running average time window in seconds;
- % time of interest
- settings.TOI_train = [-.5 3];
- settings.timesteps_train = ((settings.ori_fsample/settings.do_resample)/settings.ori_fsample); % in s. if you want it to take less sample points multiply [e.g., ((settings.ori_fsample/settings.do_resample)/settings.ori_fsample)*2
- settings.TOI_test = [-1.2 1.2]; % time around ripple (I take this time window to get a proper estimate around the edges too. Only look at -1 to 1 later.
- settings.timesteps_test = ((settings.ori_fsample/settings.do_resample)/settings.ori_fsample); % in s
- settings.classifier = 'lda';
- settings.metric = 'auc';
- %% channel settings
- settings.channel_sel = 1; % 1 exclude hippo, 2 only hippo, 3 all channels
- %% settings pca
- settings.smooth_before_dim = 1; % smooth Nans before doing dim reduction
- settings.nu_time_points = 60; % time of sliding window in ms
- settings.prc_overlap = .9; % percentage overlap sliding window
- settings.decode_components = 1; % Decode the PCA components I picked.
- %% start for loop
- timeaxis = settings.TOI_test(1):settings.timesteps_test:settings.TOI_test(2);
- freqaxis = settings.TOI_train(1):settings.timesteps_train:settings.TOI_train(2);
- perf = cell(1,numel(subjects));
- channs = cell(1,numel(subjects));
- RT_all_subj_correct = cell(1,numel(subjects));
- RT_all_subj_incorrect = cell(1,numel(subjects));
- ripple_time_correct = cell(1,numel(subjects));
- ripple_time_incorrect = cell(1,numel(subjects));
- numWorkers = 8; %
- parpool('local', numWorkers);
- tic
- parfor isubject = 1:numel(subjects)
- fprintf('processing subject %01d/%02d\n',isubject,numel(subjects));
- %% LOAD data
- tmp = load([settings.data_dir,'eeg_session01_all_chan_nobadchan_cmntrim_artdet_',subjects{isubject}]);
- data = tmp.data;
- onsets_session = tmp.onsets_session;
- tmp = [];
- %% load channels and restrict to channels that are in hippocampus
- SubjectID = SubjectIDs{isubject};
- tmp = load([settings.base_path_castle,'ripple_project_publication_for_replication/templates/channels_hipp_ripples']);
- channels_hipp_ripples = tmp.channels_hipp_ripples;
- tmp = [];
- channels = channels_hipp_ripples(isubject,:);
- channels = channels(~cellfun(@isempty,channels));
- cfg = [];
- cfg.channel = channels;
- data = ft_selectdata(cfg, data);
- % If NaNs in recording, interpolate these.
- cfg = [];
- cfg.prewindow = 3;
- cfg.postwindow = 3;
- data = ft_interpolatenan(cfg,data);
- %% Find ripples
- [inData,alldat] = detect_ripples(data, settings);
- %% remove false positives from ripple data
- if settings.remove_falsepositives
- alldat = remove_false_positives(alldat);
- end
- %% delete co-occuring ripples
- if settings.remove_ripple_duplicates
- alldat = remove_ripple_duplicates(alldat);
- end
- %% Load data to realign based on cue onset encoding and based on ripples
- data_in = load([settings.data_dir,'eeg_session01_all_chan_nobadchan_cmntrim_artdet_',subjects{isubject}],'data','onsets_session');
- data = data_in.data;
- data_in = [];
- onsets = onsets_session - data.time{1}(1)*inData.fsample;
- data.sampleinfo = 1+data.sampleinfo - data.sampleinfo(1);
- data.time{1} = 1/data.fsample+data.time{1}-data.time{1}(1);
- %% channel selection for data
- % 1 exclude hippo, 2 only hippo, 3 all channels
- tmp = load([settings.data_dir_channels,'/channels_to_exclude_all_hipp_both_hem.mat']);
- channels_to_exclude_all_hipp = tmp.channels_to_exclude_all_hipp;
- tmp = load([settings.data_dir_channels,'/channels_hipp_ripples.mat']);
- channels_hipp_ripples = tmp.channels_hipp_ripples;
- cfg = [];
- cfg.channel = data.label;
- switch settings.channel_sel
- case 1
- cfg.channel = setdiff(setdiff([data.label],char(channels_to_exclude_all_hipp{isubject,:})),settings.scalp_channels);
- case 2
- cfg.channel = intersect(cellstr(setdiff([data.label],settings.scalp_channels)),char(channels_hipp_ripples{isubject,:}));
- case 3
- cfg.channel = setdiff(data.label,settings.scalp_channels);
- end
- %--- load channel info and coordinates
- [~,~,entries] = xlsread(fullfile(settings.anatomy_dir,'well01_ripples_ROIs_w_labels.xlsx'));
- subject_colums = entries(1,:);
- column_names = entries(2,:);
- these_labels = entries(3:end,strcmp(subject_colums,['s' SubjectIDs{isubject}]) & strcmp(column_names,'label'));
- these_x = cell2mat(entries(3:end,strcmp(subject_colums,['s' SubjectIDs{isubject}]) & strcmp(column_names,'x')));
- these_y = cell2mat(entries(3:end,strcmp(subject_colums,['s' SubjectIDs{isubject}]) & strcmp(column_names,'y')));
- these_z = cell2mat(entries(3:end,strcmp(subject_colums,['s' SubjectIDs{isubject}]) & strcmp(column_names,'z')));
- data = ft_selectdata(cfg, data);
- % write out info of retained channels
- for ichannel = 1:numel(data.label)
- idx = strcmp(data.label{ichannel},these_labels);
- channs{isubject}(ichannel).names = data.label{ichannel};
- channs{isubject}(ichannel).coords = [these_x(idx) these_y(idx) these_z(idx)];
- end
- %% Load subject file and change RT
- [numbers,strings] = xlsread([settings.base_path_castle,'well01_behavior_all.xls']);
- strings = strings(2:end,:);
- if isnan(numbers(1,1))
- numbers = numbers(2:end,:);
- end
- sel = find(strcmp(strings(:,2),SubjectID));
- sel = sel(1:numel(onsets));
- trls_enc = strcmp(strings(sel,4),'encoding');
- trls_ret = strcmp(strings(sel,4),'retrieval');
- Memory = cell(size(strings(sel,12))); % Convert Memory to a cell array of the same size
- Memory = strings(sel,12);
- Memory = Memory(trls_ret);
- idx_trial = find(trls_ret);
- Memory(:, 2) = num2cell(idx_trial); % Assign idx_trial to the second column
- RT = numbers(sel,11);
- RT(RT==-1 & trls_enc==1) = 3; % -1 no press in time - set to 3s at encoding
- if settings.full_enc_trial
- RT(trls_enc==1) = 3; % [optional] set all encoding to 3s
- end
- RT(RT==-1 & trls_ret==1) = 5; % -1 no press in time - set to 5s at encoding and 5s at retrieval
- trialinfo = [];
- for itrial = 1:numel(sel)
- trialinfo(itrial).SubjectID = strings(sel(itrial),2);
- trialinfo(itrial).RunNumber = numbers(sel(itrial),3);
- trialinfo(itrial).ExpPhase = strings(sel(itrial),4);
- trialinfo(itrial).TrialNumber = numbers(sel(itrial),5);
- trialinfo(itrial).EventNumber = itrial;
- trialinfo(itrial).BlockType = strings(sel(itrial),6);
- trialinfo(itrial).Subcat = strings(sel(itrial),7);
- trialinfo(itrial).Word = strings(sel(itrial),8);
- trialinfo(itrial).OldNew = strings(sel(itrial),9);
- trialinfo(itrial).Response = strings(sel(itrial),10);
- trialinfo(itrial).Memory = strings(sel(itrial),12);
- trialinfo(itrial).RT = RT(itrial);
- end
- sel = [];
- strings = [];
- %% create onset matrices (remove last 250ms to ensure ripple event in trial)
- onsetmat = [onsets; onsets+(RT'.*data.fsample)-(settings.time_to_excl_RT*data.fsample)]';
- %% Extract ripples (optional to select long and short duration ripples)
- trl_ripple = [];
- cnt = 0;
- for ichannel = 1:numel(alldat)
- evs = alldat{ichannel}.evtIndiv.maxTime;
- envSum = alldat{ichannel}.evtIndiv.envSum;
- ripple_dur = alldat{ichannel}.evtIndiv.duration;
- duration_sel = logical(ones(1,numel(ripple_dur)));
- evs = evs(duration_sel);
- envSum = envSum(duration_sel);
- %% for each detected ripple, find the corresponding trial
- for iripple = 1:numel(evs)
- this_event = evs(iripple) >= onsetmat(:,1) & evs(iripple) <= onsetmat(:,2);
- if any(this_event)
- cnt=cnt+1;
- trl_ripple(cnt,1) = find(this_event); % note down corresponding event number
- trl_ripple(cnt,2) = evs(iripple); % note down ripple sample
- trl_ripple(cnt,3) = (evs(iripple) - onsetmat(this_event,1))/data.fsample; % note down time of ripple in trial
- trl_ripple(cnt,4) = ichannel; % note down channel
- trl_ripple(cnt,5) = envSum(iripple);
- end
- end
- end
- trl_ripple = sortrows(trl_ripple,1);
- %% restrict ripple data to retrieval
- trl_ripple = trl_ripple(ismember(trl_ripple(:,1),find(trls_ret)),:);
- %% [optional] do surrogates by taking time of ripple from other trial (for all or only for correct trials)
- correct_mem = cell2mat(Memory(ismember(Memory(:,1),'SourceCorrect'),2));
- idx_correct = ismember(trl_ripple(:,1), correct_mem);
- trl_ripple_correct = trl_ripple(idx_correct,:);
- if settings.do_surrogates == 1 % 1 for all trials
- randtrials = circshift(1:size(trl_ripple,1),1);
- tmp = trl_ripple(:,2)-round(trl_ripple(:,3).*data.fsample); % find cue onset
- tmp = tmp+round(trl_ripple(randtrials,3).*data.fsample); % add another ripple's event time
- trl_ripple(:,2) = tmp;
- trl_ripple(:,3) = trl_ripple(randtrials,3);
- elseif settings.do_surrogates == 2 % 2 for only correct trials
- randtrials_correct = circshift(1:size(trl_ripple_correct,1),-1);
- tmp_correct = trl_ripple_correct(:,2) - round(trl_ripple_correct(:,3) .* data.fsample); % find cue onset
- tmp_correct = tmp_correct + round(trl_ripple_correct(randtrials_correct,3) .* data.fsample); % add shuffled ripple event time
- trl_ripple_correct(:,2) = tmp_correct;
- trl_ripple_correct(:,3) = trl_ripple_correct(randtrials_correct,3);
- trl_ripple(idx_correct,:) = trl_ripple_correct; % add to original structure with only correct trials swapped
- end
- %% Create trial structure around ripples
- pretrig = round(abs(settings.TOI_test(1)) * data.fsample); % enough time to baseline correct later
- posttrig = round(abs(settings.TOI_test(2)) * data.fsample);
- cfg = [];
- cfg.trl = [trl_ripple(:,2)-pretrig trl_ripple(:,2)+posttrig -pretrig*ones(size(trl_ripple,1),1)];
- data_ripples = ft_redefinetrial(cfg,data);
- % add trial info for each ripple trial, accounting for multiple ripples
- % per trial
- data_ripples.trialinfo = [];
- for itrial = 1:numel(data_ripples.trial)
- corresponding_trialinfo = find([trialinfo.EventNumber]==trl_ripple(itrial,1));
- trl_info = trialinfo(corresponding_trialinfo);
- trl_info.sample_ripple = trl_ripple(itrial,2);
- trl_info.time_ripple = trl_ripple(itrial,3);
- trl_info.channel = trl_ripple(itrial,4);
- trl_info.name_channel = {alldat{trl_ripple(itrial,4)}.evtIndiv.label};
- trl_info.envSum = trl_ripple(itrial,5);
- data_ripples.trialinfo{itrial,1} = trl_info;
- end
- %% [optional] if there are multiple ripples per trial - pick the one ripple with highest activity (captured in the summed envelope metric)
- if settings.solo_ripple
- tmp_trl_info = data_ripples.trialinfo;
- % find the trials in which there were more than one ripple
- trlinfo = cell2mat(data_ripples.trialinfo);
- ripple_trial = [trlinfo.EventNumber];
- envSum = [trlinfo.envSum];
- idx_unique = unique(ripple_trial);
- sel = [];
- counter = 1;
- for itrial = 1:numel(idx_unique)
- idx = find(ripple_trial==idx_unique(itrial));
- [~,max_effect] = max(envSum(idx));
- sel(counter) = idx(max_effect);
- counter = counter+1;
- end
- cfg = [];
- cfg.trials = sel;
- data_ripples = ft_selectdata(cfg, data_ripples);
- end
- %% [optional] pick ripples in a specific time window
- if any(settings.ripple_latency)
- trlinfo = cell2mat(data_ripples.trialinfo);
- sel = [trlinfo.time_ripple] > settings.ripple_latency(1) & [trlinfo.time_ripple] < settings.ripple_latency(2);
- cfg = [];
- cfg.trials = sel;
- data_ripples = ft_selectdata(cfg, data_ripples);
- end
- %% Realign trials based on stimulus onsets
- pretrig = round(abs(settings.TOI_train(1)) * data.fsample);
- posttrig = round(abs(settings.TOI_train(2)) * data.fsample);
- cfg = [];
- cfg.trl = [onsets'-pretrig onsets'+posttrig -pretrig*ones(numel(onsets),1)];
- data_stimuli = ft_redefinetrial(cfg,data);
- data_stimuli.trialinfo = {};
- for itrial = 1:numel(trialinfo)
- data_stimuli.trialinfo{itrial,1} = trialinfo(itrial);
- end
- %% [optional] resample
- if any(settings.do_resample)
- cfg = [];
- cfg.resamplefs = settings.do_resample;
- data_ripples = ft_resampledata(cfg, data_ripples);
- data_stimuli = ft_resampledata(cfg, data_stimuli);
- end
- %% Time-lock data
- cfg = [];
- cfg.keeptrials = 'yes';
- cfg.removemean = 'no';
- data_ripples = ft_timelockanalysis(cfg, data_ripples);
- data_stimuli = ft_timelockanalysis(cfg, data_stimuli);
- fsample = round(1/(data_ripples.time(2)-data_ripples.time(1)));
- %% [optional] Running mean filter
- if ~isempty(settings.smooth_win)
- data_ripples.trial = smoothdata(data_ripples.trial,3,'movmean',settings.smooth_win*fsample);
- data_stimuli.trial = smoothdata(data_stimuli.trial,3,'movmean',settings.smooth_win*fsample);
- end
- %% [optional] BL correct (us pre-stim baseline also for ripple-locked data)
- if settings.bs_correct == 1
- % training data
- bl_idx = nearest(data_stimuli.time,settings.bs_period(1)):nearest(data_stimuli.time,settings.bs_period(2));
- bldat = trimmean(data_stimuli.trial(:,:,bl_idx),settings.bs_trim,'round',3);
- blmat = repmat(bldat,[1 1 size(data_stimuli.trial,3)]);
- data_stimuli.trial = data_stimuli.trial - blmat;
- % testing data
- trlinfo = cell2mat(data_ripples.trialinfo);
- orig_events = [trlinfo.EventNumber];
- bl4ripples = nan(size(data_ripples.trial,1),size(bldat,2));
- for iripple = 1:size(data_ripples.trial,1)
- bl4ripples(iripple,:) = bldat(orig_events(iripple),:);
- end
- blmat = repmat(bl4ripples,[1 1 size(data_ripples.trial,3)]);
- data_ripples.trial = data_ripples.trial - blmat;
- end
- %% time-lock data
- cfg = [];
- cfg.keeptrials = 'yes';
- data_stimuli = ft_timelockanalysis(cfg,data_stimuli);
- data_ripples = ft_timelockanalysis(cfg,data_ripples);
- %% calculate time of ripple and RT for those trials
- ripple_tmp = [];
- RT_tmp = [];
- for itrial = 1:numel(data_ripples.trialinfo)
- ripple_tmp(itrial) = data_ripples.trialinfo{itrial, 1}.time_ripple;
- RT_tmp(itrial) = data_ripples.trialinfo{itrial, 1}.RT;
- end
- trlinfo = cell2mat(data_ripples.trialinfo);
- sel1 = ismember([trlinfo.ExpPhase],'retrieval') & ismember([trlinfo.Memory],'SourceCorrect');
- sel2 = ismember([trlinfo.ExpPhase],'retrieval') &(ismember([trlinfo.Memory],{'SourceIncorrect' ,'SourceDunno' 'dunno'}));
- RT_all_subj_correct{isubject} = RT_tmp(sel1);
- RT_all_subj_incorrect{isubject} = RT_tmp(sel2);
- ripple_time_correct{isubject} = ripple_tmp(sel1);
- ripple_time_incorrect{isubject} = ripple_tmp(sel2);
- %%
- %%%%%%%%%%%%%%%%%%%%%%
- %%%%%%%%% PCA %%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%
- trlinfo = cell2mat(data_stimuli.trialinfo);
- sel1 = ismember([trlinfo.ExpPhase],'encoding') & ismember([trlinfo.BlockType],'color');
- sel2 = ismember([trlinfo.ExpPhase],'encoding') & ismember([trlinfo.BlockType],'scene');
- dataToClassifyTraining = cat(1,data_stimuli.trial(sel1,:,:),data_stimuli.trial(sel2,:,:));
- clabelTraining = cat(1,1*ones(sum(sel1),1),2*ones(sum(sel2),1));
- samples_train = nearest(data_stimuli.time,settings.TOI_train(1)):settings.timesteps_train*fsample:nearest(data_stimuli.time,settings.TOI_train(2));
- dataToClassifyTraining = dataToClassifyTraining(:,:,samples_train);
- %% 1. category PCA [colours vs. scenes; coarse]
- trlinfo = cell2mat(data_ripples.trialinfo);
- %% PCA on the data to get the eigenvalues that explain 90% of the variance.
- % Do it with a sliding window of 60ms with 100Hz)
- for icond = 1:2
- if icond == 1
- sel1 = ismember([trlinfo.ExpPhase],'retrieval') & ismember([trlinfo.BlockType],'color') & ismember([trlinfo.Memory],'SourceCorrect');
- sel2 = ismember([trlinfo.ExpPhase],'retrieval') & ismember([trlinfo.BlockType],'scene') & ismember([trlinfo.Memory],'SourceCorrect') ;
- perf{isubject}.correct.trl_num_test = [sum(sel1) sum(sel2)];
- elseif icond == 2
- sel1 = ismember([trlinfo.ExpPhase],'retrieval') & ismember([trlinfo.BlockType],'color')& (ismember([trlinfo.Memory],{'SourceIncorrect' ,'SourceDunno' 'dunno'}));
- sel2 = ismember([trlinfo.ExpPhase],'retrieval') & ismember([trlinfo.BlockType],'scene')& (ismember([trlinfo.Memory],{'SourceIncorrect' ,'SourceDunno' 'dunno'}));
- perf{isubject} .incorrect.trl_num_test = [sum(sel1) sum(sel2)];
- end
- clabelTest = cat(1,1*ones(sum(sel1),1),2*ones(sum(sel2),1));
- dataToClassifyTest = cat(1,data_ripples.trial(sel1,:,:),data_ripples.trial(sel2,:,:));
- sumsel1 = sum(sel1);
- sumsel2 = sum(sel2);
- fs = 1/(data_ripples.time(2)-data_ripples.time(1));
- chunk_size = round(settings.nu_time_points/((1/fs)*1000)); % Size of each chunk
- overlap_size = round(chunk_size * settings.prc_overlap);
- num_chunks = floor((size(dataToClassifyTest, 3) - overlap_size) / (chunk_size - overlap_size));
- TOI_ripple = linspace(data_ripples.time(1), data_ripples.time(end),num_chunks);
- explained_variances = [];
- how_much_variance = [];
- accuracy = [];
- ripple_to_decode = [];
- for i = 1:num_chunks
- % Calculate the start and end indices of the current chunk
- start_idx = (i - 1) * (chunk_size - overlap_size) + 1;
- end_idx = start_idx + chunk_size - 1;
- % Extract data for the current chunk and reshape
- chunk_data = dataToClassifyTest(:, :, start_idx:end_idx);
- chunk_data = reshape(chunk_data, size(dataToClassifyTest, 1), []);
- if settings.smooth_before_dim == 1 % smooth NaNs through linear interpolation
- for ismooth = 1:size(chunk_data, 1)
- valid_indices = ~isnan(chunk_data(ismooth, :));
- chunk_data(ismooth, :) = interp1(find(valid_indices), chunk_data(ismooth, valid_indices), 1:size(chunk_data, 2), 'linear', 'extrap');
- end
- end
- % Perform PCA and compute explained variance
- [coefficients, ~, latent, ~, explained] = pca(chunk_data);
- % Compute explained variance
- explained_variance_pca = latent / sum(latent);
- % use a data-driven approach to get the first elbow point where
- % least variance is explained.
- curvature = diff(diff(explained_variance_pca));
- [~, elbow_index] = max(curvature);
- elbow_component = elbow_index + 1; % Add 1 because of diff operation
- explained_variances(i, :) = elbow_component;
- how_much_variance(i,:) = sum(explained_variance_pca(1:elbow_component));
- % Do PCA inverse transformation for later decoding
- if settings.decode_components == 1
- selected_components = coefficients(:,1:elbow_component);
- transformed_data = chunk_data * selected_components;
- reconstructed_data = transformed_data * selected_components';
- reconstructed_data = reshape(reconstructed_data,[size(dataToClassifyTest(:, :, start_idx:end_idx))]);
- ripple_to_decode(:,:,i) = nanmean(reconstructed_data,3); % take mean of those time points used in sliding window
- end
- end
- accuracy = explained_variances;
- if settings.decode_components == 1
- if settings.zscore_data4class
- dataToClassifyTraining = zscore(dataToClassifyTraining);
- ripple_to_decode = zscore(ripple_to_decode);
- end
- cfg = [];
- cfg.classifier = settings.classifier;
- cfg.metric = settings.metric;
- [accuracy_dec, ~] = mv_classify_timextime(cfg, dataToClassifyTraining, clabelTraining, ripple_to_decode, clabelTest);
- end
- if icond == 1
- perf{isubject}.correct.accuracy = accuracy;
- perf{isubject}.correct.exl_var = how_much_variance;
- if settings.decode_components == 1
- perf{isubject}.dec.correct.accuracy = accuracy_dec;
- end
- elseif icond == 2
- perf{isubject}.incorrect.accuracy = accuracy;
- perf{isubject}.incorrect.exl_var = how_much_variance;
- if settings.decode_components == 1
- perf{isubject}.dec.incorrect.accuracy = accuracy_dec;
- end
- end
- % add info
- perf{isubject}.channelcount_test = size(data_ripples.trial,2);
- perf{isubject}.channels_test = data_ripples.label;
- perf{isubject}.time_train = TOI_ripple;
- perf{isubject}.time_test = TOI_ripple;
- end
- % clearvars -except perf settings isubject subjects SubjectIDs RT_all_subj_correct RT_all_subj_incorrect
- end
- toc
- delete(gcp);
- return
- %% Stats and plots
- RT_correct = cellfun(@mean, RT_all_subj_correct);
- RT_max_correct = cellfun(@max, RT_all_subj_correct);
- RT_min_correct = cellfun(@min, RT_all_subj_correct);
- RT_incorrect = cellfun(@mean, RT_all_subj_incorrect);
- RT_max_incorrect = cellfun(@max, RT_all_subj_incorrect);
- RT_min_incorrect = cellfun(@min, RT_all_subj_incorrect);
- perf{1}.RT.correct = RT_all_subj_correct;
- perf{1}.RT.incorrect = RT_all_subj_incorrect;
- RT = RT_correct;
- ripple_time_mean = cellfun(@mean, ripple_time_correct);
- ripple_time_max = cellfun(@max, ripple_time_correct);
- ripple_time_min = cellfun(@min, ripple_time_correct);
- perf{1}.ripple_times.correct = ripple_time_correct;
- perf{1}.ripple_times.incorrect = ripple_time_incorrect;
- ripples_to_plot = [];
- rt_to_plot = [];
- explained_var_corr = [];
- explained_var_incorr = [];
- for participant = 1:numel(subjects)
- ripples_to_plot = [ripples_to_plot, ripple_time_correct{participant}];
- rt_to_plot = [rt_to_plot, RT_all_subj_correct{participant}];
- explained_var_corr(participant,:) = perf{1, participant}.correct.exl_var;
- explained_var_incorr(participant,:) = perf{1, participant}.incorrect.exl_var;
- end
- delay_ripple_rt = rt_to_plot-ripples_to_plot;
- figure;
- subplot(3,1,1)
- nhist(ripples_to_plot','proportion','color',settings.colour_scheme(8,:))
- title('Time of ripples')
- xlabel('time of ripples')
- ylabel('proportion')
- set(gca,'FontSize',14)
- set(gca,'TickDir','out')
- title(sprintf('Time of ripples, median = %.2fms',median(ripple_time_mean*1000)),'interpreter','none')
- subplot(3,1,2)
- nhist(rt_to_plot','proportion','color',settings.colour_scheme(8,:))
- title('Reaction time in trials of ripples')
- xlabel('Reaction time')
- ylabel('proportion')
- set(gca,'FontSize',14)
- set(gca,'TickDir','out')
- title(sprintf('Reaction time in trials of ripples, median = %.2fms',median(RT*1000)),'interpreter','none')
- subplot(3,1,3)
- nhist(delay_ripple_rt','proportion','color',settings.colour_scheme(8,:))
- xlabel('Delay ripple RT')
- ylabel('proportion')
- set(gca,'FontSize',14)
- set(gca,'TickDir','out')
- title(sprintf('Delay ripples RT, median = %.2fms',median(delay_ripple_rt*1000)),'interpreter','none')
- for participant = 1:numel(subjects)
- trl_num_test = perf{participant}.correct.trl_num_test;
- trl_correct(participant) = sum(trl_num_test);
- trl_num_test = perf{participant}.incorrect.trl_num_test;
- trl_incorrect(participant) = sum(trl_num_test);
- end
- data_nu_trl = {};
- data_nu_trl{1,1} = trl_correct;
- data_nu_trl{2,1} = trl_incorrect;
- [~,p_val,~,stats] = ttest(trl_correct,trl_incorrect)
- figure;
- h = rm_raincloud(data_nu_trl, [settings.colour_scheme(6,:)],0,'ks',[],settings.colour_scheme);
- h.p{1, 1}.FaceColor = settings.colour_scheme(1,:);
- h.s{1, 1}.MarkerFaceColor = settings.colour_scheme(1,:);
- h.m(1, 1).MarkerFaceColor = settings.colour_scheme(1,:);
- h.p{2, 1}.FaceColor = settings.colour_scheme(10,:);
- h.s{2, 1}.MarkerFaceColor = settings.colour_scheme(10,:);
- h.m(2, 1).MarkerFaceColor = settings.colour_scheme(10,:);
- hold on
- title(sprintf('number of trials for the two conditions, t-stat = %.2f', stats.tstat))
- set(gca,'TickDir','out')
- xlabel('number of trials')
- yticklabels({sprintf('incorrect %d',mean(trl_incorrect)), sprintf('correct %d',floor(mean(trl_correct)))})
- ylabel('condition')
- set(gca,'FontSize',20)
- axis tight
- [~,p_val,~,stats] = ttest(trl_correct,trl_incorrect)
- correct_incorrect = {};
- for isubject = 1:numel(subjects)
- correct_incorrect{1}.label = {'Channels'};
- correct_incorrect{1}.time = perf{1,1}.time_train;
- correct_incorrect{1}.individual(isubject,1,:) = perf{isubject}.correct.accuracy;
- % correct_incorrect{1}.individual(isubject,1,:) = explained_var_corr(isubject,:);
- correct_incorrect{1}.dimord = 'subj_chan_time';
- end
- correct_incorrect{1}.avg = squeeze(correct_incorrect{1}.individual);
- correct_incorrect{2} = correct_incorrect{1};
- for isubject = 1:numel(subjects)
- correct_incorrect{2}.individual(isubject,1,:) = perf{isubject}.incorrect.accuracy;
- % correct_incorrect{2}.individual(isubject,1,:) = explained_var_incorr(isubject,:);
- end
- correct_incorrect{2}.avg = squeeze(correct_incorrect{2}.individual);
- % decoding
- if settings.decode_components == 1
- correct = cell(1,numel(subjects));
- incorrect = cell(1,numel(subjects));
- correct_dec = [];
- incorrect_dec = [];
- for isubject = 1:numel(subjects)
- % correct
- correct{1,isubject} = struct;
- correct{1,isubject}.label = {'chan'};
- correct{1,isubject}.dimord = 'chan_freq_time';
- correct{1,isubject}.freq = freqaxis;
- correct{1,isubject}.time = perf{1, 1}.time_test;
- correct{1,isubject}.powspctrm(1,:,:) = perf{isubject}.dec.correct.accuracy;
- % incorrect
- incorrect{1,isubject} = correct{1,isubject};
- incorrect{1,isubject}.powspctrm(1,:,:) = perf{isubject}.dec.incorrect.accuracy;
- baseline_all{1,isubject} = correct{1,isubject};
- baseline_all{1,isubject}.powspctrm(1,:,:) = .5*ones(size(perf{isubject}.dec.correct.accuracy));
- correct_dec(isubject,:,:) = perf{isubject}.dec.correct.accuracy;
- incorrect_dec(isubject,:,:) = perf{isubject}.dec.incorrect.accuracy;
- end
- end
- %% FT stats (dimensionality)
- xlimits = nearest(correct_incorrect{1, 1}.time, -1):nearest(correct_incorrect{1, 1}.time, 1);
- xlimits = correct_incorrect{1, 1}.time(xlimits);
- cfg = [];
- cfg.latency = [xlimits(1) xlimits(end)];
- cfg.channel = 'all';
- cfg.statistic = 'depsamplesT';
- cfg.method = 'montecarlo'; % 'montecarlo' 'analytic';
- cfg.correctm = 'cluster'; % 'no', cluster;
- cfg.alpha = .05;
- cfg.clusteralpha = .05;
- cfg.tail = 0;
- cfg.correcttail = 'alpha'; % alpha prob no
- cfg.neighbours = [];
- cfg.minnbchan = 0;
- cfg.avgovertime = 'no'; % 'no' 'yes'
- cfg.avgoverchan = 'no';
- cfg.computecritval = 'yes';
- cfg.numrandomization = 'all';%'all';
- cfg.clusterstatistic = 'maxsum'; % 'maxsum', 'maxsize', 'wcm'
- cfg.clustertail = cfg.tail;
- cfg.parameter = 'individual';
- nSub = size(correct_incorrect{1, 1}.individual ,1);
- % set up design matrix
- design = zeros(2,2*nSub);
- for i = 1:nSub
- design(1,i) = i;
- end
- for i = 1:nSub
- design(1,nSub+i) = i;
- end
- design(2,1:nSub) = 1;
- design(2,nSub+1:2*nSub) = 2;
- cfg.design = design;
- cfg.uvar = 1;
- cfg.ivar = 2;
- % run stats
- [Fieldtripstats] = ft_timelockstatistics(cfg, correct_incorrect{:});
- length(find(Fieldtripstats.mask))
- %% plot significant vals
- d = squeeze(correct_incorrect{1}.individual);
- m = nanmean(d);
- s = nanstd(d)./sqrt(size(d,1));
- figure;
- boundedline(perf{1,1}.time_train,m,s,'b');
- plot(perf{1,1}.time_train,m,'k','linewidth',2);
- hold on
- d = squeeze(correct_incorrect{2}.individual);
- m = nanmean(d);
- s = nanstd(d)./sqrt(size(d,1));
- boundedline(perf{1,1}.time_train,m,s,'r');
- plot(perf{1,1}.time_train,m,'k','linewidth',2);
- hold on
- stats_time = nearest(correct_incorrect{1}.time,cfg.latency(1)):nearest(correct_incorrect{1}.time,cfg.latency(2));
- sigline = nan(1,numel(correct_incorrect{1}.time));
- % sigline(stats_time(Fieldtripstats.mask==1)) = m(stats_time(Fieldtripstats.mask==1));
- sigline(stats_time(Fieldtripstats.mask==1)) = 2;
- plot(correct_incorrect{1}.time,sigline,'r','linewidth',4);
- set(gca,'FontSize',16,'FontName','Arial')
- xlabel('ripple time (s)')
- ylabel('dimensionality difference')
- set(gca,'TickDir','out')
- axis tight
- vline(0)
- xlim([cfg.latency(1), cfg.latency(end)])
- m_exp_corr = mean(explained_var_corr(:,sigline==2),2);
- m_exp_incorr = mean(explained_var_incorr(:,sigline==2),2);
- mean(m_exp_corr)
- mean(m_exp_incorr)
- std(m_exp_corr)
- std(m_exp_incorr)
- [~,p_val_expl_var,~,stat] = ttest(m_exp_corr,m_exp_incorr)
- %% relate sigline to reaction time on a group level
- d = squeeze(correct_incorrect{1}.individual);
- RT = RT_correct;
- dimensionality_change = mean(d(:,sigline==2),2);
- figure;
- scatter(RT, dimensionality_change, 'filled', 'MarkerFaceColor', '#0072BD');
- xlabel('RT', 'FontSize', 12);
- ylabel('Dimensionality Change', 'FontSize', 12);
- title('Correlation', 'FontSize', 14);
- grid on;
- box on;
- hold on;
- % Fit a linear regression line
- p = polyfit(RT, dimensionality_change, 1);
- f = polyval(p, RT);
- plot(RT, f, 'r-', 'LineWidth', 1.5);
- % Add legend
- legend('Data', 'Linear Fit', 'Location', 'best');
- % Customize the plot appearance
- set(gca, 'FontSize', 10); % Set font size for axis labels
- set(gcf, 'Color', 'w'); % Set background color of the figure to white
- yfit = polyval(p, RT);
- yresid = dimensionality_change - yfit;
- SSresid = sum(yresid.^2);
- SStotal = (length(dimensionality_change)-1) * var(dimensionality_change);
- rsq = 1 - SSresid/SStotal;
- disp(['R-squared: ', num2str(rsq)]);
- [rho_rt_dim, p_rt_dim] = corr(RT',dimensionality_change, 'type', 'Spearman');
- %% correlate RT across time
- data_to_correlate = squeeze(correct_incorrect{1}.individual);
- RT = RT_correct;
- fs = 1/(correct_incorrect{1, 1}.time(2)-correct_incorrect{1, 1}.time(1));
- chunk_size = round(100/((1/fs)*1000)); % Size of each chunk
- overlap_size = round(chunk_size * settings.prc_overlap);
- num_chunks = floor((size(correct_incorrect{1}.individual, 3) - overlap_size) / (chunk_size - overlap_size));
- TOI_corr = linspace(correct_incorrect{1, 1}.time(1), correct_incorrect{1, 1}.time(end),num_chunks);
- rho_across_time = [];
- p_across_time = [];
- for itime = 1:num_chunks
- start_idx = (itime - 1) * (chunk_size - overlap_size) + 1;
- end_idx = start_idx + chunk_size - 1;
- [rho_tmp, p_tmp] = corr(mean(data_to_correlate(:,start_idx:end_idx),2), RT','type', 'spearman');
- rho_across_time(itime) = rho_tmp;
- p_across_time(itime) = p_tmp;
- end
- rho_across_time_perm = [];
- p_across_time_perm = [];
- for nu_perm = 1:500
- rand_rt = randperm(12);
- for itime = 1:num_chunks
- start_idx = (itime - 1) * (chunk_size - overlap_size) + 1;
- end_idx = start_idx + chunk_size - 1;
- [rho_tmp, p_tmp] = corr(mean(data_to_correlate(rand_rt,start_idx:end_idx),2), RT','type', 'spearman');
- rho_across_time_perm(nu_perm,itime) = rho_tmp;
- p_across_time_perm(nu_perm,itime) = p_tmp;
- end
- end
- xlimits_ind = nearest(TOI_corr, -1):nearest(TOI_corr, 1);
- alpha = 0.05;
- z_threshold = norminv(1 - alpha/2);
- zvalue_rho = (rho_across_time(xlimits_ind)-(mean(rho_across_time_perm(:,xlimits_ind))))./std(rho_across_time_perm(:,xlimits_ind));
- xlimits = TOI_corr(xlimits_ind);
- plot(xlimits, zvalue_rho,'linewidth', 3)
- hold on
- plot(xlimits, z_threshold * ones(size(xlimits)), 'r--'); % positive threshold
- plot(xlimits, -z_threshold * ones(size(xlimits)), 'r--'); % negative threshold
- below_threshold = zvalue_rho < -z_threshold;
- scatter(xlimits(below_threshold), zvalue_rho(below_threshold), 'r', 'filled', 'MarkerFaceAlpha', 0.5)
- ylim([-3 3])
- xlim([-1 1])
- set(gca,'FontSize',16)
- set(gca,'TickDir','out')
- hold off
- xlabel('Ripple time (sec)')
- ylabel('Z-transformed correlation')
- title('Z-value of correlation Across Time')
- legend('Z-value', 'Positive Threshold', 'Negative Threshold', 'Location', 'NorthEast')
- %% plot t line
- figure
- plot(Fieldtripstats.time,Fieldtripstats.stat,'k','linewidth',2)
- hold on
- sigline05 = nan(1,numel(Fieldtripstats.prob));
- sigline01 = nan(1,numel(Fieldtripstats.prob));
- p05 = Fieldtripstats.prob < .05;
- p01 = Fieldtripstats.prob < .01;
- sigline05(p05) = Fieldtripstats.stat(p05);
- sigline01(p01) = Fieldtripstats.stat(p01);
- plot(Fieldtripstats.time,sigline05,'r','linewidth',5)
- plot(Fieldtripstats.time,sigline01,'y','linewidth',2)
- vline(0)
- hline(0)
- set(gca,'FontSize',8)
- xlabel('time (sec)')
- set(gca,'TickDir','out')
- title('dimensionality');
- xlim([cfg.latency(1), cfg.latency(end)])
- %% correlate fine-grained decoding with dimensionality
- % FT stats (dimensionality)
- xlimits = nearest(correct_incorrect{1, 1}.time, -1):nearest(correct_incorrect{1, 1}.time, 1);
- xlimits = correct_incorrect{1, 1}.time(xlimits);
- cfg = [];
- cfg.latency = [xlimits(1) xlimits(end)];
- cfg.channel = 'all';
- cfg.statistic = 'depsamplesT';
- cfg.method = 'montecarlo'; % 'montecarlo' 'analytic';
- cfg.correctm = 'cluster'; % 'no', cluster;
- cfg.alpha = .05;
- cfg.clusteralpha = .05;
- cfg.tail = 0;
- cfg.correcttail = 'alpha'; % alpha prob no
- cfg.neighbours = [];
- cfg.minnbchan = 0;
- cfg.avgovertime = 'no'; % 'no' 'yes'
- cfg.avgoverchan = 'no';
- cfg.computecritval = 'yes';
- cfg.numrandomization = 500;%'all';
- cfg.clusterstatistic = 'maxsum'; % 'maxsum', 'maxsize', 'wcm'
- cfg.clustertail = cfg.tail;
- cfg.parameter = 'individual';
- nSub = size(correct_incorrect{1, 1}.individual ,1);
- % set up design matrix
- design = zeros(2,2*nSub);
- for i = 1:nSub
- design(1,i) = i;
- end
- for i = 1:nSub
- design(1,nSub+i) = i;
- end
- design(2,1:nSub) = 1;
- design(2,nSub+1:2*nSub) = 2;
- cfg.design = design;
- cfg.uvar = 1;
- cfg.ivar = 2;
- % run stats
- [Fieldtripstats] = ft_timelockstatistics(cfg, correct_incorrect{:});
- length(find(Fieldtripstats.mask))
- %% plot significant vals
- d = squeeze(correct_incorrect{1}.individual-correct_incorrect{2}.individual);
- m = nanmean(d);
- s = nanstd(d)./sqrt(size(d,1));
- figure;
- boundedline(perf{1,1}.time_train,m,s,'k');
- plot(perf{1,1}.time_train,m,'k','linewidth',2);
- hold on
- stats_time = nearest(correct_incorrect{1}.time,cfg.latency(1)):nearest(correct_incorrect{1}.time,cfg.latency(2));
- sigline = nan(1,numel(correct_incorrect{1}.time));
- % sigline(stats_time(Fieldtripstats.mask==1)) = m(stats_time(Fieldtripstats.mask==1));
- sigline(stats_time(Fieldtripstats.mask==1)) = 0;
- plot(correct_incorrect{1}.time,sigline,'r','linewidth',4);
- set(gca,'FontSize',16,'FontName','Arial')
- xlabel('ripple time (s)')
- ylabel('dimensionality difference')
- set(gca,'TickDir','out')
- axis tight
- vline(0)
- hline(0)
- xlim([cfg.latency(1), cfg.latency(end)])
- % load original data
- load('mask_t_vals_fine_enc_ripple.mat')
- mask_t_vals_fine = squeeze(mask_t_vals_fine_enc_ripple);
- % Load data from decoding analysis
- load('correct_dec_fine_all.mat')
- load('incorrect_dec_fine_all.mat')
- correct_dec_all = correct_dec_fine_all;
- incorrect_dec_all = incorrect_dec_fine_all;
- time_dec = linspace(-.5,3,351);
- idx_time = nearest(time_dec,-.2):nearest(time_dec,3);
- correct_dec_all = correct_dec_all(:,idx_time,:);
- incorrect_dec_all = incorrect_dec_all(:,idx_time,:);
- for isubject = 1:size(settings.subjects,1)
- tmp_sub = [];
- tmp_sub = squeeze(correct_dec_all(isubject, :,:));
- tmp_sub(~mask_t_vals_fine) = NaN;
- correct_dec_all(isubject, :,:) = tmp_sub;
- tmp_sub = [];
- tmp_sub = squeeze(incorrect_dec_all(isubject, :,:));
- tmp_sub(~mask_t_vals_fine) = NaN;
- incorrect_dec_all(isubject, :,:) = tmp_sub;
- end
- correct_dec_mean = nanmean(nanmean(correct_dec_all,3),2);
- incorrect_dec_mean = nanmean(nanmean(incorrect_dec_all,3),2);
- dimensionality_change = mean(d(:,sigline==0),2);
- [r, p] = corr(dimensionality_change,correct_dec_mean-incorrect_dec_mean,'tail','right');
- % Number of data points
- n = numel(dimensionality_change);
- % Convert r to Fisher's z-score
- z = atanh(r);
- effect_size = z * sqrt(n - 3);
- disp(['Effect size (Cohen''s d): ' num2str(effect_size)]);
- %% visualise included channels
- % elec_size = 15;
- % transp = 0.25;
- % extracolor = .5;
- %
- % epos_all = [];
- %
- % for isubject = 1:numel(subjects)
- % epos_all = [epos_all;cell2mat({channs{isubject}.coords}')];
- % end
- %
- % colvec = ones(1,size(epos_all,1));
- %
- % views = [-90 0;0 0;180 -90];
- %
- % for iview=1:size(views,1)
- % figure
- % plot_ecog(colvec, ...
- % fullfile(ftpath,'template/anatomy/'),...
- % epos_all,[-max(colvec) max(colvec)+extracolor], transp, views(iview,:), elec_size);
- % colorbar off
- % end
- %%
ripple_stage_04a_dimensionality_final.m at commit 1d7307a, no license · at the source
Overview
- Max Planck Institute for Human Cognitive and Brain Sciences,Leipzig, Germany
- Department of Psychology, New York University,New York, NY USA
- Kavli Institute for Systems Neuroscience, Centre for Neural Computation, Egil and Pauline Braathen and Fred Kavli Centre for Cortical Microcircuits, Jebsen Centre for Alzheimer’s Disease, NTNU Norwegian University of Science and Technology,Trondheim, Norway
Abstract
How are past experiences reconstructed from memory? Learning is thought to compress external inputs into low-dimensional hippocampal representations, later expanded into high-dimensional cortical activity during recall. Hippocampal ripples, brief high-frequency bursts linked to retrieval, may initiate this expansion. Analysing intracranial EEG data from patients with pharmacoresistant epilepsy during an episodic memory task, we found that cortical dimensionality increased following ripple events during correct, but not incorrect, retrieval. This expansion correlated with faster reaction times and reinstatement of the target association. Crucially, hippocampal theta and cortical gamma phase-amplitude coupling emerged after ripples but before cortical expansion, suggesting a mechanism for ripple-driven communication. Ripple events also marked the separation of task-relevant variables in cortical state space, revealing how hippocampal output reshapes the geometry of memory representations to support successful recall.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 6 matches between paragraphs and lines of code.
kerrencasper/Hippocampal-ripples-initiate-cortical-dimensionality-expansion-for-memory-retrieval
1d7307a6037aa27e50b7b489b04f79bb0aa77aa9, 16 April 2025Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
19 files
- control_analyses.m, MATLAB, 850 lines
- ripple_PLOT_ALL.m, MATLAB, 19 lines
- ripple_plotting.m, MATLAB, 1,651 lines
- ripple_stage_01a_remove_
bad_chans_beyond_hipp_fi , MATLAB, 141 linesnal.m - ripple_stage_01b_reref_c
mntrim_final.m , MATLAB, 51 lines - ripple_stage_01c_autoart
_final.m , MATLAB, 250 lines - ripple_stage_02a_ripple_
detection_TFR_plot_final , MATLAB, 605 lines.m - ripple_stage_02a_ripple_
detection_final.m , MATLAB, 371 lines - ripple_stage_02b_realign
_trials_ret_final.m , MATLAB, 402 lines - ripple_stage_02b_ripple_
detection_RT_final.m , MATLAB, 406 lines - ripple_stage_03a_decodin
g_final.m , MATLAB, 939 lines - ripple_stage_04a_dimensi
onality_final.m , MATLAB, 1,223 lines, 2 matches - ripple_stage_04a_dimensi
onality_shuffled_final.m , MATLAB, 1,372 lines, 1 match - ripple_stage_04c_dimensi
onality_LME_final.m , MATLAB, 973 lines, 1 match - ripple_stage_05a_PAC_fin
al.m , MATLAB, 1,134 lines, 1 match - ripple_stage_05a_dPCA_fi
nal.m , MATLAB, 587 lines - ripple_stage_05b_PAC_acr
oss_time_final.m , MATLAB, 1,243 lines - ripple_stage_05b_PAC_acr
oss_time_shuffled_final. , MATLAB, 1,278 lines, 1 matchm - README.md, Text, 4 lines
Code availability
The code that supports the conclusions of this study is available at GitHub (https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 18 scripts, each with its path and the digest of its content;
- 6 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- zenodo:18490239, at Zenodo; found in “Data availability”
Data availability
The data that support the conclusions of this study are available at Zenodo (10.5281/
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 2, 28 September 2026
- Funding: added Deutsche Forschungsgemeinschaft: 437219953; Max-Planck-Gesellschaft
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 3 authors, 2 keywords, 10 MeSH terms, 101 references.
Cite
This paper
Kerrén, C., Michelmann, S., & Doeller, C. F. (2026). Hippocampal ripples initiate cortical dimensionality expansion for memory retrieval. Nature communications, 17(1), 6677. https://
BibTeX
@article{kerren2026hippo
author = {Kerrén, Casper and Michelmann, Sebastian and Doeller, Christian F.},
title = {{Hippocampal ripples initiate cortical dimensionality expansion for memory retrieval}},
journal = {Nature communications},
year = {2026},
month = jul,
volume = {17},
number = {1},
pages = {6677},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/
url = {https://
pmid = {42476972},
pmcid = {PMC13385388}
}
RIS
TY - JOUR
AU - Kerrén, Casper
AU - Michelmann, Sebastian
AU - Doeller, Christian F.
TI - Hippocampal ripples initiate cortical dimensionality expansion for memory retrieval
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/
VL - 17
IS - 1
SP - 6677
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "Hippocampal ripples initiate cortical dimensionality expansion for memory retrieval",
"container-title": "Nature communications",
"author": [
{
"family": "Kerrén",
"given": "Casper"
},
{
"family": "Michelmann",
"given": "Sebastian"
},
{
"family": "Doeller",
"given": "Christian F."
}
],
"container-title-short":
"volume": "17",
"issue": "1",
"page": "6677",
"DOI": "10.1038/
"PMID": "42476972",
"PMCID": "PMC13385388",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
20
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.7554/elife.100642 [code]
- Disrupted hippocampal theta-gamma coupling and spike-field coherence following experimental traumatic brain injury.Journal: eLifeIn common: Parallel Computing Toolbox, Image Processing Toolbox, Signal Processing Toolbox, 11 references
- [2] doi:10.1038/s41593-026-02345-6 [code]
- Human hippocampal ripples tune cortical responses based on predicted uncertainty.Journal: Nature neuroscienceIn common: boundedline, FieldTrip, Image Processing Toolbox, 2 other tools, cognitive, 9 references
- [3] doi:10.1093/braincomms/fcag041
- Exercise enhances hippocampal-cortical ripple interactions in the human brain.Journal: Brain communicationsIn common: 13 references
- [4] doi:10.7554/elife.110795 [code]
- REM sleep prefrontal high-frequency oscillation chains mediate distinct cortical - hippocampal reactivation patterns compared to NREM sleep.Journal: eLifeIn common: boundedline, FieldTrip, Image Processing Toolbox, 2 other tools, 8 references
- [5] doi:10.1038/s41467-026-70633-7 [code]
- Global coincident bursts of high frequency oscillations across the human cortex coordinate large-scale memory processing.Journal: Nature communicationsIn common: epilepsy, cognitive, 10 references
- [6] doi:10.1162/imag.a.1218 [code]
- Reliability and signal comparison of OPM-MEG, fMRI &
amp; iEEG in a repeated movie viewing paradigm. Journal: Imaging neuroscience (Cambridge, Mass.)In common: FieldTrip, Image Processing Toolbox, Statistics and Machine Learning Toolbox, 5 references, author Sebastian Michelmann - [7] doi:10.1016/j.celrep.2026.117845 [code]
- Hippocampal skill memory expansion drives online performance dynamics during skill learning.Journal: Cell reportsIn common: Image Processing Toolbox, cognitive, 9 references
- [8] doi:10.7554/elife.108023 [code]
- Challenges in replay detection by TDLM in post-encoding resting state.Journal: eLifeIn common: Statistics and Machine Learning Toolbox, 9 references
- [9] doi:10.1038/s42003-025-08618-3 [code]
- Physical activity simultaneously improves working memory and ripple-spindle couplingJournal: n/aIn common: Statistics and Machine Learning Toolbox, EEG, cognitive, 8 references
- [10] doi:10.1016/j.celrep.2026.117646 [code]
- Medial entorhinal-hippocampal desynchronization parallels the emergence of memory impairment in a mouse model of Alzheimer's disease pathology.Journal: Cell reportsIn common: boundedline, FieldTrip, Parallel Computing Toolbox, 3 other tools, 3 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 18 scripts, and 6 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:309c4f445d160964…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
