-
Notifications
You must be signed in to change notification settings - Fork 0
/
firingPhaseHilbert.m
33 lines (26 loc) · 999 Bytes
/
firingPhaseHilbert.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
25
26
27
28
29
30
31
32
33
function [phaseTsd, ph] = firingPhaseHilbert(CR, S)
% [ph, phaseTsd] = thetaPhaseHilbert(S, CRtheta) compute firing phase of spikes with the Hilbert Transform
% INPUTS:
% CR: tsd containing EEG filtered in the frequency domain of interest (e.g.
% theta, or gamma
% S (optional): tsd array of cells, the firing phase of each spike will be calculated
% OUTPUT:
% phaseTsd: a tsd of phas efor each of the points in the CR input (defined
% between 0 and 2*pi
% ph: a tsdArray of firing phases for the spike trains in S
% copyright (c) 2006 Francesco P. Battaglia
% This software is released under the GNU GPL
% www.gnu.org/copyleft/gpl.html
%version 0.1 under construction
zr = hilbert(Data(CR));
phzr = atan2(imag(zr), real(zr));
phzr(phzr < 0) = phzr(phzr < 0) + 2 * pi;
phaseTsd = tsd(Range(CR), phzr);
if nargin > 1
ph = {};
for i = 1:length(S)
ph{i} = Align(phaseTsd, S{i}, 'align', 'closest', 'time', 'align');
end
ph = ph(:);
ph = tsdArray(ph);
end