


Multi-taper time-frequency spectrum - continuous process
Usage:
[S,t,f,Serr]=mtspectgramc(data,movingwin,tapers,pad,Fs,fpass,err,trialave)
Input:
Note units have to be consistent. Thus, if movingwin is in seconds, Fs
has to be in Hz. see chronux.m for more information.
data (in form samples x channels/trials) -- required
movingwin (in 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 (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 when 1, don't average when 0) - optional. Default 0
Output:
S (spectrum in form time x frequency x channels/trials)
t (times)
f (frequencies)
Serr (error bars)

0001 function [S,t,f,Serr]=mtspecgramc(data,movingwin,tapers,pad,Fs,fpass,err,trialave) 0002 % Multi-taper time-frequency spectrum - continuous process 0003 % 0004 % Usage: 0005 % [S,t,f,Serr]=mtspectgramc(data,movingwin,tapers,pad,Fs,fpass,err,trialave) 0006 % Input: 0007 % Note units have to be consistent. Thus, if movingwin is in seconds, Fs 0008 % has to be in Hz. see chronux.m for more information. 0009 % data (in form samples x channels/trials) -- required 0010 % movingwin (in the form [window winstep] i.e length of moving 0011 % window and step size) 0012 % Note that units here have 0013 % to be consistent with 0014 % units of Fs 0015 % tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0016 % specified, use [NW K]=[3 5] 0017 % pad (padding factor for the FFT) - optional. Defaults to 0. 0018 % e.g. For N = 500, if PAD = 0, we pad the FFT 0019 % to 512 points; if PAD = 2, we pad the FFT 0020 % to 2048 points, etc. 0021 % Fs (sampling frequency) - optional. Default 1. 0022 % fpass (frequency band to be used in the calculation in the form 0023 % [fmin fmax])- optional. 0024 % Default all frequencies between 0 and Fs/2 0025 % err (error calculation [1 p] - Theoretical error bars; [2 p] Jackknife error bars, 0026 % [0 p] or 0 - no error bars) - optional. Default 0. 0027 % trialave (average over trials when 1, don't average when 0) - optional. Default 0 0028 % Output: 0029 % S (spectrum in form time x frequency x channels/trials) 0030 % t (times) 0031 % f (frequencies) 0032 % Serr (error bars) 0033 0034 if nargin < 2; error('Need data and window parameters'); end; 0035 if nargin < 3; tapers=[3 5]; end; 0036 if nargin < 4;pad=0;end; 0037 if nargin < 5; Fs=1; end; 0038 if nargin < 6; fpass=[0 Fs/2]; end; 0039 if nargin < 7; err=0; end; 0040 if nargin < 8; trialave=0; end; 0041 if isempty(tapers); tapers=[3 5]; end; 0042 if isempty(pad);pad=0;end; 0043 if isempty(Fs); Fs=1; end; 0044 if isempty(fpass); fpass=[0 Fs/2]; end; 0045 if isempty(err); err=0; end; 0046 if isempty(trialave); trialave=0;end; 0047 0048 0049 [N,C]=size(data); 0050 Nwin=round(Fs*movingwin(1)); % number of samples in window 0051 Nstep=round(movingwin(2)*Fs); % number of samples to step through 0052 nfft=2^(nextpow2(Nwin)+pad); 0053 [f,findx]=getfgrid(Fs,nfft,fpass); 0054 tapers=dpsschk(tapers,Nwin)/sqrt(Fs); % check tapers 0055 0056 winstart=[1:Nstep:N-Nwin+1]; 0057 nw=length(winstart); 0058 for n=1:nw; 0059 indx=winstart(n):winstart(n)+Nwin-1; 0060 datawin=data(indx,:); 0061 if nargout==4; 0062 [s,f,serr]=mtspectrumc(datawin,tapers,pad,Fs,fpass,err,trialave); 0063 Serr(1,n,:,:)=squeeze(serr(1,:,:)); 0064 Serr(2,n,:,:)=squeeze(serr(2,:,:)); 0065 else; 0066 [s,f]=mtspectrumc(datawin,tapers,pad,Fs,fpass,err,trialave); 0067 end; 0068 S(n,:,:)=s; 0069 end; 0070 S=squeeze(S); if nargout==4;Serr=squeeze(Serr);end; 0071 winmid=winstart+round(Nwin/2); 0072 t=winmid/Fs;