eeg_linfit - returns slope/intercept of linear fit USEAGE: [p] = eeg_linfit(p) p is the eeg_toolbox struct. For this function, the fields required are: p.volt.data - voltage data matrix (Npoints,Nelec) p.volt.timeArray - voltage sample points (msec) Returns slope and intercept matrices (Npoints,Nelec) for linear fit of each electrode into fields of p: p.volt.fitslope p.volt.fitintercept The column vectors of slope/intercept hold constant values. So, the linear fit data can be generated by: y = p.volt.fitslope .* p.volt.timeArray + p.volt.fitintercept; Where necessary, the p.volt.timeArray is replicated across columns for each electrode to enable this calculation
0001 function [p] = eeg_linfit(p) 0002 0003 % eeg_linfit - returns slope/intercept of linear fit 0004 % 0005 % USEAGE: [p] = eeg_linfit(p) 0006 % 0007 % p is the eeg_toolbox struct. For this function, the fields 0008 % required are: 0009 % 0010 % p.volt.data - voltage data matrix (Npoints,Nelec) 0011 % p.volt.timeArray - voltage sample points (msec) 0012 % 0013 % Returns slope and intercept matrices (Npoints,Nelec) 0014 % for linear fit of each electrode into fields of p: 0015 % 0016 % p.volt.fitslope 0017 % p.volt.fitintercept 0018 % 0019 % The column vectors of slope/intercept hold constant 0020 % values. So, the linear fit data can be generated by: 0021 % 0022 % y = p.volt.fitslope .* p.volt.timeArray + p.volt.fitintercept; 0023 % 0024 % Where necessary, the p.volt.timeArray is replicated 0025 % across columns for each electrode to enable this calculation 0026 % 0027 0028 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $ 0029 0030 % Licence: GNU GPL, no implied or express warranties 0031 % History: 07/00, Darren.Weber_at_radiology.ucsf.edu 0032 % 0033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0034 0035 % volt.timeArray is essentially a column vector, but 0036 % operations in the eeg_toolbox may replicate across N columns 0037 time = p.volt.timeArray(:,1); 0038 0039 slope = zeros(1,size(p.volt.data,2)); 0040 intercept = slope; 0041 0042 for elec = 1:size(p.volt.data,2), 0043 0044 y = polyfit(time,p.volt.data(:,elec),1); 0045 slope(1,elec) = y(1); 0046 intercept(1,elec) = y(2); 0047 end 0048 0049 % make sure that volt.timeArray is same size as volt.data 0050 if ~isequal(size(p.volt.timeArray),size(p.volt.data)), 0051 p.volt.timeArray = repmat(p.volt.timeArray(:,1),1,size(p.volt.data,2)); 0052 end 0053 0054 p.volt.fitslope = repmat(slope,size(p.volt.data,1),1); 0055 p.volt.fitintercept = repmat(intercept,size(p.volt.data,1),1); 0056 0057 return