Home > chronux_code > exploratory > correlations > helper > cohmathelper.m

cohmathelper

PURPOSE ^

Helper function called by coherency matrix computations.

SYNOPSIS ^

function [C,phi,S12,confC,phierr,Cerr]=cohmathelper(J,err,Nsp)

DESCRIPTION ^

 Helper function called by coherency matrix computations.

 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
 phierr: error bars for phase
 Cerr  : error bars for coherency (only for Jackknife estimates)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function  [C,phi,S12,confC,phierr,Cerr]=cohmathelper(J,err,Nsp)
0002 % Helper function called by coherency matrix computations.
0003 %
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
0016 % phierr: error bars for phase
0017 % Cerr  : error bars for coherency (only for Jackknife estimates)
0018 %
0019 errtype=err(1);
0020 trialave=0;
0021 [nf,K,Ch]=size(J);
0022 for ch1=1:Ch;
0023      J1=squeeze(J(:,:,ch1));
0024      C(1:nf,ch1,ch1)=1;
0025      phi(1:nf,ch1,ch1)=0;
0026      if errtype==2; 
0027           phierr(1:nf,ch1,ch1)=0;
0028           Cerr(1:2,1:nf,ch1,ch1)=0;
0029      elseif errtype==1
0030            phierr(1:nf,ch1,ch1)=0;
0031      end;
0032      s1=squeeze(mean(conj(J1).*J1,2));
0033      for ch2=1:ch1-1;
0034           J2=squeeze(J(:,:,ch2));
0035           s12=squeeze(mean(conj(J1).*J2,2));
0036           s2=squeeze(mean(conj(J2).*J2,2));
0037           C12=s12./sqrt(s1.*s2);
0038           C(:,ch1,ch2)=abs(C12);
0039           C(:,ch2,ch1)=C(:,ch1,ch2);
0040           phi(:,ch1,ch2)=angle(C12);
0041           phi(:,ch2,ch1)=phi(:,ch1,ch2);
0042           S12(:,ch1,ch2)=s12;
0043           S12(:,ch2,ch1)=S12(:,ch1,ch2);
0044           if errtype==2 
0045              if nargin<3;
0046                  [conf,phie,Ce]=coherr(abs(C12),J1,J2,err,trialave);
0047              else
0048                  [conf,phie,Ce]=coherr(abs(C12),J1,J2,err,trialave,Nsp(ch1),Nsp(ch2));
0049              end
0050              confC(ch1,ch2)=conf; 
0051              phierr(:,ch1,ch2)=phie;
0052              Cerr(1,:,ch1,ch2)=Ce(1,:);
0053              Cerr(2,:,ch1,ch2)=Ce(2,:);
0054              confC(ch2,ch1)=conf; 
0055              phierr(:,ch2,ch1)=phie;
0056              Cerr(:,:,ch2,ch1)=Ce;
0057          elseif errtype==1
0058              if nargin<3;
0059                  [conf,phie]=coherr(abs(C12),J1,J2,err,trialave);
0060              else
0061                  [conf,phie]=coherr(abs(C12),J1,J2,err,trialave,Nsp(ch1),Nsp(ch2));
0062              end
0063              confC(ch1,ch2)=conf; 
0064              phierr(:,ch1,ch2)=phie;
0065              confC(ch2,ch1)=conf; 
0066              phierr(:,ch2,ch1)=phie;
0067         end;
0068     end;
0069 end;

Generated on Tue 07-Jun-2005 12:20:32 by m2html © 2003