-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.m
executable file
·84 lines (73 loc) · 3.08 KB
/
Main.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
%% Load and project Lead Field
restoredefaultpath;
clc;
clear all;
close all;
tic
addpath('common_functions');
addpath(genpath('D:\Toolsboxs\brainstorm3'));
preproced_data_file = 'E:\Data\Conectome\175237\meg\175237\MEG\Restin\rmegpreproc\175237_MEG_5-Restin_rmegpreproc.mat';
preproced_data = load(preproced_data_file);
protocol_path = 'C:\Users\Ariosky\.brainstorm\local_db\BigBrain_Template';
leadfield_MEG_file = fullfile(protocol_path,'data','ICBM152_MEG','175237_MEG_5-Restin_rmegpreproc','headmodel_surf_os_meg.mat');
leadfield_MEG = load(leadfield_MEG_file);
MEG_channel_file = fullfile(protocol_path,'data','ICBM152_MEG','175237_MEG_5-Restin_rmegpreproc','channel_acc1.mat');
MEG_channel = load(MEG_channel_file);
disp('-->> Creating channel');
%[L_MEG3D,MEG_channel] = remove_leadfield_channel(MEG_channel,leadfield_MEG,preproced_data);
%GridOrient = leadfield_MEG.GridOrient;
%GridAtlas = leadfield_MEG.GridAtlas;
% L_MEG = bst_gain_orient(L_MEG3D, GridOrient, GridAtlas);
%L_MEG = L_MEG3D;
L_MEG3D = leadfield_MEG.Gain;
clearvars leadfield_MEG
surface_file = fullfile(protocol_path,'anat','ICBM152_MEG','tess_cortex_pial_8000V.mat');
surface = load(surface_file);
%% Data spectral analysis
disp('-->> Loading MEG trials in single file');
Ntpoints = size(preproced_data.data.trial{1,1},2);
Nsegments = length(preproced_data.data.trial);
Data_FC = zeros(size(L_MEG3D,1),Ntpoints,Nsegments);
Fs = preproced_data.data.fsample;
deltaf = Fs/Ntpoints;
F = 0:deltaf:(Ntpoints*deltaf);
F1 = 8;
F2 = 12;
[val,idf1] = min(abs(F-F1));
[val,idf2] = min(abs(F-F2));
Svv = 0;
for count3 = 1:Nsegments
disp(strcat('-->> loading and filtering segments: ', num2str(count3)));
tmp = preproced_data.data.trial{1,count3};
tmp_FC = fft(tmp,[],2);
Data_FC(:,:,count3) = tmp_FC;
Svv = Svv + tmp_FC(:,idf1:idf2)*tmp_FC(:,idf1:idf2)';
end
Nsamples = Nsegments*(idf2-idf1);
Svv = Svv/Nsamples;
%% Inverse solution filter
nonovgroups = [];
counter = 1;
for ii = 1:3:length(L_MEG3D)
nonovgroups{counter} = [ii;ii+1;ii+2];
counter = counter + 1;
end
[miu,sigma_post] = cross_nonovgrouped_enet_ssbl({Svv},{L_MEG3D},Nsamples,nonovgroups);
miu_stat = sqrt(sum(reshape(miu,3,length(L_MEG3D)/3),1))';
sigma_post_stat = sqrt(sum(reshape(sigma_post,3,length(L_MEG3D)/3),1))';
stat = abs(miu_stat)./abs(sigma_post_stat);
indms = find(stat > 1);
J = zeros(length(L_MEG3D)/3,1);
J(indms) = stat(indms); J = J/max(abs(J));
%%
figure;
title('BigBrain Template');
patch('Faces',surface.Faces,'Vertices',surface.Vertices,'FaceVertexCData',J,'FaceColor','interp',...
'EdgeColor',[0.313725501298904 0.313725501298904 0.313725501298904],'FaceAlpha',.99);
axis equal;
OptionZ.FrameRate=25;
OptionZ.Duration=50;
OptionZ.Periodic=true;
CaptureFigVid([-20,10;-110,10;-190,80;-290,10;-380,10], [pwd,filesep,'BigBrain_Template'],OptionZ);
toc
disp("done");