syncPatternFinderNSx.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. function codeKeeper = syncPatternFinderNSx(filenameNSx)
  2. % syncPatternFinderNSx
  3. %
  4. % Canculated the unique 8-bit code and the associated timestamp of the SYNC
  5. % pulse of the NSP.
  6. %
  7. % Use codeKeeper = syncPatternFinderNSx(filenameNSx)
  8. %
  9. % All input arguments are optional. Input arguments can be in any order.
  10. %
  11. % filenameNSx: Name of the file to be opened. If the fname is omitted
  12. % the user will be prompted to select a file.
  13. % DEFAULT: Will open Open File UI.
  14. %
  15. %
  16. % OUTPUT: The structure that contains all the unique 8-bit SYNC
  17. % pulse codes and their corresponding timestamps.
  18. %
  19. % Example 1:
  20. % codeKeeper = syncPatternFinderNSx('myTestNS5.ns5');
  21. %
  22. % In the example above, the file myTestNS5.ns5 will be opened and all the
  23. % SYNC pulses and their corresponding timestamps will be output in the
  24. % codeKeeper structure.
  25. %
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  27. % Kian Torab
  28. % kian@blackrockmicro.com
  29. % Blackrock Microsystems
  30. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  31. % Version History
  32. %
  33. % 1.0.0.0: November 1, 2014
  34. % - Initial release.
  35. %
  36. % 1.0.1.0: March 28, 2015
  37. % - Fixed a bug where the extension wsan't specified for the file when
  38. % the input file was not specified.
  39. %
  40. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  41. %% Opening the file to get the header information
  42. if ~exist('filenameNSx', 'var')
  43. NSx = openNSx('noread');
  44. % Determining the file name read
  45. filenameNSx = fullfile(NSx.MetaTags.FilePath, NSx.MetaTags.Filename, NSx.MetaTags.FileExt);
  46. else
  47. NSx = openNSx(filenameNSx, 'noread');
  48. end
  49. if ~isstruct(NSx)
  50. disp('Error reading the NSx file. Most likely the file name did not exist.');
  51. return;
  52. end
  53. %% Calculating the variables for the sync signal
  54. % Figuring out the channel that recorded the sync pulse. This assums that
  55. % the sync pulse was recorded on analog input 16 on the Cerebus or analog
  56. % input 3 on the Direct system.
  57. numberOfChannels = NSx.MetaTags.ChannelCount;
  58. % Calculating the maximum number of points to read
  59. maxPacketsToRead = 30 * NSx.MetaTags.SamplingFreq;
  60. if maxPacketsToRead > NSx.MetaTags.DataPoints
  61. maxPacketsToRead = NSx.MetaTags.DataPoints;
  62. end
  63. %% Reading the sync signal
  64. NSxSync = openNSx(filenameNSx, ['c:' num2str(numberOfChannels)], ['t:1:' num2str(maxPacketsToRead)], 'read');
  65. codeKeeper = syncPatternDetectNSx(NSxSync.Data(1,:));