


Multi-taper cross-spectrum - point process given as times
Usage:
[S12,f]=coherencypt(data1,data2,tapers,pad,Fs,fpass)
Input:
data1 (structure array of channels/trials with spike times; also accepts 1d column vector of times) -- required
data2 (structure array of channels/trials with spike times; also accepts 1d column vector of times) -- required
tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
specified, use [NW K]=[3 5]
pad (padding factor for the FFT) - optional. Defaults to 0.
e.g. For N = 500, if PAD = 0, we pad the FFT
to 512 points; if PAD = 2, we pad the FFT
to 2048 points, etc.
Fs (binning frequency for fft grid used to calculate fft of prolates. 1/Fs is the time between consecutive
points on the grid used for evaluation
of the prolates) - optional. Default 1.
fpass (frequency band to be used in the calculation in the form
[fmin fmax])- optional.
Default all frequencies between 0 and Fs/2
Output:
S12 (cross spectrum frequency index x channels/trials)
f (frequencies)

0001 function [S12,f]=crossspecpt(data1,data2,tapers,pad,Fs,fpass) 0002 % Multi-taper cross-spectrum - point process given as times 0003 % 0004 % Usage: 0005 % 0006 % [S12,f]=coherencypt(data1,data2,tapers,pad,Fs,fpass) 0007 % Input: 0008 % data1 (structure array of channels/trials with spike times; also accepts 1d column vector of times) -- required 0009 % data2 (structure array of channels/trials with spike times; also accepts 1d column vector of times) -- required 0010 % tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0011 % specified, use [NW K]=[3 5] 0012 % pad (padding factor for the FFT) - optional. Defaults to 0. 0013 % e.g. For N = 500, if PAD = 0, we pad the FFT 0014 % to 512 points; if PAD = 2, we pad the FFT 0015 % to 2048 points, etc. 0016 % Fs (binning frequency for fft grid used to calculate fft of prolates. 1/Fs is the time between consecutive 0017 % points on the grid used for evaluation 0018 % of the prolates) - optional. Default 1. 0019 % fpass (frequency band to be used in the calculation in the form 0020 % [fmin fmax])- optional. 0021 % Default all frequencies between 0 and Fs/2 0022 % Output: 0023 % S12 (cross spectrum frequency index x channels/trials) 0024 % f (frequencies) 0025 if nargin < 2; error('Need data1 and data2'); end; 0026 if nargin < 3; tapers=[3 5];end; 0027 if nargin < 4; pad=0;end; 0028 if nargin < 5; Fs=1; end; 0029 if nargin < 6; fpass=[0 Fs/2]; end; 0030 0031 if isempty(tapers); tapers=[3 5]; end; 0032 if isempty(pad);pad=0;end; 0033 if isempty(Fs); Fs=1; end; 0034 if isempty(fpass); fpass=[0 Fs/2]; end; 0035 0036 [mintime1,maxtime1]=minmaxsptimes(data1); 0037 [mintime2,maxtime2]=minmaxsptimes(data2); 0038 mintime=min(mintime1,mintime2); 0039 maxtime=max(maxtime1,maxtime2); 0040 dt=1/Fs; 0041 t=mintime:dt:maxtime+dt; % time grid for prolates 0042 N=length(t); % number of points in grid for dpss 0043 nfft=2^(nextpow2(N)+pad); % number of points in fft of prolates 0044 [f,findx]=getfgrid(Fs,nfft,fpass); 0045 tapers=dpsschk(tapers,N); % check tapers 0046 [J1,Msp1,Nsp1]=mtfftpt(data1,tapers,nfft,t,f,findx); 0047 [J2,Msp2,Nsp2]=mtfftpt(data2,tapers,nfft,t,f,findx); 0048 J1=J1(findx,:,:); J2=J2(findx,:,:); 0049 S12=squeeze(mean(conj(J1).*J2,2)); 0050 if trialave; S12=squeeze(mean(S12,2));end;