plotAverageWaveforms.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. % plotAverageWaveforms
  2. %
  3. % Plots average waveforms for all channels and specified units across the
  4. % array. It will prompt for a CMP file to map each channel to its electrode
  5. % representation.
  6. %
  7. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8. % Use plotAverageWaveforms(NEV, units)
  9. %
  10. % NOTE: All input arguments are optional. Input arguments may be in any order.
  11. %
  12. % NEV: NEV structure containing all waveforms.
  13. % DEFAULT: Will prompt for NEV.
  14. %
  15. % 'units': Specify the units to plot (i.e. 2 or 0:5 for all).
  16. % DEFAULT: will plot all units.
  17. %
  18. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  19. % USAGE EXAMPLE:
  20. %
  21. % openNEV(NEV, 0:3);
  22. %
  23. % In the example above, the waveforms in the NEV structure coming from
  24. % units 0 through 3 will be plotted.
  25. %
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  27. % Kian Torab
  28. % kian@blackrockmicro.com
  29. % Blackrock Microsystems
  30. % Salt Lake City, UT
  31. %
  32. % Version 2.1.0.0
  33. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34. % Version History
  35. %
  36. % 1.0.0.0:
  37. % - Initial release.
  38. %
  39. % 2.1.0.0:
  40. % - Added the ability to plot scaled or non-scaled plots. By default, the
  41. % plots are scaled.
  42. % - The color of the first unit is always selected at random, so when a
  43. % channel only has 1 unit, that 1 unit will be a different color
  44. % (visualization only).
  45. %
  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. function plotAverageWaveforms(NEV, units, plottype)
  48. mapfile = 1;
  49. colors = repmat({'magenta', 'cyan', 'red', 'green', 'blue', 'black'}, 1, 3);
  50. if ~exist('NEV', 'var')
  51. NEV = openNEV('read');
  52. end
  53. if ~exist('units', 'var')
  54. units = 0:5;
  55. end
  56. if ~exist('plottype', 'var')
  57. plottype = 'scaled';
  58. end
  59. numberOfElectrodes = length(unique(NEV.Data.Spikes.Electrode));
  60. disp('Select a map file for your array. If none, press cancel or ESC.');
  61. mapFile = KTUEAMapFile;
  62. if ~mapFile.isValid
  63. disp('Map File was not selected.');
  64. mapfile = 0;
  65. plotHeight = floor(sqrt(numberOfElectrodes));
  66. plotWidth = ceil(numberOfElectrodes/floor(sqrt(numberOfElectrodes)));
  67. end
  68. figure = KTFigure;
  69. figure.EnlargeFigure;
  70. figure.MakeBackgroundWhite;
  71. figure.SetActive;
  72. title('Spikes Average Waveforms for Individual Channels');
  73. for chanIDX = 1:numberOfElectrodes
  74. if mapfile
  75. try
  76. mapFile.GenerateChannelSubplot(chanIDX);
  77. catch
  78. disp('e');
  79. end
  80. else
  81. subplot(plotHeight, plotWidth, chanIDX);
  82. end
  83. hold on;
  84. initialColor = round(rand(1)*5);
  85. for unitIDX = units
  86. [~, allWaveforms] = findEventTimes(NEV, chanIDX, unitIDX);
  87. if ~isempty(allWaveforms)
  88. averageWaveform = mean(allWaveforms, 2);
  89. plot(averageWaveform, 'color', colors{unitIDX+1+initialColor}, 'LineWidth',2);
  90. end
  91. end
  92. hold off;
  93. if strcmpi(plottype, 'scaled')
  94. ylim([-1000, 1000]);
  95. end
  96. % if size(allWaveforms,2) ~= 0
  97. % text(1, 0, num2str(size(allWaveforms,2)), 'color', 'red');
  98. % end
  99. mapFile.setAxisBackgroundColor('white');
  100. set(gca, 'XTick', []);
  101. set(gca, 'YTick', []);
  102. end