cohmathelper

PURPOSE ^

Helper function called by coherency matrix computations.

SYNOPSIS ^

function [C,phi,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
  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,confC,phierr,Cerr]=cohmathelper(J,err,Nsp)
0002 % Helper function called by coherency matrix computations.
0003 % Inputs:
0004 % J: Fourier transforms of data
0005 % err: [0 p] or 0 for no errors; [1 p] for theoretical confidence level,
0006 %       [2 p] for Jackknife (p - p value)
0007 %Nsp: pass the number of spikes in each channel if finite size corrections
0008 %  are desired
0009 % Outputs:
0010 % C: coherence
0011 %  phi: phase of coherency
0012 %  confC: confidence level for coherency
0013 %  phierr: error bars for phase
0014 % Cerr: error bars for coherency (only for Jackknife estimates)
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;

Generated on Tue 24-Aug-2004 15:55:33 by m2html © 2003