MakePTH07.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. function [PTHout,BWout,MSRout]=MakePTH06(PSRin,Numin,PRMS)
  2. %!!!!!!!!CAUTION !!!!!
  3. %this version was modified by Fred and Ali to use DP and NOT Optimal BW
  4. %
  5. %INPUTS:
  6. %PSRin can be collapsed or not. if not, the output is uncollapsed as well
  7. %Numin= number of trials
  8. %PRMS{1}==1 for making baseline-only PSTH and ==2 for normal, main PSTH %(i.e. -15 to 15s)
  9. %PRMS{2}==0 for fixed binwidth and ==1 for DP binwidth
  10. %PRMS{3}=binwidth used
  11. %OUTPUTS:
  12. %PTHout
  13. %BWout is a vector stores the DP BW
  14. %MSRout is MSR=f(BW)
  15. global Tm Tbase
  16. if PRMS{1}==1
  17. T0=Tbase;
  18. elseif PRMS{1}==2
  19. T0=Tm;
  20. end
  21. BWx=[0.01:0.005:1]; % Range of binsizes considered
  22. PTH=[];
  23. if size(PSRin,2)==1 %if TRUE, all trials are collapsed
  24. if PRMS{2}==0 %fixed/assigned binwidth for all
  25. if numel(PRMS{3})==1,
  26. BW=repmat(PRMS{3},length(PSRin),1);
  27. else
  28. BW=PRMS{3};
  29. end
  30. for k=1:length(PSRin)
  31. Tn=[-BW(k)/2:-BW(k):T0(1)-BW(k)]; Tp=[BW(k)/2:BW(k):T0(end)+BW(k)];T=[Tn(end:-1:1),Tp];%making PSTH centered on zero
  32. %T=[T0(1)-BW(k):BW(k):T0(end)+BW(k)];
  33. TMP=hist(PSRin{k},T)/(BW(k)*Numin(k)); % make PSTH and normalize by number of refs used (Hz)
  34. %deals with low firing in which there is too few DP bins to do
  35. %interppolation
  36. if length(T)>4
  37. PTH(k,:)=interp1(T(2:end-1),TMP(2:end-1),T0,'nearest','extrap');BWout(k,1)=BW(k);
  38. else
  39. PTH(k,:)=repmat(mean(TMP),1,length(T0));BWout(k,1)=T0(end)-T0(1);
  40. end
  41. end
  42. PTHout=PTH;MSRout=[];
  43. else %DP binwidth for all
  44. for k=1:length(PSRin)
  45. [~,~,MSR]=optimalBW05(PSRin(k),T0); % make PSTH and normalize by number of refs used (Hz)
  46. [~,I]=findDP(BWx,MSR,{2,.9});%{DP=1,DEG/TSH=2,TSHOLD}
  47. Tn=[-BWx(I)/2:-BWx(I):T0(1)-BWx(I)]; Tp=[BWx(I)/2:BWx(I):T0(end)+BWx(I)];T=[Tn(end:-1:1),Tp];%making PSTH centered on zero
  48. TMP=hist(PSRin{k},T)/(BWx(I)*Numin(k)); % make PSTH and normalize by number of refs used (Hz)
  49. %deals with low firing in which there is too few DP bins to do
  50. %interppolation
  51. if length(T)>4
  52. PTH(k,:)=interp1(T(2:end-1),TMP(2:end-1),T0,'nearest','extrap'); BWout(k,1)=BWx(I);
  53. else
  54. PTH(k,:)=repmat(mean(TMP),1,length(T0));BWout(k,1)=T0(end)-T0(1);
  55. end
  56. MSRout(k,:)=MSR;
  57. end
  58. PTHout=PTH;
  59. end
  60. else % trial-by-trial PTH
  61. if PRMS{2}==0 %fixed/assigned binwidth for all
  62. if numel(PRMS{3})==1,
  63. BW=repmat(PRMS{3},length(PSRin),1);
  64. else
  65. BW=PRMS{3};
  66. end
  67. for k=1:size(PSRin,1) %neuron
  68. Tn=[-BW(k)/2:-BW(k):T0(1)-BW(k)]; Tp=[BW(k)/2:BW(k):T0(end)+BW(k)];T=[Tn(end:-1:1),Tp];%making PSTH centered on zero
  69. % T=[T0(1)-BW(k):BW(k):T0(end)+BW(k)];
  70. for n=1:size(PSRin,2)%trial
  71. TMP=hist(PSRin{k,n},T)/BW(k); % make PSTH and normalize by number of refs used (Hz)
  72. %deals with low firing in which there is too few DP bins to do
  73. %interppolation
  74. if length(T)>4
  75. PTH(k,:,n)=interp1(T(2:end-1),TMP(2:end-1),T0,'nearest','extrap');BWout(k,1)=BW(k);
  76. else
  77. PTH(k,:,n)=repmat(mean(TMP),1,length(T0));BWout(k,1)=T0(end)-T0(1);
  78. end
  79. end
  80. end
  81. PTHout=PTH;MSRout=[];
  82. else %DP binwidth for all
  83. for k=1:size(PSRin,1)%neuron
  84. [~,~,MSR]=optimalBW05(PSRin(k,:),T0);
  85. [~,I]=findDP(BWx,MSR,{2,.9});%{DP=1,DEG/TSH=2,TSHOLD}
  86. Tn=[-BWx(I)/2:-BWx(I):T0(1)-BWx(I)]; Tp=[BWx(I)/2:BWx(I):T0(end)+BWx(I)];T=[Tn(end:-1:1),Tp];%making PSTH centered on zero
  87. for n=1:size(PSRin,2)%trial
  88. TMP=hist(PSRin{k,n},T)/BWx(I); % make PSTH and normalize by number of refs used (Hz)
  89. %deals with low firing in which there is too few DP bins to do
  90. %interppolation
  91. if length(T)>4
  92. PTH(k,:,n)=interp1(T(2:end-1),TMP(2:end-1),T0,'nearest','extrap');BWout(k,1)=BWx(I);
  93. else
  94. PTH(k,:,n)=repmat(mean(TMP),1,length(T0));BWout(k,1)=T0(end)-T0(1);
  95. end
  96. end
  97. MSRout(k,:)=MSR;
  98. end
  99. PTHout=PTH;
  100. end
  101. end