createdatamatc.m 908 B

123456789101112131415161718192021222324252627
  1. function data=createdatamatc(data,E,Fs,win)
  2. % Helper function to create an event triggered matrix from univariate
  3. % continuous data
  4. % Usage: data=createdatamatc(data,E,Fs,win)
  5. % Inputs:
  6. % data (input time series as a column vector) - required
  7. % E (events to use as triggers) - required
  8. % Fs (sampling frequency of data) - required
  9. % win (window around triggers to use data matrix -[winl winr]) - required
  10. % e.g [1 1] uses a window starting 1 * Fs samples before E and
  11. % ending 1*Fs samples after E.
  12. % Note that E, Fs, and win must have consistent units
  13. %
  14. % Outputs:
  15. % data (event triggered data)
  16. %
  17. if nargin < 4; error('Need all arguments'); end;
  18. NE=length(E);
  19. nwinl=round(win(1)*Fs);
  20. nwinr=round(win(2)*Fs);
  21. nE=floor(E*Fs)+1;
  22. datatmp=[];
  23. for n=1:NE;
  24. indx=nE(n)-nwinl:nE(n)+nwinr-1;
  25. datatmp=[datatmp data(indx)];
  26. end
  27. data=datatmp;