To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / utilities / UTIL_periodHistogram.m @ 38:c2204b18f4a2

History | View | Annotate | Download (1.35 KB)

1
function [PH, binTimes]=UTIL_periodHistogram(A, dt, frequency)
2
% UTIL_makePeriodHistogram converts a time sequence into a period histogram
3
%*********************
4
% The period is 1/frequency.
5
%
6
% usage:
7
%	PH=UTIL_periodHistogram(A, dt, frequency)
8
%
9
% Input:
10
% A is a channel x time matrix of spikes (or other stuff)
11
% frequency determines the period of the histogram
12
%
13
% Output
14
%  PH is a channel by periodhistogram matrix
15
% bintimes is useful for plotting the output
16
%
17

    
18
periodInSeconds=1/frequency;
19
[numChannels signalNpoints]=size(A);
20

    
21
% retrict data array to a multiple of the period.
22
pointsPerPeriod= round(periodInSeconds/dt);
23
NcompletePeriods=floor(signalNpoints/pointsPerPeriod);
24
totalPointsUsed=NcompletePeriods*pointsPerPeriod;
25

    
26
% check that the period is a whole number of epochs
27
aliasing=NcompletePeriods*(periodInSeconds/dt-pointsPerPeriod);
28

    
29
if aliasing>.1
30
    error('UTIL_periodHistogram: irregular period length')
31
end
32

    
33
if NcompletePeriods<1
34
    error('UTIL_periodHistogram: too few datapoints')
35
end
36

    
37
% transpose data so that time is down a column
38
A=A(:,1:totalPointsUsed)';
39

    
40
% knock it into shape
41
A=reshape(A,pointsPerPeriod, NcompletePeriods, numChannels);
42
% each period is a separate column
43
% imagesc(squeeze(A)) % should have horizontal stipe
44

    
45
% channels are now the third dimension.
46
PH=squeeze(sum(A,2))';
47
% PH=PH/NcompletePeriods;
48

    
49
binTimes=dt:dt:pointsPerPeriod*dt;