


Multi-taper time-frequency spectrum - point process times
Usage:
[S,t,f,R,Serr]=mtspecgrampt(data,movingwin,params,fscorr)
Input:
data (structure array of spike times with dimension channels/trials; also accepts 1d array of spike times) -- required
movingwin (in the form [window,winstep] i.e length of moving
window and step size.
params: structure with fields tapers, pad, Fs, fpass, err, trialave
- optional
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 (sampling frequency) - 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/channels 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.
Output:
S (spectrogram with dimensions time x frequency x channels/trials if trialave=0; dimensions time x frequency if trialave=1)
t (times)
f (frequencies)
Serr (error bars) - only if err(1)>=1

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