


Helper function called by coherency matrix computations.
Usage: [C,phi,S12,confC,phierr,Cerr]=cohmathelper(J,err,Nsp)
Inputs:
J : Fourier transforms of data
err : [0 p] or 0 for no errors; [1 p] for theoretical confidence level,
[2 p] for Jackknife (p - p value)
Nsp : pass the number of spikes in each channel if finite size corrections are desired
Outputs:
C : coherence
phi : phase of coherency
S12 : cross spectral matrix
confC : confidence level for coherency - only for err(1)>=1
phierr - standard deviation for phi (note that the routine gives phierr as phierr(1,...) and phierr(2,...)
in order to incorporate Jackknife (eventually). Currently phierr(1,...)=phierr(2,...). Note that
phi + 2 phierr(1,...) and phi -2 phierr(2,...) will give 95% confidence bands for phi - only for err(1)>=1
Cerr : error bars for coherency (only for Jackknife estimates)-only for
err(1)=2

0001 function [C,phi,S12,confC,phierr,Cerr]=cohmathelper(J,err,Nsp) 0002 % Helper function called by coherency matrix computations. 0003 % Usage: [C,phi,S12,confC,phierr,Cerr]=cohmathelper(J,err,Nsp) 0004 % Inputs: 0005 % J : Fourier transforms of data 0006 % err : [0 p] or 0 for no errors; [1 p] for theoretical confidence level, 0007 % [2 p] for Jackknife (p - p value) 0008 % Nsp : pass the number of spikes in each channel if finite size corrections are desired 0009 % 0010 % Outputs: 0011 % 0012 % C : coherence 0013 % phi : phase of coherency 0014 % S12 : cross spectral matrix 0015 % confC : confidence level for coherency - only for err(1)>=1 0016 % phierr - standard deviation for phi (note that the routine gives phierr as phierr(1,...) and phierr(2,...) 0017 % in order to incorporate Jackknife (eventually). Currently phierr(1,...)=phierr(2,...). Note that 0018 % phi + 2 phierr(1,...) and phi -2 phierr(2,...) will give 95% confidence bands for phi - only for err(1)>=1 0019 % Cerr : error bars for coherency (only for Jackknife estimates)-only for 0020 % err(1)=2 0021 errtype=err(1); 0022 trialave=0; 0023 [nf,K,Ch]=size(J); 0024 clear K 0025 confC=zeros(Ch,Ch); 0026 C=zeros(nf,Ch,Ch); 0027 S12=zeros(nf,Ch,Ch); 0028 phi=zeros(nf,Ch,Ch); 0029 phierr=zeros(2,nf,Ch,Ch); 0030 if errtype==2; Cerr=zeros(2,nf,Ch,Ch);end; 0031 0032 for ch1=1:Ch; 0033 J1=squeeze(J(:,:,ch1)); 0034 C(1:nf,ch1,ch1)=1; 0035 phi(1:nf,ch1,ch1)=0; 0036 % if errtype==2; 0037 % phierr(1:nf,ch1,ch1)=0; 0038 % Cerr(1:2,1:nf,ch1,ch1)=0; 0039 % elseif errtype==1 0040 % phierr(1:2,1:nf,ch1,ch1)=0; 0041 % end; 0042 s1=squeeze(mean(conj(J1).*J1,2)); 0043 for ch2=1:ch1-1; 0044 J2=squeeze(J(:,:,ch2)); 0045 s12=squeeze(mean(conj(J1).*J2,2)); 0046 s2=squeeze(mean(conj(J2).*J2,2)); 0047 C12=s12./sqrt(s1.*s2); 0048 C(:,ch1,ch2)=abs(C12); 0049 C(:,ch2,ch1)=C(:,ch1,ch2); 0050 phi(:,ch1,ch2)=angle(C12); 0051 phi(:,ch2,ch1)=phi(:,ch1,ch2); 0052 S12(:,ch1,ch2)=s12; 0053 S12(:,ch2,ch1)=S12(:,ch1,ch2); 0054 if errtype==2 0055 if nargin<3; 0056 [conf,phie,Ce]=coherr(abs(C12),J1,J2,err,trialave); 0057 else 0058 [conf,phie,Ce]=coherr(abs(C12),J1,J2,err,trialave,Nsp(ch1),Nsp(ch2)); 0059 end 0060 confC(ch1,ch2)=conf; 0061 phierr(1,:,ch1,ch2)=phie;phierr(2,:,ch1,ch2)=phie; 0062 Cerr(1,:,ch1,ch2)=Ce(1,:); 0063 Cerr(2,:,ch1,ch2)=Ce(2,:); 0064 confC(ch2,ch1)=conf; 0065 phierr(1,:,ch2,ch1)=phie;phierr(2,:,ch2,ch1)=phie; 0066 Cerr(:,:,ch2,ch1)=Ce; 0067 elseif errtype==1 0068 if nargin<3; 0069 [conf,phie]=coherr(abs(C12),J1,J2,err,trialave); 0070 else 0071 [conf,phie]=coherr(abs(C12),J1,J2,err,trialave,Nsp(ch1),Nsp(ch2)); 0072 end 0073 confC(ch1,ch2)=conf; 0074 phierr(1,:,ch1,ch2)=phie;phierr(2,:,ch1,ch2)=phie; 0075 confC(ch2,ch1)=conf; 0076 phierr(1,:,ch2,ch1)=phie;phierr(2,:,ch2,ch1)=phie; 0077 end; 0078 end; 0079 end;