-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSTH_Simple.m
24 lines (19 loc) · 965 Bytes
/
PSTH_Simple.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Script to compute a simple PSTH
%
% Written by Vahid Esmaeili and adapted by Pierre Le Merre
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [SpikeRates,WindowCenters]= PSTH_Simple(SpikeTimes, AnchorTimes, PreTime, PostTime,sr, WindowSize)
WindowStep=WindowSize*sr;
NumberOfTrials = numel(AnchorTimes);
RelativeEdges = PreTime*sr:WindowStep:PostTime*sr;
NumberOfEdges = numel(RelativeEdges);
NumberOfWindows = NumberOfEdges - 1;
% bin the spikes in windows to have one column per trial
SpikeCounts=zeros(NumberOfWindows,NumberOfTrials);
for AnchorTimeIndex = 1:NumberOfTrials
BinEdges = AnchorTimes(AnchorTimeIndex) + RelativeEdges;
[SpikeCounts(:,AnchorTimeIndex),~]=histcounts(SpikeTimes, BinEdges);
end
SpikeRates = SpikeCounts / WindowSize;
WindowCenters = (RelativeEdges(1:NumberOfWindows) + WindowSize/2 );