calcTimeDelay.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. function timeDelay = calcTimeDelay(NSx1, NSx2)
  2. %
  3. % timeDelay = calcTimeDelay(NSx1, NSx2)
  4. %
  5. % This function calculates the time difference between the end of the
  6. % first NSx file and the beginning of the second NSx file.
  7. %
  8. % NSx1: The first NSx file passed to the function. This input is
  9. % optional. In its absense, a dialog will open and will
  10. % prompt the user to select an NSx file.
  11. % (OPTIONAL)
  12. %
  13. % NSx2: The second NSx file passed to the function. This input is
  14. % also optional. In its absense, a dialog will open and will
  15. % prompt the user to select an NSx file.
  16. % (OPTIONAL)
  17. %
  18. % Kian Torab
  19. % ktorab@blackrockmicro.com
  20. % Blackrock Microsystems
  21. %
  22. % Version 1.0.0.0
  23. if ~exist('NSx1', 'var') || ~exist('NSx2', 'var')
  24. NSx1 = openNSx;
  25. NSx2 = openNSx;
  26. end
  27. timeDifference = double(NSx2.MetaTags.DateTimeRaw - NSx1.MetaTags.DateTimeRaw);
  28. timeDifference = timeDifference(end-1)+timeDifference(end)/1000;
  29. timeDelay = (timeDifference*NSx1.MetaTags.SamplingFreq-NSx1.MetaTags.DataPoints)/NSx1.MetaTags.SamplingFreq;
  30. if ~nargout
  31. disp(['The time delay between the end of the first file and the beginning of the second file is ' num2str(timeDelay) ' seconds.']);
  32. return;
  33. end