syncPatternDetectNSx.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. function codeKeeper = syncPatternDetectNSx(data)
  2. % syncPatternDetectNSx
  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 outputs the unique code and its related timestamp.
  7. %
  8. % INPUT
  9. %
  10. % data: The data stream 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 = syncPatternDetectNSx(data)
  21. %
  22. % In the example above, the data, containing the continueus signal from
  23. % the SYNC pulse is passed to the function. The output will contain the
  24. % unique codes parsed from the signal file and their respective
  25. % timestamps.
  26. %
  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. % Kian Torab
  29. % kian@blackrockmicro.com
  30. % Blackrock Microsystems
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. % Version History
  33. %
  34. % 1.0.0.0: June 8, 2014
  35. % - Initial release.
  36. %
  37. % 1.0.1.0: July 7, 2014
  38. % - Updated the help file
  39. %
  40. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  41. %% Setup
  42. separationVar = 'D';
  43. %% Detect the rising edges
  44. edgeTS = edgeDetect(data, 10000);
  45. differenceTS = diff(edgeTS);
  46. pulseDifferenceLenght = mode(differenceTS);
  47. convertedChar = [];
  48. for idx = 1:length(differenceTS)
  49. if differenceTS(idx) < pulseDifferenceLenght*1.1;
  50. convertedChar = [convertedChar, '1'];
  51. elseif differenceTS(idx) < 9*pulseDifferenceLenght;
  52. convertedChar = [convertedChar, repmat('0', 1, round((differenceTS(idx) - pulseDifferenceLenght)/pulseDifferenceLenght)), '1'];
  53. else
  54. convertedChar = [convertedChar, separationVar];
  55. end
  56. end
  57. begTS = edgeTS(find(differenceTS > pulseDifferenceLenght * 12) + 1);
  58. %%
  59. begTS = [edgeTS(1) begTS];
  60. codeKeeper{1} = bin2dec(regexp(convertedChar, separationVar, 'split'))';
  61. codeKeeper{2} = begTS;