function snippet = PSTCaTrace(stimframe, trace, preStim, postStim)

%fs = 58.62;
stimNum = length(stimframe);
snippet = zeros(postStim+preStim+1, stimNum);

n = length(trace); % total number of frames

for i = 1:stimNum
    if stimframe(i) + postStim <= n
        snippet(:,i) = trace(stimframe(i)-preStim:stimframe(i)+postStim);
    end
end