ImaGIN_RescaleTF.m
2.38 KB
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
function D = ImaGIN_RescaleTF(S)
% Time-rescale several TF files to normalise the length of events (e.g. seizures) before averaging
% -=============================================================================
% This function is part of the ImaGIN software:
% https://f-tract.eu/
%
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE AUTHORS
% DO NOT ASSUME ANY LIABILITY OR RESPONSIBILITY FOR ITS USE IN ANY CONTEXT.
%
% Copyright (c) 2000-2018 Inserm U1216
% =============================================================================-
%
% Authors: Olivier David, 2008
[Finter,Fgraph,CmdLine] = spm('FnUIsetup','EEG time-frequency rescale',0);
%files to rescale
try
DD = S.D;
catch
DD = spm_select(inf, '\.mat$', 'Select TF EEG mat file(s) to rescale');
end
try
clear tmp
for i1=1:size(DD,1)
tmp{i1} = spm_eeg_load(deblank(DD(i1,:)));
Dname{i1}=DD(i1,:);
end
DD=tmp;
catch
error(sprintf('Trouble reading file %s', DD));
end
%start and end of events
try
S.Event;
catch
for i2=1:length(DD)
spm_input(sprintf('Onset/End for file %d',i2),1,'d');
S.Event(i2,1) = spm_input('Onset [s]', '+1', 'r', '', 1);
S.Event(i2,2) = spm_input('End [s]', '+1', 'r', '', 1);
end
end
try
S.Time
catch
S.Time(1) = spm_input('Time onset (<0)', 1, 'r', '-0.2', 1);
S.Time(2) = spm_input('Time end (>1)', '+1', 'r', '1.2', 1);
S.Time(3) = spm_input('Time resolution (<1)', '+1', 'r', '0.001', 1);
end
TimeTemplate = S.Time(1):S.Time(3):S.Time(2);
for i2=1:length(DD)
D=DD{i2};
Time=D.tf.time-S.Event(i2,1);
Time=Time/(S.Event(i2,2)-S.Event(i2,1));
%Resample
data=zeros(D.nchannels,D.Nfrequencies,length(TimeTemplate));
Dnew=clone(D, ['t' spm_str_manip(fnamedat(D),'t')], [D.nchannels D.Nfrequencies length(TimeTemplate) D.ntrials]);
for i3=1:D.nchannels
for i4=1:D.Nfrequencies
data(i3,i4,:)=interp1(Time,squeeze(D(i3,i4,:)),TimeTemplate);
end
end
Dnew(:,:,:)=data;
Dnew.tf.Label=['Rescaled ' lower(D.tf.Label)];
Dnew.tf.time=TimeTemplate;
Dnew=fsample(Dnew,1/(Dnew.tf.time(2)-Dnew.tf.time(1)));
save(Dnew);
end