staogram.m 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. function[S,tau,tc] = staogram(data_spk,data_lfp,smp,plt,Tc,Tinc,Tw,w,D)
  2. %
  3. % staogram : calculates a moving window spike triggered ave %
  4. % Usage:[S,tau,tc] = staogram(data_spk,data_lfp,smp,plt,Tc,Tinc,Tw,w,D)
  5. %
  6. % ******** INPUT *********
  7. % Note that all times have to be consistent. If data_spk
  8. % is in seconds, so must be sig and t. If data_spk is in
  9. % samples, so must sig and t. The default is seconds.
  10. %
  11. % data_spk - strucuture array of spike times data
  12. % data_lfp - array of lfp data(samples x trials)
  13. % smp - lfp times of samples
  14. %
  15. % Optional...
  16. %
  17. % Parameter
  18. %
  19. % plt 'y'|'n'
  20. %
  21. % 'y' standard staogram
  22. % 'n' no plot
  23. %
  24. % Tc = start and end times (centres) whole trial
  25. % Tinc = time increment between windows 0.1
  26. % Tw = time window width 0.3
  27. % w = smoothing width in seconds
  28. % D = plot sta out to on axis [D(1) D(2)] s
  29. %
  30. % ******** OUTPUT ********
  31. % S spike triggered average
  32. % tau - lag
  33. % tc - bin centers
  34. % setup defaults...
  35. if nargin < 3;error('Require spike, lfp and lfptimes ');end
  36. [data_spk]=padNaN(data_spk); % create a zero padded data matrix from input structural array
  37. data_spk=data_spk'; % transposes data to get it in a form compatible with Murray's routine
  38. if nargin < 4; plt = 'y';end
  39. if nargin < 6; Tinc = 0.1; end
  40. if nargin < 7; Tw = 0.5;end
  41. if nargin < 8; w = 0.01;end
  42. if nargin < 9; D = 0.15*[-1 1]; end
  43. if nargin < 5;
  44. Tc(1) = min(data_spk(:,1)) + Tw/2;
  45. Tc(2) = max(max(data_spk)) - Tw/2;
  46. end
  47. if isempty(plt); plt = 'y';end
  48. if isempty(Tinc); Tinc = 0.1; end
  49. if isempty(Tw); Tw = 0.5;end
  50. if isempty(w); w = 0.01;end
  51. if isempty(D); D = 0.15*[-1 1]; end
  52. if isempty(Tc);
  53. Tc(1) = min(data_spk(:,1)) + Tw/2;
  54. Tc(2) = max(max(data_spk)) - Tw/2;
  55. end
  56. % round to nearest tinc...
  57. t = smp;
  58. Tc(1) = ceil(Tc(1)/Tinc)*Tinc;
  59. Tc(2) = floor(Tc(2)/Tinc)*Tinc;
  60. tc = Tc(1):Tinc:Tc(2);
  61. for tt=1:length(tc)
  62. T = [tc(tt)-Tw/2 tc(tt)+Tw/2];
  63. if tt == 1
  64. [SS,tau] = sta(data_spk,data_lfp,t,'y',w,T,D,0);
  65. S = zeros(length(tc),length(SS));
  66. else
  67. [SS,tau] = sta(data_spk,data_lfp,t,'y',w,T,D,0);
  68. end
  69. S(tt,:) = SS';
  70. S(tt,:) = SS';
  71. end
  72. if ~strcmp(plt,'n')
  73. imagesc(tc,tau,squeeze(S)')
  74. set(gca,'ydir','normal')
  75. xlabel('time (s)')
  76. ylabel('frequency (Hz)')
  77. colorbar;
  78. % axes(h)
  79. % line(get(h,'xlim'),conf_C*[1 1],'color','k','linewidth',5)
  80. end