Home > eeg > egis > meg_code > image_meg_power.m

image_meg_power

PURPOSE ^

SYNOPSIS ^

function status = image_meg_power(freqs,obs,dimen,paging,plot_res,power_type,powerfilename,output_name);

DESCRIPTION ^

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).img
    if 'byobs' is selected the output is 
    obs_label.f (freqs) .img
plot_res = plot resolution e.g., 80 default is 50
power_type = 'power' or 'amplitude' (default)
powerfname = powerfilename (can be gui by skipping or passing a blank)
output_name = root name of output file, defaults to gui

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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