


Multi-taper time-frequency spectrum - binned point process
Usage:
[S,t,f,R,Serr]=mtspecgrampb(data,movingwin,tapers,pad,Fs,fpass,err,trialave,err,trialave,fscorr)
Input:
data (in form samples x channels/trials) -- required
movingwin (n the form [window winstep] i.e length of moving
window and step size.
Note that units here have
to be consistent with
units of Fs
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) - 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.
Output:
S (spectrum in form time x frequency x channels/trials)
t (times)
f (frequencies)
R (rate)
Serr (error bars)

0001 function [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,tapers,pad,Fs,fpass,err,trialave,fscorr) 0002 % Multi-taper time-frequency spectrum - binned point process 0003 % 0004 % Usage: 0005 % 0006 % [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,tapers,pad,Fs,fpass,err,trialave,err,trialave,fscorr) 0007 % Input: 0008 % data (in form samples x channels/trials) -- required 0009 % movingwin (n the form [window winstep] i.e length of moving 0010 % window and step size. 0011 % Note that units here have 0012 % to be consistent with 0013 % units of Fs 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 (binning 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 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) 0031 % t (times) 0032 % f (frequencies) 0033 % R (rate) 0034 % Serr (error bars) 0035 0036 if nargin < 2; error('Need data and window parameters'); end; 0037 if nargin < 3; tapers=[3 5]; end; 0038 if nargin < 4;pad=0;end; 0039 if nargin < 5; Fs=1; end; 0040 if nargin < 6; fpass=[0 Fs/2]; end; 0041 if nargin < 7; err=0; end; 0042 if nargin < 8; trialave=0; end; 0043 if nargin < 9; fscorr=0; end; 0044 if isempty(tapers); tapers=[3 5]; end; 0045 if isempty(pad);pad=0;end; 0046 if isempty(Fs); Fs=1; end; 0047 if isempty(fpass); fpass=[0 Fs/2]; end; 0048 if isempty(err); err=0; end; 0049 if isempty(trialave); trialave=0;end; 0050 if isempty(fscorr);fscorr=0;end; 0051 0052 N=size(data,1); 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 0059 winstart=[1:Nstep:N-Nwin+1]; 0060 nw=length(winstart); 0061 for n=1:nw; 0062 indx=winstart(n):winstart(n)+Nwin-1; 0063 datawin=data(indx,:); 0064 if nargout==5; 0065 [s,f,r,serr]=mtspectrumpb(datawin,tapers,pad,Fs,fpass,err,trialave,fscorr); 0066 Serr(1,n,:,:)=squeeze(serr(1,:,:)); 0067 Serr(2,n,:,:)=squeeze(serr(2,:,:)); 0068 else; 0069 [s,f,r]=mtspectrumpb(datawin,tapers,pad,Fs,fpass,err,trialave,fscorr); 0070 end; 0071 S(n,:,:)=s; 0072 R(n,:)=r; 0073 end; 0074 winmid=winstart+round(Nwin/2); 0075 t=winmid/Fs; 0076 S=squeeze(S); R=squeeze(R); if nargout==5; Serr=squeeze(Serr);end