rmeddis@0
|
1 function [PSTH dt]=UTIL_PSTHmaker(inputData, dt, PSTHbinWidth)
|
rmeddis@0
|
2 % UTIL_PSTHmaker accumulates values into bins.
|
rmeddis@0
|
3 % No corrections are applied
|
rmeddis@0
|
4 % usage:
|
rmeddis@0
|
5 % PSTH=UTIL_PSTHmaker(inputData, method)
|
rmeddis@0
|
6 %
|
rmeddis@0
|
7 % arguments
|
rmeddis@0
|
8 % inputData is a channel x time matrix
|
rmeddis@35
|
9 % dt is the sampling interval of the input signal (not clear why this is
|
rmeddis@35
|
10 % returned?!)
|
rmeddis@0
|
11 % PSTH is the reduced matrix, the sum of all elements in the bin
|
rmeddis@0
|
12 %
|
rmeddis@35
|
13 % e.g.
|
rmeddis@35
|
14 % [PSTH dt]=UTIL_PSTHmaker(inputData, dt, PSTHbinWidth)
|
rmeddis@26
|
15
|
rmeddis@0
|
16 [numChannels numDataPoints]= size(inputData);
|
rmeddis@0
|
17
|
rmeddis@0
|
18 % Multiple fibers is the same as repeat trials
|
rmeddis@0
|
19 % Consolidate data into a histogram
|
rmeddis@0
|
20 dataPointsPerBin=round(PSTHbinWidth/dt);
|
rmeddis@0
|
21 if dataPointsPerBin<=1;
|
rmeddis@0
|
22 % Too few data points
|
rmeddis@0
|
23 PSTH=inputData;
|
rmeddis@0
|
24 return
|
rmeddis@0
|
25 end
|
rmeddis@0
|
26
|
rmeddis@0
|
27 numBins=floor(numDataPoints/dataPointsPerBin);
|
rmeddis@0
|
28 PSTH=zeros(numChannels,numBins);
|
rmeddis@0
|
29
|
rmeddis@0
|
30 % take care that signal length is an integer multiple of bin size
|
rmeddis@0
|
31 % by dropping the last unuseable values
|
rmeddis@0
|
32 useableDataLength=numBins*dataPointsPerBin;
|
rmeddis@0
|
33 inputData=inputData(:,1:useableDataLength);
|
rmeddis@0
|
34
|
rmeddis@0
|
35 for ch=1:numChannels
|
rmeddis@0
|
36 % Convert each channel into a matrix where each column represents
|
rmeddis@0
|
37 % the content of a single PSTH bin
|
rmeddis@0
|
38 PSTH2D=reshape (inputData(ch,:), dataPointsPerBin, numBins );
|
rmeddis@0
|
39 % and sum within each bin (across the rows
|
rmeddis@0
|
40 PSTH(ch,:)=sum (PSTH2D,1);
|
rmeddis@0
|
41 end
|
rmeddis@0
|
42
|