


Multi-taper time-frequency spectrum - point process times
Usage:
[S,t,f,Serr]=mtspecgrampt(data,movingwin,tapers,pad,Fs,fpass,err,trialave,fscorr)
Input:
data (structure array of spike times for each channel; also accepts 1d column vector of spike times) -- required
movingwin (in the form [window,winstep] i.e length of moving
window and step size.
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
err (error calculation [1 p] - Theoretical error bars; [2 p] Jackknife error bars,
[0 p] or 0 - no error bars) - optional. Default 0.
trialave (average over trials when 1, don't average when 0) - optional. Default 0
fscorr (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional
(available only for spikes). Defaults 0.

0001 function [S,t,f,R,Serr]=mtspecgrampt(data,movingwin,tapers,pad,Fs,fpass,err,trialave,fscorr) 0002 % Multi-taper time-frequency spectrum - point process times 0003 % 0004 % Usage: 0005 % 0006 % [S,t,f,Serr]=mtspecgrampt(data,movingwin,tapers,pad,Fs,fpass,err,trialave,fscorr) 0007 % Input: 0008 % data (structure array of spike times for each channel; also accepts 1d column vector of spike times) -- required 0009 % movingwin (in the form [window,winstep] i.e length of moving 0010 % window and step size. 0011 % 0012 % tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0013 % specified, use [NW K]=[3 5] 0014 % pad (padding factor for the FFT) - optional. Defaults to 0. 0015 % e.g. For N = 500, if PAD = 0, we pad the FFT 0016 % to 512 points; if PAD = 2, we pad the FFT 0017 % to 2048 points, etc. 0018 % Fs (binning frequency for fft grid used to calculate fft of prolates. 1/Fs is the time between consecutive 0019 % points on the grid used for evaluation of the prolates) - optional. Default 1. 0020 % fpass (frequency band to be used in the calculation in the form 0021 % [fmin fmax])- optional. 0022 % Default all frequencies between 0 and Fs/2 0023 % err (error calculation [1 p] - Theoretical error bars; [2 p] Jackknife error bars, 0024 % [0 p] or 0 - no error bars) - optional. Default 0. 0025 % trialave (average over trials when 1, don't average when 0) - optional. Default 0 0026 % fscorr (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional 0027 % (available only for spikes). Defaults 0. 0028 0029 % Output: 0030 % S (spectrum in form time x frequency x channels/trials) 0031 % t (times) 0032 % f (frequencies) 0033 % Serr (error bars) 0034 0035 if nargin < 2; error('Need data and window parameters'); end; 0036 if nargin < 3; tapers=[3 5]; end; 0037 if nargin < 4;pad=0;end; 0038 if nargin < 5; Fs=1; end; 0039 if nargin < 6; fpass=[0 Fs/2]; end; 0040 if nargin < 7; err=0; end; 0041 if nargin < 8; trialave=0; end; 0042 if nargin < 9; fscorr=0; end; 0043 if isempty(tapers); tapers=[3 5]; end; 0044 if isempty(pad);pad=0;end; 0045 if isempty(Fs); Fs=1; end; 0046 if isempty(fpass); fpass=[0 Fs/2]; end; 0047 if isempty(err); err=0; end; 0048 if isempty(trialave); trialave=0;end; 0049 if isempty(fscorr);fscorr=0;end 0050 0051 [mintime,maxtime]=minmaxsptimes(data); 0052 tn=[mintime+movingwin(1)/2:movingwin(2):maxtime-movingwin(1)/2]; 0053 Nwin=round(Fs*movingwin(1)); % number of samples in window 0054 Nstep=round(movingwin(2)*Fs); % number of samples to step through 0055 nfft=2^(nextpow2(Nwin)+pad); 0056 [f,findx]=getfgrid(Fs,nfft,fpass); 0057 tapers=dpsschk(tapers,Nwin,Fs); % check tapers 0058 nw=length(tn); 0059 for n=1:nw; 0060 t=linspace(tn(n)-movingwin(1)/2,tn(n)+movingwin(1)/2,Nwin); 0061 datawin=extractspdata(data,[t(1) t(end)]); 0062 if nargout==5; 0063 [s,f,r,serr]=mtspectrumpt(datawin,tapers,pad,Fs,fpass,err,trialave,fscorr,t); 0064 Serr(1,n,:,:)=squeeze(serr(1,:,:)); 0065 Serr(2,n,:,:)=squeeze(serr(2,:,:)); 0066 else; 0067 [s,f,r]=mtspectrumpt(datawin,tapers,pad,Fs,fpass,err,trialave,fscorr,t); 0068 end; 0069 S(n,:,:)=s; 0070 R(n,:)=r; 0071 end; 0072 t=tn; 0073 S=squeeze(S); R=squeeze(R); if nargout==5; Serr=squeeze(Serr);end