Home > functions > device > trigger_timing > vb_plot_status.m

vb_plot_status

PURPOSE ^

plot status signal and extracted trials

SYNOPSIS ^

function vb_plot_status(fname, plot_parm)

DESCRIPTION ^

 plot status signal and extracted trials
   vb_plot_status(fname)
 fname : trigger info file name

 status : status signal
 status_val(m) = status value for m-th condition (m=1:Ncomdition)
 trig(n)       : Onset time index for n-th trial 
 cond_id(n)    : Condition ID for n-th trial 
 ix_trial(:,n) : Time index for n-th trial   [Ntrial x Tperiod]
                 Tperiod : # of time sample in one trial
                 Ntrial  : # of trials

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function    vb_plot_status(fname, plot_parm)
0002 % plot status signal and extracted trials
0003 %   vb_plot_status(fname)
0004 % fname : trigger info file name
0005 %
0006 % status : status signal
0007 % status_val(m) = status value for m-th condition (m=1:Ncomdition)
0008 % trig(n)       : Onset time index for n-th trial
0009 % cond_id(n)    : Condition ID for n-th trial
0010 % ix_trial(:,n) : Time index for n-th trial   [Ntrial x Tperiod]
0011 %                 Tperiod : # of time sample in one trial
0012 %                 Ntrial  : # of trials
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 NXmax = 4;
0018 NYmax = 4;
0019 Ymax = [];
0020 Ymin = [];
0021 plot_status = 1;
0022 plot_abs = 1;
0023 Pretrigger_ms   = [ ];  % [msec]
0024 Posttrigger_ms  = [ ]; % [msec]
0025 
0026 if nargin == 1, plot_parm = []; end;
0027 % Output PNG file
0028 if ~isfield(plot_parm,'mode'), plot_parm.mode = 1; end;
0029 if ~isfield(plot_parm,'png'), plot_parm.png = []; end;
0030 % Max number of trials in X
0031 if isfield(plot_parm,'NXmax'), NXmax = plot_parm.NXmax; end;
0032 % Max number of subplot in Y
0033 if isfield(plot_parm,'NYmax'), NYmax = plot_parm.NYmax; end;
0034 
0035 if isfield(plot_parm,'Ymax'), Ymax = plot_parm.Ymax; end;
0036 if isfield(plot_parm,'Ymin'), Ymin = plot_parm.Ymin; end;
0037 if isfield(plot_parm,'status'), plot_status = plot_parm.status; end;
0038 if isfield(plot_parm,'abs'), plot_abs = plot_parm.abs; end;
0039 if isfield(plot_parm,'Pretrigger_ms'),  Pretrigger_ms  = plot_parm.Pretrigger_ms ; end;
0040 if isfield(plot_parm,'Posttrigger_ms'), Posttrigger_ms = plot_parm.Posttrigger_ms; end;
0041 
0042 info = load(fname);
0043 parm = info.parm;
0044 ix_trial   = info.ix_trial;
0045 trig       = info.trig;
0046 status     = info.status;
0047 status_out = info.status_out;
0048 status_val = info.status_val;
0049 cond_id    = info.cond_id;
0050 
0051 % Sampling frequency
0052 fs = parm.fsamp;
0053 dt = 1000/fs; % [msec]
0054 dT = 0; % [msec]
0055 
0056 [Nch, T] = size(status);
0057 Ncond = length(status_val);
0058 
0059 % Sampleing time [msec]
0060 t = (0:(T-1))*dt;
0061 
0062 % onset time and trial period
0063 Ntrial  = length(trig);
0064 
0065 if isfield(plot_parm,'Ntrial') && ~isempty(plot_parm.Ntrial)
0066     Ntrial_id = plot_parm.Ntrial; 
0067 else
0068     Ntrial_id = 1:Ntrial;
0069 end;
0070 
0071 if ~isempty(Pretrigger_ms)
0072     % Sample number for Pre/Post period
0073     Pretrigger  = ceil(Pretrigger_ms *(fs/1000));
0074     Posttrigger = ceil(Posttrigger_ms*(fs/1000));
0075     % Time index for one trial
0076     ix = (-Pretrigger:Posttrigger)';
0077     Tp = length(ix);
0078     
0079     % Time index for all trials extracted from 'trig'
0080     ix_trial = repmat(ix,[1 Ntrial]) + repmat(trig,[Tp 1]);
0081 end
0082 
0083 trg_on  = trig*dt;
0084 trg_on  = [trg_on ;trg_on];
0085 
0086 trg_st  = ix_trial(1,:)*dt;
0087 trg_end = ix_trial(end,:)*dt;
0088 trg_mid = mean(trg_end - trg_st);
0089 trg_st2  = trg_st  - trg_mid/2;
0090 trg_end2 = trg_end + trg_mid/2;
0091 
0092 Nfig = ceil(Ntrial/NXmax);
0093 
0094 switch    plot_parm.mode
0095 case    1
0096     NX   = 1;
0097     NXmax = ceil(Ntrial/NYmax);
0098     Nfig  = NYmax;
0099 case    2
0100     NX   = NXmax;
0101 case    3
0102     NX   = 1;
0103 end
0104 
0105 if Nfig < NYmax
0106     NY = Nfig;
0107 else
0108     NY = NYmax;
0109 end
0110 
0111 switch    plot_parm.mode
0112 case    1
0113     % --- plot all trial
0114     plot_multi_cond;
0115 case    2
0116     % --- plot one trial in one subplot
0117     plot_each_trial;
0118 case    3
0119     % --- plot multi trial in one subplot
0120     plot_multi_trial;
0121 end
0122 
0123 end_figure(npng);
0124 
0125 % Program-END of primary function
0126 %return
0127 
0128 % --- plot one trial in one subplot
0129 function    plot_each_trial
0130     nfig = 1;
0131     npng = 0;
0132     figure;
0133     
0134     % plot extracted epoch
0135     for n=Ntrial_id
0136         id = cond_id(n);
0137         if Nch == Ncond
0138             y  = status(id,:);
0139             ys = status_out(id,:);
0140         else
0141             y  = status;
0142             ys = status_out;
0143         end
0144         
0145         if plot_abs == 1, y = abs(y); end
0146         
0147         y  = y/max(ys);
0148         ys = ys/max(ys);
0149         
0150         ymax = max(y(ix_trial(:,n)));
0151         
0152         y_trg    = [0; ymax];
0153         y_status = [status_val(id); status_val(id)];
0154         
0155         %nfig = new_figure(NX,NY,nfig,fname,plot_parm);
0156         [nfig ,npng] = new_figure(nfig,npng);
0157         
0158         subplot(NY,NX,nfig); 
0159         
0160         plot(t,y)
0161         hold on
0162         plot(t,ys,'-b')
0163         plot(trg_on(:,n), y_trg ,'-r')
0164         
0165         if plot_status == 1
0166 %            plot([trg_st(n) ;trg_end(n)], y_status ,'-r','LineWidth',5)
0167             plot([trg_st(n) ;trg_end(n)], y_status ,'-r')
0168         end
0169         
0170         xlim([trg_st(n)-dT , trg_end(n)+dT])
0171         if ~isempty(Ymax)
0172             ylim([Ymin Ymax])
0173         end
0174 %        if strcmp( parm.trig_type ,'voice' ), ylim([0 ymax]); end;
0175         
0176         nfig=nfig+1;
0177     end
0178     
0179 end
0180 % END plot_each_trial
0181 
0182 % --- plot multi_trial in one subplot
0183 function    plot_multi_trial
0184     nfig = 1;
0185     npng = 0;
0186     figure;
0187     
0188     % plot extracted epoch
0189     for m=1:Nfig
0190         
0191         [nfig ,npng] = new_figure(nfig,npng);
0192         subplot(NY,NX,nfig); 
0193         
0194         for n=1:Ncond
0195             id = cond_id(n);
0196             if Nch == Ncond
0197                 y  = status(id,:);
0198                 ys = status_out(id,:);
0199             else
0200                 y  = status;
0201                 ys = status_out;
0202             end
0203             
0204             if plot_abs == 1, y = abs(y); end
0205             
0206             y  = y/max(ys);
0207             ys = ys/max(ys);
0208             
0209             ymax = max(y(ix_trial(:,n)));
0210             ix = find(cond_id == n);
0211             NN = length(ix);
0212             
0213             y_trg    = [zeros(1, NN); repmat(ymax,1,NN)];
0214             y_status = repmat(status_val(n), 2, NN);
0215             
0216             plot(t,y)
0217             hold on
0218             plot(t,ys,'-b')
0219             plot(trg_on(:,ix), y_trg ,'-r')
0220             if plot_status == 1
0221 %                plot([trg_st(ix) ;trg_end(ix)], y_status ,'-r','LineWidth',5)
0222                 plot([trg_st(ix) ;trg_end(ix)], y_status ,'-r')
0223             end
0224         end
0225         
0226         n1 = NXmax*(m-1) + 1;
0227         n2 = min(n1+NXmax, Ntrial);
0228         xlim([trg_st2(n1) trg_st2(n2)])
0229         
0230         if m == Nfig,
0231             xlim([trg_st2(n1) t(end)])
0232         end
0233         if ~isempty(Ymax)
0234             ylim([Ymin Ymax])
0235         end
0236 %        if strcmp( parm.trig_type ,'voice' ), ylim([0 ymax]); end;
0237         nfig=nfig+1;
0238     end
0239 end
0240 %return
0241 % END plot_multi_trial
0242 
0243 % --- plot multi_trial in one subplot
0244 function    plot_multi_cond
0245     nfig = 1;
0246     npng = 0;
0247     figure;
0248     
0249     % plot extracted epoch
0250     if Nch == Ncond
0251         Mcond = 1;
0252     else
0253         Mcond = Ncond;
0254     end
0255     
0256     for ch=1:Nch
0257         y  = status(ch,:);
0258         ys = status_out(ch,:);
0259         
0260         if plot_abs == 1, y = abs(y); end
0261         
0262         y  = y/max(ys);
0263         ys = ys/max(ys);
0264         
0265         for m=1:Nfig
0266             [nfig ,npng] = new_figure(nfig,npng);
0267             subplot(NY,NX,nfig); 
0268         
0269             for n=1:Mcond
0270                 if Nch == Ncond
0271                     n_cond = ch;
0272                 else
0273                     n_cond = n;
0274                 end
0275 
0276                 ymax = max(y(ix_trial(:,n)));
0277                 ix = find(cond_id == n_cond);
0278                 NN = length(ix);
0279                 
0280                 y_trg    = [zeros(1, NN); repmat(ymax,1,NN)];
0281                 y_status = repmat(status_val(n), 2, NN);
0282                 
0283                 plot(t,y)
0284                 hold on
0285                 plot(t,ys,'-b')
0286                 plot(trg_on(:,ix), y_trg ,'-r')
0287                 
0288                 if plot_status == 1
0289 %                    plot([trg_st(ix) ;trg_end(ix)], y_status ,...
0290 %                         '-r','LineWidth',5)
0291                     plot([trg_st(ix) ;trg_end(ix)], y_status ,'-r')
0292                 end
0293             end
0294         
0295             n1 = NXmax*(m-1) + 1;
0296             n2 = min(n1+NXmax, Ntrial);
0297             xlim([trg_st2(n1) trg_st2(n2)])
0298             if m == Nfig,
0299                 xlim([trg_st2(n1) t(end)])
0300             end
0301             if ~isempty(Ymax)
0302                 ylim([Ymin Ymax])
0303             end
0304             
0305 %            if strcmp( parm.trig_type ,'voice' ), ylim([0 ymax]); end;
0306             nfig=nfig+1;
0307         end
0308     end
0309 end
0310 %return
0311 % END plot_multi_trial
0312 
0313 %function    nfig = new_figure(NX,NY,nfig,fname,plot_parm)
0314 function    [nfig ,npng] = new_figure(nfig,npng);
0315     if nfig > NX*NY, 
0316         nfig0 = ceil(NX/2);
0317         subplot(NY,NX,nfig0);
0318         title(['Status signal: ' fname],'Interpreter','none')
0319         
0320         if ~isempty(plot_parm.png)
0321             npng = npng + 1;
0322             nstr = num2str(npng);
0323             print(gcf, '-dpng', [plot_parm.png '_' nstr '.png']);
0324             close
0325         end
0326         figure; nfig=1; 
0327     end;
0328 end
0329 % END new_figure
0330 
0331 function    end_figure(npng);
0332     if ~isempty(plot_parm.png)
0333         nfig0 = ceil(NX/2);
0334         subplot(NY,NX,nfig0);
0335         title(['Status signal: ' fname],'Interpreter','none')
0336         npng = npng + 1;
0337         nstr = num2str(npng);
0338         print(gcf, '-dpng', [plot_parm.png '_' nstr '.png']);
0339         close
0340     end
0341 
0342 end
0343 % END end_figure
0344 
0345 end
0346 % Nested function END for primary function

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005