0001 function [C,phi,confC,phierr,Cerr]=cohmathelper(J,err,Nsp)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 warning off MATLAB:divideByZero
0016 errtype=err(1);
0017 trialave=0;
0018 [nf,K,Ch]=size(J);
0019 for ch1=1:Ch;
0020 J1=squeeze(J(:,:,ch1));
0021 C(1:nf,ch1,ch1)=1;
0022 phi(1:nf,ch1,ch1)=0;
0023 if errtype==2;
0024 phierr(1:nf,ch1,ch1)=0;
0025 Cerr(1:2,1:nf,ch1,ch1)=0;
0026 elseif errtype==1
0027 phierr(1:nf,ch1,ch1)=0;
0028 end;
0029 for ch2=1:ch1-1;
0030 J2=squeeze(J(:,:,ch2));
0031 S12=squeeze(mean(conj(J1).*J2,2));
0032 S1=squeeze(mean(conj(J1).*J1,2));
0033 S2=squeeze(mean(conj(J2).*J2,2));
0034 C12=S12./sqrt(S1.*S2);
0035 C(:,ch1,ch2)=abs(C12);
0036 C(:,ch2,ch1)=C(:,ch1,ch2);
0037 phi(:,ch2,ch1)=angle(C12);
0038 phi(:,ch2,ch1)=phi(:,ch1,ch2);
0039 if errtype==2
0040 if nargin<3;
0041 [conf,phie,Ce]=coherr(abs(C12),J1,J2,err,trialave);
0042 else;
0043 [conf,phie,Ce]=coherr(abs(C12),J1,J2,err,trialave,Nsp(ch1),Nsp(ch2));
0044 end
0045 confC(ch1,ch2)=conf;
0046 phierr(:,ch1,ch2)=phie;
0047 Cerr(1,:,ch1,ch2)=Ce(1,:);
0048 Cerr(2,:,ch1,ch2)=Ce(2,:);
0049 confC(ch2,ch1)=conf;
0050 phierr(:,ch2,ch1)=phie;
0051 Cerr(:,:,ch2,ch1)=Ce;
0052 elseif errtype==1
0053 if nargin<3;
0054 [conf,phie]=coherr(abs(C12),J1,J2,err,trialave);
0055 else;
0056 [conf,phie]=coherr(abs(C12),J1,J2,err,trialave,Nsp(ch1),Nsp(ch2));
0057 end
0058 confC(ch1,ch2)=conf;
0059 phierr(:,ch1,ch2)=phie;
0060 confC(ch2,ch1)=conf;
0061 phierr(:,ch2,ch1)=phie;
0062 end;
0063 end;
0064 end;