Home > eeg > egis > scripts > coherence_scatter_nl.m

coherence_scatter_nl

PURPOSE ^

status =coherence_scatter_nl(freqs,obs,array,lines,coherencefname);

SYNOPSIS ^

function status =coherence_scatter_nl(freqs,obs,array,lines,coherencefname);

DESCRIPTION ^

status =coherence_scatter_nl(freqs,obs,array,lines,coherencefname);
same as coherence scatter but no polynomial fits.  
freqs = frequencies to plot, e.g. [3 30] limits the plot at 3 and 30 Hz  
obs = observations in the power file to plot (defaults to all)
array = either an array name,e.g., 'all','hemisphere','quadrant','frontback',
    or 'oned' or a list of channels
 Restrictions nobs <= 3. If nobs == 1 and multiple frequencies 
 are listed then freqs < = 3. If nobs > 1 obs go on same plot one for
 each freq.  if nobs == 1 all the freqs go on the same plot
lines = 'black' or 'color'
coherencefname = coherencefilename (can be gui by skipping this param)

note also draws in solid black coherence due to uncorrelated sources
in the four spheres model.  If 'laplacian' is a reference the curve
for laplacians is drawn as well.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status =coherence_scatter_nl(freqs,obs,array,lines,coherencefname);
0002 %status =coherence_scatter_nl(freqs,obs,array,lines,coherencefname);
0003 %same as coherence scatter but no polynomial fits.
0004 %freqs = frequencies to plot, e.g. [3 30] limits the plot at 3 and 30 Hz
0005 %obs = observations in the power file to plot (defaults to all)
0006 %array = either an array name,e.g., 'all','hemisphere','quadrant','frontback',
0007 %    or 'oned' or a list of channels
0008 % Restrictions nobs <= 3. If nobs == 1 and multiple frequencies
0009 % are listed then freqs < = 3. If nobs > 1 obs go on same plot one for
0010 % each freq.  if nobs == 1 all the freqs go on the same plot
0011 %lines = 'black' or 'color'
0012 %coherencefname = coherencefilename (can be gui by skipping this param)
0013 %
0014 %note also draws in solid black coherence due to uncorrelated sources
0015 %in the four spheres model.  If 'laplacian' is a reference the curve
0016 %for laplacians is drawn as well.
0017 if nargin < 5
0018     [fid] = get_fid('rb');
0019 else
0020     fid = fopen(coherencefname,'rb');
0021 end;
0022 version = fread(fid,1,'int16');
0023 if version ~= -2
0024     error('this is not a coherence file');
0025 end;
0026  [nfiles,obs_labels,Epoch,Window_Length,NEpoch,Nbad_chan,bad_chan,ref_flag,reference,NChan,NFreq] = rd_anal_hdr(fid);
0027 if nargin == 0
0028     freqs = [0:40];
0029     obs = [1:nfiles];
0030     array = 'all';
0031     lines = 'black';
0032 end;
0033 if nargin == 1
0034     obs = [1:nfiles];
0035     array = 'all';
0036     lines = 'black';
0037 end;        
0038 if nargin == 2
0039     array = 'all';
0040     lines = 'black';
0041 end;    
0042 if nargin == 3
0043     lines = 'black';
0044 end;
0045 if isempty(lines)
0046     lines = 'black';
0047 end
0048 if isempty(array)
0049     array = 'all';
0050 end
0051 if isempty(obs)
0052     obs = [1:nfiles];
0053 end;
0054 if isempty(freqs)
0055     freqs = [0:40];
0056 end;
0057 if size(obs,2) > 3
0058     fclose('all')
0059     error('too many observations > 3 to be plotted in a single plot')
0060 end;
0061 if size(obs,2) == 1
0062     if size(freqs,2) > 3 
0063         error('too many frequencies for a single plot')
0064     end;
0065 end;
0066 ch_pair_indices;
0067 if strcmp(lines,'black')
0068 line_type = ['w- ';'w--';'w-.'];
0069 scat_type = ['wx';'wo';'w.'];
0070 else    
0071 line_type = ['r-';'b-';'w-'];
0072 scat_type = ['rx';'bo';'w.'];
0073 end;
0074 coherencemax = 1;
0075 iline = 1;
0076 [xelec,yelec,zelec] = electrodes(129);
0077 twod_dist = twod_pos(xelec,yelec,zelec,9.2);
0078 coherence_array = real(get_eeg_coherence(fid,freqs,obs,nfiles,NChan,NFreq,Epoch));
0079 [dist,bcohpotential,bcohlaplacian] = baseline_coherence(0.2,80,8,8.2,8.7,9.2,7.8);
0080 if isstr(array)
0081     [arrayg,gnames] = arrays(array,[]);
0082 else
0083     arrayg = array;
0084 end
0085 if size(obs,2) > 1
0086     for g = 1:size(arrayg,1)
0087             for i= 1:size(freqs,2)
0088                 figure
0089                 hold on
0090                 for io = 1:size(obs,2)
0091                     if ~strcmp(deblank(setstr(reference(obs(io),:))),'laplacian')
0092                         hold on,plot(dist,bcohpotential,'k-');
0093                     else 
0094                         hold on,plot(dist,bcohlaplacian,'k-');
0095                     end;
0096                 end
0097                 iline = 1;
0098                 
0099                 for j = 1:size(obs,2)
0100                 
0101                     if isstr(array)
0102                         [arrayh,hnames] = arrays(array,bad_chan(obs(j),find(bad_chan(obs(j),:))));
0103                     else
0104                         arrayh = array;
0105                     end
0106                 pairels = arrayh(g,find(arrayh(g,:)));
0107                 npairs = size(pairels,2)*(size(pairels,2)+1)/2;
0108                 pairs = zeros(1,npairs);
0109                 ipairs = 1;
0110                 for ip = 1:size(pairels,2)
0111                     for jp=ip:size(pairels,2)
0112                         pairs(ipairs) = chpair(pairels(ip),pairels(jp));
0113                         ipairs = ipairs + 1;
0114                     end;
0115                 end;
0116                 pairnames = hnames(g,:);
0117                 hold on, plot(real(twod_dist(pairs)),coherence_array((j-1)*size(freqs,2)+i,pairs),scat_type(iline,:))
0118                 p_coh = polyfit(twod_dist(pairs),coherence_array((j-1)*size(freqs,2)+i,pairs),4);
0119                 coh_fit = real(polyval(p_coh,[0:1:fix(max(twod_dist(pairs)))]));
0120                 hold on, plot([0:1:max(twod_dist(pairs))],coh_fit,line_type(iline,:)), axis([0 max(twod_dist(pairs))+1 0 1])
0121                 title(['Coherence versus Distance:  @' int2str(freqs(i)) ' Hz ' hnames(g,:)]);
0122                 text([max(twod_dist(pairs))-1],[1-0.1*j],[scat_type(iline,2) ' ' deblank(setstr(obs_labels(obs(j),:)))])
0123                 xlabel('Interelectrode Distance (cm)')
0124                 ylabel('Coherence')
0125                  iline = iline+ 1;
0126             end
0127         end
0128     end
0129 else
0130     if isstr(array)
0131         [arrayh,hnames] = arrays(array,bad_chan(obs,find(bad_chan(obs,:))));
0132     else
0133         arrayh = array;
0134     end
0135     for g = 1:size(arrayh,1)
0136         iline = 1;
0137         figure
0138         hold on
0139         for io = 1:size(obs,2)
0140             if ~strcmp(deblank(setstr(reference(obs(io),:))),'laplacian')
0141                 hold on,plot(dist,bcohpotential,'w-');
0142             else
0143                 hold on,plot(dist,bcohlaplacian,'w-');
0144             end;
0145         end
0146         for j = 1:size(freqs,2)
0147             pairels = arrayh(g,find(arrayh(g,:)));
0148             
0149             npairs = size(pairels,2)*(size(pairels,2)+1)/2;
0150             pairs = zeros(1,npairs);
0151             ipairs = 1;
0152             for ip = 1:size(pairels,2)
0153                 for jp=ip:size(pairels,2)
0154                     pairs(ipairs) = chpair(pairels(ip),pairels(jp));
0155                     ipairs = ipairs + 1;
0156                 end;
0157             end;
0158             chpair(pairels(1),pairels(2))
0159             pairnames = hnames(g,:);
0160             
0161             hold on, plot(real(twod_dist(pairs)),coherence_array(j,pairs),scat_type(iline,:))
0162             p_coh = polyfit(real(twod_dist(pairs)),coherence_array(j,pairs),4);
0163             coh_fit = real(polyval(p_coh,[0:1:fix(max(twod_dist(pairs)))]));
0164             hold on, plot([0:1:max(twod_dist(pairs))],coh_fit,line_type(iline,:)), axis([0 max(twod_dist(pairs))+1 0 1])
0165             title(['Coherence versus Distance: ' deblank(setstr(obs_labels(obs(1),:))) ' ' hnames(g,:)]);
0166             text([max(twod_dist(pairs))-1],[1-0.1*j],[scat_type(iline,2) ' ' int2str(freqs(j)) ' Hz'])
0167             xlabel('Interelectrode Distance (cm)')
0168             ylabel('Coherence')
0169             iline = iline+ 1;
0170         end
0171     end
0172 end
0173 status = 1;
0174 
0175 
0176 
0177 
0178 
0179 
0180 
0181 
0182 
0183 
0184 
0185 
0186 
0187 
0188 
0189 
0190 
0191 
0192 
0193 
0194 
0195 
0196 
0197 
0198 
0199 
0200 
0201 
0202

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003