Home > eeg > egis > scripts > coherence_scatter.m

coherence_scatter

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

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

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(freqs,obs,array,lines,coherencefname);
0002 %status =coherence_scatter(freqs,obs,array,lines,coherencefname);
0003 %
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 = ['k- ';'k--';'k-.'];
0069 scat_type = ['kx';'ko';'k.'];
0070 else    
0071 line_type = ['r-';'b-';'k-'];
0072 scat_type = ['rx';'bo';'k.'];
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 ~(ref_flag(obs(io)) == 5|ref_flag(obs(io)) == 7)
0092                         hold on,bar(dist,bcohpotential,'w-');
0093                     elseif ref_flag(obs(io)) == 5 
0094                         hold on,bar(dist,bcohlaplacian,'w-');
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                 if ref_flag(obs(io)) ~= 5
0119                 p_coh = polyfit(twod_dist(pairs),coherence_array((j-1)*size(freqs,2)+i,pairs),4);
0120                 coh_fit = real(polyval(p_coh,[0:1:fix(max(twod_dist(pairs)))]));
0121                 hold on, plot([0:1:max(twod_dist(pairs))],coh_fit,line_type(iline,:))
0122                 end;
0123                 axis([0 max(twod_dist(pairs))+1 0 1])
0124                 title(['Coherence versus Distance:  @' int2str(freqs(i)) ' Hz ' hnames(g,:)]);
0125                 text([max(twod_dist(pairs))-2.5],[1-0.1*j],[scat_type(iline,2) ' ' deblank(setstr(obs_labels(obs(j),:)))])
0126                 xlabel('Interelectrode Distance (cm)')
0127                 ylabel('Coherence')
0128                  iline = iline+ 1;
0129             end
0130         end
0131     end
0132 else
0133     if isstr(array)
0134         [arrayh,hnames] = arrays(array,bad_chan(obs,find(bad_chan(obs,:))));
0135     else
0136         arrayh = array;
0137     end
0138     for g = 1:size(arrayh,1)
0139         iline = 1;
0140         figure
0141         hold on
0142         for io = 1:size(obs,2)
0143             if ~(ref_flag(obs(io)) == 5|ref_flag(obs(io)) == 7)
0144                 hold on,bar(dist,bcohpotential,'w-');
0145             elseif ref_flag(obs(io)) == 5
0146                 hold on,bar(dist,bcohlaplacian,'w-');
0147             end;
0148         end
0149         for j = 1:size(freqs,2)
0150             pairels = arrayh(g,find(arrayh(g,:)));
0151             
0152             npairs = size(pairels,2)*(size(pairels,2)+1)/2;
0153             pairs = zeros(1,npairs);
0154             ipairs = 1;
0155             for ip = 1:size(pairels,2)
0156                 for jp=ip:size(pairels,2)
0157                     pairs(ipairs) = chpair(pairels(ip),pairels(jp));
0158                     ipairs = ipairs + 1;
0159                 end;
0160             end;
0161             chpair(pairels(1),pairels(2))
0162             pairnames = hnames(g,:);
0163             
0164             hold on, plot(real(twod_dist(pairs)),coherence_array(j,pairs),scat_type(iline,:))
0165             if ref_flag(obs(io)) ~= 5
0166             p_coh = polyfit(real(twod_dist(pairs)),coherence_array(j,pairs),4);
0167             coh_fit = real(polyval(p_coh,[0:1:fix(max(twod_dist(pairs)))]));
0168             hold on, plot([0:1:max(twod_dist(pairs))],coh_fit,line_type(iline,:))
0169             end
0170             axis([0 max(twod_dist(pairs))+1 0 1])
0171             title(['Coherence versus Distance: ' deblank(setstr(obs_labels(obs(1),:))) ' ' hnames(g,:)]);
0172             text([max(twod_dist(pairs))-2.5],[1-0.1*j],[scat_type(iline,2) ' ' int2str(freqs(j)) ' Hz'])
0173             xlabel('Interelectrode Distance (cm)')
0174             ylabel('Coherence')
0175             iline = iline+ 1;
0176         end
0177     end
0178 end
0179 status = 1;
0180 
0181 
0182 
0183 
0184 
0185 
0186 
0187 
0188 
0189 
0190 
0191 
0192 
0193 
0194 
0195 
0196 
0197 
0198 
0199 
0200 
0201 
0202 
0203 
0204 
0205 
0206 
0207 
0208

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