Home > eeg > egis > scripts > coherence_scat_2cond.m

coherence_scat_2cond

PURPOSE ^

[chpair_coh] =coherence_scatter_2cond(freqs,obs,array,coh_crit,...

SYNOPSIS ^

function [chpair_coh] =coherence_scatter_2cond(freqs,obs,array,coh_crit,coherencefname);

DESCRIPTION ^

 [chpair_coh] =coherence_scatter_2cond(freqs,obs,array,coh_crit,...
 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 <= 2. If nobs == 1 and multiple frequencies 
 are listed then freqs < = 2. If nobs > 1 obs go on same plot one for
 each freq.  if nobs == 1 all the freqs go on the same plot
 coh_crit = critical value for coherence change (** will default to 95%
    confidence intervals but not implemented yet)
coherencefname = coherencefilename (can be gui by skipping this param)

 chpair_coh = differnce data (see Manual for interpretation)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [chpair_coh] =coherence_scatter_2cond(freqs,obs,array,coh_crit,coherencefname);
0002 % [chpair_coh] =coherence_scatter_2cond(freqs,obs,array,coh_crit,...
0003 % coherencefname);
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 <= 2. If nobs == 1 and multiple frequencies
0009 % are listed then freqs < = 2. 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 % coh_crit = critical value for coherence change (** will default to 95%
0012 %    confidence intervals but not implemented yet)
0013 %coherencefname = coherencefilename (can be gui by skipping this param)
0014 %
0015 % chpair_coh = differnce data (see Manual for interpretation)
0016 %
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     coh_crit = 0.1;
0032 end;
0033 if nargin == 1
0034     obs = [1:nfiles];
0035     array = 'all';
0036     coh_crit = 0.1;
0037 end;        
0038 if nargin == 2
0039     array = 'all';
0040     coh_crit = 0.1;
0041 end;    
0042 if nargin == 3
0043     coh_crit = 0.1;
0044 end;
0045 if isempty(coh_crit)
0046     coh_crit = 0.1;
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) > 2
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) > 2 
0063         error('too many frequencies for a single plot')
0064     end;
0065 end;
0066 lines = 'color';
0067 ch_pair_indices;
0068 if strcmp(lines,'black')
0069 line_type = ['k- ';'k--';'k-.'];
0070 scat_type = ['ko';'k.';'ko'];
0071 else    
0072 line_type = ['k-';'r-';'b-'];
0073 scat_type = ['ko';'r.';'bo'];
0074 end;
0075 coherencemax = 1;
0076 iline = 1;
0077 [xelec,yelec,zelec] = electrodes(129);
0078 twod_dist = twod_pos(xelec,yelec,zelec,9.2);
0079 coherence_array = real(get_eeg_coherence(fid,freqs,obs,nfiles,NChan,NFreq,Epoch));
0080 [dist,bcohpotential,bcohlaplacian] = baseline_coherence(0.2,80,8,8.2,8.7,9.2,7.8);
0081 if isstr(array)
0082     [arrayg,gnames] = arrays(array,[]);
0083 else
0084     arrayg = array;
0085 end
0086 if size(obs,2) > 1
0087     for g = 1:size(arrayg,1)
0088             for i= 1:size(freqs,2)
0089                 figure
0090                 hold on
0091                 for io = 1:size(obs,2)
0092                     if ~(ref_flag(obs(io)) == 5|ref_flag(obs(io)) == 7)
0093                         hold on,bar(dist,bcohpotential,'w-');
0094                     elseif ref_flag(obs(io)) == 5 
0095                         hold on,bar(dist,bcohlaplacian,'w-');
0096                     end;
0097                 end
0098                 iline = 1;
0099                 
0100                 for j = 1:size(obs,2)
0101                 
0102                     if isstr(array)
0103                         [arrayh,hnames] = arrays(array,bad_chan(obs(j),find(bad_chan(obs(j),:))));
0104                     else
0105                         arrayh = array;
0106                     end
0107                 pairels = arrayh(g,find(arrayh(g,:)));
0108                 npairs = size(pairels,2)*(size(pairels,2)+1)/2;
0109                 pairs = zeros(1,npairs);
0110                 ipairs = 1;
0111                 for ip = 1:size(pairels,2)
0112                     for jp=ip:size(pairels,2)
0113                         pairs(ipairs) = chpair(pairels(ip),pairels(jp));
0114                         ipairs = ipairs + 1;
0115                     end;
0116                 end;
0117                 pairnames = hnames(g,:);
0118 %                if j == 1
0119 %                hold on, plot(real(twod_dist(pairs)),coherence_array((j-1)*size(freqs,2)+i,pairs),scat_type(2,:))
0120 %                end;
0121                 if j == 2
0122                 hold on, plot(real(twod_dist(pairs)),coherence_array((j-1)*size(freqs,2)+i,pairs),scat_type(iline,:))
0123                 diff_pairs = find(abs(coherence_array(size(freqs,2)+i,:) - coherence_array(i,:)) > coh_crit);
0124                 mask = zeros(1,size(coherence_array,2));
0125                 mask(pairs) = ones(1,size(pairs,2));
0126                 mask_diff = zeros(1,size(coherence_array,2));
0127                 mask_diff(diff_pairs) = ones(1,size(diff_pairs,2));
0128                 new_mask = mask_diff.*mask;
0129                 pairs_diff = find(new_mask);
0130                 hold on, plot(real(twod_dist(pairs_diff)),coherence_array((j-1)*size(freqs,2)+i,pairs_diff),scat_type(3,:))
0131                 end
0132 %                p_coh = polyfit(twod_dist(pairs),coherence_array((j-1)*size(freqs,2)+i,pairs),4);
0133 %                coh_fit = real(polyval(p_coh,[0:1:fix(max(twod_dist(pairs)))]));
0134 %                hold on, plot([0:1:max(twod_dist(pairs))],coh_fit,line_type(iline,:)),
0135                 hold on, axis([0 max(twod_dist(pairs))+1 0 1])
0136                 title(['Coherence versus Distance:  @' int2str(freqs(i)) ' Hz ' hnames(g,:)]);
0137                 text([max(twod_dist(pairs))-2.5],[1-0.1*j],[scat_type(iline+1,2) ' ' deblank(setstr(obs_labels(obs(j),:)))])
0138                 xlabel('Interelectrode Distance (cm)')
0139                 ylabel('Coherence')
0140                  iline = iline+ 1;
0141             end
0142         chpair_list = chpairindex_2chpair(pairs_diff);
0143         chpair_coh((g-1)*size(chpair_list,1)+1:g*size(chpair_list,1),:) = [g*ones(size(chpair_list,1),1) freqs(i)*ones(size(chpair_list,1),1) obs(1)*ones(size(chpair_list,1),1) obs(2)*ones(size(chpair_list,1),1) chpair_list twod_dist(pairs_diff)' coherence_array(i,pairs_diff)' coherence_array(i+size(freqs,2),pairs_diff)'];
0144         
0145         end
0146     end
0147 else
0148     if isstr(array)
0149         [arrayh,hnames] = arrays(array,bad_chan(obs,find(bad_chan(obs,:))));
0150     else
0151         arrayh = array;
0152     end
0153     for g = 1:size(arrayh,1)
0154         iline = 1;
0155         figure
0156         hold on
0157         for io = 1:size(obs,2)
0158             if ~(ref_flag(obs(io)) == 5|ref_flag(obs(io)) == 7)
0159                 hold on,bar(dist,bcohpotential,'w-');
0160             elseif ref_flag(obs(io)) == 5
0161                 hold on,bar(dist,bcohlaplacian,'w-');
0162             end;
0163         end
0164         for j = 1:size(freqs,2)
0165             pairels = arrayh(g,find(arrayh(g,:)));
0166             npairs = size(pairels,2)*(size(pairels,2)+1)/2;
0167             pairs = zeros(1,npairs);
0168             ipairs = 1;
0169             for ip = 1:size(pairels,2)
0170                 for jp=ip:size(pairels,2)
0171                     pairs(ipairs) = chpair(pairels(ip),pairels(jp));
0172                     ipairs = ipairs + 1;
0173                 end;
0174             end;
0175 %            chpair(pairels(1),pairels(2))
0176             pairnames = hnames(g,:);
0177 %            if j == 1
0178 %            hold on, plot(real(twod_dist(pairs)),coherence_array(j,pairs),scat_type(iline,:))
0179 %            end;
0180             if j == 2
0181             hold on, plot(real(twod_dist(pairs)),coherence_array(j,pairs),scat_type(2,:))
0182             diff_pairs = find(abs(coherence_array(2,:) - coherence_array(1,:)) > coh_crit);
0183             mask = zeros(1,size(coherence_array,2));
0184             mask(pairs) = ones(1,size(pairs,2));
0185             mask_diff = zeros(1,size(coherence_array,2));
0186             mask_diff(diff_pairs) = ones(1,size(diff_pairs,2));
0187             new_mask = mask_diff.*mask;
0188             pairs_diff = find(new_mask);
0189             hold on, plot(real(twod_dist(pairs_diff)),coherence_array(j,pairs_diff),scat_type(3,:))
0190             end
0191 %            p_coh = polyfit(real(twod_dist(pairs)),coherence_array(j,pairs),4);
0192 %            coh_fit = real(polyval(p_coh,[0:1:fix(max(twod_dist(pairs)))]));
0193 %            hold on, plot([0:1:max(twod_dist(pairs))],coh_fit,line_type(iline,:)),
0194             hold on, axis([0 max(twod_dist(pairs))+1 0 1])
0195             title(['Coherence versus Distance: ' deblank(setstr(obs_labels(obs(1),:))) ' ' hnames(g,:)]);
0196             text([max(twod_dist(pairs))-2.5],[1-0.1*j],[scat_type(iline+1,2) ' ' int2str(freqs(j)) ' Hz'])
0197             xlabel('Interelectrode Distance (cm)')
0198             ylabel('Coherence')
0199             iline = iline+ 1;
0200         end
0201         chpair_list = chpairindex_2chpair(pairs_diff);
0202         chpair_coh((g-1)*size(chpair_list,1)+1:g*size(chpair_list,1),:) = [g*ones(size(chpair_list,1),1) obs(1)*ones(size(chpair_list,1),1) freqs(1)*ones(size(chpair_list,1),1) freqs(2)*ones(size(chpair_list,1),1) chpair_list twod_dist(pairs_diff)' coherence_array(1,pairs_diff)' coherence_array(2,pairs_diff)'];
0203         
0204     end
0205 end
0206 status = 1;
0207 
0208 
0209 
0210 
0211 
0212 
0213 
0214 
0215 
0216 
0217 
0218 
0219 
0220 
0221 
0222 
0223 
0224 
0225 
0226 
0227 
0228 
0229 
0230 
0231 
0232 
0233 
0234 
0235

Generated on Sun 25-Aug-2019 04:00:39 by m2html © 2003