Home > eeg > egis > scripts > image_eeg_phase.m

image_eeg_phase

PURPOSE ^

status = = image_eeg_phase(freqs,dimen,obs,paging,plot_res,ref_chan,phasefname,output_name);

SYNOPSIS ^

function status = image_eeg_phase(freqs,dimen,obs,paging,plot_res,ref_chan,phase_type,phasefname,output_name);

DESCRIPTION ^

status = = image_eeg_phase(freqs,dimen,obs,paging,plot_res,ref_chan,phasefname,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 phase w/respect to (default is 73)
phase_type =default is cosine, can be actual phase
phasefname = phasefilename (can be gui by skipping)
output_name = output filename root (can be gui)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = image_eeg_phase(freqs,dimen,obs,paging,plot_res,ref_chan,phase_type,phasefname,output_name);
0002 %status = = image_eeg_phase(freqs,dimen,obs,paging,plot_res,ref_chan,phasefname,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 phase w/respect to (default is 73)
0016 %phase_type =default is cosine, can be actual phase
0017 %phasefname = phasefilename (can be gui by skipping)
0018 %output_name = output filename root (can be gui)
0019 if nargin < 8
0020     [fid, phasefname, pathname] = get_fid('rb');
0021     output_name = powerfname;
0022 elseif isempty(phasefname)
0023     [fid, phasefname, pathname] = get_fid('rb');
0024 else
0025     fid = fopen(phasefname,'rb');
0026     pathname = [];
0027 end;
0028 version = fread(fid,1,'int16');
0029 if version ~= -2
0030     error('this is not a phase file');
0031 end;
0032  [nfiles,obs_labels,Epoch,Window_Length,NEpoch,Nbad_chan,bad_chan,ref_flag,reference,NChan,NFreq] = rd_anal_hdr(fid);
0033 if nargin == 0
0034     freqs = [5:1:20];
0035     obs = [1:nfiles];
0036     dimen = [sqrt(size(freqs,2)) sqrt(size(freqs,2))];
0037     paging = 'byobs';
0038     plot_res = 50;
0039     ref_chan = 73;
0040     phase_type = 'cos';
0041 end;
0042 if nargin == 1
0043     obs = [1:nfiles];
0044     dimen = [sqrt(size(freqs,2)) sqrt(size(freqs,2))];
0045     paging = 'byobs';
0046     plot_res = 50;
0047     ref_chan = 73;
0048     phase_type = 'cos';
0049 end;        
0050 if nargin == 2
0051     obs = [1:nfiles];
0052     paging = 'byobs';
0053     plot_res = 50;
0054     ref_chan = 73;
0055     phase_type = 'cos';
0056 end;    
0057 if nargin == 3
0058     paging = 'byobs';
0059     plot_res = 50;
0060     ref_chan = 73;
0061     phase_type = 'cos';
0062 end;
0063 if nargin == 4
0064     plot_res = 50;
0065     ref_chan = 73;
0066     phase_type = 'cos';
0067 end;
0068 if nargin == 5
0069     ref_chan = 73;
0070     phase_type = 'cos';
0071 end;
0072 if isempty(paging)
0073     paging = 'byobs';
0074 end
0075 if isempty(plot_res)
0076     plot_res = 50;
0077 end;
0078 if isempty(dimen)
0079     dimen = [sqrt(size(freqs,2)) sqrt(size(freqs,2))];
0080 end
0081 if nargin < 9
0082     [outfid,output_name] = put_fid('wb');
0083     fclose(outfid);
0084 end
0085 
0086 if isempty(obs)
0087     obs = [1:nfiles];
0088 end;
0089 if isempty(ref_chan)
0090     ref_chan = 73;
0091 end;
0092 if isempty(phase_type)
0093     phase_type = 'cos'
0094 end;
0095 obs_mask = zeros(1,nfiles);
0096 obs_mask(obs) = ones(1,size(obs,2));
0097 ch_pair_indices;
0098 if strcmp(paging,'byobs')
0099     for i = 1:nfiles
0100         if obs_mask(i) > 0 
0101         avgphase = fread(fid,[NChan(i),NFreq(i)],'float');
0102         avgphase = avgphase';
0103         bins = freqs*Epoch(i) + ones(1,size(freqs,2));
0104         bchan = bad_chan(i,find(bad_chan(i,:)));
0105         imagename = [output_name '.f' int2str(freqs) '.r' int2str(ref_chan) '.pha'];
0106         pchan = chpair2nchan(NChan(i));
0107         cohplt = zeros(bins,pchan);
0108         for i = 1:pchan
0109             cohplt(bins,i) = avgphase(bins,chpair(ref_chan,i));
0110         end;
0111         if strcmp(phase_type,'cos')
0112             cohplt = cos(cohplt);
0113         end;
0114         make_a_image(cohplt(bins,:),bchan,plot_res,dimen(1),dimen(2),imagename);
0115         else
0116         skip_bytes = NChan(i)*NFreq(i)*4;
0117         fseek(fid,skip_bytes,'cof');
0118         end;
0119     end;
0120 elseif strcmp(paging,'cross') 
0121     image_binary = zeros(dimen(1)*plot_res,dimen(2)*plot_res);
0122     iff = 1;
0123     for i = 1:nfiles
0124         if obs_mask(i) > 0 
0125         avgphase = fread(fid,[NChan(i),NFreq(i)],'float');
0126         avgphase = avgphase';
0127         bins = freqs*Epoch(i) + ones(1,size(freqs,2));
0128         bchan = bad_chan(i,find(bad_chan(i,:)));
0129         pchan = chpair2nchan(NChan(i));
0130         for i = 1:pchan
0131             cohplt(bins,i) = avgphase(bins,chpair(ref_chan,i));
0132         end;
0133         if strcmp(phase_type,'cos')
0134             cohplt = cos(cohplt);
0135         end
0136         image_binary((iff-1)*plot_res+1:iff*plot_res,:) = make_a_image(cohplt(bins,:),bchan,plot_res,1,size(bins,2),[]);
0137         iff = iff + 1;
0138         else
0139         skip_bytes = NChan(i)*NFreq(i)*4;
0140         fseek(fid,skip_bytes,'cof');
0141         end;
0142     end;
0143     imagename = [output_name '.o' int2str(obs) '.f' int2str(freqs) '.r' int2str(ref_chan) '.pha.img'];
0144     ifid = fopen(imagename,'wb');
0145     if ifid < 0
0146         fclose('all');
0147         error('file open for image failed');
0148     end;
0149     num_written = fwrite(ifid, size(image_binary), 'float');
0150     if num_written ~= 2
0151             error('Failed to write header info');
0152     end 
0153 
0154     num_written = fwrite(ifid,image_binary','float');
0155     if num_written ~= size(image_binary,1)*size(image_binary,2)
0156         error('write-out failed')
0157     end;
0158 end;    
0159 status = 1;
0160 
0161 
0162 
0163 
0164 
0165 
0166 
0167

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