Home > eeg > egis > meg_code > plot_meg_coherence.m

plot_meg_coherence

PURPOSE ^

SYNOPSIS ^

function status = plot_meg_coherence(freqs,chans,obs,lines,coherencefilename);

DESCRIPTION ^

 plots meg coherence

 freqs = [min_freq mex_freq];
 chans = channel pair list (absolute)
 obs = observation number
 lines = 'color' or 'black'
 coherencefilename = can be gui

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = plot_meg_coherence(freqs,chans,obs,lines,coherencefilename);
0002 %
0003 % plots meg coherence
0004 %
0005 % freqs = [min_freq mex_freq];
0006 % chans = channel pair list (absolute)
0007 % obs = observation number
0008 % lines = 'color' or 'black'
0009 % coherencefilename = can be gui
0010 %
0011 
0012 if nargin < 3
0013     error('insufficient input arguments');
0014 end;
0015 
0016 if nargin < 5
0017     [fid,coherencefilename] = get_fid('rb');
0018     fclose(fid);
0019 end;
0020 
0021 if nargin == 3
0022     lines = 'black';
0023 end;
0024 
0025 if isempty(lines)
0026     lines = 'black';
0027 end
0028 
0029 if size(obs,2) > 4
0030     error('too many observations for a single plot');
0031 end;
0032 if lines  == 'black'
0033     line_type = ['k- ';'k--';'k-.';'k- '];
0034 else
0035     line_type = ['k-';'r-';'b-';'g-'];
0036 end;
0037 pfid = open_file_w_byte_order(coherencefilename,-3);
0038 if size(chans,1) > 1
0039 layout = ceil(sqrt(size(chans,1)+1));
0040 else
0041 layout =1;
0042 end
0043 [pversion,nfile,NChan,NMeg,NReference,NEeg,NAnalog,NBad_chan,bad_chan,NEpoch,Epoch,nfreq,obs_labels] = rd_meg_anal_hdr(pfid);
0044 obs_mask = zeros(1,nfile);
0045 all_NChan = NChan.*(NChan+ones(1,size(NChan,2)))/2;
0046 obs_mask(obs) = ones(1,size(obs,2));
0047 coherencemax = 1;
0048 figure
0049 iline = 1;
0050 for i = 1:nfile
0051     if obs_mask(i) > 0
0052     avgcoherence = fread(fid,[all_NChan(i),nfreq(i)],'float');
0053     avgcoherence = avgcoherence';
0054     binmin = fix(freqs(1)*Epoch(i) + 1);
0055     binmax = fix(freqs(2)*Epoch(i) + 1);
0056     freqstep = 1/Epoch(i);
0057     freq = [(binmin-1):(binmax-1)]*(1/(Epoch(i)));
0058     chpair = channel_pairs(NChan(i));
0059     for ic = 1:size(chans,1) 
0060         hold on, subplot(layout,layout,ic), plot(freq,avgcoherence(binmin:binmax,chpair(chans(ic,1),chans(ic,2))),line_type(iline,:))
0061         if layout < 3
0062             title(['Channels ' int2str(chans(ic,1)) ':' int2str(chans(ic,2))])
0063             xlabel('Frequency(Hz)')
0064             ylabel('Coherence')
0065         end    
0066     end
0067     iline = iline + 1;
0068     else
0069     skip_bytes = NChan(i)*nfreq(i)*4;
0070     fseek(fid,skip_bytes,'cof');
0071     end;
0072 end    
0073 for ic = 1:size(chans,1)
0074     subplot(layout,layout,ic), axis([0 freqs(2) 0 1]);
0075 end;
0076 maxcoherence = 1;
0077 if layout < 2
0078     for i = 1:size(obs,2)
0079         hold on, plot([0.6*freqs(2) 0.7*freqs(2)],[(1-0.1*i)*maxcoherence  (1-0.1*i)*maxcoherence],line_type(i,:))
0080         text(0.75*freqs(2),(1-0.1*i)*maxcoherence,deblank(setstr(obs_labels(obs(i),:))));
0081     end;
0082 end 
0083 if layout > 2
0084     for i = 1:size(chans,1)
0085         hold on, subplot(layout,layout,i), text(0.6*freqs(2),0.6*maxcoherence,[int2str(chans(i,1)) ' : ' int2str(chans(i,2))]);
0086     end;
0087 status = 1;
0088 end;
0089 if layout > 1
0090     for i = 1:size(obs,2)
0091         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])
0092         hold on, subplot(layout,layout,layout*layout),text(1.2,(1.1-0.2*i),deblank(setstr(obs_labels(obs(i),:))))
0093         hold on, subplot(layout,layout,layout*layout),axis('off')
0094     end;
0095     hold on, subplot(layout,layout,layout*layout),axis('off');
0096 end;
0097 status = 1;
0098 
0099 
0100

Generated on Fri 22-Mar-2019 04:00:52 by m2html © 2003