-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcameg_datapre_readdata_ave.m
143 lines (124 loc) · 3.46 KB
/
cameg_datapre_readdata_ave.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
function cameg_datapre_readdata_ave()
% ___________________________________________________________________________
% 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]
% ___________________________________________________________________________
disp('Reading source data ...')
mt = 2;
if nargin == 0
files = spm_select(1,'.mat','Select source MEG files');
end
load(files);
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
Value = Value(1:L,:);
h1 = figure,
hl = plot(Time, Value(1:L,:));
xlabel('Time(s)');
ylabel('Amplitude(AU)');
title('source activities');
for i = 1:L, lab{i} = num2str(i); end
clickableLegend(hl,lab, 'plotOptions', {'MarkerSize', 6});
set(gcf, 'Position', [800 100 1200 800]);
B = num2cell(1:L);
ROI = (cell2table([B;roi;roi_l]'))
%% 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 = mValue(:,:,f1:f2);
% Time = Time(:,f1:f2);
sValue = Value(:,f1:f2);
Time = Time(:,f1:f2);
clf,
hl = plot(Time, sValue);
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 = Value;
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)
x = ssValue(i,:);
pxx(i,:) = pwelch(x',[],[],fs);
end
mpxx = pxx;
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
disp('Data was imported!')