syncPatternDetectNEV.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function codeKeeper = syncPatternDetectNEV(NEVStruct)
  2. % syncPatternDetectNEV
  3. %
  4. % Finds the code for the SYNC pattern on the SYNC output of Blackrock
  5. % Microsystems Neural Signal Processor (NSP) recorded by analog input
  6. % channel 16 and thresholded as extracted spikes and saved in the NEV file.
  7. %
  8. % INPUT
  9. %
  10. % NEVStruct: The NEV structure containing the SYNC pulse.
  11. %
  12. % OUTPUT
  13. %
  14. % codeKeeper: A cell structure containing the unique code and their
  15. % respective timestamps.
  16. %
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18. % USAGE EXAMPLE:
  19. %
  20. % codeKeeper = syncPatternDetectNEV(NEVStruct)
  21. %
  22. % In the example above, the NEV structure, containing the continueus
  23. % signal from the SYNC pulse is passed to the function. The output will
  24. % contain the unique codes parsed from the signal file and their
  25. % respective timestamps.
  26. %
  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. % Kian Torab
  29. % kian@blackrockmicro.com
  30. % Blackrock Microsystems
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. % Version History
  33. %
  34. % 1.0.0.0: July 7, 2014
  35. % - Initial release.
  36. %
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38. %% Setup
  39. separationVar = 'D';
  40. %% Detect the rising edges
  41. edgeTS = NEVStruct.Data.Spikes.TimeStamp(NEVStruct.Data.Spikes.Electrode == 144);
  42. differenceTS = double(diff(edgeTS));
  43. pulseDifferenceLenght = mode(differenceTS);
  44. convertedChar = [];
  45. for idx = 1:length(differenceTS)
  46. if differenceTS(idx) < pulseDifferenceLenght*1.1;
  47. convertedChar = [convertedChar, '1'];
  48. elseif differenceTS(idx) < 9*pulseDifferenceLenght;
  49. convertedChar = [convertedChar, repmat('0', 1, round((differenceTS(idx) - pulseDifferenceLenght)/pulseDifferenceLenght)), '1'];
  50. else
  51. convertedChar = [convertedChar, separationVar];
  52. end
  53. end
  54. begTS = edgeTS(find(differenceTS > pulseDifferenceLenght * 12) + 1);
  55. %%
  56. begTS = [edgeTS(1) begTS];
  57. codeKeeper{1} = bin2dec(regexp(convertedChar, separationVar, 'split'))';
  58. codeKeeper{2} = begTS;