This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdoTFRcontinuous.m
105 lines (82 loc) · 4.21 KB
/
doTFRcontinuous.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function [TFR] = doTFRcontinuous(cfg,MuseStruct,force)
% This file is part of EpiCode, see
% http://www.github.com/stephenwhitmarsh/EpiCode for documentation and details.
%
% EpiCode is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% EpiCode is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with EpiCode. If not, see <http://www.gnu.org/licenses/>.
fname_out = fullfile(cfg.datasavedir,[cfg.prefix,'TFR.mat']);
if exist(fname_out,'file') && force == false
fprintf('************************************\n');
fprintf('*** Loading precomputed TFR data ***\n');
fprintf('************************************\n\n');
load(fname_out,'TFR');
else
fprintf('********************************\n');
fprintf('*** (re-) computing TFR data ***\n');
fprintf('********************************\n\n');
for ipart = 1 : size(MuseStruct,2)
% just define MuseStruct_macro here for only one part to simplify code
% and similarity with no-parts
fprintf('\n*** Working on part %d ***\n',ipart)
% process channels separately
chan_counter = 1;
clear chandat
for ichan = 1 : size(cfg.TFR.channel,2)
clear dirdat
% loop over all directories (time), concatinating channel
for idir = 1 : size(MuseStruct{ipart},2)
% find corresponding file
d = dir2(fullfile(cfg.rawdir,cfg.directorylist{ipart}{idir},['*',cfg.TFR.channel{ichan},'*.ncs']));
% load data
cfgtemp = [];
cfgtemp.dataset = fullfile(d.folder,d.name);
fprintf('LOADING: %s\n',cfgtemp.dataset);
clear fname
fname{1} = cfgtemp.dataset;
dirdat{idir} = ft_read_neuralynx_interp(fname);
% downsample data
cfgtemp = [];
cfgtemp.resamplefs = 100;
dirdat{idir} = ft_resampledata(cfgtemp,dirdat{idir});
% truncate label to make them equal over files
dirdat{idir}.label{1} = dirdat{idir}.label{1}(end-6:end); % can be replaced by circus.channel
% save sampleinfo
hdr = ft_read_header(fullfile(d.folder,d.name));
cfg.sampleinfo_TFR{ipart}{ichan}(idir,:) = [1 hdr.nSamples];
end % idir
% concatinate data over files
chandat{chan_counter} = dirdat{1};
for idir = 2 : length(MuseStruct{ipart})
fprintf('Concatinating directory %d, channel %d\n',idir, ichan);
chandat{chan_counter}.trial{1} = [chandat{chan_counter}.trial{1} dirdat{idir}.trial{1}];
chandat{chan_counter}.time{1} = [chandat{chan_counter}.time{1} (dirdat{idir}.time{1} + chandat{chan_counter}.time{1}(end))];
end
chan_counter = chan_counter + 1;
end % ichan
dat{ipart} = ft_appenddata([],chandat{:});
% TFR
% time frequency analysis
cfgtemp = [];
cfgtemp.channel = 'all'; %ichannel;
cfgtemp.method = 'mtmconvol';
cfgtemp.output = 'pow';
cfgtemp.taper = 'hanning';
cfgtemp.pad = 'nextpow2';
cfgtemp.keeptrials = 'yes';
cfgtemp.foi = 1:1:30;
cfgtemp.t_ftimwin = ones(size(cfgtemp.foi))*60;
cfgtemp.toi = 0:30:dat{ipart}.time{1}(end);
TFR{ipart} = ft_freqanalysis(cfgtemp,dat{ipart});
end % ipart
save(fname_out,'TFR','-v7.3');
end % if file already exists