Home > eeg > egis > meg_code > plot_meg_power.m

plot_meg_power

PURPOSE ^

SYNOPSIS ^

function status = plot_meg_power(freqs,chans,obs,power_type,lines,powerfilename);

DESCRIPTION ^

 plots meg power

 freqs = [min_freq mex_freq];
 chans = channel list (absolute)
 obs = observation number
 power_type = 'amplitude','power','logpower'
 lines = 'color' or 'black'
 powerfilename = can be gui

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = plot_meg_power(freqs,chans,obs,power_type,lines,powerfilename);
0002 %
0003 % plots meg power
0004 %
0005 % freqs = [min_freq mex_freq];
0006 % chans = channel list (absolute)
0007 % obs = observation number
0008 % power_type = 'amplitude','power','logpower'
0009 % lines = 'color' or 'black'
0010 % powerfilename = can be gui
0011 %
0012 
0013 if nargin < 4
0014     error('insufficient input arguments');
0015 end;
0016 
0017 if nargin < 6
0018     [fid,powerfilename] = get_fid('rb');
0019     fclose(fid);
0020 end;
0021 
0022 if nargin == 4
0023     lines = 'black';
0024 end;
0025 
0026 if isempty(lines)
0027     lines = 'black';
0028 end
0029 
0030 if size(obs,2) > 4
0031     error('too many observations for a single plot');
0032 end;
0033 if lines  == 'black'
0034     line_type = ['k- ';'k--';'k-.';'k- '];
0035 else
0036     line_type = ['k-';'r-';'b-';'g-'];
0037 end;
0038 pfid = open_file_w_byte_order(powerfilename,-2);
0039 if size(chans,2) > 1
0040 lay_out = ceil(sqrt(size(chans,2)+1));
0041 else
0042 lay_out =1;
0043 end
0044 [pversion,nfile,NChan,NMeg,NReference,NEeg,NAnalog,NBad_chan,bad_chan,NEpoch,Epoch,nfreq,obs_labels] = rd_meg_anal_hdr(pfid);
0045 obs_mask = zeros(1,nfile);
0046 obs_mask(obs) = ones(1,size(obs,2));
0047 maxpower = 0;
0048 figure
0049 iline = 1;
0050 for i = 1:nfile
0051     power = fread(pfid,[NChan(i),nfreq(i)],'real*4');
0052     if obs_mask(i) > 0
0053     power = power';
0054     if strcmp(power_type,'amplitude')
0055         power = sqrt(power);
0056     end;
0057     binmin = fix(freqs(1)*Epoch(i) + 1);
0058     binmax = fix(freqs(2)*Epoch(i) + 1);
0059     freqstep = 1/Epoch(i);
0060     freq = [(binmin-1):(binmax-1)]*(1/(Epoch(i)));
0061     for ic = 1:size(chans,2) 
0062         if strcmp(power_type,'logpower')
0063             hold on,subplot(lay_out,lay_out,ic),  semilogy(freq,power(binmin:binmax,chans(ic)),line_type(iline,:))
0064             if lay_out < 3
0065             if chans(ic) <= 148
0066             title(['MEG ' int2str(chans(ic))])
0067             elseif chans(ic) <= 148+NReference
0068             title(['Ref ' int2str(chans(ic))])
0069             elseif chans(ic) <= 148+NReference+NEeg
0070             title(['EEG ' int2str(chans(ic))])
0071             else
0072             title(['Ana ' int2str(chans(ic))])
0073             end;
0074             xlabel('Frequency(Hz)')
0075             ylabel('Power')
0076             end;
0077         else
0078             hold on, subplot(lay_out,lay_out,ic), plot(freq,power(binmin:binmax,chans(ic)),line_type(iline,:))
0079             if lay_out < 3
0080                 title(['Channel ' int2str(chans(ic))])
0081                 xlabel('Frequency(Hz)')
0082                 if strcmp(power_type,'amplitude')
0083                     ylabel('Amplitude');
0084                 else
0085                     ylabel('Power')
0086                 end                
0087             end;
0088         end    
0089     end
0090     mpower = max(max(power(binmin:binmax,chans)));
0091     maxpower = max([maxpower mpower]);
0092     iline = iline + 1;
0093     end;
0094 end    
0095 for ic = 1:size(chans,2)
0096     subplot(lay_out,lay_out,ic), axis([freqs(1) freqs(2) 0 1.05*maxpower]);
0097 end;
0098 if lay_out < 2
0099     for i = 1:size(obs,2)
0100         hold on, plot([0.6*freqs(2) 0.7*freqs(2)],[(1-0.1*i)*maxpower  (1-0.1*i)*maxpower],line_type(i,:))
0101         
0102         text(0.75*freqs(2),(1-0.1*i)*maxpower,obs_labels(obs(i),:));
0103     end;
0104 end
0105 if lay_out > 2
0106     for i = 1:size(chans,2)
0107         if chans(i) <= 148
0108         chan_label = ['MEG ' int2str(chans(i))];
0109         elseif chans(i) <= 148 + NReference
0110         chan_label = ['Ref ' int2str(chans(i))];
0111         elseif chans(i) <= 148 + NReference +NEeg
0112         chan_label = ['EEG ' int2str(chans(i))];
0113         else
0114         chan_label = ['Ana ' int2str(chans(i))];
0115         end 
0116         hold on, subplot(lay_out,lay_out,i), text(0.8*freqs(2),0.8*maxpower,chan_label);
0117     end;
0118 end;
0119 if lay_out > 1
0120     for i = 1:size(obs,2)
0121         hold on, subplot(lay_out,lay_out,lay_out*lay_out),plot([0.2 1],[1 1]*(1.1-0.2*i),line_type(i,:)), axis([0 1.5 0 1])
0122         hold on, subplot(lay_out,lay_out,lay_out*lay_out),text(1.2,(1.1-0.2*i),obs_labels(obs(i),:))
0123         hold on, subplot(lay_out,lay_out,lay_out*lay_out),axis('off')
0124     end;
0125     hold on, subplot(lay_out,lay_out,lay_out*lay_out),axis('off');
0126 end;
0127 status = 1;
0128 
0129 
0130 
0131 
0132

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