0001 function status =coherence_contours(freqs,obs,array,coherencefname);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 4
0013 [fid] = get_fid('rb');
0014 else
0015 fid = fopen(coherencefname,'rb');
0016 end;
0017 version = fread(fid,1,'int16');
0018 if version ~= -2
0019 error('this is not a coherence file');
0020 end;
0021 [nfiles,obs_labels,Epoch,Window_Length,NEpoch,Nbad_chan,bad_chan,ref_flag,reference,NChan,NFreq] = rd_anal_hdr(fid);
0022 frewind(fid);
0023 if nargin == 0
0024 freqs = [0:40];
0025 obs = [1:nfiles];
0026 array = 'all';
0027 lines = 'black';
0028 end;
0029 if nargin == 1
0030 obs = [1:nfiles];
0031 array = 'all';
0032 lines = 'black';
0033 end;
0034 if nargin == 2
0035 array = 'all';
0036 lines = 'black';
0037 end;
0038
0039 if isempty(array)
0040 array = 'all';
0041 end
0042 if isempty(obs)
0043 obs = [1:nfiles];
0044 end;
0045 if isempty(freqs)
0046 freqs = [0:40];
0047 end;
0048
0049 ch_pair_indices;
0050 coherencemax = 1;
0051 iline = 1;
0052 [xelec,yelec,zelec] = electrodes(129);
0053 twod_dist = real(twod_pos(xelec,yelec,zelec,9.2));
0054 if isstr(array)
0055 [arrayg,gnames] = arrays(array,[]);
0056 else
0057 arrayg = array;
0058 end
0059 for g = 1:size(arrayg,1)
0060 for io = 1:size(obs,2)
0061 figure
0062 [npairs, pairs, pairnames] = look_up_pairs(array,g,bad_chan,obs(io));
0063 version = fread(fid,1,'int16');
0064 [nfiles,obs_labels,Epoch,Window_Length,NEpoch,Nbad_chan,bad_chan,ref_flag,reference,NChan,NFreq] = rd_anal_hdr(fid);
0065 coherence_array = real(get_eeg_coherence(fid,freqs,obs(io),nfiles,NChan,NFreq,Epoch));
0066 distance = [0:1:fix(max(twod_dist(pairs)))];
0067 coh_fit = zeros(size(freqs,2),size(distance,2));
0068 for j = 1:size(freqs,2)
0069
0070 p_coh = polyfit(twod_dist(pairs),coherence_array(j,pairs),4);
0071 coh_fit(j,:) = real(polyval(p_coh,distance));
0072 end;
0073 distance = [0:1:fix(max(twod_dist(pairs)))];
0074 hottie = hot;
0075 hotties = hottie(33:64,:);
0076 colormap(hotties);
0077 contourf(distance,freqs,coh_fit,[1:-0.1:0.1]),colorbar
0078 hold on, contour(distance,freqs,coh_fit,[0.1:0.1:0.2],'w--')
0079 hold on, contour(distance,freqs,coh_fit,[0.3:0.1:1],'k-')
0080 axis([0 max(twod_dist(pairs)) 0 max(freqs)]);
0081 ylabel('Frequency(Hz)')
0082 xlabel('Interelectrode Distance (cm)')
0083 title(['Coherence versus Distance and Frequency: ' deblank(setstr(obs_labels(obs(io),:))) ' ' pairnames]);
0084 end
0085 end
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114