Helper function to create an event triggered matrix from univariate continuous data Usage: data=createdatamatc(data,E,Fs,win) Inputs: data (input time series as a column vector) - required E (events to use as triggers) - required Fs (sampling frequency of data) - required win (window around triggers to use data matrix -[winl winr]) - required e.g [1 1] uses a window starting 1 * Fs samples before E and ending 1*Fs samples after E. Note that E, Fs, and win must have consistent units Outputs: data (event triggered data)
0001 function data=createdatamatc(data,E,Fs,win) 0002 % Helper function to create an event triggered matrix from univariate 0003 % continuous data 0004 % Usage: data=createdatamatc(data,E,Fs,win) 0005 % Inputs: 0006 % data (input time series as a column vector) - required 0007 % E (events to use as triggers) - required 0008 % Fs (sampling frequency of data) - required 0009 % win (window around triggers to use data matrix -[winl winr]) - required 0010 % e.g [1 1] uses a window starting 1 * Fs samples before E and 0011 % ending 1*Fs samples after E. 0012 % Note that E, Fs, and win must have consistent units 0013 % 0014 % Outputs: 0015 % data (event triggered data) 0016 % 0017 if nargin < 4; error('Need all arguments'); end; 0018 NE=length(E); 0019 nwinl=round(win(1)*Fs); 0020 nwinr=round(win(2)*Fs); 0021 nE=floor(E*Fs)+1; 0022 datatmp=[]; 0023 for n=1:NE; 0024 indx=nE(n)-nwinl:nE(n)+nwinr-1; 0025 datatmp=[datatmp data(indx)]; 0026 end 0027 data=datatmp;