├── .DS_Store ├── FCLAB1.0.0 ├── DESCRIPTION.txt ├── EEG_test_v2.mat ├── EXAMPLE_READ_ME.txt ├── FC_colormap │ ├── fccolor_hot.m │ ├── fccolor_hsv.m │ ├── fccolor_jet.m │ ├── fccolor_parula.m │ └── fccolor_redblue.m ├── FC_metrics │ ├── data2cs_event.m │ ├── fcmetric_MSC.m │ ├── fcmetric_PLI.m │ ├── fcmetric_correlation.m │ ├── fcmetric_iCOH.m │ ├── fcmetric_mutualinf.m │ ├── mutualinf.m │ └── pn_eegPLV.m ├── MST_params │ ├── betweenness_wei.m │ ├── bfs.m │ ├── csr_to_sparse.m │ ├── degrees_und.m │ ├── diameter.m │ ├── dmatrix.m │ ├── eigenvector_centrality_und.m │ ├── grDistances.m │ ├── grEccentricity.m │ ├── grShortPath.m │ ├── grValidation.m │ ├── kappa.m │ ├── leaf_nodes.m │ ├── minSpanTreeKruskal.m │ ├── minimal_spanning_tree.m │ ├── mst_prim.m │ ├── pearson.m │ ├── simple_dijkstra.m │ ├── sparse_to_csr.m │ └── treeHierarchy.m ├── eegplugin_fclab.m ├── fcgraph.m ├── fclab.m ├── fclab_MST.m ├── fclab_dependences.m ├── fclab_graphproperties.m ├── headinhead │ ├── cs.mat │ ├── cs_eeg.mat │ ├── eeg_sens │ ├── locphys2locphys.m │ ├── locs_247 │ ├── main.m │ ├── mk_sensors_plane.m │ ├── select_chans.m │ ├── sensor3d2sensor2d.m │ ├── showcs.m │ ├── showcs1111.m │ ├── showfield.m │ ├── sphfit.m │ ├── test.fig │ ├── test.png │ └── test.tif ├── pop_fcgraph.m ├── pop_fclab.m ├── pop_fcvisual.fig ├── pop_fcvisual.m ├── pop_fcvisual_MSTs.fig ├── pop_fcvisual_MSTs.m ├── pop_fcvisual_parameters.fig ├── pop_fcvisual_parameters.m ├── test.m ├── topoplot.m └── topoplot_connect.m └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramsys28/FCLAB/68596db265cc28052928766be4b8cdf549d69d19/.DS_Store -------------------------------------------------------------------------------- /FCLAB1.0.0/DESCRIPTION.txt: -------------------------------------------------------------------------------- 1 | ======================================== | Functional Connectivity LAB (FCLAB) plugin for EEGLAB | ======================================== 2 | 3 | Authors 4 | Vasileios C. Pezoulas, PhD Student, University of Ioannina 5 | Manousos A. Klados, PhD, Lecturer in Biomedical Engineering, Aston University 6 | 7 | Supported functions 8 | 1. Compute functional connectivity analysis on single subject EEG data 9 | 2. Visualize functional connectivity graphs using head (and head-in-head) models 10 | 3. Compute various graph and(or) Minimum Spanning Tree local and global parameters 11 | 4. Visualize graph and(or) Minimum Spanning Tree parameters using charts and head models 12 | 13 | Description 14 | eegplugin_fclab() -> loads the FCLAB options on EEGLAB's interface 15 | fclab_dependences() -> downloads (if necessary) all the required packages for executing graph/MST analysis 16 | pop_fclab() -> loads the FCLAB environment and calls fclab() 17 | pop_fcvisual() -> loads the Graph visualization interface through pop_fcvisual.fig 18 | pop_fcgraph() -> loads the Graph analysis interface and calls fcgraph() 19 | pop_fcvisual_parameters -> loads the Graph/MST parameters visualization interface through pop_fcvisual_parameters.fig 20 | pop_fcvisual_MSTs -> loads the MST visualization interface through pop_fcvisual_MSTs.fig 21 | fclab() -> executes functional connectivity for the selected similarity measure and for the bands of interest 22 | fcgraph() -> computes various local and global parameters for different types of graphs/MSTs through fclab_graphproperties() and fclab_MST() 23 | fclab_graphproperties() -> computes local and global graph parameters for the bands of interest 24 | fclab_MST() -> computes various local and global MST parameters for the bands of interest 25 | 26 | Notes 27 | 1. All the *.fig files were created using MATLAB's guide 28 | 2. EEG epoch data are automatically averaged across the epochs 29 | 3. topoplot() and topoplot_connect() are slightly modified versions of eeglab's original ones -------------------------------------------------------------------------------- /FCLAB1.0.0/EEG_test_v2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramsys28/FCLAB/68596db265cc28052928766be4b8cdf549d69d19/FCLAB1.0.0/EEG_test_v2.mat -------------------------------------------------------------------------------- /FCLAB1.0.0/EXAMPLE_READ_ME.txt: -------------------------------------------------------------------------------- 1 | The following series of steps comprise an alternative way for executing FCLAB using simple MATLAB commands: 2 | 3 | load('EEG_test.mat'); %load the sample dataset which is is located in the parent folder 4 | EEG = pop_fclab(EEG); %this will create the FC structure according to the specified FC measure 5 | pop_fcvisual(EEG); %this will open the graph panel for visualization 6 | EEG = pop_fcgraph(EEG); %this will compute graph theoretical properties 7 | pop_fcvisual_parameters(EEG); %this will open the graph panel for visualization of the graph parameters 8 | pop_fcvisual_MSTs(EEG); %this will open the graph panel for visualization of the MST parameters (in case you selected it in pop_fcgraph) 9 | 10 | 11 | P.S. In general, try to formulate your data so as to match the format of the EEG_test.mat. 12 | 13 | Best, 14 | The FCLAB's developers team -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_colormap/fccolor_hot.m: -------------------------------------------------------------------------------- 1 | function c = fccolor_hot(m) 2 | c=hot(m); 3 | 4 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_colormap/fccolor_hsv.m: -------------------------------------------------------------------------------- 1 | function c = fccolor_hsv(m) 2 | c=hsv(m); 3 | 4 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_colormap/fccolor_jet.m: -------------------------------------------------------------------------------- 1 | function c = fccolor_jet(m) 2 | c=jet(m); 3 | 4 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_colormap/fccolor_parula.m: -------------------------------------------------------------------------------- 1 | function c = fccolor_parula(m) 2 | c=parula(m); 3 | 4 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_colormap/fccolor_redblue.m: -------------------------------------------------------------------------------- 1 | function c = fccolor_redblue(m) 2 | %REDBLUE Shades of red and blue color map 3 | % REDBLUE(M), is an M-by-3 matrix that defines a colormap. 4 | % The colors begin with bright blue, range through shades of 5 | % blue to white, and then through shades of red to bright red. 6 | % REDBLUE, by itself, is the same length as the current figure's 7 | % colormap. If no figure exists, MATLAB creates one. 8 | % 9 | % For example, to reset the colormap of the current figure: 10 | % 11 | % colormap(redblue) 12 | % 13 | % See also HSV, GRAY, HOT, BONE, COPPER, PINK, FLAG, 14 | % COLORMAP, RGBPLOT. 15 | 16 | % Adam Auton, 9th October 2009 17 | 18 | if nargin < 1, m = size(get(gcf,'colormap'),1); end 19 | 20 | if (mod(m,2) == 0) 21 | % From [0 0 1] to [1 1 1], then [1 1 1] to [1 0 0]; 22 | m1 = m*0.5; 23 | r = (0:m1-1)'/max(m1-1,1); 24 | g = r; 25 | r = [r; ones(m1,1)]; 26 | g = [g; flipud(g)]; 27 | b = flipud(r); 28 | else 29 | % From [0 0 1] to [1 1 1] to [1 0 0]; 30 | m1 = floor(m*0.5); 31 | r = (0:m1-1)'/max(m1,1); 32 | g = r; 33 | r = [r; ones(m1+1,1)]; 34 | g = [g; 1; flipud(g)]; 35 | b = flipud(r); 36 | end 37 | 38 | c = [r g b]; -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/data2cs_event.m: -------------------------------------------------------------------------------- 1 | function [cs,coh,nave]=data2cs_event(data,segleng,segshift,epleng,maxfreqbin,para); 2 | % usage: [cs,coh,nave]=data2cs_event(data,segleng,segshift,epleng,maxfreqbin,para) 3 | % 4 | % calculates cross-spectra and coherency from data for event-related measurement 5 | % input: 6 | % data: ndat times nchan matrix each colum is the time-series in one 7 | % channel; 8 | % segleng: length of each segment in bins, e.g. segleng=1000; 9 | % segshift: numer of bins by which neighboring segments are shifted; 10 | % e.g. segshift=segleng/2 makes overlapping segments 11 | % epleng: length of each epoch 12 | % maxfreqbin: max frequency in bins 13 | % para: optional structure: 14 | % para.segave=0 -> no averaging across segments 15 | % para.segave neq 0 -> averaging across segments (default is 1)% \ 16 | % para.subave =1 subtracts the average across epochs, 17 | % para.subave ~= 1 -> no subtraction (default is 1) 18 | % IMPORTANT: if you just one epoch (e.g. for continuous data) 19 | % set para.subave=0 20 | % 21 | % -> averaging across segments (default is 0) 22 | % para.proj must be a set of vector in channel space, 23 | % if it exists then the output raw contains the single trial 24 | % Fourier-transform in that channel 25 | % para.zeropad=n adds n zeros at the end of each segment and at the end 26 | % of the window. default n=0 27 | % para.mydetrend=1 (detrends linear trends in all segments; default=0 (no detrending)) 28 | % 29 | % output: 30 | % cs: nchan by chan by maxfreqbin by nseg tensor cs(:,:,f,i) contains 31 | % the cross-spectrum at frequency f and segment i 32 | % coh: complex coherency calculated from cs 33 | % nave: number of averages 34 | % PROVIDED BY GUIDO NOLTE 35 | 36 | subave=0; 37 | 38 | if nargin<6 39 | para=[]; 40 | end 41 | 42 | 43 | 44 | segave=1; 45 | mydetrend=0; 46 | proj=[]; 47 | zeropad=0; 48 | if isfield(para,'segave') 49 | segave=para.segave; 50 | end 51 | if isfield(para,'detrend') 52 | mydetrend=para.detrend; 53 | end 54 | if isfield(para,'proj') 55 | proj=para.proj; 56 | end 57 | if isfield(para,'subave') 58 | subave=para.subave; 59 | end 60 | if isfield(para,'zeropad') 61 | zeropad=para.zeropad; 62 | end 63 | [ndum,npat]=size(proj); 64 | 65 | [ndat,nchan]=size(data); 66 | if npat>0 67 | data=data*proj; 68 | nchan=npat; 69 | end 70 | 71 | maxfreqbin=min([maxfreqbin,floor((segleng+zeropad)/2)+1]); 72 | nep=floor(ndat/epleng); 73 | 74 | nseg=floor((epleng-segleng)/segshift)+1; %total number of segments 75 | 76 | 77 | 78 | if segave==0 79 | cs=zeros(nchan,nchan,maxfreqbin,nseg); 80 | av=zeros(nchan,maxfreqbin,nseg); 81 | else 82 | cs=zeros(nchan,nchan,maxfreqbin); 83 | av=zeros(nchan,maxfreqbin); 84 | end 85 | 86 | if npat>0 87 | if segave==0 88 | cs=zeros(nchan,nchan,maxfreqbin,nep,nseg); 89 | av=zeros(nchan,maxfreqbin,nep,nseg); 90 | else 91 | cs=zeros(nchan,nchan,maxfreqbin,nep); 92 | av=zeros(nchan,maxfreqbin,nep); 93 | end 94 | end 95 | 96 | 97 | mywindow=repmat(hanning(segleng),1,nchan); 98 | if isfield(para,'mywindow'); 99 | mywindow=repmat(para.mywindow,1,nchan); 100 | end 101 | if zeropad>0 102 | mywindow=[mywindow;zeros(zeropad,nchan)]; 103 | end 104 | %figure;plot(mywindow); 105 | nave=0; 106 | for j=1:nep; 107 | dataep=data((j-1)*epleng+1:j*epleng,:); 108 | for i=1:nseg; %average over all segments; 109 | dataloc=dataep((i-1)*segshift+1:(i-1)*segshift+segleng,:); 110 | if mydetrend==1; 111 | dataloc=detrend(dataloc); 112 | end 113 | 114 | 115 | if zeropad>0 116 | dataloc=[dataloc;zeros(zeropad,nchan)]; 117 | end 118 | 119 | datalocfft=fft(dataloc.*mywindow); 120 | 121 | 122 | 123 | for f=1:maxfreqbin % for all frequencies 124 | if npat==0 125 | if segave==0 126 | cs(:,:,f,i)=cs(:,:,f,i)+conj(datalocfft(f,:)'*datalocfft(f,:)); 127 | av(:,f,i)=av(:,f,i)+conj(datalocfft(f,:)'); 128 | else 129 | %disp([i,f,size(datalocfft)]) 130 | cs(:,:,f)=cs(:,:,f)+conj(datalocfft(f,:)'*datalocfft(f,:)); 131 | av(:,f)=av(:,f)+conj(datalocfft(f,:)'); 132 | end 133 | else 134 | if segave==0 135 | cs(:,:,f,j,i)=conj(datalocfft(f,:)'*datalocfft(f,:)); 136 | av(:,f,j,i)=conj(datalocfft(f,:)'); 137 | else 138 | %disp([i,f,size(datalocfft)]) 139 | cs(:,:,f,j)=cs(:,:,f,j)+conj(datalocfft(f,:)'*datalocfft(f,:)); 140 | av(:,f,j)=av(:,f,j)+conj(datalocfft(f,:)'); 141 | end 142 | end 143 | 144 | end 145 | end 146 | nave=nave+1; 147 | end 148 | 149 | if segave==0 150 | cs=cs/nave; 151 | av=av/nave; 152 | else 153 | nave=nave*nseg; 154 | cs=cs/nave; 155 | av=av/nave; 156 | end 157 | 158 | for f=1:maxfreqbin 159 | if subave==1 160 | if npat==0 161 | if segave==0 162 | for i=1:nseg;cs(:,:,f,i)=cs(:,:,f,i)-av(:,f,i)*av(:,f,i)';end; 163 | else 164 | cs(:,:,f)=cs(:,:,f)-av(:,f)*av(:,f)'; 165 | end 166 | else 167 | if segave==0 168 | for i=1:nseg;for j=1:nep; 169 | cs(:,:,f,j,i)=cs(:,:,f,j,i)-av(:,f,j,i)*av(:,f,j,i)'; 170 | end;end; 171 | else 172 | for j=1:nep;cs(:,:,f,j)=cs(:,:,f,j)-av(:,f,j)*av(:,f,j)';end 173 | end 174 | end 175 | end 176 | end 177 | 178 | ndim=length(size(cs)); 179 | if ndim==3; 180 | [n1,n2,n3]=size(cs); 181 | coh=cs; 182 | for i=1:n3; 183 | c=squeeze(cs(:,:,i)); 184 | coh(:,:,i)=c./sqrt(diag(c)*diag(c)'); 185 | end 186 | elseif ndim==4 187 | [n1,n2,n3,n4]=size(cs); 188 | coh=cs; 189 | for i=1:n3;for j=1:n4; 190 | c=squeeze(cs(:,:,i,j)); 191 | coh(:,:,i,j)=c./sqrt(diag(c)*diag(c)'); 192 | end;end; 193 | end 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | return; 203 | 204 | 205 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/fcmetric_MSC.m: -------------------------------------------------------------------------------- 1 | function outEEG = fcmetric_MSC(inEEG) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Usage: 4 | % 5 | % >> outEEG = fcmetric_MSC(inEEG); 6 | % 7 | % Input(s): 8 | % inEEG - input EEG dataset 9 | % 10 | % Output(s): 11 | % outEEG - output EEG dataset 12 | % 13 | % Info: 14 | % Computes the magnitude squared coherence for each possible pair 15 | % of EEG channels and for every band as well. 16 | % 17 | % Mathematical background: 18 | % For two signals, assume x, y, the magnitude squared coherence 19 | % at frequency f, |R(f)|^2, can be defined as follows: 20 | % 21 | % |R(f)|^2 = (|C(f)|^2)/[(C_xx(f)*C_yy(f))] 22 | % 23 | % where C(f) is the cross-spectrum of signals x, y at f, and C_xx, 24 | % C_yy are the power spectra of x and y, respectively, at the same 25 | % frequency. 26 | % 27 | % Fundamental basis: 28 | % The coherence values vary on the interval [0, 1], where 1 29 | % indicates a perfect linear prediction of y from x. 30 | % 31 | % Reference(s): 32 | % Rosenberg J.R., Amjad A.M., Breeze P., Brilinger D.R., and D. 33 | % M. Halliday (1989). The Fourier approach to the identification 34 | % offunctional coupling between neuronal spike trains. Prog. 35 | % Biophys. molec. Biol., 53, 1-31. 36 | % 37 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 38 | 39 | [m1 n1] = size(inEEG.data); 40 | mf = size(inEEG.FC.parameters.bands,1); 41 | outEEG = inEEG; 42 | disp('>> FCLAB: MSC is being computed...'); 43 | 44 | for i1 = 1:m1 45 | for j1=i1:m1 46 | [Cxy F]=mscohere(inEEG.data(i1,:),inEEG.data(j1,:),50,1,[],inEEG.srate); 47 | for bands=1:mf 48 | freq_range=str2num(inEEG.FC.parameters.bands{bands,1}); 49 | for i=1:length(F) 50 | if F(i,1)>freq_range(1) 51 | start_freq=i; 52 | break; 53 | end 54 | end 55 | for i=1:length(F) 56 | if F(i,1)>freq_range(2) 57 | stop_freq=i-1; 58 | break; 59 | end 60 | end 61 | end 62 | eval(['outEEG.FC.MSC.'... 63 | strrep(inEEG.FC.parameters.bands{bands,2},' ','_') ... 64 | '.adj_matrix(i1,j1)=mean(Cxy(start_freq:stop_freq-1,1));']); 65 | end 66 | end 67 | 68 | for i = 1:mf 69 | eval(['outEEG.FC.MSC.'... 70 | strrep(inEEG.FC.parameters.bands{i,2},' ','_') ... 71 | '.adj_matrix(outEEG.nbchan,:)=0;']); 72 | eval(['outEEG.FC.MSC.'... 73 | strrep(inEEG.FC.parameters.bands{i,2},' ','_') ... 74 | '.adj_matrix=outEEG.FC.MSC.'... 75 | strrep(inEEG.FC.parameters.bands{i,2},' ','_') ... 76 | '.adj_matrix+outEEG.FC.MSC.'... 77 | strrep(inEEG.FC.parameters.bands{i,2},' ','_') ... 78 | '.adj_matrix''']); 79 | end 80 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/fcmetric_PLI.m: -------------------------------------------------------------------------------- 1 | function outEEG = fcmetric_PLI(inEEG) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Usage: 4 | % 5 | % >> outEEG = fcmetric_PLI(inEEG); 6 | % 7 | % Input(s): 8 | % inEEG - input EEG dataset 9 | % 10 | % Output(s): 11 | % outEEG - output EEG dataset 12 | % 13 | % Info: 14 | % Computes the phase lag index proposed by Stam et al., 2007 for 15 | % each possible pair of EEG channels and for every band as well. 16 | % 17 | % Mathematical background: 18 | % According to Stam et al., 2007 PLI is defined in a complete 19 | % mathematical formula as: 20 | % 21 | % PLI = mean(|sign([sin(Df(t))])|) (1) 22 | % 23 | % where: 24 | % 25 | % Df(t) = phase1(t)-phase2(t)), is the phase difference 26 | % of the two signals at time t, 27 | % 28 | % phase1(t) is the phase of the 1st signal and is equal 29 | % to arctan(x1_H(t)/x1(t)) where x1_H(t) is the Hilbert 30 | % transformed version of signal x1(t), 31 | % 32 | % phase2(t) is the phase of the 2nd signal and is equal 33 | % to arctan(x2_H(t)/x2(t)) where x2_H(t) is the Hilbert 34 | % transformed version of signal x2(t). 35 | % 36 | % Fundamental basis: 37 | % The PLI ranges between 0 and 1. 38 | % A PLI of zero indicates either no coupling or coupling with 39 | % a phase difference centered around 0 mod p. A PLI of 1 40 | % indicates perfect phase locking at a value of Df different 41 | % from 0 mod p. The stronger this nonzero phase locking is, 42 | % the larger PLI will be. 43 | % 44 | % Important notes: 45 | % the sinus in (1) is used in order to convert the phases on 46 | % the interval (0, 2pi] instead of (-pi, pi], 47 | % 48 | % the mean value is used as an alternative way in order to 49 | % highlight the fact that when the distibution of Df is 50 | % symmetric then the two signals originate from the same 51 | % source. The same happens when the mean Df is equal to or 52 | % centered around 0 mod pi. 53 | % 54 | % Reference(s): Stam C. J., Nolte G., and Daffertshofer A (2007). Phase lag 55 | % index: assessment of functional connectivity from multi channel EEG and 56 | % MEG with diminished bias from common sources. Hum. Brain Mapp. 28(3), 57 | % 1178-1193. 58 | % 59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 60 | 61 | mf = size(inEEG.FC.parameters.bands, 1); 62 | [m, ~, o] = size(inEEG.data); 63 | outEEG = inEEG; 64 | 65 | disp('>> FCLAB: PLI is being computed...'); 66 | 67 | for i = 1:mf 68 | testEEG = inEEG; 69 | temp_adj = zeros(m, m); 70 | freq_range = str2num(inEEG.FC.parameters.bands{i,1}); 71 | [testEEG, ~, ~] = pop_eegfiltnew(testEEG, freq_range(1)); 72 | [testEEG, ~, ~] = pop_eegfiltnew(testEEG, [], freq_range(2)); 73 | 74 | if (o > 1) 75 | X = mean(testEEG.data, 3); %events data 76 | else 77 | X = testEEG.data; 78 | end 79 | 80 | for j = 1:m-1 81 | for k = j+1:m 82 | hilbert1 = hilbert(X(j, :)); 83 | hilbert2 = hilbert(X(k, :)); 84 | df = angle(hilbert1) - angle(hilbert2); 85 | temp_adj(j, k) = abs(mean((sign(sin(df))))); 86 | end 87 | end 88 | temp_adj = temp_adj + triu(temp_adj)'; 89 | 90 | eval(['outEEG.FC.PLI.' strrep(inEEG.FC.parameters.bands{i,2},' ','_') '.adj_matrix = temp_adj;']); 91 | end 92 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/fcmetric_correlation.m: -------------------------------------------------------------------------------- 1 | function outEEG = fcmetric_correlation(inEEG) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Usage: 4 | % 5 | % >> outEEG = fcmetric_correlation(inEEG); 6 | % 7 | % Input(s): 8 | % inEEG - input EEG dataset 9 | % 10 | % Outputs: 11 | % outEEG - output EEG dataset 12 | % 13 | % Info: 14 | % Computes Pearson's temporal correlation coefficient for each 15 | % possible pair of EEG channels and for every band as well. 16 | % 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | 19 | mf = size(inEEG.FC.parameters.bands, 1); 20 | [m, n, o] = size(inEEG.data); 21 | outEEG = inEEG; 22 | disp('>> FCLAB: Pearson''s correlation is being computed...'); 23 | 24 | for i = 1:mf 25 | testEEG = inEEG; 26 | freq_range = str2num(inEEG.FC.parameters.bands{i,1}); 27 | [testEEG, com, b] = pop_eegfiltnew(testEEG, freq_range(1)); 28 | [testEEG, com, b] = pop_eegfiltnew(testEEG, [], freq_range(2)); 29 | if (o == 1) 30 | temp_adj = corrcoef(testEEG.data'); 31 | else 32 | temp_adj = corrcoef(mean(testEEG.data,3)'); % events data 33 | end 34 | eval(['outEEG.FC.correlation.' strrep(inEEG.FC.parameters.bands{i,2},' ','_') '.adj_matrix=temp_adj;']); 35 | end; 36 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/fcmetric_iCOH.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramsys28/FCLAB/68596db265cc28052928766be4b8cdf549d69d19/FCLAB1.0.0/FC_metrics/fcmetric_iCOH.m -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/fcmetric_mutualinf.m: -------------------------------------------------------------------------------- 1 | function outEEG = fcmetric_mutualinf(inEEG) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Usage: 4 | % 5 | % >> outEEG = fcmetric_mutualinf(inEEG); 6 | % 7 | % Inputs: 8 | % inEEG - input EEG dataset 9 | % 10 | % Outputs: 11 | % outEEG - output EEG dataset 12 | % 13 | % Info: 14 | % Computes the mutual information for each possible pair of EEG 15 | % channels and for every band as well. 16 | % 17 | % Mathematical background: 18 | % Mutual information quantifies the mutual dependence between two 19 | % random variables, assume x and y. It can be defined as: 20 | % 21 | % I = ?[p(x,y)*log(p(x,y)/p(x)*p(y))] 22 | % 23 | % where p(x,y) is the joint probability function between x and y, 24 | % and p(x), p(y) are the marginal probability distribution 25 | % functions of x and y, respectively. 26 | % 27 | % Fundamental basis: 28 | % Mutual information varies between 0 and 1 where 1 denotes a 29 | % complete dependence between the two variables and 0 otherwise. 30 | % 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | 33 | w = warning('query','last'); 34 | outEEG = inEEG; 35 | id = w.identifier; 36 | warning('off',id); 37 | mf = size(inEEG.FC.parameters.bands, 1); 38 | disp('>> FCLAB: Mututal information is being computed...'); 39 | 40 | for band = 1:mf 41 | testEEG = inEEG; 42 | freq_range = str2num(inEEG.FC.parameters.bands{band,1}); 43 | [testEEG, ~, ~] = pop_eegfiltnew(testEEG, freq_range(1)); 44 | [testEEG, ~, ~] = pop_eegfiltnew(testEEG, [], freq_range(2)); 45 | for i = 1:inEEG.nbchan 46 | for j = 1:inEEG.nbchan 47 | Matrix(i,j) = mutualinf(inEEG.data(i,:)',inEEG.data(j,:)',inEEG.srate,freq_range(1),freq_range(2)); 48 | end 49 | end 50 | disp(num2str(size(Matrix,1))) 51 | disp(num2str(size(Matrix,2))) 52 | Matrix = Matrix + Matrix'; 53 | eval(['outEEG.FC.mutualinf.' strrep(inEEG.FC.parameters.bands{band,2},' ','_') '.adj_matrix=Matrix;']); 54 | end 55 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/mutualinf.m: -------------------------------------------------------------------------------- 1 | % Function by the Functional Connectivity Toolbox 2 | % by Dongli Zhou, Wesley Thompson, and Greg Siegle 3 | % Zhou D, Thompson T, Siegle G. (2009) NeuroImage 47:1590-1607. 4 | function phi=mutualinf(y1,y2,sr,lambdamin,lambdamax) 5 | 6 | if nargin<3, lambdamin=0;lambdamax=1/2; sr=1;end 7 | 8 | lambdamin=lambdamin/(sr/2); 9 | lambdamax=lambdamax/(sr/2); 10 | 11 | %sr is the sampling rate in Hz (e.g., 0.6) 12 | % lambdamin and lambdamax are the frequency boundaries in Hz 13 | % The analysis operates IN BETWEEN these boundaries 14 | % The minimum lambdamin is 0 15 | % The maximum lambdamax is half the sampling rate (Nyquest frequency) 16 | % The default (if sr, lambdamin, lambdamax are not specified) is 17 | % to use the whole frequency range 18 | 19 | l1=length(y1); 20 | l2=length(y2); 21 | if (l1~=l2) 22 | error('the length of the two time series are not the same.'); 23 | else 24 | y=[y1,y2]; 25 | l=l1; 26 | m=2; 27 | odd=mod(l,2); %check length is odd or even 28 | if (odd==1) 29 | t=(l+1)/2; 30 | else t=l/2+1; 31 | end 32 | f_lambda=zeros(m,m,t); 33 | for p1=1:m 34 | for p2=1:m 35 | f_lambda(p1,p2,:)=cpsd(y(:,p1),y(:,p2),[],[],l)/2/pi; 36 | end; 37 | end; 38 | [a,w]=cpsd(y(:,1),y(:,2),[],[],l,sr); 39 | lambda_f=zeros(2*t-1,1); 40 | lambda_f(t:(2*t-1),:)=w; 41 | for j=1:(t-1) 42 | lambda_f(j,:)=-lambda_f((2*t-j),:); 43 | end 44 | 45 | temp=f_lambda; 46 | temp1=temp(:,:,2:t); 47 | temp2=zeros(m,m,(t-1)); 48 | for p1=1:m 49 | for p2=1:m 50 | for i=1:(t-1) 51 | temp2(p1,p2,i)=conj(temp1(p1,p2,(t-i))); 52 | end 53 | end; 54 | end; 55 | 56 | f_lambda=zeros(m,m,(2*t-1)); 57 | f_lambda(:,:,1:(t-1))=temp2; 58 | f_lambda(:,:,t:(2*t-1))=temp; 59 | 60 | g_lambda=zeros(m,m,(2*t-1)); 61 | for lambda=1:(2*t-1) 62 | warning('OFF','MATLAB:nearlySingularMatrix') 63 | g_lambda(:,:,lambda)=inv(f_lambda(:,:,lambda)); 64 | end 65 | R_lambda=zeros(m,m,(2*t-1)); 66 | for lambda=1:(2*t-1) 67 | R_lambda(:,:,lambda)= diag(diag(g_lambda(:,:,lambda)))^(-1/2)*g_lambda(:,:,lambda)*... 68 | diag(diag(g_lambda(:,:,lambda)))^(-1/2); 69 | end 70 | 71 | Pcoh=zeros(m,m,(2*t-1)); 72 | for p1=1:m 73 | for p2=1:m 74 | for lambda=1:(2*t-1) 75 | Pcoh(p1,p2,lambda) = abs(R_lambda(p1,p2,lambda))^2; 76 | end 77 | end 78 | end 79 | 80 | %----------------specify the frequency band---------------- 81 | lw=0; up=0; 82 | for i=t:2*t-1 83 | if (lambda_f(i)lambdamax) , up=up+1; end 85 | end; 86 | %---------------------------------------------------------- 87 | if (lw==0) 88 | Pcoh_fb=Pcoh(:,:,(up+1):(2*t-1-up)); 89 | else Pcoh_fb=Pcoh(:,:,[(up+1):(t-lw);(t+lw):(2*t-1-up)]); 90 | end 91 | delta=zeros(m,m); 92 | for p1=2:m 93 | for p2=1:(p1-1) 94 | delta(p1,p2)=-mean(log(1-Pcoh_fb(p1,p2,:)))/2/pi; 95 | end 96 | end 97 | delta=delta+delta'; 98 | 99 | 100 | phi=(1-exp(-2*delta(1,2)))^.5; 101 | end 102 | -------------------------------------------------------------------------------- /FCLAB1.0.0/FC_metrics/pn_eegPLV.m: -------------------------------------------------------------------------------- 1 | function [plv] = pn_eegPLV(eegData, dataSelectArr) 2 | % Computes the Phase Locking Value (PLV) for an EEG dataset. 3 | % 4 | % Input parameters: 5 | % eegData is a 3D matrix numChannels x numTimePoints x numTrials 6 | % srate is the sampling rate of the EEG data 7 | % filtSpec is the filter specification to filter the EEG signal in the 8 | % desired frequency band of interest. It is a structure with two 9 | % fields, order and range. 10 | % Range specifies the limits of the frequency 11 | % band, for example, put filtSpec.range = [35 45] for gamma band. 12 | % Specify the order of the FIR filter in filtSpec.order. A useful 13 | % rule of thumb can be to include about 4 to 5 cycles of the desired 14 | % signal. For example, filtSpec.order = 50 for eeg data sampled at 15 | % 500 Hz corresponds to 100 ms and contains ~4 cycles of gamma band 16 | % (40 Hz). 17 | % dataSelectArr (OPTIONAL) is a logical 2D matrix of size - numTrials x 18 | % numConditions. For example, if you have a 250 trials in your EEG 19 | % dataset and the first 125 correspond to the 'attend' condition and 20 | % the last 125 correspond to the 'ignore' condition, then use 21 | % dataSelectArr = [[true(125, 1); false(125, 1)],... 22 | % [false(125, 1); true(125, 1)]]; 23 | % 24 | % Output parameters: 25 | % plv is a 4D matrix - 26 | % numTimePoints x numChannels x numChannels x numConditions 27 | % If 'dataSelectArr' is not specified, then it is assumed that there is 28 | % only one condition and all trials belong to that condition. 29 | % 30 | %-------------------------------------------------------------------------- 31 | % Example: Consider a 28 channel EEG data sampled @ 500 Hz with 231 trials, 32 | % where each trial lasts for 2 seconds. You are required to plot the phase 33 | % locking value in the gamma band between channels Fz (17) and Oz (20) for 34 | % two conditions (say, attend and ignore). Below is an example of how to 35 | % use this function. 36 | % 37 | % eegData = rand(28, 1000, 231); 38 | % srate = 500; %Hz 39 | % filtSpec.order = 50; 40 | % filtSpec.range = [35 45]; %Hz 41 | % dataSelectArr = rand(231, 1) >= 0.5; % attend trials 42 | % dataSelectArr(:, 2) = ~dataSelectArr(:, 1); % ignore trials 43 | % [plv] = pn_eegPLV(eegData, srate, filtSpec, dataSelectArr); 44 | % figure; plot((0:size(eegData, 2)-1)/srate, squeeze(plv(:, 17, 20, :))); 45 | % xlabel('Time (s)'); ylabel('Plase Locking Value'); 46 | % 47 | % NOTE: 48 | % As you have probably noticed in the plot from the above example, the PLV 49 | % between two random signals is spuriously large in the first 100 ms. While 50 | % using FIR filtering and/or hilbert transform, it is good practice to 51 | % discard both ends of the signal (same number of samples as the order of 52 | % the FIR filter, or more). 53 | % 54 | % Also note that in order to extract the PLV between channels 17 and 20, 55 | % use plv(:, 17, 20, :) and NOT plv(:, 20, 17, :). The smaller channel 56 | % number is to be used first. 57 | %-------------------------------------------------------------------------- 58 | % 59 | % Reference: 60 | % Lachaux, J P, E Rodriguez, J Martinerie, and F J Varela. 61 | % Measuring phase synchrony in brain signals. 62 | % Human brain mapping 8, no. 4 (January 1999): 194-208. 63 | % http://www.ncbi.nlm.nih.gov/pubmed/10619414. 64 | % 65 | %-------------------------------------------------------------------------- 66 | % Written by: 67 | % Praneeth Namburi 68 | % Cognitive Neuroscience Lab, DUKE-NUS 69 | % 01 Dec 2009 70 | % 71 | % Present address: Neuroscience Graduate Program, MIT 72 | % email: praneeth@mit.edu 73 | % ADAPTED FROM THE ORIGINAL FUNCTION FOR FC LAB 74 | 75 | numChannels = size(eegData, 1); 76 | numTrials = size(eegData, 3); 77 | if ~exist('dataSelectArr', 'var') 78 | dataSelectArr = true(numTrials, 1); 79 | else 80 | if ~islogical(dataSelectArr) 81 | error('Data selection array must be a logical'); 82 | end 83 | end 84 | numConditions = size(dataSelectArr, 2); 85 | 86 | % disp('Filtering data...'); 87 | %filtPts = fir1(filtSpec.order, 2/srate*filtSpec.range); 88 | %filteredData = filter(filtPts, 1, eegData, [], 2); 89 | filteredData = eegData; 90 | 91 | % disp(['Calculating PLV for ' mat2str(sum(dataSelectArr, 1)) ' trials...']); 92 | for channelCount = 1:numChannels 93 | filteredData(channelCount, :, :) = angle(hilbert(squeeze(filteredData(channelCount, :, :)))); 94 | end 95 | plv = zeros(size(filteredData, 2), numChannels, numChannels, numConditions); 96 | for channelCount = 1:numChannels-1 97 | channelData = squeeze(filteredData(channelCount, :, :)); 98 | for compareChannelCount = channelCount+1:numChannels 99 | compareChannelData = squeeze(filteredData(compareChannelCount, :, :)); 100 | for conditionCount = 1:numConditions 101 | plv(:, channelCount, compareChannelCount, conditionCount) = abs(sum(exp(1i*... 102 | (channelData(:, dataSelectArr(:, conditionCount))... 103 | - compareChannelData(:, dataSelectArr(:, conditionCount)))), 2))... 104 | /sum(dataSelectArr(:, conditionCount)); 105 | end 106 | end 107 | end 108 | plv = squeeze(plv); 109 | return; -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/betweenness_wei.m: -------------------------------------------------------------------------------- 1 | function BC=betweenness_wei(G) 2 | %BETWEENNESS_WEI Node betweenness centrality 3 | % 4 | % BC = betweenness_wei(W); 5 | % 6 | % Node betweenness centrality is the fraction of all shortest paths in 7 | % the network that contain a given node. Nodes with high values of 8 | % betweenness centrality participate in a large number of shortest paths. 9 | % 10 | % Input: W, weighted (directed/undirected) connection matrix. 11 | % 12 | % Output: BC, node betweenness centrality vector. 13 | % 14 | % Notes: 15 | % The input matrix must be a mapping from weight to distance. For 16 | % instance, in a weighted correlation network, higher correlations are 17 | % more naturally interpreted as shorter distances, and the input matrix 18 | % should consequently be some inverse of the connectivity matrix. 19 | % Betweenness centrality may be normalised to [0,1] via BC/[(N-1)(N-2)] 20 | % 21 | % Reference: Brandes (2001) J Math Sociol 25:163-177. 22 | % 23 | % 24 | % Mika Rubinov, UNSW, 2007-2010 25 | 26 | n=length(G); 27 | % E=find(G); G(E)=1./G(E); %invert weights 28 | BC=zeros(n,1); %vertex betweenness 29 | 30 | for u=1:n 31 | D=inf(1,n); D(u)=0; %distance from u 32 | NP=zeros(1,n); NP(u)=1; %number of paths from u 33 | S=true(1,n); %distance permanence (true is temporary) 34 | P=false(n); %predecessors 35 | Q=zeros(1,n); q=n; %order of non-increasing distance 36 | 37 | G1=G; 38 | V=u; 39 | while 1 40 | S(V)=0; %distance u->V is now permanent 41 | G1(:,V)=0; %no in-edges as already shortest 42 | for v=V 43 | Q(q)=v; q=q-1; 44 | W=find(G1(v,:)); %neighbours of v 45 | for w=W 46 | Duw=D(v)+G1(v,w); %path length to be tested 47 | if Duww shorter than old 48 | D(w)=Duw; 49 | NP(w)=NP(v); %NP(u->w) = NP of new path 50 | P(w,:)=0; 51 | P(w,v)=1; %v is the only predecessor 52 | elseif Duw==D(w) %if new u->w equal to old 53 | NP(w)=NP(w)+NP(v); %NP(u->w) sum of old and new 54 | P(w,v)=1; %v is also a predecessor 55 | end 56 | end 57 | end 58 | 59 | minD=min(D(S)); 60 | if isempty(minD), break %all nodes reached, or 61 | elseif isinf(minD), %...some cannot be reached: 62 | Q(1:q)=find(isinf(D)); break %...these are first-in-line 63 | end 64 | V=find(D==minD); 65 | end 66 | 67 | DP=zeros(n,1); %dependency 68 | for w=Q(1:n-1) 69 | BC(w)=BC(w)+DP(w); 70 | for v=find(P(w,:)) 71 | DP(v)=DP(v)+(1+DP(w)).*NP(v)./NP(w); 72 | end 73 | end 74 | end -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/bfs.m: -------------------------------------------------------------------------------- 1 | function [d dt pred] = bfs(A,u,target) 2 | % BFS Compute breadth first search distances, times, and tree for a graph 3 | % 4 | % [d dt pred] = bfs(A,u) returns the distance (d) and the discover time 5 | % (dt) for each vertex in the graph in a breadth first search 6 | % starting from vertex u. 7 | % d = dt(i) = -1 if vertex i is not reachable from u 8 | % pred is the predecessor array. pred(i) = 0 if vertex (i) 9 | % is in a component not reachable from u and i != u. 10 | % 11 | % [...] = bfs(A,u,v) stops the bfs when it hits the vertex v 12 | % 13 | % Example: 14 | % load_gaimc_graph('bfs_example.mat') % use the dfs example from Boost 15 | % d = bfs(A,1) 16 | % 17 | % See also DFS 18 | 19 | % David F. Gleich 20 | % Copyright, Stanford University, 2008-20098 21 | 22 | % History 23 | % 2008-04-13: Initial coding 24 | 25 | if ~exist('target','var') || isempty(full), target=0; end 26 | 27 | if isstruct(A), rp=A.rp; ci=A.ci; 28 | else [rp ci]=sparse_to_csr(A); 29 | end 30 | 31 | n=length(rp)-1; 32 | d=-1*ones(n,1); dt=-1*ones(n,1); pred=zeros(1,n); 33 | sq=zeros(n,1); sqt=0; sqh=0; % search queue and search queue tail/head 34 | 35 | % start bfs at u 36 | sqt=sqt+1; sq(sqt)=u; 37 | t=0; 38 | d(u)=0; dt(u)=t; t=t+1; pred(u)=u; 39 | while sqt-sqh>0 40 | sqh=sqh+1; v=sq(sqh); % pop v off the head of the queue 41 | for ri=rp(v):rp(v+1)-1 42 | w=ci(ri); 43 | if d(w)<0 44 | sqt=sqt+1; sq(sqt)=w; 45 | d(w)=d(v)+1; dt(w)=t; t=t+1; pred(w)=v; 46 | if w==target, return; end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/csr_to_sparse.m: -------------------------------------------------------------------------------- 1 | function [nzi,nzj,nzv] = csr_to_sparse(rp,ci,ai,ncols) 2 | % CSR_TO_SPARSE Convert from compressed row arrays to a sparse matrix 3 | % 4 | % A = csr_to_sparse(rp,ci,ai) returns the sparse matrix represented by the 5 | % compressed sparse row representation rp, ci, and ai. The number of 6 | % columns of the output sparse matrix is max(max(ci),nrows). See the call 7 | % below. 8 | % 9 | % A = csr_to_sparse(rp,ci,ai,ncol) While we can infer the number of rows 10 | % in the matrix from this expression, you may want a 11 | % different number of 12 | % 13 | % [nzi,nzj,nzv] = csr_to_sparse(...) returns the arrays that feed the 14 | % sparse call in matlab. You can use this to avoid the sparse call and 15 | % customize the behavior. 16 | % 17 | % This command "inverts" the behavior of sparse_to_csr. 18 | % Repeated entries in the matrix are summed, just like sparse does. 19 | % 20 | % See also SPARSE SPARSE_TO_CSR 21 | % 22 | % Example: 23 | % A=sparse(6,6); A(1,1)=5; A(1,5)=2; A(2,3)=-1; A(4,1)=1; A(5,6)=1; 24 | % [rp ci ai]=sparse_to_csr(A); 25 | % A2 = csr_to_sparse(rp,ci,ai) 26 | 27 | % David F. Gleich 28 | % Copyright, Stanford University, 2008-2009 29 | 30 | % History 31 | % 2009-05-01: Initial version 32 | % 2009-05-16: Documentation and example 33 | 34 | nrows = length(rp)-1; 35 | nzi = zeros(length(ci),1); 36 | for i=1:nrows 37 | for j=rp(i):rp(i+1)-1 38 | nzi(j) = i; 39 | end 40 | end 41 | 42 | if nargout<2, 43 | if nargin>3, 44 | nzi = sparse(nzi,ci,ai,nrows,ncols); 45 | else 46 | % we make the matrix square unless there are more columns 47 | ncols = max(max(ci),nrows); 48 | if isempty(ncols), ncols=0; end 49 | nzi = sparse(nzi,ci,ai,nrows,ncols); 50 | end 51 | else 52 | nzj = ci; 53 | nzv = ai; 54 | end 55 | -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/degrees_und.m: -------------------------------------------------------------------------------- 1 | function [deg] = degrees_und(CIJ) 2 | %DEGREES_UND Degree 3 | % 4 | % deg = degrees_und(CIJ); 5 | % 6 | % Node degree is the number of links connected to the node. 7 | % 8 | % Input: CIJ, undirected (binary/weighted) connection matrix 9 | % 10 | % Output: deg, node degree 11 | % 12 | % Note: Weight information is discarded. 13 | % 14 | % 15 | % Olaf Sporns, Indiana University, 2002/2006/2008 16 | 17 | 18 | % ensure CIJ is binary... 19 | CIJ = double(CIJ~=0); 20 | 21 | deg = sum(CIJ); 22 | 23 | -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/diameter.m: -------------------------------------------------------------------------------- 1 | % The longest shortest path between any two nodes nodes in the network 2 | % INPUTS: adjacency matrix, adj 3 | % OUTPUTS: network diameter, diam 4 | % Other routines used: simple_dijkstra.m 5 | % GB, Last updated: June 8, 2010 6 | 7 | function diam = diameter(adj) 8 | 9 | diam=0; 10 | for i=1:size(adj,1) 11 | d=simple_dijkstra(adj,i); 12 | diam = max([max(d),diam]); 13 | end -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/dmatrix.m: -------------------------------------------------------------------------------- 1 | function y = dmatrix(x) 2 | % d=dmatrix(data =[N x p]), data=[#vectors x dimensionality of the vector-space] 3 | % data=[channels x time-instants] 4 | % or data=[#trials x time-imstants] 5 | 6 | [m,n]=size(x); 7 | 8 | 9 | 10 | a=x*x'; 11 | e=ones(m,m) ; 12 | d=diag(diag(a))*e + e*diag(diag(a))-2*a ; 13 | 14 | 15 | 16 | y=d; 17 | 18 | 19 | -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/eigenvector_centrality_und.m: -------------------------------------------------------------------------------- 1 | function v = eigenvector_centrality_und(CIJ) 2 | %EIGENVECTOR_CENTRALITY_UND Spectral measure of centrality 3 | % 4 | % v = eigenvector_centrality_und(CIJ) 5 | % 6 | % Eigenector centrality is a self-referential measure of centrality: 7 | % nodes have high eigenvector centrality if they connect to other nodes 8 | % that have high eigenvector centrality. The eigenvector centrality of 9 | % node i is equivalent to the ith element in the eigenvector 10 | % corresponding to the largest eigenvalue of the adjacency matrix. 11 | % 12 | % Inputs: CIJ, binary/weighted undirected adjacency matrix. 13 | % 14 | % Outputs: v, eigenvector associated with the largest 15 | % eigenvalue of the adjacency matrix CIJ. 16 | % 17 | % Reference: Newman, MEJ (2002). The mathematics of networks. 18 | % 19 | % Contributors: 20 | % Xi-Nian Zuo, Chinese Academy of Sciences, 2010 21 | % Rick Betzel, Indiana University, 2012 22 | % Mika Rubinov, University of Cambridge, 2015 23 | 24 | % MODIFICATION HISTORY 25 | % 2010/2012: original (XNZ, RB) 26 | % 2015: ensure the use of leading eigenvector (MR) 27 | 28 | 29 | n = length(CIJ); 30 | if n < 1000 31 | [V,D] = eig(CIJ); 32 | else 33 | [V,D] = eigs(sparse(CIJ)); 34 | end 35 | [~,idx] = max(diag(D)); 36 | ec = abs(V(:,idx)); 37 | v = reshape(ec, length(ec), 1); -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/grDistances.m: -------------------------------------------------------------------------------- 1 | function [dSP,sp]=grDistances(E,s,t) 2 | % Function dSP=grDistances(E) find the distances 3 | % between any vertexes of graph. 4 | % Input parameter: 5 | % E(m,2) or (m,3) - the edges of graph and their weight; 6 | % 1st and 2nd elements of each row is numbers of vertexes; 7 | % 3rd elements of each row is weight of arrow; 8 | % m - number of arrows. 9 | % If we set the array E(m,2), then all weights is 1. 10 | % Output parameter: 11 | % dSP(n,n) - the symmetric matrix of destances between 12 | % all vertexes (may be dSP(i,j)=inf for disconnected graph). 13 | % [dSP,sp]=grDistances(E,s,t) - find also 14 | % the shortest path between vertexes s and t. 15 | % In this case output parameter sp is vector with numbers 16 | % of vertexes, included to shortest path between s and t. 17 | % Author: Sergii Iglin 18 | % e-mail: siglin@yandex.ru 19 | % personal page: http://iglin.exponenta.ru 20 | 21 | % ============= Input data validation ================== 22 | if nargin<1, 23 | error('There are no input data!') 24 | end 25 | [m,n,E] = grValidation(E); % E data validation 26 | 27 | Ev=[E;E(:,[2 1 3])]; % all arrows and vice versa 28 | sp=[]; 29 | if (nargin<3)|(isempty(s))|(isempty(t)), 30 | dSP=grShortPath(Ev); % the shortest path 31 | else 32 | s=s(1); 33 | t=t(1); 34 | if s==t, % the trivial way 35 | dSP=grShortPath(Ev); % the shortest path 36 | sp=s; 37 | else 38 | [dSP,sp]=grShortPath(Ev,s,t); 39 | end 40 | end 41 | dSP=dSP-diag(diag(dSP)); % we delete the main diagonal 42 | return -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/grEccentricity.m: -------------------------------------------------------------------------------- 1 | function [Ec,Rad,Diam,Cv,Pv]=grEccentricity(E) 2 | % Function Ec=grEccentricity(E) find the (weighted) 3 | % eccentricity of all vertexes of graph. 4 | % Input parameter: 5 | % E(m,2) or (m,3) - the edges of graph and their weight; 6 | % 1st and 2nd elements of each row is numbers of vertexes; 7 | % 3rd elements of each row is weight of arrow; 8 | % m - number of arrows. 9 | % If we set the array E(m,2), then all weights is 1. 10 | % Output parameter: 11 | % Ec(1,n) - the (weighted) eccentricity of all vertexes. 12 | % [Ec,Rad,Diam]=grEccentricity(E) find also the radius Rad and 13 | % diameter Diam of the graph (the scalars). 14 | % [Ec,Rad,Diam,Cv,Pv]=grEccentricity(E) find also 15 | % the center vertexes Cv and the periphery vertexes Pv 16 | % of the graph (the vector-rows with numbers of vertexes). 17 | % Author: Sergii Iglin 18 | % e-mail: siglin@yandex.ru 19 | % personal page: http://iglin.exponenta.ru 20 | 21 | if nargin<1, 22 | error('There are no input data!') 23 | end 24 | dSP=grDistances(E); % the matrix of distances 25 | Ec=max(dSP); % the eccentricity of all vertexes 26 | if nargout>=2, 27 | Rad=min(Ec); % the radius 28 | if nargout>=3, 29 | Diam=max(Ec); % the diameter 30 | if nargout>=4, 31 | Cv=find(Ec==Rad); % the center vertexes of the graph 32 | if nargout>=5, 33 | Pv=find(Ec==Diam); % the periphery vertexes of the graph 34 | end 35 | end 36 | end 37 | end 38 | return -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/grShortPath.m: -------------------------------------------------------------------------------- 1 | function [dSP,sp]=grShortPath(E,s,t) 2 | % Function dSP=grShortPath(E) solve the problem about 3 | % the shortest path between any vertexes of digraph. 4 | % Input parameter: 5 | % E(m,2) or (m,3) - the arrows of digraph and their weight; 6 | % 1st and 2nd elements of each row is numbers of vertexes; 7 | % 3rd elements of each row is weight of arrow; 8 | % m - number of arrows. 9 | % If we set the array E(m,2), then all weights is 1. 10 | % Output parameter: 11 | % dSP(n,n) - the matrix of shortest path. 12 | % Each element dSP(i,j) is the shortest path 13 | % from vertex i to vertex j (may be inf, 14 | % if vertex j is not accessible from vertex i). 15 | % Uses the algorithm of R.W.Floyd, S.A.Warshall. 16 | % [dSP,sp]=grShortPath(E,s,t) - find also 17 | % the shortest paths from vertex s (source) to vertex t (tail). 18 | % In this case output parameter sp is vector with numbers 19 | % of vertexes, included to shortest path from s to t. 20 | % Author: Sergii Iglin 21 | % e-mail: siglin@yandex.ru 22 | % personal page: http://iglin.exponenta.ru 23 | % Acknowledgements to Prof. Gerard Biau (France) 24 | % for testing of this algorithm. 25 | 26 | % ============= Input data validation ================== 27 | if nargin<1, 28 | error('There are no input data!') 29 | end 30 | [m,n,E] = grValidation(E); % E data validation 31 | 32 | % ================ Initial values =============== 33 | dSP=ones(n)*inf; % initial distances 34 | dSP((E(:,2)-1)*n+E(:,1))=E(:,3); 35 | %dSP0=dSP; 36 | % ========= The main cycle of Floyd-Warshall algorithm ========= 37 | for j=1:n, 38 | i=setdiff((1:n),j); 39 | dSP(i,i)=min(dSP(i,i),repmat(dSP(i,j),1,n-1)+repmat(dSP(j,i),n-1,1)); 40 | end 41 | sp=[]; 42 | if (nargin<3)|(isempty(s))|(isempty(t)), 43 | return 44 | end 45 | s=s(1); 46 | t=t(1); 47 | if (~(s==round(s)))|(~(t==round(t)))|(s<1)|(s>n)|(t<1)|(t>n), 48 | error(['s and t must be integer from 1 to ' num2str(n)]) 49 | end 50 | if isinf(dSP(s,t)), % t is not accessible from s 51 | return 52 | end 53 | dSP1=dSP; 54 | dSP1(1:n+1:n^2)=0; % modified dSP 55 | l=ones(m,1); % label for each arrow 56 | sp=t; % final vertex 57 | while ~(sp(1)==s), 58 | nv=find((E(:,2)==sp(1))&l); % all labeled arrows to sp(1) 59 | vnv=abs((dSP1(s,sp(1))-dSP1(s,E(nv,1)))'-E(nv,3))0)), 21 | error('1st and 2nd columns of the array E must be positive!') 22 | end 23 | if ~all(all((E(:,1:2)==round(E(:,1:2))))), 24 | error('1st and 2nd columns of the array E must be integer!') 25 | end 26 | m=se(1); 27 | if se(2)<3, % not set the weight 28 | E(:,3)=1; % all weights =1 29 | end 30 | newE=E(:,1:3); 31 | n=max(max(newE(:,1:2))); % number of vertexes 32 | return -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/kappa.m: -------------------------------------------------------------------------------- 1 | function [k] = kappa(deg) 2 | 3 | k = mean(deg)/mean(deg.^2); 4 | -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/leaf_nodes.m: -------------------------------------------------------------------------------- 1 | % Return the leaf nodes of the graph - degree 1 nodes 2 | % Note: For a directed graph, leaf nodes are those with a single incoming edge 3 | % Note 2: There could be other definitions of leaves ex: farthest away from a given root node 4 | % Note 3: Nodes with self-loops are not considered leaf nodes. 5 | % Input: adjacency matrix 6 | % Output: indexes of leaf nodes 7 | % Last updated: Mar 25, 2011, by GB 8 | 9 | function leaves=leaf_nodes(adj) 10 | 11 | adj=int8(adj>0); 12 | 13 | leaves=find(sum(adj)==1); -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/minSpanTreeKruskal.m: -------------------------------------------------------------------------------- 1 | function [T, cost] = minSpanTreeKruskal (CostMatrix) 2 | % Kruskal's algorithm for MST 3 | % CostMatrix 4 | % T is adjacency matrix 5 | % cost is overall cost of tree 6 | 7 | % This file is from pmtk3.googlecode.com 8 | 9 | 10 | %PMTKauthor Soshant Bali 11 | %PMTKurl http://www.ittc.ku.edu/~sbali/graphSoftware.htm 12 | 13 | 14 | % Extract the edge weights from the cost matrix 15 | % Sort the edges in a non decreasing order of weights 16 | n = size (CostMatrix,1); %Number of vertices 17 | EdgeWeights = 0; %Edges and corresponding weights 18 | EdgeWeightsCounter = 0; 19 | for i = 1:n 20 | for j = (i+1):n 21 | if ((CostMatrix(i,j))~=inf) 22 | EdgeWeightsCounter = EdgeWeightsCounter + 1; 23 | EdgeWeights(EdgeWeightsCounter,1) = CostMatrix(i,j); 24 | EdgeWeights(EdgeWeightsCounter,2) = i; 25 | EdgeWeights(EdgeWeightsCounter,3) = j; 26 | end 27 | end 28 | end 29 | 30 | SortedEdgeWeights = 0; 31 | SortedEdgeWeights = sortrows(EdgeWeights); 32 | % First column of SortedEdgeWeights are the weights 33 | % Second and third column are the vertices that the edges connect 34 | m = size(SortedEdgeWeights,1); % number of edges 35 | 36 | 37 | % We use the Disjoint sets data structures to detect cycle while adding new 38 | % edges. Union by Rank with path compression is implemented here. 39 | 40 | % Assign parent pointers to each vertex. Initially each vertex points to 41 | % itself. Now we have a conceptual forest of n trees representing n disjoint 42 | % sets 43 | global ParentPointer ; 44 | ParentPointer = 0; 45 | ParentPointer(1:n) = 1:n; 46 | 47 | % Assign a rank to each vertex (root of each tree). Initially all vertices 48 | % have the rank zero. 49 | TreeRank = 0; 50 | TreeRank(1:n) = 0; 51 | 52 | % Visit each edge in the sorted edges array 53 | % If the two end vertices of the edge are in different sets (no cycle), add 54 | % the edge to the set of edges in minimum spanning tree 55 | MSTreeEdges = 0; 56 | MSTreeEdgesCounter = 0; i = 1; 57 | while ((MSTreeEdgesCounter < (n-1)) && (i<=m)) 58 | % Find the roots of the trees that the selected edge's two vertices 59 | % belong to. Also perform path compression. 60 | root1=0; root2=0; temproot=0; 61 | temproot = SortedEdgeWeights(i,2); 62 | root1 = FIND_PathCompression(temproot); 63 | 64 | temproot = SortedEdgeWeights(i,3); 65 | root2 = FIND_PathCompression(temproot); 66 | 67 | if (root1 ~= root2) 68 | MSTreeEdgesCounter = MSTreeEdgesCounter + 1; 69 | MSTreeEdges(MSTreeEdgesCounter,1:3) = SortedEdgeWeights(i,:); 70 | if (TreeRank(root1)>TreeRank(root2)) 71 | ParentPointer(root2)=root1; 72 | else 73 | if (TreeRank(root1)==TreeRank(root2)) 74 | TreeRank(root2)=TreeRank(root2) + 1; 75 | end 76 | ParentPointer(root1)=root2; 77 | end 78 | end 79 | i = i + 1; 80 | end 81 | 82 | cost = sum (MSTreeEdges(:,1)); 83 | 84 | MSTreeEdgesCounter = 0; 85 | T = 0; 86 | T(1:n,1:n)=0; 87 | while (MSTreeEdgesCounter < (n-1)) 88 | MSTreeEdgesCounter = MSTreeEdgesCounter + 1; 89 | T(MSTreeEdges(MSTreeEdgesCounter,2),MSTreeEdges(MSTreeEdgesCounter,3))=1; 90 | T(MSTreeEdges(MSTreeEdgesCounter,3),MSTreeEdges(MSTreeEdgesCounter,2))=1; 91 | end 92 | end 93 | 94 | 95 | %%%%%%%%%% 96 | function [parent] = FIND_PathCompression(temproot) 97 | 98 | global ParentPointer; 99 | ParentPointer(temproot); 100 | if (ParentPointer(temproot)~=temproot) 101 | ParentPointer(temproot) = FIND_PathCompression(ParentPointer(temproot)); 102 | end 103 | parent = ParentPointer(temproot); 104 | 105 | 106 | 107 | end -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/minimal_spanning_tree.m: -------------------------------------------------------------------------------- 1 | function [links,weights]=minimal_spanning_tree(d) 2 | 3 | % [links,weights]=minimal_spanning_tree(distance_matrix/weights) 4 | % 5 | % Prim's algorithm for constructing the Minimal-Spanning Tree (MST) 6 | % from a given symmetric distance/similarity matrix 7 | % links contains the edges, i.e. pairs of nodes, which constitute the MST 8 | % weights contains the corresponding weights 9 | 10 | 11 | [N,N]=size(d);, V=[1:N];, r=1;, VT=r;, 12 | 13 | weights=zeros(1,N); links=zeros(1,N); 14 | 15 | V_VT=setdiff(V,VT); 16 | 17 | weights(V_VT)=d(r,V_VT); 18 | links(V_VT)=r; 19 | 20 | for i=1:N-2 21 | 22 | [edge_weight,u]=min(weights(V_VT)); 23 | node=V_VT(u); 24 | VT=union(VT,node); 25 | V_VT=setdiff(V,VT); 26 | 27 | for j=1:N-1-i, 28 | 29 | [weights(V_VT(j)),index]=min( [weights(V_VT(j)),d(node,V_VT(j))] );, 30 | if index == 2, links(V_VT(j))=node;, else,end 31 | 32 | 33 | end 34 | 35 | end 36 | 37 | links=[2:N; links(2:N)]'; 38 | weights=weights(2:N)'; 39 | 40 | [ignore,list]=sort(weights); 41 | links=links(list,:); weights=weights(list); -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/mst_prim.m: -------------------------------------------------------------------------------- 1 | function varargout=mst_prim(A,full,u) 2 | % MST_PRIM Compute a minimum spanning tree with Prim's algorithm 3 | % 4 | % T = mst_prim(A) computes a minimum spanning tree T using Prim's algorithm 5 | % for the spanning tree of a graph with non-negative edge weights. 6 | % 7 | % T = mst_prim(A,0) produces an MST for just the component at A containing 8 | % vertex 1. T = mst_prim(A,0,u) produces the MST for the component 9 | % containing vertex u. 10 | % 11 | % [ti tj tv] = mst_prim(...) returns the edges from the matrix and does not 12 | % convert to a sparse matrix structure. This saves a bit of work and is 13 | % required when there are 0 edge weights. 14 | % 15 | % Example: 16 | % load_gaimc_graph('airports'); % A(i,j) = negative travel time 17 | % A = -A; % convert to travel time. 18 | % A = max(A,A'); % make the travel times symmetric 19 | % T = mst_prim(A); 20 | % gplot(T,xy); % look at the minimum travel time tree in the US 21 | 22 | % David F. Gleich 23 | % Copyright, Stanford University, 2008-2009 24 | 25 | % History: 26 | % 2009-05-02: Added example 27 | 28 | % TODO: Add example 29 | 30 | if ~exist('full','var') || isempty(full), full=0; end 31 | if ~exist('target','var') || isempty(full), u=1; end 32 | 33 | if isstruct(A), 34 | rp=A.rp; ci=A.ci; ai=A.ai; 35 | check=0; 36 | else 37 | [rp ci ai]=sparse_to_csr(A); 38 | check=1; 39 | end 40 | if check && any(ai)<0, error('gaimc:prim', ... 41 | 'prim''s algorithm cannot handle negative edge weights.'); 42 | end 43 | if check && ~isequal(A,A'), error('gaimc:prim', ... 44 | 'prim''s algorithm requires an undirected graph.'); 45 | end 46 | nverts=length(rp)-1; 47 | d=Inf*ones(nverts,1); T=zeros(nverts,1); L=zeros(nverts,1); 48 | pred=zeros(1,length(rp)-1); 49 | 50 | % enter the main dijkstra loop 51 | for iter=1:nverts 52 | if iter==1, root=u; 53 | else 54 | root=mod(u+iter-1,nverts)+1; 55 | if L(v)>0, continue; end 56 | end 57 | n=1; T(n)=root; L(root)=n; % oops, n is now the size of the heap 58 | d(root) = 0; 59 | while n>0 60 | v=T(1); L(v)=-1; ntop=T(n); T(1)=ntop; n=n-1; 61 | if n>0, L(ntop)=1; end % pop the head off the heap 62 | k=1; kt=ntop; % move element T(1) down the heap 63 | while 1, 64 | i=2*k; 65 | if i>n, break; end % end of heap 66 | if i==n, it=T(i); % only one child, so skip 67 | else % pick the smallest child 68 | lc=T(i); rc=T(i+1); it=lc; 69 | if d(rc)ew 82 | d(w)=ew; pred(w)=v; 83 | % check if w is in the heap 84 | k=L(w); onlyup=0; 85 | if k==0 86 | % element not in heap, only move the element up the heap 87 | n=n+1; T(n)=w; L(w)=n; k=n; kt=w; onlyup=1; 88 | else kt=T(k); 89 | end 90 | % update the heap, move the element down in the heap 91 | while 1 && ~onlyup, 92 | i=2*k; 93 | if i>n, break; end % end of heap 94 | if i==n, it=T(i); % only one child, so skip 95 | else % pick the smallest child 96 | lc=T(i); rc=T(i+1); it=lc; 97 | if d(rc)1, % j==1 => element at top of heap 106 | j2=floor(j/2); tj2=T(j2); % parent element 107 | if d(tj2)0, nmstedges=nmstedges+1; end 121 | end 122 | ti = zeros(nmstedges,1); tj=ti; tv = zeros(nmstedges,1); 123 | k=1; 124 | for i=1:nverts 125 | if pred(i)>0, 126 | j = pred(i); 127 | ti(k)=i; tj(k)=j; 128 | for rpi=rp(i):rp(i+1)-1 129 | if ci(rpi)==j, tv(k)=ai(rpi); break; end 130 | end 131 | k=k+1; 132 | end 133 | end 134 | if nargout==1, 135 | T = sparse(ti,tj,tv,nverts,nverts); 136 | T = T + T'; 137 | varargout{1} = T; 138 | else 139 | varargout = {ti, tj, tv}; 140 | end 141 | 142 | -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/pearson.m: -------------------------------------------------------------------------------- 1 | % Calculating the Pearson coefficient for a degree sequence 2 | % INPUTs: M - matrix, square 3 | % OUTPUTs: r - Pearson coefficient 4 | % Courtesy: Dr. Daniel Whitney, circa 2006 5 | 6 | function prs = pearson(M) 7 | 8 | %calculates pearson degree correlation of M 9 | [rows,colms]=size(M); 10 | won=ones(rows,1); 11 | k=won'*M; 12 | ksum=won'*k'; 13 | ksqsum=k*k'; 14 | xbar=ksqsum/ksum; 15 | num=(won'*M-won'*xbar)*M*(M*won-xbar*won); 16 | M*(M*won-xbar*won); 17 | kkk=(k'-xbar*won).*(k'.^.5); 18 | denom=kkk'*kkk; 19 | 20 | prs=num/denom; 21 | 22 | 23 | % ALTERNATIVE ===== BETTER-DOCUMENTED ==================================== 24 | 25 | % Calculating the Pearson coefficient for a degree sequence 26 | % INPUTs: M - matrix, square 27 | % OUTPUTs: r - Pearson coefficient 28 | % source: "Assortative Mixing in Network", M.E.J. Newman, PhysRevLet 2002 29 | % GB, March 15, 2006 30 | 31 | % function r = pearson(M) 32 | % 33 | % [degs,~,~] = degrees(M); % get the total degree sequence 34 | % m = numedges(M); % number of edges in M 35 | % inc = adj2inc(M); % get incidence matrix for convience 36 | % 37 | % % j,k - remaining degrees of adjacent nodes for a given edge 38 | % % sumjk - sum of all products jk 39 | % % sumjplusk - sum of all sums j+k 40 | % % sumj2plusk2 - sum of all sums of squares j^2+k^2 41 | % 42 | % % compute sumjk, sumjplusk, sumj2plusk2 43 | % sumjk = 0; sumjplusk = 0; sumj2plusk2 = 0; 44 | % for i=1:m 45 | % [v] = find(inc(:,i)==1); 46 | % j = degs(v(1))-1; k = degs(v(2))-1; % remaining degrees of 2 end-nodes 47 | % sumjk = sumjk + j*k; 48 | % sumjplusk = sumjplusk + 0.5*(j+k); 49 | % sumj2plusk2 = sumj2plusk2 + 0.5*(j^2+k^2); 50 | % end 51 | % 52 | % % Pearson coefficient formula 53 | % r = (sumjk - sumjplusk^2/m)/(sumj2plusk2-sumjplusk^2/m); -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/simple_dijkstra.m: -------------------------------------------------------------------------------- 1 | % Implements a simple version of the Dijkstra shortest path algorithm 2 | % Returns the distance from a single vertex to all others, doesn't save the path 3 | % INPUTS: adjacency matrix (adj), start node (s) 4 | % OUTPUTS: shortest path length from start node to all other nodes 5 | % Note: works with a weighted/directed matrix 6 | % GB, Last Updated: December 13, 2004 7 | 8 | function d = simple_dijkstra(adj,s) 9 | 10 | n=length(adj); 11 | d = inf*ones(1,n); % distance s-all nodes 12 | d(s) = 0; % s-s distance 13 | T = 1:n; % node set with shortest paths not found 14 | 15 | while not(isempty(T)) 16 | [dmin,ind] = min(d(T)); 17 | for j=1:length(T) 18 | if adj(T(ind),T(j))>0 & d(T(j))>d(T(ind))+adj(T(ind),T(j)) 19 | d(T(j))=d(T(ind))+adj(T(ind),T(j)); 20 | end 21 | end 22 | T = setdiff(T,T(ind)); 23 | end -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/sparse_to_csr.m: -------------------------------------------------------------------------------- 1 | function [rp ci ai ncol]=sparse_to_csr(A,varargin) 2 | % SPARSE_TO_CSR Convert a sparse matrix into compressed row storage arrays 3 | % 4 | % [rp ci ai] = sparse_to_csr(A) returns the row pointer (rp), column index 5 | % (ci) and value index (ai) arrays of a compressed sparse representation of 6 | % the matrix A. 7 | % 8 | % [rp ci ai] = sparse_to_csr(i,j,v,n) returns a csr representation of the 9 | % index sets i,j,v with n rows. 10 | % 11 | % Example: 12 | % A=sparse(6,6); A(1,1)=5; A(1,5)=2; A(2,3)=-1; A(4,1)=1; A(5,6)=1; 13 | % [rp ci ai]=sparse_to_csr(A) 14 | % 15 | % See also CSR_TO_SPARSE, SPARSE 16 | 17 | % David F. Gleich 18 | % Copyright, Stanford University, 2008-2009 19 | 20 | % History 21 | % 2008-04-07: Initial version 22 | % 2008-04-24: Added triple array input 23 | % 2009-05-01: Added ncol output 24 | % 2009-05-15: Fixed triplet input 25 | 26 | error(nargchk(1, 5, nargin, 'struct')) 27 | retc = nargout>1; reta = nargout>2; 28 | 29 | if nargin>1 30 | if nargin>4, ncol = varargin{4}; end 31 | nzi = A; nzj = varargin{1}; 32 | if reta && length(varargin) > 2, nzv = varargin{2}; end 33 | if nargin<4, n=max(nzi); else n=varargin{3}; end 34 | nz = length(A); 35 | if length(nzi) ~= length(nzj), error('gaimc:invalidInput',... 36 | 'length of nzi (%i) not equal to length of nzj (%i)', nz, ... 37 | length(nzj)); 38 | end 39 | if reta && length(varargin) < 3, error('gaimc:invalidInput',... 40 | 'no value array passed for triplet input, see usage'); 41 | end 42 | if ~isscalar(n), error('gaimc:invalidInput',... 43 | ['the 4th input to sparse_to_csr with triple input was not ' ... 44 | 'a scalar']); 45 | end 46 | if nargin < 5, ncol = max(nzj); 47 | elseif ~isscalar(ncol), error('gaimc:invalidInput',... 48 | ['the 5th input to sparse_to_csr with triple input was not ' ... 49 | 'a scalar']); 50 | end 51 | else 52 | n = size(A,1); nz = nnz(A); ncol = size(A,2); 53 | retc = nargout>1; reta = nargout>2; 54 | if reta, [nzi nzj nzv] = find(A); 55 | else [nzi nzj] = find(A); 56 | end 57 | end 58 | if retc, ci = zeros(nz,1); end 59 | if reta, ai = zeros(nz,1); end 60 | rp = zeros(n+1,1); 61 | for i=1:nz 62 | rp(nzi(i)+1)=rp(nzi(i)+1)+1; 63 | end 64 | rp=cumsum(rp); 65 | if ~retc && ~reta, rp=rp+1; return; end 66 | for i=1:nz 67 | if reta, ai(rp(nzi(i))+1)=nzv(i); end 68 | ci(rp(nzi(i))+1)=nzj(i); 69 | rp(nzi(i))=rp(nzi(i))+1; 70 | end 71 | for i=n:-1:1 72 | rp(i+1)=rp(i); 73 | end 74 | rp(1)=0; 75 | rp=rp+1; 76 | 77 | -------------------------------------------------------------------------------- /FCLAB1.0.0/MST_params/treeHierarchy.m: -------------------------------------------------------------------------------- 1 | function [Th] = treeHierarchy(L, M, BC_max) 2 | 3 | %Tree hierarchy quantifies the tradeoff between large scale integration in 4 | %the MST and the overload of central nodes. 5 | 6 | Th = L/(2*M*BC_max); 7 | -------------------------------------------------------------------------------- /FCLAB1.0.0/eegplugin_fclab.m: -------------------------------------------------------------------------------- 1 | function vers = eegplugin_fclab(fig, try_strings, catch_strings) 2 | vers = 'FCLAB v1.0'; 3 | if nargin < 3 4 | error('eegplugin_fclab requires 3 arguments'); 5 | end 6 | 7 | menu = findobj(fig, 'tag', 'tools'); 8 | 9 | comfc = [try_strings.no_check 'EEG = pop_fclab(EEG); [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);' catch_strings.new_and_hist]; 10 | % vizfc = [try_strings.check_chanlocs 'EEG = pop_fcvisual(EEG); [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);' catch_strings.new_and_hist]; 11 | vizfc = [try_strings.no_check 'pop_fcvisual(EEG);' catch_strings.new_and_hist]; 12 | graphfc = [try_strings.no_check 'EEG = pop_fcgraph(EEG);' catch_strings.new_and_hist]; 13 | graphparamvizfc = [try_strings.no_check 'pop_fcvisual_parameters(EEG);' catch_strings.new_and_hist]; 14 | vizmst = [try_strings.no_check 'pop_fcvisual_MSTs(EEG);' catch_strings.new_and_hist]; 15 | submenu = uimenu(menu, 'Label', 'FCLAB', 'separator', 'on'); 16 | 17 | uimenu(submenu, 'label', 'Compute Functional Connectivity', 'callback', comfc); 18 | % uimenu( submenu, 'label', 'Visualize Functional Connectivity', 'callback', vizfc, 'userdata','chanloc:off'); 19 | uimenu(submenu, 'label', 'Visualize Functional Connectivity', 'callback', vizfc); 20 | uimenu(submenu, 'label', 'Graph/MST analysis', 'callback', graphfc); 21 | uimenu(submenu, 'label', 'Visualize Graph/MST parameters', 'callback', graphparamvizfc); 22 | uimenu(submenu, 'label', 'Visualize MST', 'callback', vizmst); 23 | 24 | return -------------------------------------------------------------------------------- /FCLAB1.0.0/fcgraph.m: -------------------------------------------------------------------------------- 1 | function outEEG = fcgraph(inEEG) 2 | metric = inEEG.FC.graph_prop.metric; 3 | disp('>> FCLAB: Computing graph theoretical parameters'); 4 | eval(['bands=fieldnames(inEEG.FC.' metric ');']); 5 | 6 | if(inEEG.FC.graph_prop.plus_minus) 7 | %SEPERATE THE NETWORKS 8 | for i=1:length(bands) 9 | eval(['A=inEEG.FC.' metric '.' bands{i} '.adj_matrix;']); 10 | Amin=A; 11 | Apl=A; 12 | Amin(Amin>0)=0; 13 | Amin=-Amin; 14 | Apl(Apl<0)=0; 15 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_plus=Apl;']); 16 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_minus=Amin;']); 17 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_plus_GP=fclab_graphproperties(inEEG.FC.'... 18 | metric '.' bands{i} '.adj_matrix_plus, bands{i});']); 19 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_minus_GP=fclab_graphproperties(inEEG.FC.'... 20 | metric '.' bands{i} '.adj_matrix_minus, bands{i});']); 21 | if(inEEG.FC.graph_prop.mst) 22 | eval(['[inEEG.FC.' metric '.' bands{i}... 23 | '.adj_matrix_minus_MST, inEEG.FC.' metric '.' bands{i}... 24 | '.adj_matrix_minus_MST_GP]=fclab_MST(inEEG.FC.'... 25 | metric '.' bands{i} '.adj_matrix_minus, bands{i});']); 26 | eval(['[inEEG.FC.' metric '.' bands{i}... 27 | '.adj_matrix_plus_MST, inEEG.FC.' metric '.' bands{i}... 28 | '.adj_matrix_plus_MST_GP]=fclab_MST(inEEG.FC.'... 29 | metric '.' bands{i} '.adj_matrix_plus, bands{i});']); 30 | end 31 | end 32 | 33 | if(inEEG.FC.graph_prop.symmetrize) 34 | for i=1:length(bands) 35 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_plus_sym=symmetrize(inEEG.FC.' metric '.' bands{i} '.adj_matrix_plus);']); 36 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_minus_sym=symmetrize(inEEG.FC.' metric '.' bands{i} '.adj_matrix_minus);']); 37 | 38 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_plus_sym_GP=fclab_graphproperties(inEEG.FC.'... 39 | metric '.' bands{i} '.adj_matrix_plus_sym, bands{i});']); 40 | 41 | eval(['inEEG.FC.' metric '.' bands{i} '.adj_matrix_minus_sym_GP=fclab_graphproperties(inEEG.FC.'... 42 | metric '.' bands{i} '.adj_matrix_minus_sym, bands{i});']); 43 | 44 | if(inEEG.FC.graph_prop.mst) 45 | eval(['[inEEG.FC.' metric '.' bands{i}... 46 | '.adj_matrix_minus_sym_MST, inEEG.FC.' metric '.' bands{i}... 47 | '.adj_matrix_minus_sym_MST_GP]=fclab_MST(inEEG.FC.'... 48 | metric '.' bands{i} '.adj_matrix_minus_sym, bands{i});']); 49 | eval(['[inEEG.FC.' metric '.' bands{i}... 50 | '.adj_matrix_plus_sym_MST, inEEG.FC.' metric '.' bands{i}... 51 | '.adj_matrix_plus_sym_MST_GP]=fclab_MST(inEEG.FC.'... 52 | metric '.' bands{i} '.adj_matrix_plus_sym, bands{i});']); 53 | end 54 | end 55 | end 56 | else % no plus minus 57 | %just a check 58 | if((inEEG.FC.graph_prop.threshold==1) && isempty(inEEG.FC.graph_prop.absthr) && isempty(inEEG.FC.graph_prop.propthr)) 59 | error('No Value for Threshold'); return; 60 | end 61 | 62 | if (inEEG.FC.graph_prop.threshold==1) % threshold 63 | if (~isempty(inEEG.FC.graph_prop.absthr))%abs threshold yes 64 | if (inEEG.FC.graph_prop.binarize==0) %binarize no 65 | if (inEEG.FC.graph_prop.symmetrize==0) %symmetrize no 66 | for i = 1:length(bands) 67 | eval(['inEEG.FC.' metric '.' bands{i} '.absthr_'... 68 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 69 | '=threshold_absolute(inEEG.FC.' metric '.' bands{i}... 70 | '.adj_matrix,' inEEG.FC.graph_prop.absthr ');']); 71 | 72 | eval(['inEEG.FC.' metric '.' bands{i} '.absthr_'... 73 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 74 | '_GP=fclab_graphproperties(inEEG.FC.' metric '.' bands{i} '.absthr_'... 75 | strrep(inEEG.FC.graph_prop.absthr,'.','_') ', bands{i});']); 76 | 77 | if(inEEG.FC.graph_prop.mst) 78 | eval(['[inEEG.FC.' metric '.' bands{i}... 79 | '.absthr_'... 80 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 81 | '_MST, inEEG.FC.' metric '.' bands{i}... 82 | '.absthr_'... 83 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 84 | '_MST_GP]=fclab_MST(inEEG.FC.'... 85 | metric '.' bands{i} '.absthr_'... 86 | strrep(inEEG.FC.graph_prop.absthr,'.','_') ', bands{i});']); 87 | end 88 | end 89 | else %abs threshold yes, binarize no, symmetrize yes 90 | for i=1:length(bands) 91 | % eval(['[inEEG.FC.' metric '.' bands{i} '.absthr_'... 92 | % strrep(inEEG.FC.graph_prop.absthr,'.','_') '_sym]=symmetrize(inEEG.FC.' metric '.' bands{i} '.absthr_'... 93 | % strrep(inEEG.FC.graph_prop.absthr,'.','_') ');']); 94 | 95 | eval(['[inEEG.FC.' metric '.' bands{i} '.absthr_'... 96 | strrep(inEEG.FC.graph_prop.absthr,'.','_') '_sym]=symmetrize(inEEG.FC.' metric '.' bands{i} '.adj_matrix);']); 97 | 98 | eval(['[inEEG.FC.' metric '.' bands{i} '.absthr_'... 99 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 100 | '_sym_GP]=fclab_graphproperties(inEEG.FC.' metric '.' bands{i} '.absthr_'... 101 | strrep(inEEG.FC.graph_prop.absthr,'.','_') '_sym, bands{i});']); 102 | 103 | if(inEEG.FC.graph_prop.mst) 104 | eval(['[inEEG.FC.' metric '.' bands{i}... 105 | '.absthr_'... 106 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 107 | '_sym_MST, inEEG.FC.' metric '.' bands{i}... 108 | '.absthr_'... 109 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 110 | '_sym_MST_GP]=fclab_MST(inEEG.FC.'... 111 | metric '.' bands{i} '.absthr_'... 112 | strrep(inEEG.FC.graph_prop.absthr,'.','_') '_sym, bands{i});']); 113 | end 114 | end 115 | end 116 | else %binarize 117 | if (inEEG.FC.graph_prop.symmetrize==0) %abs threshold yes, binarize yes, symmetrize no 118 | for i=1:length(bands) 119 | eval(['A=threshold_absolute(inEEG.FC.' metric '.' bands{i} ... 120 | '.adj_matrix,' inEEG.FC.graph_prop.absthr ');']); 121 | A(A~=0)=1; 122 | eval(['inEEG.FC.' metric '.' bands{i} '.bin_absthr_'... 123 | strrep(inEEG.FC.graph_prop.absthr,'.','_') '=A;']); 124 | 125 | eval(['[inEEG.FC.' metric '.' bands{i} '.bin_absthr_'... 126 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 127 | '_GP]=fclab_graphproperties(inEEG.FC.' metric '.' bands{i} '.bin_absthr_'... 128 | strrep(inEEG.FC.graph_prop.absthr,'.','_') ', bands{i});']); 129 | clear A; 130 | 131 | if(inEEG.FC.graph_prop.mst) 132 | eval(['[inEEG.FC.' metric '.' bands{i}... 133 | '.bin_absthr_'... 134 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 135 | '_MST, inEEG.FC.' metric '.' bands{i}... 136 | '.bin_absthr_'... 137 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 138 | '_MST_GP]=fclab_MST(inEEG.FC.'... 139 | metric '.' bands{i} '.bin_absthr_'... 140 | strrep(inEEG.FC.graph_prop.absthr,'.','_') ', bands{i});']); 141 | end 142 | end 143 | else %abs threshold yes, binarize yes, symmetrize yes 144 | for i=1:length(bands) 145 | eval(['A=threshold_absolute(inEEG.FC.' metric '.' bands{i} ... 146 | '.adj_matrix,' inEEG.FC.graph_prop.absthr ');']); 147 | A(A~=0)=1; 148 | eval(['inEEG.FC.' metric '.' bands{i} '.bin_absthr_'... 149 | strrep(inEEG.FC.graph_prop.absthr,'.','_') '_sym=symmetrize(A);']); 150 | 151 | eval(['inEEG.FC.' metric '.' bands{i} '.bin_absthr_'... 152 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 153 | '_sym_GP=fclab_graphproperties(inEEG.FC.' metric '.' bands{i} '.bin_absthr_'... 154 | strrep(inEEG.FC.graph_prop.absthr,'.','_') '_sym, bands{i});']); 155 | clear A; 156 | 157 | if(inEEG.FC.graph_prop.mst) 158 | eval(['[inEEG.FC.' metric '.' bands{i}... 159 | '.bin_absthr_'... 160 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 161 | '_sym_MST, inEEG.FC.' metric '.' bands{i}... 162 | '.bin_absthr_'... 163 | strrep(inEEG.FC.graph_prop.absthr,'.','_')... 164 | '_sym_MST_GP]=fclab_MST(inEEG.FC.'... 165 | metric '.' bands{i} '.bin_absthr_'... 166 | strrep(inEEG.FC.graph_prop.absthr,'.','_') '_sym, bands{i});']); 167 | end 168 | end 169 | end 170 | end 171 | end 172 | 173 | if(~isempty(inEEG.FC.graph_prop.propthr)) % Proportional threshold 174 | if (inEEG.FC.graph_prop.binarize==0) 175 | if (inEEG.FC.graph_prop.symmetrize==0) %prop threshold yes, binarize no, symmetrize no 176 | for i=1:length(bands) 177 | 178 | eval(['inEEG.FC.' metric '.' bands{i} '.propthr_'... 179 | inEEG.FC.graph_prop.propthr ... 180 | '=threshold_proportional(inEEG.FC.' metric '.'... 181 | bands{i} '.adj_matrix,' ... 182 | num2str(str2num(inEEG.FC.graph_prop.propthr)/100) ');']); 183 | 184 | eval(['inEEG.FC.' metric '.' bands{i} '.propthr_'... 185 | inEEG.FC.graph_prop.propthr '_GP=fclab_graphproperties(inEEG.FC.'... 186 | metric '.' bands{i} '.propthr_'... 187 | inEEG.FC.graph_prop.propthr ', bands{i});']); 188 | 189 | 190 | if(inEEG.FC.graph_prop.mst) 191 | eval(['[inEEG.FC.' metric '.' bands{i}... 192 | '.propthr_'... 193 | inEEG.FC.graph_prop.propthr... 194 | '_MST, inEEG.FC.' metric '.' bands{i}... 195 | '.propthr_'... 196 | inEEG.FC.graph_prop.propthr... 197 | '_MST_GP]=fclab_MST(inEEG.FC.'... 198 | metric '.' bands{i} '.propthr_'... 199 | inEEG.FC.graph_prop.propthr ', bands{i});']); 200 | end 201 | 202 | end 203 | 204 | else %prop threshold yes, binarize no, symmetrize yes 205 | for i=1:length(bands) 206 | 207 | eval(['inEEG.FC.' metric '.' bands{i} '.propthr_'... 208 | inEEG.FC.graph_prop.propthr ... 209 | '=threshold_proportional(inEEG.FC.' metric '.'... 210 | bands{i} '.adj_matrix,' ... 211 | num2str(str2num(inEEG.FC.graph_prop.propthr)/100) '_sym);']); 212 | 213 | eval(['inEEG.FC.' metric '.' bands{i} '.propthr_'... 214 | inEEG.FC.graph_prop.propthr '_sym_GP=fclab_graphproperties(inEEG.FC.'... 215 | metric '.' bands{i} '.propthr_'... 216 | inEEG.FC.graph_prop.propthr '_sym, bands{i});']); 217 | 218 | 219 | if(inEEG.FC.graph_prop.mst) 220 | eval(['[inEEG.FC.' metric '.' bands{i}... 221 | '.propthr_'... 222 | inEEG.FC.graph_prop.propthr... 223 | '_sym_MST, inEEG.FC.' metric '.' bands{i}... 224 | '.propthr_'... 225 | inEEG.FC.graph_prop.propthr... 226 | '_sym_MST_GP]=fclab_MST(inEEG.FC.'... 227 | metric '.' bands{i} '.propthr_'... 228 | inEEG.FC.graph_prop.propthr '_sym, bands{i});']); 229 | end 230 | 231 | end 232 | 233 | end 234 | 235 | else % binary 236 | if (inEEG.FC.graph_prop.symmetrize==0) %prop threshold yes, binarize yes, symmetrize no 237 | for i=1:length(bands) 238 | eval(['A=threshold_proportional(inEEG.FC.' metric '.' bands{i} ... 239 | '.adj_matrix,' num2str(str2num(inEEG.FC.graph_prop.propthr)/100) ');']); 240 | A(A~=0)=1; 241 | eval(['inEEG.FC.' metric '.' bands{i} '.bin_propthr_'... 242 | inEEG.FC.graph_prop.propthr '=A;']); 243 | 244 | eval(['inEEG.FC.' metric '.' bands{i} '.bin_propthr_'... 245 | inEEG.FC.graph_prop.propthr '_GP=fclab_graphproperties(A, bands{i});']); 246 | clear A; 247 | 248 | if(inEEG.FC.graph_prop.mst) 249 | eval(['[inEEG.FC.' metric '.' bands{i}... 250 | '.bin_propthr_'... 251 | inEEG.FC.graph_prop.propthr... 252 | '_MST, inEEG.FC.' metric '.' bands{i}... 253 | '.propthr_'... 254 | inEEG.FC.graph_prop.propthr... 255 | '_MST_GP]=fclab_MST(inEEG.FC.'... 256 | metric '.' bands{i} '.bin_propthr_'... 257 | inEEG.FC.graph_prop.propthr ', bands{i});']); 258 | end 259 | end 260 | else %prop threshold yes, binarize yes, symmetrize yes 261 | for i=1:length(bands) 262 | eval(['A=threshold_proportional(inEEG.FC.' metric '.' bands{i} ... 263 | '.adj_matrix,' num2str(str2num(inEEG.FC.graph_prop.propthr)/100) ');']); 264 | A(A~=0)=1; 265 | A=symmetrize(A); 266 | eval(['inEEG.FC.' metric '.' bands{i} '.bin_propthr_'... 267 | inEEG.FC.graph_prop.propthr '_sym=A;']); 268 | 269 | eval(['inEEG.FC.' metric '.' bands{i} '.bin_propthr_'... 270 | inEEG.FC.graph_prop.propthr '_sym_GP=fclab_graphproperties(A, bands{i});']); 271 | clear A; 272 | 273 | if(inEEG.FC.graph_prop.mst) 274 | eval(['[inEEG.FC.' metric '.' bands{i}... 275 | '.bin_propthr_'... 276 | inEEG.FC.graph_prop.propthr... 277 | '_sym_MST, inEEG.FC.' metric '.' bands{i}... 278 | '.propthr_'... 279 | inEEG.FC.graph_prop.propthr... 280 | '_sym_MST_GP]=fclab_MST(inEEG.FC.'... 281 | metric '.' bands{i} '.bin_propthr_'... 282 | inEEG.FC.graph_prop.propthr '_sym, bands{i});']); 283 | end 284 | end 285 | end 286 | end 287 | end 288 | else % no thresholding 289 | if (inEEG.FC.graph_prop.binarize==0) 290 | if (inEEG.FC.graph_prop.symmetrize==1) 291 | for i=1:length(bands) 292 | eval(['inEEG.FC.' metric '.' bands{i} ... 293 | '.adj_matrix_sym=symmetrize(inEEG.FC.' metric '.' bands{i} ... 294 | '.adj_matrix);']); 295 | 296 | eval(['inEEG.FC.' metric '.' bands{i} ... 297 | '.adj_matrix_sym_GP=fclab_graphproperties(inEEG.FC.'... 298 | metric '.' bands{i} ... 299 | '.adj_matrix_sym, bands{i});']); 300 | 301 | 302 | if(inEEG.FC.graph_prop.mst) 303 | eval(['[inEEG.FC.' metric '.' bands{i}... 304 | '.adj_matrix_sym_MST, inEEG.FC.' metric '.' bands{i}... 305 | '.adj_matrix_sym_MST_GP]=fclab_MST(inEEG.FC.'... 306 | metric '.' bands{i} '.adj_matrix_sym, bands{i});']); 307 | 308 | end 309 | 310 | end 311 | 312 | else 313 | for i=1:length(bands) 314 | eval(['inEEG.FC.' metric '.' bands{i} ... 315 | '.adj_matrix_GP=fclab_graphproperties(inEEG.FC.'... 316 | metric '.' bands{i} ... 317 | '.adj_matrix, bands{i});']); 318 | 319 | 320 | if(inEEG.FC.graph_prop.mst) 321 | eval(['[inEEG.FC.' metric '.' bands{i}... 322 | '.adj_matrix_MST, inEEG.FC.' metric '.' bands{i}... 323 | '.adj_matrix_MST_GP]=fclab_MST(inEEG.FC.'... 324 | metric '.' bands{i} '.adj_matrix, bands{i});']); 325 | end 326 | end 327 | end 328 | else 329 | error('FCLAB>>Cannot Binarize Without Threshold'); return; 330 | end 331 | end 332 | end 333 | 334 | outEEG = inEEG; 335 | -------------------------------------------------------------------------------- /FCLAB1.0.0/fclab.m: -------------------------------------------------------------------------------- 1 | % pop_fclab() - Functional Connectivity Lab for EEGLAB 2 | % 3 | % Usage: 4 | % >> OUTEEG = pop_fclab( INEEG, type ); 5 | % 6 | % Inputs: 7 | % INEEG - input EEG dataset 8 | % type - type of processing. 1 process the raw 9 | % data and 0 the ICA components. 10 | % 11 | % 12 | % Outputs: 13 | % OUTEEG - output dataset 14 | % 15 | % See also: 16 | % SAMPLE, EEGLAB 17 | 18 | % Copyright (C) 19 | % 20 | % This program is free software; you can redistribute it and/or modify 21 | % it under the terms of the GNU General Public License as published by 22 | % the Free Software Foundation; either version 2 of the License, or 23 | % (at your option) any later version. 24 | % 25 | % This program is distributed in the hope that it will be useful, 26 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 | % GNU General Public License for more details. 29 | % 30 | % You should have received a copy of the GNU General Public License 31 | % along with this program; if not, write to the Free Software 32 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | 34 | function [outEEG, com] = fclab(inEEG) 35 | if nargin < 1 36 | error('fclab: Need parameters!'); return; 37 | end 38 | outEEG = inEEG; 39 | fclab_dependences(); % check for dependences and download if necessary 40 | 41 | %check for epochs and if any compute the average 42 | if(numel(size(inEEG.data)) > 2) 43 | inEEG.data = mean(inEEG.data, 3); 44 | end 45 | 46 | % if ~strcmp(inEEG.FC.parameters.metric, 'all') 47 | eval(['outEEG=' inEEG.FC.parameters.metric '(inEEG);']); 48 | % else 49 | % eeglab_path = which('eeglab'); 50 | % eeglab_path = strrep(eeglab_path,'eeglab.m',''); 51 | % metrics_file = dir([eeglab_path 'plugins/FCLAB1.0.0/FC_metrics/fcmetric_*.m']); 52 | % 53 | % for i = 1:5 54 | % eval(['inEEG=' strrep(metrics_file(i).name,'.m','') '(inEEG);']); 55 | % end 56 | % end 57 | 58 | disp('fclab: Done!'); 59 | 60 | %% Print executed command 61 | com = sprintf('fclab( %s, %s );', inputname(1), 'params'); 62 | 63 | return 64 | -------------------------------------------------------------------------------- /FCLAB1.0.0/fclab_MST.m: -------------------------------------------------------------------------------- 1 | function [MST_net, MST_params]=fclab_MST(Matrix, band_ID) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % [MST_net, MST_params] = fclab_MST(Matrix) 4 | % 5 | % Input(s): 6 | % Matrix, Weighted matrix [nxn] 7 | % 8 | % Outputs: 9 | % MST_net, MST network using Kruskal's/Prim's algorithm 10 | % MST_params, MST's local and global parameters 11 | % 12 | % Notes: 13 | % The weighted matrix should be non-negative. 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | Matrix = double(Matrix); 17 | n = size(Matrix, 2); 18 | 19 | disp('fclab_MST: Automatically ignoring negative weights (if not already discarded)...'); 20 | Matrix(Matrix<0) = 0; %retain only positive values (for sure) 21 | 22 | tic; 23 | [MST_net.Kruskal, MST_net.cost] = minSpanTreeKruskal(1./Matrix); 24 | [MST_net.links, MST_net.weights] = minimal_spanning_tree(1./Matrix); 25 | 26 | %Compute Degree of every node 27 | MST_params.local.DEG_MST = (degrees_und(MST_net.Kruskal))'; 28 | MST_params.local.DEG_MST = MST_params.local.DEG_MST./(n-1); %normalize per Subject 29 | 30 | %Compute Betweenness centrality of every node 31 | MST_params.local.BC_MST = betweenness_wei(MST_net.Kruskal); 32 | MST_params.local.BC_MST = MST_params.local.BC_MST./((n-1)*(n-2)); 33 | 34 | %Compute Eccentricity of every node, given edges and corresponding weights 35 | E = [MST_net.links MST_net.weights]; 36 | [MST_params.local.ECC_MST(:,1), MST_params.global.rad_MST, MST_params.global.diam_MST, ~, ~] = grEccentricity(E); 37 | MST_params.local.ECC_MST = MST_params.local.ECC_MST./MST_params.global.diam_MST; 38 | 39 | %Compute some MST global metrics 40 | MST_params.global.leaves_MST = max(size(leaf_nodes(MST_net.Kruskal))); 41 | MST_params.global.leaf_fraction_MST = max(size(leaf_nodes(MST_net.Kruskal)))/(n-1); 42 | MST_params.global.Th_MST = treeHierarchy(MST_params.global.leaves_MST, n-1, max(MST_params.local.BC_MST)); 43 | MST_params.global.DEGcor_MST = pearson(MST_net.Kruskal); 44 | MST_params.global.kappa_MST = kappa(MST_params.local.DEG_MST); 45 | timer = toc; 46 | disp(['fclab_MST: Elapsed time for ', band_ID, ' band = ', num2str(timer), ' sec']); 47 | disp(' '); 48 | 49 | return; 50 | -------------------------------------------------------------------------------- /FCLAB1.0.0/fclab_dependences.m: -------------------------------------------------------------------------------- 1 | % Automatically download and add BCT, MITSE toolboxes in the plugin path 2 | eeglab_path=which('eeglab'); 3 | eeglab_path=strrep(eeglab_path,'eeglab.m',''); 4 | general_folders = dir([eeglab_path 'plugins/FCLAB1.0.0']); 5 | flag_BCT = 0; 6 | flag_MITSE = 0; 7 | addpath('MST_params'); 8 | 9 | %remove non-folders and ./.. 10 | for k = length(general_folders):-1:1 11 | if~general_folders(k).isdir 12 | general_folders(k) = []; 13 | continue 14 | end 15 | 16 | fname = general_folders(k).name; 17 | if (fname(1) == '.') 18 | general_folders(k) = [ ]; 19 | end 20 | end 21 | 22 | %search if BCT toolbox already exists 23 | for k = length(general_folders):-1:1 24 | fname = general_folders(k).name; 25 | if (strcmp(fname, 'BCT') == 1) 26 | disp('>> FCLAB: BCT toolbox found!'); 27 | BCT_version = dir([eeglab_path 'plugins/FCLAB1.0.0/BCT']); 28 | 29 | %find BCT version folder 30 | for j = length(BCT_version):-1:1 31 | if~BCT_version(j).isdir 32 | BCT_version(j) = []; 33 | continue 34 | end 35 | 36 | fname = BCT_version(j).name; 37 | if (fname(1) == '.') 38 | BCT_version(j) = [ ]; 39 | end 40 | end 41 | 42 | disp('>> FCLAB: Adding to path...'); 43 | addpath(strcat([eeglab_path 'plugins/FCLAB1.0.0/BCT/'], BCT_version.name)); 44 | flag_BCT = 1; 45 | break; 46 | end 47 | end 48 | 49 | %search if MITSE toolbox already exists 50 | for k = length(general_folders):-1:1 51 | fname = general_folders(k).name; 52 | if (strcmp(fname, 'code') == 1) 53 | disp('>> FCLAB: MIT SE toolbox found!'); 54 | disp('>> FCLAB: Adding to path...'); 55 | delete([eeglab_path 'plugins\FCLAB1.0.0\code\issymmetric.m']); %due to conflict with MATLAB's issymetric 56 | addpath([eeglab_path 'plugins\FCLAB1.0.0\code']); 57 | flag_MITSE = 1; 58 | break; 59 | end 60 | end 61 | 62 | %BCT doesn't exist - download from site and automatically unzip 63 | if(flag_BCT == 0) 64 | disp('>> FCLAB: BCT toolbox not found!'); 65 | url = 'https://sites.google.com/site/bctnet/Home/functions/BCT.zip?attredirects=0'; 66 | filename = [eeglab_path 'plugins/FCLAB1.0.0/BCT.zip']; 67 | disp(['>> FCLAB: Downloading BCT toolbox from: ', url]); 68 | websave(filename, url); 69 | disp('>> FCLAB: Unzipping...'); 70 | unzip([eeglab_path 'plugins/FCLAB1.0.0/BCT.zip'], [eeglab_path 'plugins/FCLAB1.0.0/']); 71 | folders = dir([eeglab_path 'plugins/FCLAB1.0.0/BCT']); 72 | for j = length(folders):-1:1 73 | if (~folders(j).isdir) 74 | folders(j) = []; 75 | continue 76 | end 77 | 78 | fname = folders(j).name; 79 | if (fname(1) == '.') 80 | folders(j) = [ ]; 81 | end 82 | end 83 | disp('>> FCLAB: Adding to path...'); 84 | addpath(strcat([eeglab_path 'plugins/FCLAB1.0.0/BCT/'], folders.name)); 85 | delete([eeglab_path 'plugins/FCLAB1.0.0/BCT.zip']); 86 | disp('>> FCLAB: Done...'); 87 | end 88 | 89 | %MITSE doesn't exist - download from site and automatically unzip 90 | if(flag_MITSE == 0) 91 | url = 'http://strategic.mit.edu/docs/matlab_networks/matlab_networks_routines.zip'; 92 | filename = [eeglab_path 'plugins/FCLAB1.0.0/matlab_networks_routines.zip']; 93 | disp(' '); disp(['>> FCLAB: Downloading MIT Strategic Engineering toolbox from: ', url]); 94 | websave(filename, url); 95 | disp('>> FCLAB: Unzipping...'); 96 | unzip([eeglab_path 'plugins/FCLAB1.0.0/matlab_networks_routines.zip'], [eeglab_path 'plugins/FCLAB1.0.0/']); 97 | delete([eeglab_path 'plugins/FCLAB1.0.0/code/issymmetric.m']); %due to conflict with MATLAB's issymetric 98 | disp('>> FCLAB: Adding to path...'); 99 | addpath([eeglab_path 'plugins/FCLAB1.0.0/code']); 100 | delete([eeglab_path 'plugins/FCLAB1.0.0/matlab_networks_routines.zip']); 101 | disp('>> FCLAB: Done...'); 102 | end 103 | -------------------------------------------------------------------------------- /FCLAB1.0.0/fclab_graphproperties.m: -------------------------------------------------------------------------------- 1 | function struct = fclab_graphproperties(W, band_ID) 2 | 3 | if issymmetric(W) 4 | directed = 0; 5 | else 6 | directed = 1; 7 | end 8 | 9 | if isequal(unique(W), [0;1]) 10 | weighted = 0; 11 | else 12 | weighted = 1; 13 | end 14 | 15 | struct = []; 16 | 17 | tic; 18 | if(weighted && ~directed) %weighted & undirected 19 | disp('fclab_graphproperties: Weighted and undirected graph analysis'); 20 | struct = wu(W); 21 | elseif(~weighted && ~directed) %binary & undirected 22 | disp('fclab_graphproperties: Binary and undirected graph analysis'); 23 | struct = bu(W); 24 | end 25 | timer = toc; 26 | 27 | disp(['fclab_graphproperties: Elapsed time for ', band_ID, ' band = ', num2str(timer), ' sec']); 28 | 29 | return 30 | 31 | 32 | function s = wu(C) 33 | s.global.assortativity=assortativity_wei(C,0); 34 | 35 | A = C; 36 | B = C > 0; 37 | A(B) = 1./C(B); 38 | s.length_matrix = A; 39 | 40 | s.distance = distance_wei(s.length_matrix); %distance matrix 41 | s.nodal.BC = betweenness_wei(s.length_matrix); 42 | s.nodal.BCnorm = betweenness_wei(s.length_matrix)./((size(C,1)-1)*(size(C,1)-2)); 43 | [s.global.CPL,s.global.GE,s.nodal.ECC,s.global.radius,s.global.diameter] = charpath(s.distance); 44 | s.nodal.CC = clustering_coef_wu(C); 45 | s.global.DEN = density_und(C); 46 | %[s.global.GEdiff,s.edge.Ediff] = diffusion_efficiency(C); problem check 47 | s.edge.EBC = edge_betweenness_wei(C); 48 | s.local.LE = real(efficiency_wei(C,1)); 49 | s.local.EVC = eigenvector_centrality_und(C); 50 | % [s.edge.Erange,s.global.eta,s.edge.Eshort,s.global.fs] = erange(C); %%%%%%%%%%%%Attention 51 | % [s.wlaks.Wq,s.wlaks.twalk,s.wlaks.wlq] = findwalks(C); %%%%%%%%%%%%Attention 52 | [s.edge.JointDeg,s.global.J_od,s.global.J_id,s.global.J_bl] = jdegree(C); 53 | [s.local.loc_assort_pos,s.local.loc_assort_neg] = local_assortativity_wu_sign(C); 54 | s.local.STR = strengths_und(C); 55 | return 56 | 57 | function s = bu(C) 58 | s.global.assortativity = assortativity_bin(C, 0); 59 | s.length_matrix = C; 60 | s.distance = distance_bin(s.length_matrix); %distance matrix 61 | s.nodal.BC = betweenness_bin(s.length_matrix); 62 | s.nodal.BCnorm = betweenness_bin(s.length_matrix)./((size(C,1)-1)*(size(C,1)-2)); 63 | [s.global.CPL,s.global.GE,s.nodal.ECC,s.global.radius,s.global.diameter] = charpath(s.distance); 64 | s.nodal.CC = clustering_coef_bu(C); 65 | s.global.DEN = density_und(C); 66 | s.edge.EBC = edge_betweenness_bin(C); 67 | s.local.LE = real(efficiency_bin(C,1)); 68 | s.local.EVC = eigenvector_centrality_und(C); 69 | [s.edge.Erange,s.global.eta,s.edge.Eshort,s.global.fs] = erange(C); 70 | [s.wlaks.Wq,s.wlaks.twalk,s.wlaks.wlq] = findwalks(C); 71 | [s.edge.JointDeg,s.global.J_od,s.global.J_id,s.global.J_bl] = jdegree(C); 72 | % [s.local.loc_assort_pos,s.local.loc_assort_neg] = local_assortativity_wu_sign(C); 73 | s.local.STR = strengths_und(C); 74 | return 75 | -------------------------------------------------------------------------------- /FCLAB1.0.0/headinhead/cs.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramsys28/FCLAB/68596db265cc28052928766be4b8cdf549d69d19/FCLAB1.0.0/headinhead/cs.mat -------------------------------------------------------------------------------- /FCLAB1.0.0/headinhead/cs_eeg.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramsys28/FCLAB/68596db265cc28052928766be4b8cdf549d69d19/FCLAB1.0.0/headinhead/cs_eeg.mat -------------------------------------------------------------------------------- /FCLAB1.0.0/headinhead/eeg_sens: -------------------------------------------------------------------------------- 1 | 6.4408482e-002 -1.1049192e+001 2.5250000e+000 2 | 2.5668165e+000 -1.0851257e+001 2.4870000e+000 3 | 1.6769382e-001 -9.8808062e+000 9.0560000e+000 4 | 4.7492188e+000 -9.3143916e+000 7.5660000e+000 5 | 6.5327992e+000 -7.6602184e+000 3.4030000e+000 6 | 8.7024883e-002 -7.6253207e+000 1.1281000e+001 7 | 5.6969052e+000 -7.1594569e+000 9.4230000e+000 8 | 7.9597916e+000 -5.4272344e+000 4.4330000e+000 9 | 6.9562168e-001 -4.9024289e+000 1.3146000e+001 10 | 6.4745633e+000 -4.6889839e+000 1.0861000e+001 11 | 8.6489851e+000 -2.7562770e+000 5.2400000e+000 12 | 8.7025042e-001 -2.3348552e+000 1.3898000e+001 13 | 6.6002487e+000 -2.1190547e+000 1.1715000e+001 14 | 8.7832918e+000 -4.4406017e-001 6.6510000e+000 15 | 1.4311106e+000 7.0669981e-001 1.3539000e+001 16 | 6.2405331e+000 6.4142871e-001 1.2021000e+001 17 | 7.9118160e+000 2.0216835e+000 7.5330000e+000 18 | 1.7244489e+000 5.7824667e+000 9.9680000e+000 19 | 3.9627783e+000 5.4234520e+000 9.7270000e+000 20 | -2.2274578e+000 -1.0741663e+001 2.4960000e+000 21 | -4.1119853e+000 -8.4814583e+000 7.6700000e+000 22 | -5.7855427e+000 -6.5597864e+000 3.4140000e+000 23 | -4.9019137e+000 -6.0686959e+000 9.5220000e+000 24 | -6.6951883e+000 -3.9510425e+000 4.5060000e+000 25 | -5.0116938e+000 -3.4403800e+000 1.0944000e+001 26 | -7.0269522e+000 -1.3170490e+000 5.1290000e+000 27 | -4.3638324e+000 -6.7132233e-001 1.2026000e+001 28 | -6.4363021e+000 1.0953466e+000 6.6240000e+000 29 | -3.0695638e+000 1.9034370e+000 1.2154000e+001 30 | -5.2720696e+000 3.2148307e+000 7.5830000e+000 31 | -3.9824594e-002 5.9024165e+000 9.9860000e+000 32 | -------------------------------------------------------------------------------- /FCLAB1.0.0/headinhead/locphys2locphys.m: -------------------------------------------------------------------------------- 1 | function [loc_phys,names]=locphys2locphys(loc_phys_in); 2 | % Purpose: create 'physical' locations from neoroscan-data 3 | % 4 | % usage: [loc_phys,names]=loc2locphys(fn,ind_phys,loctype) 5 | % 6 | % output: loc_phys nX5 matrix; each row contains information 7 | % about a physical electrode in the form 8 | % [channelnumber x_coord y_coord x'_coord y'_coord] 9 | % the primed coordinates differ from the 10 | % non-primed coordinates if loctype is set to 1. 11 | % Then the primed coordinates are slightly shifted to 12 | % avoid overlapping subplots in plots with subplots 13 | % placed on electrode locations. 14 | % names list of channel names 15 | % 16 | % input: fn filename of neurocan-file with electrode locations and names 17 | % ind_phys row-vector of indices which are regarded as 'physical' 18 | % i.e. electrodes on the scalp 19 | % (e.g. if we have 64 channels and channels 31,32,61,62,63,64 20 | % do not refer to electrodes on the scalp, then 21 | % ind_phys=[1:30,33:60]; 22 | % loctype if set to 1: calculate modified coordinates for plotting purposes 23 | % any other value: set the shifted locations to the original 24 | % 25 | % CC Guido Nolte 26 | 27 | ind_phys=loc_phys_in(:,1); 28 | [nphys,m]=size(ind_phys); 29 | 30 | xx=loc_phys_in(:,2); 31 | yy=loc_phys_in(:,3); 32 | 33 | 34 | xx(abs(xx)<.01)=0; 35 | yy(abs(yy)<.01)=0; 36 | 37 | % 38 | % figure 39 | % plot(xx,yy,'.'); 40 | % hold on; 41 | % for i=1:nphys 42 | % text(xx(i),yy(i),num2str(i)); 43 | % end 44 | 45 | xp=xx; 46 | yp=yy; 47 | step=.0001; 48 | mag=200; 49 | %d=.13; 50 | d=1.2*sqrt(pi/4/nphys); 51 | % [xp,yp]=plotcoordc(xx,yy,d,mag,step); 52 | % 53 | % figure 54 | % plot(xp,yp,'.'); 55 | % hold on; 56 | % for i=1:nphys 57 | % text(xp(i),yp(i),num2str(i)); 58 | % end 59 | 60 | 61 | 62 | loc_phys=[ind_phys,xx,yy,xp,yp]; 63 | 64 | 65 | return; 66 | function [xp,yp]=plotcoordc(x,y,d,mag,step); 67 | 68 | [n,m]=size(x); 69 | 70 | dx=zeros(n,1); 71 | dy=zeros(n,1); 72 | 73 | 74 | 75 | 76 | for k=1:150 77 | [x,y]=onestep(x,y,d,mag,step); 78 | [minmin,minmax]=mindis(x,y); 79 | display([k,minmin,minmax]); 80 | 81 | 82 | if round(k/1)*1==k 83 | %figure; 84 | %plot(x,y,'.'); 85 | end 86 | end 87 | xp=x;yp=y; 88 | 89 | return; 90 | 91 | function [x,y]=onestep(x,y,d,mag,step); 92 | 93 | xn=x;yn=y; 94 | [n,m]=size(x); 95 | for i=1:n 96 | fallx=0;fally=0; 97 | r=norm([x(i),y(i)])+sqrt(eps); 98 | for j=1:n 99 | if j~=i 100 | [fx,fy]=force(x(i),x(j),y(i),y(j),d,mag); 101 | fallx=fallx+fx;fally=fally+fy; 102 | end 103 | 104 | end 105 | fallx=fallx-x(i)/(r);fally=fally-y(i)/(r); 106 | 107 | if abs(x(i))>.01 108 | xn(i)=x(i)+step*fallx; 109 | end 110 | if abs(y(i))>.01 111 | yn(i)=y(i)+step*fally; 112 | end 113 | 114 | end 115 | 116 | x=xn;y=yn; 117 | 118 | return; 119 | 120 | function [fx,fy]=force(x1,x2,y1,y2,d,mag); 121 | 122 | dis=max(abs(x1-x2),abs(y1-y2)); 123 | dis=norm([x1-x2,y1-y2]); 124 | diffvec=[x2-x1;y2-y1];diffvec=diffvec/norm(diffvec); 125 | fx=0;fy=0; 126 | if dis1 7 | if isfield(pars,'rot'); 8 | rot=pars.rot; 9 | else 10 | rot=0; 11 | end 12 | if isfield(pars,'nin'); 13 | nin=pars.nin; 14 | else 15 | nin=ns_ori; 16 | end 17 | if isfield(pars,'indices'); 18 | indices=pars.indices; 19 | else 20 | indices=[1:ns_ori]'; 21 | end 22 | if isfield(pars,'circle_shift'); 23 | shift_cont=pars.circle_shift; 24 | else 25 | shift_cont=1; 26 | end 27 | 28 | else 29 | rot=0; 30 | nin=ns_ori; 31 | indices=[1:ns_ori]'; 32 | shift_cont=1; 33 | end 34 | 35 | 36 | 37 | if nin0 67 | loc_phys_sparse=locphys2locphys([[1:ns]',s2d_n]); 68 | else 69 | loc_phys_sparse=[[1:ns]',s2d_n,s2d_n]; 70 | % figure; 71 | % for i=1:ns; 72 | % text(s2d_n(i,1),s2d_n(i,2),num2str(i)); 73 | % end 74 | % axis([-.6 .6 -.6 .6]); 75 | 76 | end 77 | 78 | if nin1 27 | if lr==1 28 | locs=[-locs(:,1),locs(:,2)]; 29 | end 30 | end 31 | 32 | if nargin>2 33 | if ud==1 34 | locs=[locs(:,1),-locs(:,2)]; 35 | end 36 | end 37 | 38 | locs=locs/max(max(abs(locs)))/2; 39 | 40 | 41 | 42 | 43 | s2d=locs; 44 | 45 | return; 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /FCLAB1.0.0/headinhead/showcs.m: -------------------------------------------------------------------------------- 1 | function [out]=showcs(data,locs,pars,hp); 2 | % usage showcs(data,locs,pars); 3 | % makes head-in-head plots e.g. to show cross-spectra 4 | % data is an NxN matrix where N is the number of channels 5 | % locs is (ideally) an Nx5 matrix: 6 | % 1st column: a channel i gets a circle only if locs(i,1)>.5 7 | % if locs is an Mx5 matrix with M2 46 | if isfield(pars,'scale') 47 | scal=pars.scale; 48 | if length(scal)==1 49 | scal=[-scal scal]; 50 | end 51 | 52 | end 53 | 54 | if isfield(pars,'global_size'); 55 | global_size=pars.global_size; 56 | 57 | end 58 | if isfield(pars,'relative_size'); 59 | rel_size=pars.relative_size; 60 | 61 | end 62 | if isfield(pars,'resolution') 63 | resolution=pars.resolution; 64 | 65 | end 66 | 67 | if isfield(pars,'head_right') 68 | head_right=pars.head_right; 69 | 70 | end 71 | if isfield(pars,'head_up') 72 | head_up=pars.head_up; 73 | 74 | end 75 | if isfield(pars,'mytext') 76 | mytext=pars.mytext; 77 | 78 | end 79 | if isfield(pars,'colormap') 80 | mycolormap=pars.colormap; 81 | end 82 | 83 | 84 | end 85 | 86 | 87 | 88 | [n,m]=size(locs); 89 | locs_all=locs; 90 | [nall,ndum]=size(locs_all); 91 | ind2chan=(1:nall)'; 92 | [nc,nc]=size(data); 93 | 94 | if m==5 95 | if nc>n 96 | ind2chan=abs(locs(:,1)); 97 | end 98 | indd=ind2chan(locs(:,1)>.5); 99 | locs=locs(locs(:,1)>.5,:); 100 | end 101 | 102 | 103 | [n,m]=size(locs); 104 | if m==2; 105 | locs=[(1:n)',locs,locs]; 106 | elseif m==3 107 | locs=[locs,locs(:,2:3)]; 108 | elseif m==4 109 | locs=[(1:n)',locs]; 110 | end 111 | %ind2chan=locs(:,1); 112 | 113 | locs(:,5)=detrend(locs(:,5),0); 114 | %locs(:,4)=detrend(locs(:,4),'constant'); 115 | 116 | 117 | coor=locs(:,4:5); 118 | 119 | ymin=min(coor(:,1)); 120 | ymax=max(coor(:,1)); 121 | xmin=max(coor(:,1)); 122 | xmax=max(coor(:,1)); 123 | 124 | 125 | %minmin=mindis(coor(:,1),coor(:,2)); 126 | [minmin,minmax,meanmin]=mindis(coor(:,1),coor(:,2)); 127 | 128 | tot_scale=max(abs([xmin,xmax,ymin,ymax]))+minmin/2; 129 | tot_scale=tot_scale/1.1; 130 | locs(:,2:5)=locs(:,2:5)*.5/tot_scale; 131 | meanmin=meanmin*.5/tot_scale; 132 | 133 | 134 | no=zeros(n,1); 135 | for i=1:n 136 | no(i)=norm(coor(i,:)); 137 | end 138 | faktor=1/max(no)/2/1.3; 139 | %wfaktor=faktor*1.3 140 | wfaktor=meanmin/1.6; 141 | 142 | wfaktor=wfaktor*global_size; 143 | 144 | 145 | meanx=mean(faktor*locs(:,4)*.85+.45); 146 | meany=mean(faktor*locs(:,5)*.85+.45); 147 | 148 | rad=max(sqrt( (faktor*locs(:,4)*.85+.45-meanx).^2+(faktor*locs(:,5)*.85+.45-meany).^2 )); 149 | cirx=(rad*cos((1:1000)*2*pi/1000)+meanx)';ciry=(rad*sin((1:1000)*2*pi/1000)+meany)'; 150 | faktor=.75; 151 | faktor=faktor*global_size*rel_size; 152 | 153 | nplot=n; 154 | 155 | %set(gcf, 'Renderer', 'painters') 156 | 157 | for chan=1:n 158 | 159 | zp=data(indd(chan),ind2chan)'; 160 | 161 | %zp=z(ind2chan); 162 | 163 | 164 | 165 | 166 | %subplot(nplot,50,chan); 167 | axes('Position',[faktor*locs(chan,4)*.85+.45 faktor*(locs(chan,5)*1.+.01)+.45 wfaktor wfaktor*.088/.07],'Parent',hp); 168 | 169 | plot_elec_empty_lowres(zp,locs_all(:,2:3),scal,indd(chan),resolution); 170 | 171 | 172 | 173 | 174 | set(gca,'visible','off'); 175 | set(gca,'xTick',[]) 176 | set(gca,'yTick',[]) 177 | caxis('manual'); 178 | caxis(scal); 179 | if chan==1 180 | %set(gca,'Position',[faktor*locs(chan,4)*.85+.45 faktor*(locs(chan,5)*1.-.05)+.45 wfaktor*0.08 wfaktor*0.08]); 181 | set(gca,'Position',[faktor*locs(chan,4)*.85+.45 faktor*(locs(chan,5)*1.+.01)+.45 wfaktor*1.1 wfaktor*.088/.07]); 182 | 183 | %h1=colorbar; 184 | %set(h1,'position',[.86 .2 .04 .6]); 185 | %set(h1,'fontweight','bold','fontsize',20); 186 | end 187 | 188 | 189 | 190 | end; 191 | caxis('manual'); 192 | caxis(scal); 193 | 194 | axes('Position',[0.12 0.01 .7/.88 .99],'Parent',hp); 195 | %set(gca,'Position',[0.12 0.01 1 1]); 196 | 197 | scalx=1.0; 198 | 199 | 200 | 201 | drawhead(meanx+wfaktor/4+head_right,.45+wfaktor/4+head_up,.43,scalx); 202 | axis([ 0 1 0 1]); 203 | if length(mytext)>0 204 | text(.0, .9,mytext,'fontsize',12,'fontweight','bold'); 205 | end 206 | %text(.1,.85,figtitle,'HorizontalAlignment','center'); 207 | %title('Titel') 208 | set(gca,'visible','off'); 209 | %get(h1) 210 | %h=colorbar; 211 | %set(h,'yticklabel', 212 | 213 | %out.scale=scal; 214 | 215 | %colormap(mycolormap); 216 | 217 | return; 218 | 219 | function plot_elec_empty_lowres(z,loc,skal,chan,resolution); 220 | 221 | x=loc(:,1); 222 | y=loc(:,2); 223 | 224 | xlin = linspace(1.4*min(x),1.4*max(x),resolution); 225 | ylin = linspace(1.4*min(y),1.4*max(y),resolution); 226 | [X,Y] = meshgrid(xlin,ylin); 227 | %Z = griddata(x,y,z,X,Y,'invdist'); 228 | Z = griddata(x,y,double(z),X,Y,'v4'); 229 | 230 | 231 | % Take data within head 232 | rmax=1.1*max(sqrt(x.^2+y.^2)); 233 | mask = (sqrt(X.^2+Y.^2) <= rmax); 234 | ii = find(mask == 0); 235 | Z(ii) = NaN; 236 | 237 | 238 | surface(X,Y,zeros(size(Z)),Z,'edgecolor','none');shading interp; 239 | %caxis([ - max(abs(z)) max(abs(z))]); 240 | %disp([ - max(abs(z)) max(abs(z))]); 241 | %caxis([ -skal skal]); 242 | %disp([ -skal skal]); 243 | 244 | hold on; 245 | %plot(x,y,'.k'); 246 | axis([-rmax rmax -rmax rmax]); 247 | %colorbar; 248 | plot(loc(chan,1),loc(chan,2),'.k'); 249 | %set(gcf,'color','none'); 250 | 251 | set(gca,'xTick',[]) 252 | set(gca,'yTick',[]) 253 | plot(.985*rmax*sin((0:1000)/1000*2*pi), .985*rmax*cos((0:1000)/1000*2*pi),'linewidth',2,'color','k'); 254 | %set(gcf,'color','none'); 255 | 256 | return; 257 | 258 | function drawhead(x,y,size,scalx); 259 | 260 | cirx=(x+scalx*size*cos((1:1000)*2*pi/1000) )';ciry=(y+size*sin((1:1000)*2*pi/1000))'; 261 | 262 | plot(cirx,ciry,'k','linewidth',1); 263 | hold on; 264 | 265 | ndiff=20; 266 | plot( [x cirx(250-ndiff) ],[y+1.1*size ciry(250-ndiff)],'k','linewidth',1); 267 | plot( [x cirx(250+ndiff) ],[y+1.1*size ciry(250+ndiff)],'k','linewidth',1); 268 | 269 | 270 | return; 271 | 272 | function [minmin,minmax,meanmin]=mindis(x,y); 273 | 274 | [n,m]=size(x); 275 | 276 | minall=zeros(n,1); 277 | 278 | 279 | 280 | for i=1:n 281 | md=1.e8; 282 | for j=1:n 283 | if j~=i 284 | %dis=max( abs(x(i)-x(j)),abs(y(i)-y(j))); 285 | dis=norm([x(i)-x(j),y(i)-y(j)]); 286 | if dis.5 7 | % if locs is an Mx5 matrix with M2 38 | if isfield(pars,'scale') 39 | scal=pars.scale; 40 | if length(scal)==1 41 | scal=[-scal scal]; 42 | end 43 | else 44 | scal=[-max(max(abs(data))),max(max(abs(data)))]; 45 | end 46 | 47 | if isfield(pars,'global_size'); 48 | global_size=pars.global_size; 49 | else 50 | global_size=1; 51 | end 52 | if isfield(pars,'relative_size'); 53 | rel_size=pars.relative_size; 54 | else 55 | rel_size=1; 56 | end 57 | if isfield(pars,'resolution') 58 | resolution=pars.resolution; 59 | else 60 | resolution=25; 61 | end 62 | 63 | if isfield(pars,'head_right') 64 | head_right=pars.head_right; 65 | else 66 | head_right=0; 67 | end 68 | if isfield(pars,'head_up') 69 | head_up=pars.head_up; 70 | else 71 | head_up=0; 72 | end 73 | if isfield(pars,'mytext') 74 | mytext=pars.mytext; 75 | else 76 | mytext=''; 77 | end 78 | 79 | else 80 | scal=[-max(max(abs(data))),max(max(abs(data)))]; 81 | resolution=25; 82 | global_size=1; 83 | rel_size=1; 84 | head_right=0; 85 | head_up=0; 86 | 87 | end 88 | 89 | 90 | 91 | [n,m]=size(locs); 92 | locs_all=locs; 93 | [nall,ndum]=size(locs_all); 94 | ind2chan=(1:nall)'; 95 | [nc,nc]=size(data); 96 | 97 | if m==5 98 | if nc>n 99 | ind2chan=abs(locs(:,1)); 100 | end 101 | indd=ind2chan(locs(:,1)>.5); 102 | locs=locs(locs(:,1)>.5,:); 103 | end 104 | 105 | 106 | [n,m]=size(locs); 107 | if m==2; 108 | locs=[(1:n)',locs,locs]; 109 | elseif m==3 110 | locs=[locs,locs(:,2:3)]; 111 | elseif m==4 112 | locs=[(1:n)',locs]; 113 | end 114 | %ind2chan=locs(:,1); 115 | 116 | locs(:,5)=detrend(locs(:,5),0); 117 | %locs(:,4)=detrend(locs(:,4),'constant'); 118 | 119 | 120 | coor=locs(:,4:5); 121 | 122 | ymin=min(coor(:,1)); 123 | ymax=max(coor(:,1)); 124 | xmin=max(coor(:,1)); 125 | xmax=max(coor(:,1)); 126 | 127 | 128 | %minmin=mindis(coor(:,1),coor(:,2)); 129 | [minmin,minmax,meanmin]=mindis(coor(:,1),coor(:,2)); 130 | 131 | tot_scale=max(abs([xmin,xmax,ymin,ymax]))+minmin/2; 132 | tot_scale=tot_scale/1.1; 133 | locs(:,2:5)=locs(:,2:5)*.5/tot_scale; 134 | meanmin=meanmin*.5/tot_scale; 135 | 136 | 137 | no=zeros(n,1); 138 | for i=1:n 139 | no(i)=norm(coor(i,:)); 140 | end 141 | faktor=1/max(no)/2/1.3; 142 | %wfaktor=faktor*1.3 143 | wfaktor=meanmin/1.6; 144 | 145 | wfaktor=wfaktor*global_size; 146 | 147 | 148 | meanx=mean(faktor*locs(:,4)*.85+.45); 149 | meany=mean(faktor*locs(:,5)*.85+.45); 150 | 151 | rad=max(sqrt( (faktor*locs(:,4)*.85+.45-meanx).^2+(faktor*locs(:,5)*.85+.45-meany).^2 )); 152 | cirx=(rad*cos((1:1000)*2*pi/1000)+meanx)';ciry=(rad*sin((1:1000)*2*pi/1000)+meany)'; 153 | faktor=.75; 154 | faktor=faktor*global_size*rel_size; 155 | 156 | nplot=n; 157 | 158 | for chan=1:n 159 | zp=data(indd(chan),ind2chan)'; 160 | %zp=z(ind2chan); 161 | 162 | 163 | subplot(nplot,nplot,n*chan); 164 | 165 | % set(gca,'Position',[faktor*locs(chan,4)*.85+.45 faktor*(locs(chan,5)*1.-.05)+.45 wfaktor*0.070 wfaktor*0.088]); 166 | set(gca,'Position',[faktor*locs(chan,4)*.85+.45 faktor*(locs(chan,5)*1.+.01)+2.45 wfaktor wfaktor*.088/.07]); 167 | 168 | plot_elec_empty_lowres(zp,locs_all(:,2:3),scal,indd(chan),resolution); 169 | set(gca,'visible','off'); 170 | set(gca,'xTick',[]) 171 | set(gca,'yTick',[]) 172 | caxis('manual'); 173 | caxis(scal); 174 | if chan==1 175 | %set(gca,'Position',[faktor*locs(chan,4)*.85+.45 faktor*(locs(chan,5)*1.-.05)+.45 wfaktor*0.08 wfaktor*0.08]); 176 | set(gca,'Position',[faktor*locs(chan,4)*.85+.45 faktor*(locs(chan,5)*1.+.01)+.45 wfaktor*1.1 wfaktor*.088/.07]); 177 | 178 | %h1=colorbar; 179 | %set(h1,'position',[.85 .1 .05 .8]); 180 | %set(h1,'fontweight','bold','fontsize',20); 181 | end 182 | end; 183 | caxis('manual'); 184 | caxis(scal); 185 | subplot(nplot,nplot,1); 186 | set(gca,'Position',[0.12 0.01 .7/.88 .99]); 187 | %set(gca,'Position',[0.12 0.01 1 1]); 188 | 189 | scalx=1.0; 190 | 191 | 192 | 193 | 194 | drawhead(meanx+wfaktor/4+head_right,.45+wfaktor/4+head_up,.43,scalx); 195 | axis([ 0 1 0 1]); 196 | if length(mytext)>0 197 | text(.0, .9,mytext,'fontsize',12,'fontweight','bold'); 198 | end 199 | %text(.1,.85,figtitle,'HorizontalAlignment','center'); 200 | %title('Titel') 201 | set(gca,'visible','off'); 202 | %get(h1) 203 | %h=colorbar; 204 | %set(h,'yticklabel', 205 | 206 | return; 207 | 208 | function plot_elec_empty_lowres(z,loc,skal,chan,resolution) 209 | 210 | x=loc(:,1); 211 | y=loc(:,2); 212 | 213 | xlin = linspace(1.4*min(x),1.4*max(x),resolution); 214 | ylin = linspace(1.4*min(y),1.4*max(y),resolution); 215 | [X,Y] = meshgrid(xlin,ylin); 216 | %Z = griddata(x,y,z,X,Y,'invdist'); 217 | Z = griddata(x,y,double(z),X,Y,'nearest'); 218 | 219 | 220 | % Take data within head 221 | rmax=1.1*max(sqrt(x.^2+y.^2)); 222 | mask = (sqrt(X.^2+Y.^2) <= rmax); 223 | ii = find(mask == 0); 224 | Z(ii) = NaN; 225 | 226 | 227 | surface(X,Y,zeros(size(Z)),Z,'edgecolor','none');shading interp; 228 | %caxis([ - max(abs(z)) max(abs(z))]); 229 | %disp([ - max(abs(z)) max(abs(z))]); 230 | %caxis([ -skal skal]); 231 | %disp([ -skal skal]); 232 | 233 | hold on; 234 | %plot(x,y,'.k'); 235 | axis([-rmax rmax -rmax rmax]); 236 | %colorbar; 237 | plot(loc(chan,1),loc(chan,2),'.k'); 238 | %set(gcf,'color','none'); 239 | 240 | set(gca,'xTick',[]) 241 | set(gca,'yTick',[]) 242 | plot(.985*rmax*sin((0:1000)/1000*2*pi), .985*rmax*cos((0:1000)/1000*2*pi),'linewidth',2,'color','k'); 243 | %set(gcf,'color','none'); 244 | 245 | return; 246 | 247 | function drawhead(x,y,size,scalx); 248 | 249 | cirx=(x+scalx*size*cos((1:1000)*2*pi/1000) )';ciry=(y+size*sin((1:1000)*2*pi/1000))'; 250 | 251 | plot(cirx,ciry,'k','linewidth',1); 252 | hold on; 253 | 254 | ndiff=20; 255 | plot( [x cirx(250-ndiff) ],[y+1.1*size ciry(250-ndiff)],'k','linewidth',1); 256 | plot( [x cirx(250+ndiff) ],[y+1.1*size ciry(250+ndiff)],'k','linewidth',1); 257 | 258 | 259 | return; 260 | 261 | function [minmin,minmax,meanmin]=mindis(x,y); 262 | 263 | [n,m]=size(x); 264 | 265 | minall=zeros(n,1); 266 | 267 | 268 | 269 | for i=1:n 270 | md=1.e8; 271 | for j=1:n 272 | if j~=i 273 | %dis=max( abs(x(i)-x(j)),abs(y(i)-y(j))); 274 | dis=norm([x(i)-x(j),y(i)-y(j)]); 275 | if dis2 23 | if isfield(pars,'scale') 24 | scal=pars.scale; 25 | if length(scal)==1 26 | scal=[-scal scal]; 27 | end 28 | end 29 | if isfield(pars,'cbar') 30 | cbar=pars.cbar; 31 | end 32 | if isfield(pars,'colorbar') 33 | cbar=pars.colorbar; 34 | end 35 | if isfield(pars,'resolution') 36 | resolution=pars.resolution; 37 | end 38 | 39 | end 40 | 41 | 42 | 43 | [n,m]=size(loc); 44 | if m==2; 45 | x=loc(:,1); 46 | y=loc(:,2); 47 | else; 48 | x=loc(:,2); 49 | y=loc(:,3); 50 | end 51 | 52 | 53 | xlin = linspace(1.4*min(x),1.4*max(x),resolution); 54 | ylin = linspace(1.4*min(y),1.4*max(y),resolution); 55 | [X,Y] = meshgrid(xlin,ylin); 56 | Z = griddata(x,y,z,X,Y,'invdist'); 57 | %Z = griddata(x,y,z,X,Y,'nearest'); 58 | 59 | 60 | % Take data within head 61 | rmax=1.02*max(sqrt(x.^2+y.^2)); 62 | mask = (sqrt(X.^2+Y.^2) <= rmax); 63 | ii = find(mask == 0); 64 | Z(ii) = NaN; 65 | 66 | 67 | surface(X,Y,zeros(size(Z)),Z,'edgecolor','none');shading interp; 68 | %caxis([ - max(abs(z)) max(abs(z))]); 69 | caxis(scal); 70 | hold on; 71 | plot(x,y,'.k','markersize',2); 72 | 73 | 74 | %meanx=mean(loc(:,2)*.85+.45); 75 | %meany=mean(loc(:,3)*.85+.45); 76 | scalx=1; 77 | drawhead(0,.0,rmax,scalx); 78 | set(gca,'visible','off'); 79 | 80 | axis([-1.2*rmax 1.2*rmax -1.0*rmax 1.4*rmax]); 81 | axis equal; 82 | %axis([-1.4*rmax 1.4*rmax -1.0*rmax 1.4*rmax]); 83 | if cbar==1 84 | h=colorbar;set(h,'fontweight','bold') 85 | %P=get(h,'Position');P(1)=P(1)+.1; 86 | %set(h,'Position',P); 87 | end 88 | 89 | %plot(.985*rmax*sin((0:1000)/1000*2*pi), .985*rmax*cos((0:1000)/1000*2*pi),'linewidth',2,'color','k'); 90 | return; 91 | 92 | 93 | 94 | function drawhead(x,y,size,scalx); 95 | 96 | cirx=(x+scalx*size*cos((1:1000)*2*pi/1000) )';ciry=(y+size*sin((1:1000)*2*pi/1000))'; 97 | 98 | plot(cirx,ciry,'k','linewidth',1); 99 | hold on; 100 | 101 | ndiff=20; 102 | plot( [x cirx(250-ndiff) ],[y+1.1*size ciry(250-ndiff)],'k','linewidth',1); 103 | plot( [x cirx(250+ndiff) ],[y+1.1*size ciry(250+ndiff)],'k','linewidth',1); 104 | 105 | 106 | return; 107 | -------------------------------------------------------------------------------- /FCLAB1.0.0/headinhead/sphfit.m: -------------------------------------------------------------------------------- 1 | function [center,radius]=sphfit(vc) 2 | % fits a sphere to a set of surface points 3 | % 4 | % input: 5 | % vc nx3 matrix, where each row represents the location 6 | % of one surface point. vc can have more than 3 columns 7 | % (e.g. orientations) - then only the first 3 columns are used 8 | % 9 | % center 1x3 vector denoting the center 10 | % radius scalar denoting the radius 11 | 12 | vc=vc(:,1:3); 13 | [nvc,ndum]=size(vc); 14 | 15 | center_0=mean(vc); 16 | vcx=vc-repmat(center_0,nvc,1); 17 | radius_0=mean(sqrt(vcx(:,1).^2+vcx(:,2).^2+vcx(:,3).^2)); 18 | 19 | alpha=1; 20 | err_0=costfun(vc,center_0,radius_0); 21 | 22 | for k=1:5; 23 | 24 | [center_new,radius_new]=lm1step(vc,center_0,radius_0,alpha); 25 | 26 | err_new=costfun(vc,center_new,radius_new); 27 | %disp([k,err_0,err_new,center_new,radius_new]); 28 | 29 | if err_new> OUTEEG = pop_fclab( INEEG, type ); 6 | % 7 | % Inputs: 8 | % INEEG - input EEG dataset 9 | % type - type of processing. 1 process the raw 10 | % data and 0 the ICA components. 11 | % 12 | % 13 | % Outputs: 14 | % OUTEEG - output dataset 15 | % 16 | % See also: 17 | % SAMPLE, EEGLAB 18 | 19 | % Copyright (C) 20 | % 21 | % This program is free software; you can redistribute it and/or modify 22 | % it under the terms of the GNU General Public License as published by 23 | % the Free Software Foundation; either version 2 of the License, or 24 | % (at your option) any later version. 25 | % 26 | % This program is distributed in the hope that it will be useful, 27 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | % GNU General Public License for more details. 30 | % 31 | % You should have received a copy of the GNU General Public License 32 | % along with this program; if not, write to the Free Software 33 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 34 | 35 | function [outEEG, com] = pop_fcgraph(inEEG) 36 | 37 | % the command output is a hidden output that does not have to 38 | % be described in the header 39 | 40 | com = ''; % this initialization ensure that the function will return something 41 | % if the user press the cancel button 42 | 43 | if(isfield(inEEG, 'FC') == 0) 44 | error('Run a graph analysis first!'); return; 45 | end 46 | 47 | temEEG = inEEG; 48 | 49 | %maintain only those fields that are related to the fcmetrics 50 | eeglab_path = which('eeglab'); 51 | eeglab_path = strrep(eeglab_path,'eeglab.m',''); 52 | metrics_file = dir([eeglab_path 'plugins/FCLAB1.0.0/FC_metrics/fcmetric_*.m']); 53 | for i = 1:length(metrics_file) 54 | measure_full = metrics_file(i,:).name; 55 | fcmetrics{i} = measure_full(10:end-2); 56 | end 57 | 58 | if(isfield(temEEG.FC, 'parameters')) 59 | temEEG.FC = rmfield(temEEG.FC, {'parameters'}); 60 | end 61 | 62 | if(isfield(temEEG.FC, 'graph_prop')) 63 | temEEG.FC = rmfield(temEEG.FC, {'graph_prop'}); 64 | end 65 | 66 | matrices = fieldnames(temEEG.FC); 67 | 68 | %clear any past graph analysis results 69 | metrics = intersect(fields(inEEG.FC), fcmetrics); 70 | bands = fieldnames(inEEG.FC.(metrics{1})); 71 | GP_fields = fieldnames(inEEG.FC.(metrics{1}).(bands{1})); 72 | previous_GP_fields_indx = find(~strcmp(GP_fields, 'adj_matrix')); 73 | previous_GP_fields = GP_fields(previous_GP_fields_indx); 74 | 75 | for i = 1:length(metrics) 76 | for j = 1:length(bands) 77 | for k = 1:length(previous_GP_fields) 78 | inEEG.FC.(metrics{i}).(bands{j}) = rmfield(inEEG.FC.(metrics{i}).(bands{j}), previous_GP_fields{k}); 79 | end 80 | end 81 | end 82 | %end 83 | 84 | clear temEEG; 85 | 86 | if nargin < 3 87 | g = [1 1]; 88 | geometry = { [g] [g 1] [g 1] [g 1]}; 89 | uilist = { ... 90 | { 'Style', 'text', 'string', 'Choose FC matrix', 'fontweight', 'bold' } ... 91 | { 'Style', 'popupmenu', 'string', matrices 'tag' 'metric'}... 92 | { 'Style', 'checkbox', 'string' 'Threshold?' 'value' 0 'tag' 'threshold' 'Callback', @popupCallback_threshquest} ... 93 | { 'Style', 'checkbox', 'string' 'MST?' 'value' 0 'tag' 'mst'}... 94 | { 'Style', 'checkbox', 'string' '+/-' 'value' 0 'tag' 'plus_minus' 'Callback', @popupCallback_plusminus} ... 95 | { 'Style', 'text', 'string', 'Absolute Threshold', 'visible' 'off' 'tag' 'absthr_label' } ... 96 | { 'Style', 'edit', 'string', '' 'tag' 'absthr' 'visible' 'off' } ... 97 | { 'Style', 'checkbox', 'string' 'Symmetrize?' 'value' 0 'tag' 'symmetrize'} ... 98 | { 'Style', 'text', 'string', 'Proportional Threshold (%)', 'visible' 'off' 'tag' 'prop_label' } ... 99 | { 'Style', 'edit', 'string', '' 'tag' 'propthr' 'visible' 'off' } ... 100 | { 'Style', 'checkbox', 'string' 'Binarize?' 'value' 0 'tag' 'binarize' 'Callback', @popupCallback_binarize} ... 101 | }; 102 | 103 | [ tmp1 tmp2 strhalt structout ] = inputgui(geometry, uilist, ... 104 | 'pophelp(''pop_fclab'');', 'Functional Connectivity Lab'); 105 | 106 | inEEG.FC.graph_prop=structout; 107 | clear inEEG.FC.graph_prop.metric 108 | inEEG.FC.graph_prop.metric = matrices{structout.metric}; 109 | 110 | outEEG = fcgraph(inEEG); 111 | else 112 | error('Too many inputs'); 113 | end 114 | 115 | 116 | % return the string command 117 | % ------------------------- 118 | com = sprintf('pop_fcgraph( %s);', inputname(1)); 119 | 120 | return 121 | 122 | 123 | function popupCallback_threshquest(obj,event) 124 | if obj.Value==1 125 | handle = findobj('Tag', 'absthr'); 126 | handle(1).Visible='on'; 127 | handle = findobj('Tag', 'absthr_label'); 128 | handle(1).Visible='on'; 129 | handle = findobj('Tag', 'propthr'); 130 | handle(1).Visible='on'; 131 | handle = findobj('Tag', 'prop_label'); 132 | handle(1).Visible='on'; 133 | handle = findobj('Tag', 'binarize'); 134 | handle(1).Visible='on'; 135 | handle = findobj('Tag', 'plus_minus'); 136 | handle(1).Value = 0; 137 | else 138 | handle = findobj('Tag', 'absthr'); 139 | handle(1).Visible='off'; 140 | handle = findobj('Tag', 'absthr_label'); 141 | handle(1).Visible='off'; 142 | handle = findobj('Tag', 'propthr'); 143 | handle(1).Visible='off'; 144 | handle = findobj('Tag', 'prop_label'); 145 | handle(1).Visible='off'; 146 | handle = findobj('Tag', 'binarize'); 147 | handle(1).Value = 0; 148 | end 149 | return 150 | 151 | function popupCallback_plusminus(obj, event) 152 | handle = findobj('Tag', 'threshold'); 153 | if handle(1).Value == 1 154 | handle(1).Value = 0; 155 | popupCallback_threshquest(handle(1),event); 156 | else 157 | popupCallback_threshquest(handle(1),event); 158 | end 159 | return 160 | 161 | function popupCallback_binarize(obj,event) 162 | handle = findobj('Tag', 'plus_minus'); 163 | handle(1).Value = 0; 164 | return 165 | -------------------------------------------------------------------------------- /FCLAB1.0.0/pop_fclab.m: -------------------------------------------------------------------------------- 1 | 2 | % pop_fclab() - Functional Connectivity Lab for EEGLAB 3 | % 4 | % Usage: 5 | 6 | % >> OUTEEG = pop_fclab( INEEG, type ); 7 | % 8 | % Inputs: 9 | % INEEG - input EEG dataset 10 | % type - type of processing. 1 process the raw 11 | % data and 0 the ICA components. 12 | % 13 | % 14 | % Outputs: 15 | % OUTEEG - output dataset 16 | % 17 | % See also: 18 | % SAMPLE, EEGLAB 19 | 20 | % Copyright (C) 21 | % 22 | % This program is free software; you can redistribute it and/or modify 23 | % it under the terms of the GNU General Public License as published by 24 | % the Free Software Foundation; either version 2 of the License, or 25 | % (at your option) any later version. 26 | % 27 | % This program is distributed in the hope that it will be useful, 28 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | % GNU General Public License for more details. 31 | % 32 | % You should have received a copy of the GNU General Public License 33 | % along with this program; if not, write to the Free Software 34 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 35 | 36 | function [outEEG, com] = pop_fclab(inEEG) 37 | 38 | % the command output is a hidden output that does not have to 39 | % be described in the header 40 | 41 | com = ''; % this initialization ensure that the function will return something 42 | % if the user press the cancel button 43 | 44 | 45 | typeproc=1; 46 | % pop up window 47 | % ------------- 48 | 49 | eeglab_path = which('eeglab'); 50 | eeglab_path = strrep(eeglab_path,'eeglab.m',''); 51 | metrics_file = dir([eeglab_path 'plugins/FCLAB1.0.0/FC_metrics/fcmetric_*.m']); 52 | metrics = []; 53 | for i = length(metrics_file):-1:1 54 | fcmetrics(i,1)={strrep(strrep(metrics_file(i).name,'fcmetric_',''),'.m','')}; 55 | metrics=strcat(metrics, strrep(strrep(metrics_file(i).name,'fcmetric_',''),'.m','')); 56 | metrics=strcat(metrics,'|'); 57 | end 58 | metrics = metrics(1:end-1); 59 | 60 | %clear any past connectivity or/and graph analysis results 61 | if(isfield(inEEG, 'FC')) 62 | existing_metric = intersect(fieldnames(inEEG.FC), fcmetrics); 63 | inEEG.FC = rmfield(inEEG.FC, existing_metric); 64 | 65 | if(isfield(inEEG, 'parameters')) 66 | inEEG.FC = rmfield(inEEG.FC, 'parameters'); 67 | end 68 | 69 | if(isfield(inEEG, 'graph_prop')) 70 | inEEG.FC = rmfield(inEEG.FC, 'graph_prop'); 71 | end 72 | end 73 | 74 | if nargin < 3 75 | g = [1 1 1]; 76 | geometry = { [g] [g 1] [g 1] [g 1] [g 1] [g 1] [g 1] [g 1] [g 1] [g 1] [g 1]}; 77 | uilist = { ... 78 | { 'Style', 'text', 'string', 'Choose Metric', 'fontweight', 'bold' } ... 79 | { 'Style', 'popupmenu', 'string', metrics 'tag' 'metric' 'Callback', @popupCallback_drp}... 80 | { 'Style', 'text', 'string', ' '} ... 81 | { 'Style', 'text', 'string', 'Brainwaves', 'fontweight', 'bold' }... 82 | { 'Style', 'text', 'string', 'Frequency [low high]', 'fontweight', 'bold' }... 83 | { 'Style', 'text', 'string', 'Name (delta, theta)', 'fontweight', 'bold' }... 84 | { 'Style', 'checkbox', 'string' 'Auto Compete' 'value' 0 'tag' 'auto_cmpl' 'Callback', @popupCallback_autocmpl} ... 85 | { 'Style', 'text', 'string', 'Frequency Band1 [low high]', } ... 86 | { 'Style', 'edit', 'string', '' 'tag' 'frb1'} ... 87 | { 'Style', 'edit', 'string', '' 'tag' 'frb1_name'} {} ... 88 | { 'Style', 'text', 'string', 'Frequency Band2 [low high]', } ... 89 | { 'Style', 'edit', 'string', '' 'tag' 'frb2'} ... 90 | { 'Style', 'edit', 'string', '' 'tag' 'frb2_name'} { } ... 91 | { 'Style', 'text', 'string', 'Frequency Band3 [low high]', } ... 92 | { 'Style', 'edit', 'string', '' 'tag' 'frb3'} ... 93 | { 'Style', 'edit', 'string', '' 'tag' 'frb3_name'} { }... 94 | { 'Style', 'text', 'string', 'Frequency Band4 [low high]', } ... 95 | { 'Style', 'edit', 'string', '' 'tag' 'frb4'} ... 96 | { 'Style', 'edit', 'string', '' 'tag' 'frb4_name'} {} ... 97 | { 'Style', 'text', 'string', 'Frequency Band5 [low high]', } ... 98 | { 'Style', 'edit', 'string', '' 'tag' 'frb5'} ... 99 | { 'Style', 'edit', 'string', '' 'tag' 'frb5_name'} {}... 100 | { 'Style', 'text', 'string', 'Frequency Band6 [low high]', } ... 101 | { 'Style', 'edit', 'string', '' 'tag' 'frb6'} ... 102 | { 'Style', 'edit', 'string', '' 'tag' 'frb6_name'} {} ... 103 | { 'Style', 'text', 'string', 'Frequency Band7 [low high]', } ... 104 | { 'Style', 'edit', 'string', '' 'tag' 'frb7'} ... 105 | { 'Style', 'edit', 'string', '' 'tag' 'frb7_name'} {}... 106 | { 'Style', 'text', 'string', 'Frequency Band8 [low high]', } ... 107 | { 'Style', 'edit', 'string', '' 'tag' 'frb8'} ... 108 | { 'Style', 'edit', 'string', '' 'tag' 'frb8_name'} {} ... 109 | { 'Style', 'text', 'string', 'Frequency Band9 [low high]', } ... 110 | { 'Style', 'edit', 'string', '' 'tag' 'frb9'} ... 111 | { 'Style', 'edit', 'string', '' 'tag' 'frb9_name'} {} ... 112 | 113 | }; 114 | 115 | [ tmp1 tmp2 strhalt structout ] = inputgui(geometry, uilist, ... 116 | 'pophelp(''pop_fclab'');', 'Functional Connectivity Lab'); 117 | else 118 | error('Too many inputs'); 119 | end 120 | 121 | map = (length(metrics_file):-1:1); 122 | structout.metric = map(structout.metric); 123 | 124 | inEEG.FC.parameters.metric = strrep(metrics_file(structout.metric).name,'.m',''); 125 | 126 | % if (structout.metric_all == 1) 127 | % inEEG.FC.parameters.metric = 'all'; 128 | % end 129 | 130 | fields = fieldnames(structout); 131 | k = 1; 132 | if prod([isempty(structout.frb1),isempty(structout.frb2),isempty(structout.frb3),... 133 | isempty(structout.frb4),isempty(structout.frb5),isempty(structout.frb6),... 134 | isempty(structout.frb7),isempty(structout.frb8),isempty(structout.frb9)]) 135 | error('Please fill a specific bandwidth or click to Auto Complete'); 136 | else 137 | inEEG.FC.parameters.bands = []; 138 | for i = 3:2:20 139 | if ~isempty(getfield(structout,fields{i})) 140 | inEEG.FC.parameters.bands{k,1} = getfield(structout,fields{i}); 141 | inEEG.FC.parameters.bands{k,2} = getfield(structout,fields{i+1}); 142 | k = k+1; 143 | end 144 | end 145 | end 146 | 147 | [outEEG, com] = fclab(inEEG); 148 | 149 | % return the string command 150 | % ------------------------- 151 | com = sprintf('pop_fclab( %s);', inputname(1)); 152 | 153 | return 154 | 155 | % callback for the drop-down menu 156 | function popupCallback_drp(obj,event) 157 | if ((obj.Value==3) || (obj.Value==5)) 158 | msgbox('Plase note that this similarity measure might be influenced by volume conduction!', 'Notification', 'warn'); 159 | end 160 | return 161 | 162 | % function popupCallback_all(obj,event) 163 | % if (obj.Value == 1) 164 | % handle = findobj('Tag', 'metric'); 165 | % set(handle,'Visible','Off') 166 | % else 167 | % handle = findobj('Tag', 'metric'); 168 | % set(handle,'Visible','On') 169 | % end 170 | % return 171 | 172 | 173 | function popupCallback_autocmpl(obj,event) 174 | if (obj.Value == 1) 175 | set(findobj('Tag', 'frb1'),'String','[0.5 4]'); 176 | set(findobj('Tag', 'frb1_name'),'String','Delta'); 177 | set(findobj('Tag', 'frb2'),'String','[4 8]'); 178 | set(findobj('Tag', 'frb2_name'),'String','Theta'); 179 | set(findobj('Tag', 'frb3'),'String','[8 10]'); 180 | set(findobj('Tag', 'frb3_name'),'String','Alpha1'); 181 | set(findobj('Tag', 'frb4'),'String','[10 12]'); 182 | set(findobj('Tag', 'frb4_name'),'String','Alpha2'); 183 | set(findobj('Tag', 'frb5'),'String','[13 30]'); 184 | set(findobj('Tag', 'frb5_name'),'String','Beta'); 185 | set(findobj('Tag', 'frb6'),'String','[30 45]'); 186 | set(findobj('Tag', 'frb6_name'),'String','Gamma'); 187 | set(findobj('Tag', 'frb7'),'String','[0.5 45]'); 188 | set(findobj('Tag', 'frb7_name'),'String','All Spectrum'); 189 | else 190 | set(findobj('Tag', 'frb1'),'String',' '); 191 | set(findobj('Tag', 'frb1_name'),'String',' '); 192 | set(findobj('Tag', 'frb2'),'String',' '); 193 | set(findobj('Tag', 'frb2_name'),'String',' '); 194 | set(findobj('Tag', 'frb3'),'String',' '); 195 | set(findobj('Tag', 'frb3_name'),'String',' '); 196 | set(findobj('Tag', 'frb4'),'String',' '); 197 | set(findobj('Tag', 'frb4_name'),'String',' '); 198 | set(findobj('Tag', 'frb5'),'String',' '); 199 | set(findobj('Tag', 'frb5_name'),'String',' '); 200 | set(findobj('Tag', 'frb6'),'String',' '); 201 | set(findobj('Tag', 'frb6_name'),'String',' '); 202 | set(findobj('Tag', 'frb7'),'String',' '); 203 | set(findobj('Tag', 'frb7_name'),'String',' '); 204 | end 205 | return 206 | -------------------------------------------------------------------------------- /FCLAB1.0.0/pop_fcvisual.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramsys28/FCLAB/68596db265cc28052928766be4b8cdf549d69d19/FCLAB1.0.0/pop_fcvisual.fig -------------------------------------------------------------------------------- /FCLAB1.0.0/pop_fcvisual.m: -------------------------------------------------------------------------------- 1 | function varargout = pop_fcvisual(varargin) 2 | % POP_FCVISUAL MATLAB code for pop_fcvisual.fig 3 | % POP_FCVISUAL, by itself, creates a new POP_FCVISUAL or raises the existing 4 | % singleton*. 5 | % 6 | % H = POP_FCVISUAL returns the handle to a new POP_FCVISUAL or the handle to 7 | % the existing singleton*. 8 | % 9 | % POP_FCVISUAL('CALLBACK',hObject,eventData,handles,...) calls the local 10 | % function named CALLBACK in POP_FCVISUAL.M with the given input arguments. 11 | % 12 | % POP_FCVISUAL('Property','Value',...) creates a new POP_FCVISUAL or raises the 13 | % existing singleton*. Starting from the left, property value pairs are 14 | % applied to the GUI before pop_fcvisual_OpeningFcn gets called. An 15 | % unrecognized property name or invalid value makes property application 16 | % stop. All inputs are passed to pop_fcvisual_OpeningFcn via varargin. 17 | % 18 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 19 | % instance to run (singleton)". 20 | % 21 | % See also: GUIDE, GUIDATA, GUIHANDLES 22 | 23 | % Edit the above text to modify the response to help pop_fcvisual 24 | 25 | % Last Modified by GUIDE v2.5 04-Sep-2017 14:17:42 26 | 27 | % Begin initialization code - DO NOT EDIT 28 | gui_Singleton = 1; 29 | gui_State = struct('gui_Name', mfilename, ... 30 | 'gui_Singleton', gui_Singleton, ... 31 | 'gui_OpeningFcn', @pop_fcvisual_OpeningFcn, ... 32 | 'gui_OutputFcn', @pop_fcvisual_OutputFcn, ... 33 | 'gui_LayoutFcn', [] , ... 34 | 'gui_Callback', []); 35 | if nargin && ischar(varargin{1}) 36 | gui_State.gui_Callback = str2func(varargin{1}); 37 | end 38 | 39 | if nargout 40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 41 | else 42 | gui_mainfcn(gui_State, varargin{:}); 43 | end 44 | % End initialization code - DO NOT EDIT 45 | 46 | 47 | % --- Executes just before pop_fcvisual is made visible.a 48 | function pop_fcvisual_OpeningFcn(hObject, eventdata, handles, varargin) 49 | % This function has no output args, see OutputFcn. 50 | % hObject handle to figure 51 | % eventdata reserved - to be defined in a future version of MATLAB 52 | % handles structure with handles and user data (see GUIDATA) 53 | % varargin command line arguments to pop_fcvisual (see VARARGIN) 54 | 55 | a=varargin{1}; 56 | handles.popupmenu1.UserData=a; 57 | handles.pushbutton2.UserData=a; 58 | handles.popupmenu3.UserData=a; 59 | handles.pushbutton3.UserData=a; 60 | handles.pushbutton4.UserData=a; 61 | handles.slider1.UserData=a; 62 | % Choose default command line output for pop_fcvisual 63 | 64 | % colormaps -- start 65 | eeglab_path=which('eeglab'); 66 | eeglab_path=strrep(eeglab_path,'eeglab.m',''); 67 | s=dir(fullfile(eeglab_path,'plugins','FCLAB1.0.0','FC_colormap','fccolor*.m')); 68 | colors=[]; 69 | for i=1:length(s) 70 | aa=strsplit(s(i).name,'_'); 71 | col=aa{1,2}; 72 | colors{i,1}=col(1:end-2); 73 | clear aa col 74 | end 75 | set(handles.popupmenu1, 'String', colors); 76 | % colormaps -- end 77 | 78 | set(gcf, 'units', 'normalized', 'outerposition', [0 0 1 1]); 79 | fieldnames = fields(a.FC); 80 | % fieldnames(strcmp(fieldnames,'parameters'))=[]; 81 | 82 | %maintain only those fields that are related to the fcmetrics 83 | metrics_file = dir([eeglab_path 'plugins/FCLAB1.0.0/FC_metrics/fcmetric_*.m']); 84 | 85 | for i = 1:length(metrics_file) 86 | measure_full = metrics_file(i,:).name; 87 | fcmetrics{i} = measure_full(10:end-2); 88 | end 89 | 90 | fieldnames = intersect(fields(a.FC), fcmetrics); 91 | 92 | if isempty(fieldnames) 93 | error('FCLAB: Compute first a connectivity matrix'); return; 94 | else 95 | handles.popupmenu2.String=fieldnames; 96 | fieldnames_freq=fields(a.FC.(fieldnames{1})); 97 | handles.popupmenu3.String=fieldnames_freq; 98 | 99 | axes(handles.axes1); 100 | imagesc(a.FC.(fieldnames{1}).(fieldnames_freq{1}).adj_matrix); 101 | hold all 102 | handles.axes1.XTick=[1:a.nbchan]; 103 | chanlabels=[]; 104 | 105 | for i=1:a.nbchan 106 | chanlabels{i,1}=a.chanlocs(i).labels; 107 | end 108 | 109 | handles.axes1.XTickLabel=chanlabels; 110 | handles.axes1.XTickLabelRotation=90; 111 | handles.axes1.Visible='on'; 112 | handles.axes1.YTick=handles.axes1.XTick; 113 | handles.axes1.YTickLabel=chanlabels; 114 | 115 | if ~isempty(a.chanlocs) 116 | ds.chanPairs=[]; 117 | ds.connectStrength=[]; 118 | 119 | for i=1:a.nbchan-1 120 | for j=i+1:a.nbchan 121 | ds.chanPairs=[ds.chanPairs; i j]; 122 | ds.connectStrength=[ds.connectStrength... 123 | a.FC.(fieldnames{1}).(fieldnames_freq{1}).adj_matrix(i,j)]; 124 | end 125 | end 126 | 127 | handles.ds = ds;%!!! 128 | axes(handles.axes2); 129 | eval(['topoplot_connect(ds,a.chanlocs,fccolor_' handles.popupmenu1.String{handles.popupmenu1.Value} '(64));']); 130 | handles.axes2.Visible='off'; %!!! 131 | colormap(eval(['fccolor_' handles.popupmenu1.String{handles.popupmenu1.Value} '(64);'])); 132 | para.rot=90; 133 | locs(:,1)=cell2mat({a.chanlocs.X}); 134 | locs(:,2)=cell2mat({a.chanlocs.Y}); 135 | locs(:,3)=cell2mat({a.chanlocs.Z}); 136 | locs_2D=mk_sensors_plane(locs,para); 137 | 138 | hp=handles.uipanel2; 139 | showcs(a.FC.(fieldnames{1}).(fieldnames_freq{1}).adj_matrix,locs_2D,para,hp); 140 | 141 | hp.Visible='on'; 142 | 143 | 144 | handles.slider1.Min=min(min(a.FC.(fieldnames{1}).(fieldnames_freq{1}).adj_matrix)); 145 | handles.slider1.Max=max(max(a.FC.(fieldnames{1}).(fieldnames_freq{1}).adj_matrix)); 146 | handles.slider1.Max=handles.slider1.Max-eps; 147 | handles.slider1.Value=handles.slider1.Min; 148 | 149 | handles.edit1.String=num2str(handles.slider1.Value); 150 | set(gcf, 'units', 'normalized', 'outerposition', [0 0 1 1]); 151 | 152 | axes(handles.axes7); 153 | colormap(handles.popupmenu1.String{handles.popupmenu1.Value}); 154 | colorbar('south'); 155 | set(gca, 'CLim', [handles.slider1.Min handles.slider1.Max]); 156 | handles.UserData=a; 157 | else 158 | error('fcvisual: need channels for topoplot!'); return; 159 | end 160 | end 161 | 162 | % Update handles structure 163 | guidata(hObject, handles); 164 | 165 | 166 | %G = evalin('base', 'EEG.FC.Correlation.adj_matrix'); 167 | %axes(handles.axes1); 168 | %imagesc(double(G)); colormap(jet); colorbar; 169 | 170 | % UIWAIT makes pop_fcvisual wait for user response (see UIRESUME) 171 | % uiwait(handles.figure1); 172 | 173 | 174 | % --- Outputs from this function are returned to the command line. 175 | function varargout = pop_fcvisual_OutputFcn(hObject, eventdata, handles) 176 | % varargout cell array for returning output args (see VARARGOUT); 177 | % hObject handle to figure 178 | % eventdata reserved - to be defined in a future version of MATLAB 179 | % handles structure with handles and user data (see GUIDATA) 180 | 181 | % Get default command line output from handles structure 182 | %varargout{1} = handles.output; 183 | set(gcf, 'units', 'normalized', 'outerposition', [0 0 1 1]); 184 | 185 | 186 | function edit1_Callback(hObject, eventdata, handles) 187 | % hObject handle to edit1 (see GCBO) 188 | % eventdata reserved - to be defined in a future version of MATLAB 189 | % handles structure with handles and user data (see GUIDATA) 190 | 191 | % Hints: get(hObject,'String') returns contents of edit1 as text 192 | % str2double(get(hObject,'String')) returns contents of edit1 as a double 193 | handles.slider1.Value=str2num(hObject.String); 194 | slider1_Callback(handles.slider1, eventdata, handles); 195 | guidata(hObject, handles); 196 | 197 | % --- Executes during object creation, after setting all properties. 198 | function edit1_CreateFcn(hObject, eventdata, handles) 199 | % hObject handle to edit1 (see GCBO) 200 | % eventdata reserved - to be defined in a future version of MATLAB 201 | % handles empty - handles not created until after all CreateFcns called 202 | 203 | % Hint: edit controls usually have a white background on Windows. 204 | % See ISPC and COMPUTER. 205 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 206 | set(hObject,'BackgroundColor','white'); 207 | end 208 | 209 | % --- Executes on selection change in popupmenu1. 210 | function popupmenu1_Callback(hObject, eventdata, handles) 211 | % hObject handle to popupmenu1 (see GCBO) 212 | % eventdata reserved - to be defined in a future version of MATLAB 213 | % handles structure with handles and user data (see GUIDATA) 214 | 215 | % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array 216 | % contents{get(hObject,'Value')} returns selected item from popupmenu1 217 | 218 | colormap(gcf, eval(['fccolor_'... 219 | handles.popupmenu1.String{handles.popupmenu1.Value} '(64);'])); 220 | 221 | aa=hObject.UserData.FC.(handles.popupmenu2.String{handles.popupmenu2.Value}).(handles.popupmenu3.String{handles.popupmenu3.Value}).adj_matrix; 222 | % aa(aa=32 108 | % EMARKERSIZE = 8; 109 | % elseif length(y)>=48 110 | % EMARKERSIZE = 6; 111 | % elseif length(y)>=64 112 | % EMARKERSIZE = 5; 113 | % elseif length(y)>=80 114 | % EMARKERSIZE = 4; 115 | % elseif length(y)>=100 116 | % EMARKERSIZE = 3; 117 | % elseif length(y)>=128 118 | % EMARKERSIZE = 3; 119 | % elseif length(y)>=160 120 | % EMARKERSIZE = 3; 121 | % end 122 | % end 123 | 124 | %%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations only %%%%%%%%%%%%%%%%%%%%%%%%%% 125 | 126 | % ELECTRODE_HEIGHT = 2.1; % z value for plotting electrode information (above the surf) 127 | % plot3(y,x,ones(size(x))*ELECTRODE_HEIGHT,... 128 | % EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH); 129 | 130 | %define colormap 131 | cmap = zeros(length(loc_file), 3); 132 | % cmap_total = jet(10); 133 | for ch = 1:length(loc_file) 134 | for colors = 1:9 135 | if((LM(ch) >= (colors)*(max(LM)/10)) && (LM(ch) < (colors+1)*(max(LM)/10))) %intermediate case 136 | cmap(ch,:) = cmap_total(colors,:); 137 | elseif((LM(ch) >= (0.9*max(LM)) && (LM(ch) < 1))) %upper case 138 | cmap(ch,:) = cmap_total(10,:); 139 | elseif((LM(ch) >= min(LM) && (LM(ch) < 0.1*(max(LM))))) %lower case 140 | cmap(ch,:) = cmap_total(1,:); 141 | end 142 | end 143 | end 144 | 145 | %fill each sensor's location 146 | for ch = 1:length(loc_file) 147 | plot(y(ch),x(ch),'o','MarkerSize',12,'MarkerEdgeColor','k','MarkerFaceColor',cmap(ch,:)); 148 | end 149 | return 150 | -------------------------------------------------------------------------------- /FCLAB1.0.0/topoplot_connect.m: -------------------------------------------------------------------------------- 1 | function [] = topoplot_connect(displayStruct, loc_file,cM) 2 | % NOTE: The cartoon head is drawn using code in topoplot.m file from EEGLAB 3 | % v6.01b (http://sccn.ucsd.edu/eeglab/). 4 | % 5 | % Reference: 6 | % Delorme A & Makeig S (2004) EEGLAB: an open source toolbox for analysis 7 | % of single-trial EEG dynamics. Journal of Neuroscience Methods 134:9-21 8 | % 9 | % Usage: 10 | % 11 | % >> topoplot_connect(ds, EEG.chanlocs); 12 | % 13 | % *ds* is the display strcture with the folowing fields: 14 | % 15 | % * *ds.chanPairs* (required) - N x 2 matrix, with N being the number of 16 | % connected channel pairs. For example, ds.chanPairs = [7, 12; 13 20]; 17 | % specifies two connected channel pairs (7, 12) and (13, 20). 18 | % * *ds.connectStrength* (optional) - N x 1 matrix, a vector specifying 19 | % connection strengths. If unspecified, then the connections will be 20 | % rendered in a color at the center of the current colormap. 21 | % * *ds.connectStrengthLimits* (optional) - 1 x 2 matrix specifying minimum 22 | % and maximum values of connection strengths to display. If it is not 23 | % specified, then the minimum and maximum values from ds.connectStrength 24 | % are used. 25 | % 26 | % EEG.chanlocs is a structure specifying channel locations (or an locs 27 | % filename) 28 | % 29 | % For comments and/or suggestions, please send me an email at 30 | % praneeth@mit.edu 31 | % 32 | 33 | BACKCOLOR = [0.643 0.776 1]; % EEGLAB standard 34 | rmax = 0.5; % actual head radius - Don't change this! 35 | CIRCGRID = 201; % number of angles to use in drawing circles 36 | AXHEADFAC = 1.3; % head to axes scaling factor 37 | HEADCOLOR = [0 0 0]; % default head color (black) 38 | EMARKER = '.'; % mark electrode locations with small disks 39 | ECOLOR = [0 0 0]; % default electrode color = black 40 | EMARKERSIZE = []; % default depends on number of electrodes, set in code 41 | EMARKERLINEWIDTH = 1; % default edge linewidth for emarkers 42 | HLINEWIDTH = 1.7; % default linewidth for head, nose, ears 43 | HEADRINGWIDTH = .007;% width of the cartoon head ring 44 | 45 | % 46 | %%%%%%%%%%%%%%%%%%%% Read the channel location information %%%%%%%%%%%%%%%%%%%%%%%% 47 | % 48 | if ischar(loc_file) 49 | [~, ~, Th Rd indices] = readlocs( loc_file,'filetype','loc'); 50 | elseif isstruct(loc_file) % a locs struct 51 | [~, ~, Th Rd indices] = readlocs( loc_file ); 52 | % Note: Th and Rd correspond to indices channels-with-coordinates only 53 | else 54 | error('loc_file must be a EEG.locs struct or locs filename'); 55 | end 56 | Th = pi/180*Th; % convert degrees to radians 57 | plotchans = indices; 58 | % 59 | %%%%%%%%%%%%%%%%%%% remove infinite and NaN values %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 60 | % 61 | 62 | [x,y] = pol2cart(Th,Rd); % transform electrode locations from polar to cartesian coordinates 63 | plotchans = abs(plotchans); % reverse indicated channel polarities 64 | Rd = Rd(plotchans); 65 | x = x(plotchans); 66 | y = y(plotchans); 67 | plotrad = min(1.0,max(Rd)*1.02); % default: just outside the outermost electrode location 68 | plotrad = max(plotrad,0.5); % default: plot out to the 0.5 head boundary 69 | headrad = rmax; 70 | pltchans = find(Rd <= plotrad); % plot channels inside plotting circle 71 | x = x(pltchans); 72 | y = y(pltchans); 73 | squeezefac = rmax/plotrad; 74 | x = x*squeezefac; 75 | y = y*squeezefac; 76 | 77 | % 78 | %%%%%%%%%%%%%%%%%%%%%%% Draw blank head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 79 | % 80 | cla 81 | hold on 82 | set(gca,'Xlim',[-rmax rmax]*AXHEADFAC,'Ylim',[-rmax rmax]*AXHEADFAC) 83 | 84 | % 85 | %%%%%%%%%%%%%%%%%%% Plot filled ring to mask jagged grid boundary %%%%%%%%%%%%%%%%%%%%%%%%%%% 86 | % 87 | hwidth = HEADRINGWIDTH; % width of head ring 88 | hin = squeezefac*headrad*(1- hwidth/2); % inner head ring radius 89 | circ = linspace(0,2*pi,CIRCGRID); 90 | rx = sin(circ); 91 | ry = cos(circ); 92 | 93 | % 94 | %%%%%%%%%%%%%%%%%%%%%%%%% Plot cartoon head, ears, nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 95 | % 96 | headx = [[rx(:)' rx(1) ]*(hin+hwidth) [rx(:)' rx(1)]*hin]; 97 | heady = [[ry(:)' ry(1) ]*(hin+hwidth) [ry(:)' ry(1)]*hin]; 98 | 99 | patch(headx,heady,ones(size(headx)),HEADCOLOR,'edgecolor',HEADCOLOR); hold on 100 | 101 | %%%%%%%%%%%%%%%%%%% Plot ears and nose %%%%%%%%%%%%%%%%%%%%%%%%%%% 102 | % 103 | base = rmax-.0046; 104 | basex = 0.18*rmax; % nose width 105 | tip = 1.15*rmax; 106 | tiphw = .04*rmax; % nose tip half width 107 | tipr = .01*rmax; % nose tip rounding 108 | q = .04; % ear lengthening 109 | EarX = [.497-.005 .510 .518 .5299 .5419 .54 .547 .532 .510 .489-.005]; % rmax = 0.5 110 | EarY = [q+.0555 q+.0775 q+.0783 q+.0746 q+.0555 -.0055 -.0932 -.1313 -.1384 -.1199]; 111 | sf = headrad/plotrad; 112 | 113 | plot3([basex;tiphw;0;-tiphw;-basex]*sf,[base;tip-tipr;tip;tip-tipr;base]*sf,... 114 | 2*ones(size([basex;tiphw;0;-tiphw;-basex])),... 115 | 'Color',HEADCOLOR,'LineWidth',HLINEWIDTH); % plot nose 116 | plot3(EarX*sf,EarY*sf,2*ones(size(EarX)),'color',HEADCOLOR,'LineWidth',HLINEWIDTH) % plot left ear 117 | plot3(-EarX*sf,EarY*sf,2*ones(size(EarY)),'color',HEADCOLOR,'LineWidth',HLINEWIDTH) % plot right ear 118 | 119 | % 120 | % %%%%%%%%%%%%%%%%%%% Show electrode information %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 121 | % 122 | plotax = gca; 123 | axis square % make plotax square 124 | axis off 125 | 126 | pos = get(gca,'position'); 127 | set(plotax,'position',pos); 128 | 129 | xlm = get(gca,'xlim'); 130 | set(plotax,'xlim',xlm); 131 | 132 | ylm = get(gca,'ylim'); 133 | set(plotax,'ylim',ylm); % copy position and axis limits again 134 | 135 | 136 | if isempty(EMARKERSIZE) 137 | EMARKERSIZE = 10; 138 | if length(y)>=32 139 | EMARKERSIZE = 8; 140 | elseif length(y)>=48 141 | EMARKERSIZE = 6; 142 | elseif length(y)>=64 143 | EMARKERSIZE = 5; 144 | elseif length(y)>=80 145 | EMARKERSIZE = 4; 146 | elseif length(y)>=100 147 | EMARKERSIZE = 3; 148 | elseif length(y)>=128 149 | EMARKERSIZE = 3; 150 | elseif length(y)>=160 151 | EMARKERSIZE = 3; 152 | end 153 | end 154 | % 155 | %%%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations only %%%%%%%%%%%%%%%%%%%%%%%%%% 156 | % 157 | ELECTRODE_HEIGHT = 2.1; % z value for plotting electrode information (above the surf) 158 | plot3(y,x,ones(size(x))*ELECTRODE_HEIGHT,... 159 | EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH); 160 | 161 | % praneeth - starts 162 | numChanPairs = size(displayStruct.chanPairs, 1); 163 | 164 | if ~isfield(displayStruct, 'connectStrength') 165 | cmapPos = ceil(size(cM, 1)/2)*ones(size(displayStruct.chanPairs, 1), 1); 166 | else 167 | if ~isfield(displayStruct, 'connectStrengthLimits') 168 | displayStruct.connectStrengthLimits = [min(displayStruct.connectStrength), max(displayStruct.connectStrength)]; 169 | end 170 | xp = displayStruct.connectStrengthLimits(1); 171 | yp = displayStruct.connectStrengthLimits(2); 172 | displayStruct.connectStrength(displayStruct.connectStrength < xp) = xp; 173 | displayStruct.connectStrength(displayStruct.connectStrength > yp) = yp; 174 | if xp == yp 175 | cmapPos = ceil(size(cM, 1)/2)*ones(size(displayStruct.chanPairs, 1), 1); 176 | else 177 | cmapPos = round((displayStruct.connectStrength - xp)/(yp - xp)*(size(cM, 1) - 1) + 1); 178 | end 179 | end 180 | 181 | for kk = 1:numChanPairs 182 | plot3(y(displayStruct.chanPairs(kk, :)), x(displayStruct.chanPairs(kk, :)), [ELECTRODE_HEIGHT, ELECTRODE_HEIGHT], 'LineWidth', 2, 'Color', cM(cmapPos(kk), :)); 183 | end 184 | % praneeth - ends 185 | set(gcf, 'color', BACKCOLOR); 186 | return; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FCLAB 2 | Functional Connectivity Lab 3 | 4 | ## Please Cite: 5 | 6 | Pezoulas, V. C., Athanasiou, A., Nolte, G., Zervakis, M., Fratini, A., Fotiadis, D. I., & Klados, M. A. (2018). FCLAB: An EEGLAB module for performing functional connectivity analysis on single-subject EEG data. In 2018 IEEE EMBS International Conference on Biomedical & Health Informatics (BHI) (pp. 96–99). IEEE. https://doi.org/10.1109/BHI.2018.8333378 7 | --------------------------------------------------------------------------------