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 pathaddSlidingWindows.m
104 lines (87 loc) · 4.51 KB
/
addSlidingWindows.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
function [config, MuseStruct] = addSlidingWindows(config, MuseStruct)
% [config, MuseStruct] = addSlidingWindows(config, MuseStruct)
% Add a "window" field to the config and MuseStruct, allowing sliding
% time-window analyses for both LFP, TFR, FFT and spike data.
%
% ### Necessary input:
% cfg.prefix = prefix to output files
% cfg.datasavedir = data directory of results
% MuseStruct = info (e.g. events, files) of original data,
% used to segment the spikes into trials
%
% config.window.length = 60 (seconds)
% config.window.overlap = 0.5 (fraction)
%
% 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/>.
% get the default cfg options
config.window = ft_getopt(config, 'window', []);
config.window.name = ft_getopt(config.window, 'name', {'window'});
config.window.length = ft_getopt(config.window, 'length', []);
config.window.overlap = ft_getopt(config.window, 'overlap', []);
for markername = string(config.window.name)
% window is symmetrical around 0
length = config.window.length.(markername);
start_name = sprintf('%s__START__', markername);
end_name = sprintf('%s__END__', markername);
for ipart = 1 : size(config.directorylist, 2)
for idir = 1 : size(config.directorylist{ipart}, 2)
ft_info('Adding %s in part %d, dir %d\n', markername, ipart, idir)
temp = dir(fullfile(config.rawdir, config.directorylist{ipart}{idir}, ['*', config.circus.channel{1}, '.ncs']));
hdr = ft_read_header(fullfile(config.rawdir, config.directorylist{ipart}{idir}, temp.name));
MuseStruct{ipart}{idir}.markers.(start_name).synctime = 0 : (length - length * config.window.overlap.(markername)) : (hdr.nSamples / hdr.Fs - length / 2);
MuseStruct{ipart}{idir}.markers.(start_name).clock = seconds(MuseStruct{ipart}{idir}.markers.(start_name).synctime) + MuseStruct{ipart}{idir}.starttime;
MuseStruct{ipart}{idir}.markers.(start_name).events = size(MuseStruct{ipart}{idir}.markers.(start_name).synctime, 2);
MuseStruct{ipart}{idir}.markers.(end_name).synctime = MuseStruct{ipart}{idir}.markers.(start_name).synctime + length;
MuseStruct{ipart}{idir}.markers.(end_name).clock = MuseStruct{ipart}{idir}.markers.(start_name).clock + seconds(length);
MuseStruct{ipart}{idir}.markers.(end_name).events = size(MuseStruct{ipart}{idir}.markers.(end_name).synctime, 2);
end
end
config.muse.startmarker.(markername) = start_name;
config.muse.endmarker.(markername) = end_name;
config.epoch.toi.(markername) = [0 config.window.length.(markername)];
config.epoch.pad.(markername) = 0;
% add window configuration to settings
if isfield(config, 'LFP')
if isfield(config.LFP, 'name')
config.LFP.toi.(markername) = [0 0];
config.LFP.pad.(markername) = 0;
config.epoch.toi.(markername) = [0 0];
config.epoch.pad.(markername) = 0;
end
end
if isfield(config, 'FFT')
if isfield(config.FFT, 'name')
config.FFT.toi.(markername) = [0 0];
config.FFT.pad.(markername) = 0;
end
end
if isfield(config, 'TFR')
if isfield(config.TFR, 'name')
config.TFR.toi.(markername) = [0 0];
config.TFR.pad.(markername) = 0;
end
end
if isfield(config, 'spike')
if isfield(config.spike, 'name')
config.spike.toi.(markername) = [0 0];
config.spike.pad.(markername) = 0;
end
end
end
if isempty(markername)
warning('No sliding window was added');
end