-
Notifications
You must be signed in to change notification settings - Fork 0
/
cameg_datapre_readdata_gs.m
160 lines (140 loc) · 4 KB
/
cameg_datapre_readdata_gs.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
function cameg_datapre_readdata_gs()
% ___________________________________________________________________________
% Connectivity analysis of MEG data (CA-MEG)
%
% Copyright 2016 Cincinnati Children's Hospital Medical Center
% Reference
%
%
% v1.0 Vahab Youssofzadeh 21/07/2016
% email: [email protected]
% ___________________________________________________________________________
path = spm_select(Inf,'dir','Select folder');
datatype = '*_Mindall.mat';
files = sinead_findfiles (path,datatype);
for j = 1:size(files,2)
path2 = files{1,j}(1:end-12);
f = dir([path2,datatype]);
load ([path2,f.name]);
aValue(:,:,j) = Value(:,:);
end
mt = 3;
fs = input('Enter sampling frequency e.g. 1200 [Hz]: ');
L = length(Atlas.Scouts);
for i = 1:L
roi{i}= Atlas.Scouts(i).Region;
roi_l{i}= Atlas.Scouts(i).Label;
end
ntrl = size(Value,1)./L;
display(['nTrial: ', num2str(ntrl)])
display(['ROIs: ', num2str(L)])
mValue = reshape(squeeze(mean(aValue,3)),[ntrl,size(Value,1)/ntrl,size(Value,2)]);
maValue = squeeze(mean(mValue,1));
%%
h1 = figure,
hl = plot(Time, maValue);
xlabel('Time(s)');
ylabel('Amplitude(AU)');
title('Ave of source activities');
for i = 1:L, lab{i} = num2str(i); end
clickableLegend(hl,lab, 'plotOptions', {'MarkerSize', 6});
box off
set(gca,'color','none');
set(gcf, 'Position', [800 100 1200 800]);
B = num2cell(1:L);
ROI = (cell2table([B;roi;roi_l]'))
% pause
%% Segmenting data
in1 = input('Segment data (yes = 1)?');
if in1 ==1
seg = input('Set time intervals e.g., [300,700] ms: ');
f1 = knnsearch(Time',seg(1)/1e3);
f2 = knnsearch(Time',seg(2)/1e3);
sValue = aValue(:,f1:f2,:);
Time = Time(:,f1:f2);
saValue = squeeze(mean(sValue,3));
saaValue = reshape(saValue,[ntrl,size(sValue,1)/ntrl,size(sValue,2)]);
saaaValue = squeeze(mean(saaValue,1));
for i = 1:
clf,
hl = plot(Time, saaaValue);
xlabel('Time(s)');
ylabel('Amplitude(AU)');
title('source activities (selected)');
clickableLegend(hl,lab, 'plotOptions', {'MarkerSize', 6});
box off
set(gca,'color','none');
set(gcf, 'Position', [800 100 1200 800]);
else
sValue = aValue;
end
%% informed by CT
in2 = input('informing by CT (yes = 1)?');
if in2 ==1
load([pwd,'\saved outputs\cameg_CT_all.mat']);
sROI = ROI(idxp,:);
id = table([1:length(idxp)]','VariableNames',{'id'});
C = [id,sROI]
ssValue = sValue(:,idxp,:);
ssaValue = squeeze(mean(ssValue,1));
clf,
hl = plot(Time, ssaValue);
xlabel('Time(s)');
ylabel('Amplitude(AU)');
title('source activities (selected)');
clickableLegend(hl,lab, 'plotOptions', {'MarkerSize', 6});
box off
set(gca,'color','none');
set(gcf, 'Position', [800 100 1200 800]);
else
ssValue = sValue;
sROI = ROI;
idxp = 1:L;
end
%% Spectral analysis
in3 = input('informing by PSD (yes = 1)?');
for i = 1:size(ssValue,1)
for j = 1:size(ssValue,2)
x = squeeze(ssValue(i,j,:));
pxx(i,j,:) = pwelch(x',[],[],fs);
end
end
mpxx = squeeze(mean(pxx,1));
if in3 == 1
h2 = figure;
plot(10*log10(mpxx(:,2:29)'));
title('PSD');
mmpxx = squeeze(mean(mpxx(:,2:29),2));
h3 = figure;
barh(mmpxx),
for j = 1:L, lab{j} = num2str(j); end
set(gca,'color','none');
title('PSD ');
set(gca,'ytick', 1:L,'ytickLabel',num2cell(1:L));
box off
set(gcf, 'Position', [900 200 700 900]);
%%
nroi = input('number of ROIs (e.g., 5)?');
[~, idxp] = sort(mmpxx, 'descend');
ssValue_roi = ssValue(:,idxp(1:nroi),:);
ssROI = sROI(idxp(1:nroi),:);
idxp = idxp(1:nroi);
else
ssValue_roi = ssValue;
ssROI = sROI;
idxp = 1:L;
nroi = L;
end
%%
save([pwd,'\saved outputs\cameg_datafile.mat'], 'files', 'Atlas', 'fs', 'ssValue','ssValue_roi', 'Time', 'idxp','sROI','ssROI', 'mt','mpxx','nroi');
disp('Data was imported!')
% pause(4),
in4 = input('close the openned figures (yes = 1)?');
if in4 == 1
delete(h1)
if in3 == 1
delete(h2)
delete(h3)
end
end
end