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