0001 function avg_coherence = eeg_coherence(ravgcsdm,iavgcsdm,bad_chan);
0002
0003
0004
0005
0006
0007
0008 if nargin < 2
0009 error('you missing either the real or the imaginary part');
0010 end;
0011 if nargin == 2
0012 bad_chan = [];
0013 end;
0014 if size(ravgcsdm,2) == 8385
0015 NChan = 129;
0016 else
0017 error('unknown number of channels');
0018 end;
0019 mask = ones(1,NChan);
0020 mask(bad_chan) = zeros(1,size(bad_chan,2));
0021 good_chan = find(mask);
0022 ch_pair_indices;
0023
0024 avg_coherence = zeros(size(ravgcsdm,1),size(ravgcsdm,2));
0025
0026 for i = 1:size(good_chan,2)
0027 for j = i:size(good_chan,2)
0028 avg_coherence(:,chpair(good_chan(i),good_chan(j)))= ((ravgcsdm(:,chpair(good_chan(i),good_chan(j))).^2)+(iavgcsdm(:,chpair(good_chan(i),good_chan(j))).^2))./ravgcsdm(:,chpair(good_chan(i),good_chan(i)))./ravgcsdm(:,chpair(good_chan(j),good_chan(j)));
0029 end;
0030 end;
0031
0032 avg_coherence(find(isnan(avg_coherence))) = zeros(size(find(isnan(avg_coherence))));
0033