createdatamatpb.m 923 B

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