Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

findEventTimes.m 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function [allTimestamps allSnippets allIndices] = findEventTimes(NEV, Channel, Units)
  2. % Given a NEV file, an channel number, and a unit number this function
  3. % will return indices corresponding to those spikes, timestamps
  4. % corresponding to those spikes (optional), and snippets corresponding to
  5. % those spikes (optional).
  6. %
  7. % Use [timestamps snippets indices] = findEventTimes(NEV, Channel, Unit)
  8. %
  9. % INPUTS
  10. %
  11. % NEV: This corresponds to the NEV file the desired data is
  12. % being extracted from.
  13. %
  14. % Channel: The channel number the data is being extracted for.
  15. %
  16. % Units: The unit numbers the data is being extracted for. This
  17. % variable can be one unit or many units passed as an array
  18. % of integers.
  19. % DEFAULY: If units is not specified all timestamps from
  20. % all units will be passed to the calling function. For
  21. % noise pass 255.
  22. %
  23. % OUTPUT
  24. %
  25. % indices: An array of all indices that correspond to neural data
  26. % for channel and unit passed.
  27. %
  28. % timestamps: An array of all timestamps that correspond to neural data
  29. % for channel and unit passed.
  30. %
  31. % snippets: A matrix of all indices that correspond to neural data
  32. % for channel and unit passed.
  33. %
  34. % IF OUTPUT IS NOT SPECIFIED only "timestamps" WILL BE PASSED TO THE
  35. % CALLING FUNCTION.
  36. %
  37. % Example:
  38. %
  39. % [timestamps snippets indices] = findEventTimes(NEV, 3, [1,3:5]);
  40. %
  41. % In the example above, the indices, timestamps, and snippets for
  42. % channel #3 and units 1, 3, 4, and 5 will be passed to the calling
  43. % function.
  44. %
  45. % Kian Torab
  46. % ktorab@blackrockmicro.com
  47. % Blackrock Microsystems
  48. % Salt Lake City, UT
  49. % Version 2.0.0
  50. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  51. if ~exist('Units', 'var')
  52. Units = 0:5;
  53. end
  54. if ischar(Channel) && exist('Units', 'var')
  55. strcmpi(Channel, 'DigitalIn')
  56. allSnippets = find(NEV.Data.SerialDigitalIO.UnparsedData == Units);
  57. allTimestamps = NEV.Data.SerialDigitalIO.TimeStamp(allSnippets);
  58. allIndices = [];
  59. else
  60. % Find indices that correspond to "Channel"
  61. ChannelIndices = find([NEV.Data.Spikes.Electrode] == Channel);
  62. for i = 1:length(Units)
  63. % Find indices that correspond to "Units" within "Channel" indices
  64. UnitIndices{i} = find([NEV.Data.Spikes.Unit(ChannelIndices)] == Units(i));
  65. % Updating the indices so they correspond to the original NEV indices
  66. indices{i} = ChannelIndices(UnitIndices{i});
  67. % Finding the timestamps corresponding to the indices
  68. timestamps{i} = NEV.Data.Spikes.TimeStamp(indices{i});
  69. % Finding the snippets corresponding to the indices
  70. if isfield(NEV.Data.Spikes, 'Waveform')
  71. snippets{i} = NEV.Data.Spikes.Waveform(:,indices{i});
  72. elseif nargout == 3 && i == 1
  73. display('Snippet data was not retrieved because the NEV does not contain any snippets.');
  74. snippets{i} = [];
  75. end
  76. end
  77. allIndices = cell2mat(indices);
  78. allTimestamps = double(cell2mat(timestamps));
  79. if exist('snippets', 'var')
  80. allSnippets = cell2mat(snippets);
  81. end
  82. end