LoadTT_Intan.m 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. function [t, wv] = LoadTT_Intan(fn,records_to_get,record_units)
  2. %LOADTT_INTAN MClust loading engine for Intan data.
  3. % LOADTT_INTAN loads Intan data and fullfils all requirement for
  4. % Neuralynx loading engines (see MClust 3.5 documentation for details on
  5. % MClust loading engines).
  6. %
  7. % Syntax:
  8. % [T, WV] = LOADTT_INTAN(FN,RECORDS_TO_GET,RECORD_UNITS)
  9. %
  10. % Input arguments:
  11. % FN - file name with full path for Intan data to load
  12. % RECORDS_TO_GET, RECORD_UNITS - allows options for returning a
  13. % restricted data set; if not passed, the full data file is
  14. % returned;
  15. % RECORD_UNITS = 1 - return specific time stamps, given by
  16. % RECORDS_TO_GET
  17. % RECORD_UNITS = 2 - return data points at specific indices,
  18. % given by RECORDS_TO_GET
  19. % RECORD_UNITS = 3 - return data in a time stamp range, given by
  20. % RECORDS_TO_GET (2-elements vector)
  21. % RECORD_UNITS = 4 - return data in an index range, given by
  22. % RECORDS_TO_GET (2-elements vector)
  23. % RECORD_UNITS = 5 - return number of spikes as first output
  24. % argument; RECORDS_TO_GET should be empty
  25. %
  26. % Output arguments:
  27. % T - time stamps in seconds; 1 x N, N = number of spikes (exeption:
  28. % RECORD_UNITS = 5, see above)
  29. % WV - waveforms; N X 4 X 30, N = number of spikes, 4 tetrode
  30. % channels, 30 time points for spikes
  31. %
  32. % See also INTANDISC and LOADTT_NEURALYNXNT.
  33. % Balazs Hangya, Cold Spring Harbor Laboratory
  34. % 1 Bungtown Road, Cold Spring Harbor
  35. % balazs.cshl@gmail.com
  36. % 9-May-2013
  37. % Input argument check
  38. narginchk(1,3)
  39. switch nargin
  40. case 1
  41. record_units = 0;
  42. case 2
  43. error('LoadTT_Intan:inputArg','Record_units argument should be provided.')
  44. end
  45. % Load data
  46. TTdata = load(fn);
  47. t = TTdata.TimeStamps;
  48. wv = TTdata.WaveForms;
  49. % Restrict data to the required range
  50. switch record_units
  51. case 0 % return full data
  52. case 1 % return specific time stamps
  53. [jnk inxa] = intersect(t,records_to_get); %#ok<*ASGLU> % indices for the time stamps
  54. t = t(inxa);
  55. wv = wv(inxa,:,:);
  56. case 2 % return specific data indices
  57. t = t(records_to_get);
  58. wv = wv(records_to_get,:,:);
  59. case 3 % select a time range
  60. if ~isequal(numel(records_to_get),2)
  61. error('LoadTT_Intan:inputArg','Input argument mismatch.')
  62. end
  63. [jnk inxa] = intersect(t,records_to_get); % indices for the time stamps
  64. t = t(inxa(1):inxa(2));
  65. wv = wv(inxa(1):inxa(2),:,:);
  66. case 4 % select an index range
  67. if ~isequal(numel(records_to_get),2)
  68. error('LoadTT_Intan:inputArg','Input argument mismatch.')
  69. end
  70. t = t(records_to_get(1):records_to_get(2));
  71. wv = wv(records_to_get(1):records_to_get(2),:,:);
  72. case 5 % special case: number of spikes
  73. if ~isempty(records_to_get)
  74. error('LoadTT_Intan:inputArg','Input argument mismatch.')
  75. end
  76. t = length(t); % number of spikes
  77. wv = [];
  78. otherwise
  79. error('LoadTT_Intan:inputArg','Record_units should take an integer value from 1 to 5.')
  80. end
  81. if record_units < 5
  82. t = t(:) * 1e4; % enforce column vector form; use MClust time stamp convention
  83. end