-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththetapeak_localizer.m
77 lines (65 loc) · 2.31 KB
/
thetapeak_localizer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
%% THETA PEAK LOCALIZER
%addpath 'C:\Users\Hilde Althof\OneDrive\Universiteiten\Radboud Universiteit\BabyBRAIN Lab (BRC)\fieldtrip-20230118'
addpath 'C:\Users\luuks\OneDrive\Documents\BCRC\Fieldtrip Toolbox\fieldtrip-20221004'
clc
close all
clearvars
ft_defaults
% Introduce subject number
subject = 39;
% Read data and cut trials
cd(sprintf('//cnas.ru.nl//wrkgrp//STD-Donders-DCC-Hunnius-ReadyToLearnEEG//Ready_to_learn_Children_Study//Data//Raw data//Neural//sub-39',subject));
%up to participant 8, this should be changed to 'S 80'.
%participant >= 36 should also be 'S 80' again
eventval = {'S 80'};
cfg = [];
cfg.trialfun = 'ft_trialfun_general';
cfg.trialdef.eventtype = 'Stimulus'; % for participant <= 8 and >= 36 , this should be changed to 'Stimulus'
cfg.trialdef.eventvalue = eventval;
cfg.trialdef.prestim = -0.5;
cfg.trialdef.poststim = 2.5;
cfg.dataset = sprintf('subject%02d.eeg',subject);
cfg = ft_definetrial(cfg);
data_trials=ft_preprocessing(cfg);
cfg=[];
%cfg.channel = {'4','3','6','7','28','29','30','31','2','10','21'}; %for participants with workspace 'error'
channels_selection =ft_selectdata (cfg,data_trials);
% Quick artefact rejection
if ~exist(fullfile(sprintf('dataclean_s%02d.mat',subject)))
cfg=[];
cfg.method='summary';
dataclean=ft_rejectvisual(cfg,channels_selection);
dataclean.goodchannels=dataclean.label(find(~isnan(dataclean.trial{1,1}(:,1))));
save(sprintf('dataclean_s%02d.mat',subject),'dataclean');
else
load (fullfile(sprintf('dataclean_s%02d.mat',subject)));
end
% Re-reference
cfg = [];
cfg.derivative = 'yes'; %'Turn it on if peak is not clear without it'
cfg.reref = 'yes';
cfg.implicitref = 'FCz';
cfg.refchannel = {'TP9', 'TP10'};
data_rereference = ft_preprocessing(cfg, dataclean);
% Power anaylsis
cfg = [];
cfg.method = 'mtmfft';
cfg.output = 'pow';
cfg.foilim = [2 15];
cfg.taper = 'hanning';
freq_outcome = ft_freqanalysis(cfg, data_rereference);
cfg=[];
cfg.avgoverchan = 'yes';
cfg.nanmean ='yes';
TFR_averag_channels = ft_selectdata(cfg, freq_outcome);
% Quick plot
plot(TFR_averag_channels.freq,TFR_averag_channels.powspctrm);
%%
% Possibilities and correspoding freq code
% 6Hz - 20
% 5.5Hz - 22
% 5Hz - 24
% 4.5Hz - 27
% 4Hz - 30
% 3.5Hz - 34
% 3Hz - 40