Home > eeg > egis > petr_dirtier > egis_trial_stats.m

egis_trial_stats

PURPOSE ^

SYNOPSIS ^

function [stats, ep] = egis_trial_stats(ses_fname, ep)

DESCRIPTION ^

 [stats, edit_params] = egis_trial_stats(ses_fname, edit_params);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [stats, ep] = egis_trial_stats(ses_fname, ep)
0002 %
0003 % [stats, edit_params] = egis_trial_stats(ses_fname, edit_params);
0004 
0005 byte_sex = 'ieee-be';
0006 
0007 %
0008 %  Read in  information from the session file
0009 %
0010 ses_hdr_offsets_v;
0011 
0012 ses_fid = fopen(ses_fname, 'rb', byte_sex);
0013 if ses_fid == -1, error(['Error opening session file' ses_fname]), end
0014 
0015 [ses_fhdr,ses_chdr,ses_ename,ses_czeros,ses_cgains,ses_cnames,ses_fcom,ses_ftext, ses_coff]=rd_egis_hdr_v(ses_fid);
0016 
0017 %
0018 %  Check for necessary fields in edit_params (ep) structure
0019 %
0020 
0021 if nargin < 2
0022   ep = edit_params;
0023 end
0024 
0025 if ~isfield(ep,'start_samp')
0026   ep.start_samp = 1;
0027 end
0028 
0029 if ~isfield(ep,'stop_samp')
0030   ep.stop_samp = ses_chdr(1,NPoints);
0031 end
0032 
0033 if isempty(ep.start_samp), ep.start_samp = 1; end
0034 if isempty(ep.stop_samp), ep.stop_samp = ses_chdr(c, NPoints); end
0035 
0036 samp_vect = ep.start_samp:ep.stop_samp;
0037 
0038 if ~isfield(ep,'do_eyemove')
0039   ep.do_eyemove = 0;
0040 end
0041 
0042 %
0043 %  Run through all the trial data
0044 %
0045 
0046 i = 1;
0047 for c = 1:ses_fhdr(NCells)
0048   disp(['Processing cell ' int2str(c) ' ...'])
0049   for t = 1:ses_chdr(c,NTrials)
0050     disp(['  Trial ' int2str(t) ' ...'])
0051 
0052     stats.cell(i) = c;
0053     stats.trial(i) = t;
0054     
0055     % READ IN DATA FOR SINGLE TRIAL
0056     trialdata = rd_onetr_allch(ses_fid, ses_coff(c), t, ses_fhdr(NChan), ses_chdr(c, NPoints));
0057 
0058     %
0059     % CUT OUT THE RELEVANT PORTION
0060     %
0061     trialdata = trialdata(samp_vect,:);
0062     
0063     % APPLY CALIBRATIONS AND GAINS
0064     
0065     if ~any(ses_cgains)
0066       disp(sprintf('Setting gains to %d', 195))
0067       ses_cgains = ones(size(ses_cgains)) * 195;
0068     end
0069     if ~any(ses_czeros)
0070       %disp('Setting zeros to zero')
0071       ses_czeros = zeros(size(ses_czeros));
0072     end
0073 
0074     stats.cgains = ses_cgains;
0075     stats.czeros = ses_czeros;
0076 
0077     trialdata = cal_gain(trialdata,ses_cgains,ses_czeros);
0078 
0079     % Compute the mean and standard deviation of the trialdata
0080     
0081     stats.vol_mean(i,:) = mean(trialdata);
0082     stats.vol_std(i,:) = std(trialdata);
0083     stats.vol_absmax(i,:) = max(max(trialdata, abs(trialdata)));
0084     stats.vol_diff(i,:) = max(abs(diff(trialdata)));
0085 
0086     % If eye-movement data is desired ...
0087     
0088     if ep.do_eyemove
0089       stats.eye_vert_lft(i) = max(abs(diff(trialdata(:,[ep.suplfteye ...
0090         ep.inflfteye]),1,2)));
0091       stats.eye_vert_rt(i) = max(abs(diff(trialdata(:,[ep.suprteye ...
0092         ep.infrteye]),1,2)));
0093     end % if ep.do_eyemove
0094     
0095     i = i + 1;
0096   end
0097 end
0098 
0099 fclose(ses_fid);

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