Home > eeg > egis > scripts > image_eeg_coherence.m

image_eeg_coherence

PURPOSE ^

status = = image_eeg_coherence(freqs,dimen,obs,paging,plot_res,ref_chan,coherencefname,output_name);

SYNOPSIS ^

function status = image_eeg_coherence(freqs,dimen,obs,paging,plot_res,ref_chan,coherencefname,output_name);

DESCRIPTION ^

status = = image_eeg_coherence(freqs,dimen,obs,paging,plot_res,ref_chan,coherencefname,output_name);

freqs = frequencies to plot, e.g. [3:7 10] is 3 4 5 6 and 7 and 10 
 [3:0.5:5] is 3 , 3.5 4,4.5,5, default is 5:1:20 
dimen = dimensions of image e.g., [2 3] default is [sqrt(size(freqs,2)] sqrt(size(freqs,2) 
obs = observations (default is all)
paging = 'byobs' or 'cross' default is 'byobs', cross means frequencies
    are columns and observations are rows. 
    if 'cross' is selected the output is 
    image.o (observation nums) .f (freqs).coh.img
    if 'byobs' is selected the output is 
    obs_label.f (freqs) .coh.img
plot_res = plot resolution e.g., 80 default is 50
ref_chan = channel to plot coherence w/respect to (default is 73)
coherencefname = coherencefilename (can be gui by skipping)
output_name = root name of output file, will default to gui.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = image_eeg_coherence(freqs,dimen,obs,paging,plot_res,ref_chan,coherencefname,output_name);
0002 %status = = image_eeg_coherence(freqs,dimen,obs,paging,plot_res,ref_chan,coherencefname,output_name);
0003 %
0004 %freqs = frequencies to plot, e.g. [3:7 10] is 3 4 5 6 and 7 and 10
0005 % [3:0.5:5] is 3 , 3.5 4,4.5,5, default is 5:1:20
0006 %dimen = dimensions of image e.g., [2 3] default is [sqrt(size(freqs,2)] sqrt(size(freqs,2)
0007 %obs = observations (default is all)
0008 %paging = 'byobs' or 'cross' default is 'byobs', cross means frequencies
0009 %    are columns and observations are rows.
0010 %    if 'cross' is selected the output is
0011 %    image.o (observation nums) .f (freqs).coh.img
0012 %    if 'byobs' is selected the output is
0013 %    obs_label.f (freqs) .coh.img
0014 %plot_res = plot resolution e.g., 80 default is 50
0015 %ref_chan = channel to plot coherence w/respect to (default is 73)
0016 %coherencefname = coherencefilename (can be gui by skipping)
0017 %output_name = root name of output file, will default to gui.
0018 if nargin < 7
0019     [fid, coherencefname, pathname] = get_fid('rb');
0020 elseif isempty(coherencefname)
0021     [fid, coherencefname, pathname] = get_fid('rb');
0022 else
0023     fid = fopen(coherencefname,'rb');
0024     pathname = [];
0025 end;
0026 version = fread(fid,1,'int16');
0027 if version ~= -2
0028     error('this is not a coherence file');
0029 end;
0030  [nfiles,obs_labels,Epoch,Window_Length,NEpoch,Nbad_chan,bad_chan,ref_flag,reference,NChan,NFreq] = rd_anal_hdr(fid);
0031 if nargin == 0
0032     freqs = [5:1:20];
0033     obs = [1:nfiles];
0034     dimen = [sqrt(size(freqs,2)) sqrt(size(freqs,2))];
0035     paging = 'byobs';
0036     plot_res = 50;
0037     ref_chan = 73;
0038 end;
0039 if nargin == 1
0040     obs = [1:nfiles];
0041     dimen = [sqrt(size(freqs,2)) sqrt(size(freqs,2))];
0042     paging = 'byobs';
0043     plot_res = 50;
0044     ref_chan = 73;
0045 end;        
0046 if nargin == 2
0047     obs = [1:nfiles];
0048     paging = 'byobs';
0049     plot_res = 50;
0050     ref_chan = 73;
0051 end;    
0052 if nargin == 3
0053     paging = 'byobs';
0054     plot_res = 50;
0055     ref_chan = 73;
0056 end;
0057 if nargin == 4
0058     plot_res = 50;
0059     ref_chan = 73;
0060 end;
0061 if nargin == 5
0062     ref_chan = 73;
0063 end;
0064 if isempty(paging)
0065     paging = 'byobs';
0066 end
0067 if isempty(plot_res)
0068     plot_res = 50;
0069 end;
0070 if isempty(dimen)
0071     dimen = [sqrt(size(freqs,2)) sqrt(size(freqs,2))];
0072 end
0073 
0074 if isempty(obs)
0075     obs = [1:nfiles];
0076 end;
0077 if isempty(ref_chan)
0078     ref_chan = 73;
0079 end;
0080 if nargin < 8
0081     [outfid,output_name] = put_fid('wb');
0082     fclose(outfid);
0083 end
0084 obs_mask = zeros(1,nfiles);
0085 obs_mask(obs) = ones(1,size(obs,2));
0086 ch_pair_indices;
0087 if strcmp(paging,'byobs')
0088     for i = 1:nfiles
0089         if obs_mask(i) > 0 
0090         avgcoherence = fread(fid,[NChan(i),NFreq(i)],'float');
0091         avgcoherence = avgcoherence';
0092         bins = freqs*Epoch(i) + ones(1,size(freqs,2));
0093         bchan = bad_chan(i,find(bad_chan(i,:)));
0094         imagename = [output_name '.f' int2str(freqs) '.coh'];
0095         pchan = chpair2nchan(NChan(i));
0096         cohplt = zeros(bins,pchan);
0097         for i = 1:pchan
0098             cohplt(bins,i) = avgcoherence(bins,chpair(ref_chan,i));
0099         end;
0100         make_a_image(cohplt(bins,:),bchan,plot_res,dimen(1),dimen(2),imagename);
0101         else
0102         skip_bytes = NChan(i)*NFreq(i)*4;
0103         fseek(fid,skip_bytes,'cof');
0104         end;
0105     end;
0106 elseif strcmp(paging,'cross') 
0107     image_binary = zeros(dimen(1)*plot_res,dimen(2)*plot_res);
0108     iff = 1;
0109     for i = 1:nfiles
0110         if obs_mask(i) > 0 
0111         avgcoherence = fread(fid,[NChan(i),NFreq(i)],'float');
0112         avgcoherence = avgcoherence';
0113         bins = freqs*Epoch(i) + ones(1,size(freqs,2));
0114         bchan = bad_chan(i,find(bad_chan(i,:)));
0115         pchan = chpair2nchan(NChan(i));
0116         for i = 1:pchan
0117             cohplt(bins,i) = avgcoherence(bins,chpair(ref_chan,i));
0118         end;
0119         image_binary((iff-1)*plot_res+1:iff*plot_res,:) = make_a_image(cohplt(bins,:),bchan,plot_res,1,size(bins,2),[]);
0120         iff = iff + 1;
0121         else
0122         skip_bytes = NChan(i)*NFreq(i)*4;
0123         fseek(fid,skip_bytes,'cof');
0124         end;
0125     end;
0126     imagename = [output_name '.o' int2str(obs) '.f' int2str(freqs) '.coh.img'];
0127     ifid = fopen(imagename,'wb');
0128     if ifid < 0
0129         fclose('all');
0130         error('file open for image failed');
0131     end;
0132     num_written = fwrite(ifid, size(image_binary), 'float');
0133     if num_written ~= 2
0134             error('Failed to write header info');
0135     end 
0136 
0137     num_written = fwrite(ifid,image_binary','float');
0138     if num_written ~= size(image_binary,1)*size(image_binary,2)
0139         error('write-out failed')
0140     end;
0141 end;    
0142 status = 1;
0143 
0144 
0145 
0146 
0147 
0148 
0149 
0150

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