normalize.m 804 B

123456789101112131415161718192021
  1. function [data, peakresp] = normalize(data,trials,t,peakwin)
  2. % this function normalizes data by first smoothing the psth of the
  3. % trials indicated by the trials array (ONLY INCLUDE TRIALS THAT HAVE A
  4. % PEAK RESPONSE, i.e. trials in which there was a stimulus). it looks for
  5. % the peak in this smoothed psth within a given peak window, and divides
  6. % all data by the size of this peak
  7. %
  8. % input:
  9. % - data (time by trials, should be already BASELINE CORRECTED)
  10. % - trials (array of booleans indicating which trials to include in the
  11. % psth for peak calculation)
  12. % - time axis in same unit as peak window
  13. % - [start end] peak window
  14. %
  15. % Rob Teeuwen 20190815
  16. psth = nanmean(data(:,trials==1),2);
  17. psths = smooth(psth,20,'lowess');
  18. peakresp = max(psths(t>peakwin(1) & t<peakwin(2)));
  19. data = data./peakresp;