function [snippets, tt] = get_snippets (lfp, win, eventidx,fs, mkplt)
% eventidx: indices of the event, not in sec

tt = -win(1):1/fs:win(2);


snippets = zeros(length(eventidx),length(tt));

for i = 1:length(eventidx)
    
    if eventidx(i)-win(1)*fs<0
        pad = zeros(1, -(eventidx(i)-win(1)*fs)+1)';
        snippets(i,:) = [pad; lfp(1:eventidx(i)+win(2)*fs)];
    else    
        
        snippets(i,:) = lfp(eventidx(i)-win(1)*fs:eventidx(i)+win(2)*fs);
    end
    
end

if mkplt  
    plot(tt, nanmean(snippets,1))
    xlabel('Time(s)')
    ylabel('uV')
end

