Home > eeg > egis > scripts > plot_eeg_coherence.m

plot_eeg_coherence

PURPOSE ^

status = plot_eeg_coherence(freqs,obs,chans,lines,coherencefname);

SYNOPSIS ^

function status = plot_eeg_coherence(freqs,obs,chans,lines,coherencefname);

DESCRIPTION ^

status = plot_eeg_coherence(freqs,obs,chans,lines,coherencefname);

freqs = frequencies to plot, e.g. [3 30] limits the plot to 3 to 30 Hz  
obs = observations in the power file to plot (defaults to all)
chans = channel pairs to plot (defaults to all pairs of F3 F4 P3 P4);
    e.g. [26 124; 32 34;], i.e. the pairs are separated by a semicolon
 nobs <= 5. 
lines = 'black' or 'color'
coherencefname = coherencefilename (can be gui by skipping or passing a blank)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = plot_eeg_coherence(freqs,obs,chans,lines,coherencefname);
0002 %status = plot_eeg_coherence(freqs,obs,chans,lines,coherencefname);
0003 %
0004 %freqs = frequencies to plot, e.g. [3 30] limits the plot to 3 to 30 Hz
0005 %obs = observations in the power file to plot (defaults to all)
0006 %chans = channel pairs to plot (defaults to all pairs of F3 F4 P3 P4);
0007 %    e.g. [26 124; 32 34;], i.e. the pairs are separated by a semicolon
0008 % nobs <= 5.
0009 %lines = 'black' or 'color'
0010 %coherencefname = coherencefilename (can be gui by skipping or passing a blank)
0011 %
0012 if nargin < 5
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 if nargin == 0
0023     freqs = [0 40];
0024     obs = [1:nfiles];
0025     chans = [25 124;25 62;25 86;124 62;124 86;62 86];
0026     lines = 'black';
0027 end;
0028 if nargin == 1
0029     obs = [1:nfiles];
0030     chans = [25 124;25 62;25 86;124 62;124 86;62 86];
0031     lines = 'black';
0032 end;        
0033 if nargin == 2
0034     chans = [25 124;25 62;25 86;124 62;124 86;62 86];
0035     lines = 'black';
0036 end;    
0037 if nargin == 3
0038     lines = 'black';
0039 end;
0040 
0041 if isempty(lines)
0042     lines = 'black';
0043 end
0044 if isempty(chans)
0045     chans = [25 124;25 62;25 86;124 62;124 86;62 86];
0046 end
0047 if isempty(obs)
0048     obs = [1:nfiles];
0049 end;
0050 if isempty(freqs)
0051     freqs = [0 40];
0052 end;
0053 if size(obs,2) > 5
0054     fclose('all')
0055     error('too many observations > 5 to be plotted in a single plot')
0056 end;
0057 if size(chans,1) > 1
0058 layout = ceil(sqrt(size(chans,1)+1));
0059 else
0060 layout = 1;
0061 end;
0062 ch_pair_indices;
0063 if strcmp(lines,'black')
0064 line_type = ['k- ';'k--';'k-.';'kx ';'ko '];
0065 else    
0066 line_type = ['k-';'r-';'b-';'g-';'m-';'c-'];
0067 end;
0068 figure
0069 coherencemax = 1;
0070 obs_mask = zeros(1,nfiles);
0071 obs_mask(obs) = ones(1,size(obs,2));
0072 iline = 1;
0073 for i = 1:nfiles
0074     if obs_mask(i) > 0
0075     avgcoherence = fread(fid,[NChan(i),NFreq(i)],'float');
0076     avgcoherence = avgcoherence';
0077     binmin = freqs(1)*Epoch(i) + 1;
0078     binmax = freqs(2)*Epoch(i) + 1;
0079     freqstep = 1/Epoch(i);
0080     freq = [freqs(1):freqstep:freqs(2)];
0081     for ic = 1:size(chans,1) 
0082         hold on, subplot(layout,layout,ic), plot(freq,avgcoherence(binmin:binmax,chpair(chans(ic,1),chans(ic,2))),line_type(iline,:))
0083         if layout < 3
0084             title(['Channels ' int2str(chans(ic,1)) ':' int2str(chans(ic,2))])
0085             xlabel('Frequency(Hz)')
0086             ylabel('Coherence')
0087         end    
0088     end
0089     iline = iline + 1;
0090     else
0091     skip_bytes = NChan(i)*NFreq(i)*4;
0092     fseek(fid,skip_bytes,'cof');
0093     end;
0094 end    
0095 for ic = 1:size(chans,1)
0096     subplot(layout,layout,ic), axis([0 freqs(2) 0 1]);
0097 end;
0098 maxcoherence = 1;
0099 if layout < 2
0100     for i = 1:size(obs,2)
0101         hold on, plot([0.6*freqs(2) 0.7*freqs(2)],[(1-0.1*i)*maxcoherence  (1-0.1*i)*maxcoherence],line_type(i,:))
0102         text(0.75*freqs(2),(1-0.1*i)*maxcoherence,deblank(setstr(obs_labels(obs(i),:))));
0103     end;
0104 end 
0105 if layout > 2
0106     for i = 1:size(chans,1)
0107         hold on, subplot(layout,layout,i), text(0.6*freqs(2),0.6*maxcoherence,[int2str(chans(i,1)) ' : ' int2str(chans(i,2))]);
0108     end;
0109 status = 1;
0110 end;
0111 if layout > 1
0112     for i = 1:size(obs,2)
0113         hold on, subplot(layout,layout,layout*layout),plot([0.2 1],[1 1]*(1.1-0.2*i),line_type(i,:)), axis([0 1.5 0 1])
0114         hold on, subplot(layout,layout,layout*layout),text(1.2,(1.1-0.2*i),deblank(setstr(obs_labels(obs(i),:))))
0115         hold on, subplot(layout,layout,layout*layout),axis('off')
0116     end;
0117     hold on, subplot(layout,layout,layout*layout),axis('off');
0118 end;
0119 status = 1;
0120

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