Home > eeg > egis > scripts > coherence_lines.m

coherence_lines

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

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

freqs = frequencies to plot, e.g. [3 30] limits the plot to  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_lines(freqs,obs,array,lines,coherencefname);
0002 %status =coherence_lines(freqs,obs,array,lines,coherencefname);
0003 %
0004 %freqs = frequencies to plot, e.g. [3 30] limits the plot to  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 = ['b-';'r-';'k-'];
0072 scat_type = ['kx';'ko';'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                 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                 hold on, plot([9 10 ],[1-0.1*j 1-0.1*j],line_type(iline,:))
0123                 text([11],[1-0.1*j],[deblank(setstr(obs_labels(obs(j),:)))])
0124                 xlabel('Interelectrode Distance (cm)')
0125                 ylabel('Coherence')
0126                  iline = iline+ 1;
0127             end
0128         end
0129     end
0130 else
0131     if isstr(array)
0132         [arrayh,hnames] = arrays(array,bad_chan(obs,find(bad_chan(obs,:))));
0133     else
0134         arrayh = array;
0135     end
0136     for g = 1:size(arrayh,1)
0137         iline = 1;
0138         figure
0139         hold on
0140         for io = 1:size(obs,2)
0141             if  ~(ref_flag(obs(io)) == 5|ref_flag(obs(io)) == 7)
0142                 hold on,bar(dist,bcohpotential,'w-');
0143             elseif ref_flag(obs(io)) == 5
0144                 hold on,bar(dist,bcohlaplacian,'w-');
0145             end;
0146         end
0147         for j = 1:size(freqs,2)
0148             pairels = arrayh(g,find(arrayh(g,:)));
0149             
0150             npairs = size(pairels,2)*(size(pairels,2)+1)/2;
0151             pairs = zeros(1,npairs);
0152             ipairs = 1;
0153             for ip = 1:size(pairels,2)
0154                 for jp=ip:size(pairels,2)
0155                     pairs(ipairs) = chpair(pairels(ip),pairels(jp));
0156                     ipairs = ipairs + 1;
0157                 end;
0158             end;
0159             chpair(pairels(1),pairels(2))
0160             pairnames = hnames(g,:);
0161             
0162 %            hold on, plot(real(twod_dist(pairs)),coherence_array(j,pairs),scat_type(iline,:))
0163             p_coh = polyfit(real(twod_dist(pairs)),coherence_array(j,pairs),4);
0164             coh_fit = real(polyval(p_coh,[0:1:fix(max(twod_dist(pairs)))]));
0165             hold on, plot([0:1:max(twod_dist(pairs))],coh_fit,line_type(iline,:)), axis([0 max(twod_dist(pairs))+1 0 1])
0166             title(['Coherence versus Distance: ' deblank(setstr(obs_labels(obs(1),:))) ' ' hnames(g,:)]);
0167             hold on, plot([9 10],[1-0.1*j 1-0.1*j],linetype(iline,:))
0168             text([11],[1-0.1*j],[int2str(freqs(j)) ' Hz'])
0169             xlabel('Interelectrode Distance (cm)')
0170             ylabel('Coherence')
0171             iline = iline+ 1;
0172         end
0173     end
0174 end
0175 status = 1;
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 
0203 
0204

Generated on Wed 20-Mar-2019 04:00:51 by m2html © 2003