


Multi-taper time-frequency spectrum - binned point process
Usage:
[S,t,f,R,Serr]=mtspecgrampb(data,movingwin,params,fscorr)
Input:
data (in form samples x channels/trials) -- 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/channnels 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 (spectrum in form time x frequency x channels/trials for trialave=0; or as a function of frequency if trialave=1)
t (times)
f (frequencies)
R (rate)
Serr (error bars) - only for err(1)>=1

0001 function [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,params,fscorr) 0002 % Multi-taper time-frequency spectrum - binned point process 0003 % 0004 % Usage: 0005 % 0006 % [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,params,fscorr) 0007 % Input: 0008 % data (in form samples x channels/trials) -- 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/channnels 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 % Output: 0030 % S (spectrum in form time x frequency x channels/trials for trialave=0; or as a function of frequency if trialave=1) 0031 % t (times) 0032 % f (frequencies) 0033 % R (rate) 0034 % Serr (error bars) - only for err(1)>=1 0035 0036 if nargin < 2; error('Need data and window parameters'); end; 0037 if nargin < 3; params=[]; end; 0038 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params); 0039 if nargin < 4 || isempty(fscorr); fscorr=0; end; 0040 if nargout > 4 && err(1)==0; 0041 % error('Cannot compute errors with err(1)=0'); 0042 error('When Serr is desired, err(1) has to be non-zero.'); 0043 end; 0044 N=size(data,1); 0045 Nwin=round(Fs*movingwin(1)); % number of samples in window 0046 Nstep=round(movingwin(2)*Fs); % number of samples to step through 0047 nfft=2^(nextpow2(Nwin)+pad); 0048 [f,findx]=getfgrid(Fs,nfft,fpass); 0049 params.tapers=dpsschk(tapers,Nwin,Fs); % check tapers 0050 whos data 0051 winstart=1:Nstep:N-Nwin+1; 0052 nw=length(winstart); 0053 for n=1:nw; 0054 indx=winstart(n):winstart(n)+Nwin-1; 0055 datawin=data(indx,:); 0056 if nargout==5; 0057 [s,f,r,serr]=mtspectrumpb(datawin,params,fscorr); 0058 Serr(1,n,:,:)=squeeze(serr(1,:,:)); 0059 Serr(2,n,:,:)=squeeze(serr(2,:,:)); 0060 else 0061 [s,f,r]=mtspectrumpb(datawin,params,fscorr); 0062 end; 0063 S(n,:,:)=s; 0064 R(n,:)=r'; 0065 end; 0066 winmid=winstart+round(Nwin/2); 0067 t=winmid/Fs; 0068 S=squeeze(S); R=squeeze(R); if nargout==5; Serr=squeeze(Serr);end