


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 or single vector) -- 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 (can take values -1,0,1,2...).
-1 corresponds to no padding, 0 corresponds to padding
to the next highest power of 2 etc.
e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
to 512 points, if pad=1, we pad to 1024 points etc.
Defaults to 0.
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 or single vector) -- 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 (can take values -1,0,1,2...). 0017 % -1 corresponds to no padding, 0 corresponds to padding 0018 % to the next highest power of 2 etc. 0019 % e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT 0020 % to 512 points, if pad=1, we pad to 1024 points etc. 0021 % Defaults to 0. 0022 % Fs (sampling frequency) - optional. Default 1. 0023 % fpass (frequency band to be used in the calculation in the form 0024 % [fmin fmax])- optional. 0025 % Default all frequencies between 0 and Fs/2 0026 % err (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars 0027 % [0 p] or 0 - no error bars) - optional. Default 0. 0028 % trialave (average over trials/channnels when 1, don't average when 0) - optional. Default 0 0029 % fscorr (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional 0030 % (available only for spikes). Defaults 0. 0031 % Output: 0032 % S (spectrum in form time x frequency x channels/trials for trialave=0; or as a function of frequency if trialave=1) 0033 % t (times) 0034 % f (frequencies) 0035 % R (rate) 0036 % Serr (error bars) - only for err(1)>=1 0037 0038 if nargin < 2; error('Need data and window parameters'); end; 0039 if nargin < 3; params=[]; end; 0040 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params); 0041 0042 if nargin < 4 || isempty(fscorr); fscorr=0; end; 0043 if nargout > 4 && err(1)==0; 0044 % error('Cannot compute errors with err(1)=0'); 0045 error('When Serr is desired, err(1) has to be non-zero.'); 0046 end; 0047 data=change_row_to_column(data); 0048 [N,Ch]=size(data); 0049 Nwin=round(Fs*movingwin(1)); % number of samples in window 0050 Nstep=round(movingwin(2)*Fs); % number of samples to step through 0051 nfft=max(2^(nextpow2(Nwin)+pad),Nwin); 0052 f=getfgrid(Fs,nfft,fpass); Nf=length(f); 0053 params.tapers=dpsschk(tapers,Nwin,Fs); % check tapers 0054 winstart=1:Nstep:N-Nwin+1; 0055 nw=length(winstart); 0056 if trialave 0057 S = zeros(nw,Nf); 0058 R = zeros(nw,Nwin); 0059 if nargout==4; Serr=zeros(2,nw,Nf); end; 0060 else 0061 S = zeros(nw,Nf,Ch); 0062 R = zeros(nw,Nwin,Ch); 0063 if nargout==4; Serr=zeros(2,nw,Nf,Ch); end; 0064 end 0065 0066 for n=1:nw; 0067 indx=winstart(n):winstart(n)+Nwin-1; 0068 datawin=data(indx,:); 0069 if nargout==5; 0070 [s,f,r,serr]=mtspectrumpb(datawin,params,fscorr); 0071 Serr(1,n,:,:)=squeeze(serr(1,:,:)); 0072 Serr(2,n,:,:)=squeeze(serr(2,:,:)); 0073 else 0074 [s,f,r]=mtspectrumpb(datawin,params,fscorr); 0075 end; 0076 S(n,:,:)=s; 0077 R(n,:)=r'; 0078 end; 0079 winmid=winstart+round(Nwin/2); 0080 t=winmid/Fs; 0081 S=squeeze(S); R=squeeze(R); if nargout==5; Serr=squeeze(Serr);end