


Multi-taper derivatives of time-frequency spectrum - binned point process
Usage:
[dS,t,f]=mtdspecgrampb(data,movingwin,phi,params)
Input:
Note that all times can be in arbitrary units. But the units have to be
consistent. So, if E is in secs, win, t have to be in secs, and Fs has to
be Hz. If E is in samples, so are win and t, and Fs=1. In case of spike
times, the units have to be consistent with the units of data as well.
data (in form samples x channels/trials or a single vector) -- 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
phi (angle for evaluation of derivative) -- required.
e.g. phi=[0,pi/2] giving the time and frequency
derivatives
params: structure with fields tapers, pad, Fs, fpass,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
trialave (average over trials when 1, don't average when 0) -
optional. Default 0
Output:
dS (spectral derivative in form phi x time x frequency x channels/trials if trialave=0; phi x time x frequency if trialave=1)
t (times)
f (frequencies)

0001 function [dS,t,f]=mtdspecgrampb(data,movingwin,phi,params) 0002 % Multi-taper derivatives of time-frequency spectrum - binned point process 0003 % 0004 % Usage: 0005 % 0006 % [dS,t,f]=mtdspecgrampb(data,movingwin,phi,params) 0007 % Input: 0008 % Note that all times can be in arbitrary units. But the units have to be 0009 % consistent. So, if E is in secs, win, t have to be in secs, and Fs has to 0010 % be Hz. If E is in samples, so are win and t, and Fs=1. In case of spike 0011 % times, the units have to be consistent with the units of data as well. 0012 % data (in form samples x channels/trials or a single vector) -- required 0013 % movingwin (in the form [window winstep] i.e length of moving 0014 % window and step size. 0015 % Note that units here have 0016 % to be consistent with 0017 % units of Fs 0018 % phi (angle for evaluation of derivative) -- required. 0019 % e.g. phi=[0,pi/2] giving the time and frequency 0020 % derivatives 0021 % params: structure with fields tapers, pad, Fs, fpass,trialave 0022 % -optional 0023 % tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0024 % specified, use [NW K]=[3 5] 0025 % pad (padding factor for the FFT) - optional (can take values -1,0,1,2...). 0026 % -1 corresponds to no padding, 0 corresponds to padding 0027 % to the next highest power of 2 etc. 0028 % e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT 0029 % to 512 points, if pad=1, we pad to 1024 points etc. 0030 % Defaults to 0. 0031 % Fs (sampling frequency) - optional. Default 1. 0032 % fpass (frequency band to be used in the calculation in the form 0033 % [fmin fmax])- optional. 0034 % Default all frequencies between 0 and 0035 % Fs/2 0036 % trialave (average over trials when 1, don't average when 0) - 0037 % optional. Default 0 0038 % Output: 0039 % dS (spectral derivative in form phi x time x frequency x channels/trials if trialave=0; phi x time x frequency if trialave=1) 0040 % t (times) 0041 % f (frequencies) 0042 0043 if nargin < 3; error('Need data, window parameters and angle'); end; 0044 if nargin < 4; params=[]; end; 0045 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params); 0046 clear err 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 0055 winstart=1:Nstep:N-Nwin+1; 0056 nw=length(winstart); 0057 if trialave==0; dS=zeros(length(phi),nw,Nf,Ch); else dS=zeros(length(phi),nw,Nf); end; 0058 for n=1:nw; 0059 indx=winstart(n):winstart(n)+Nwin-1; 0060 datawin=data(indx,:); 0061 [ds,f]=mtdspectrumpb(datawin,phi,params); 0062 dS(:,n,:,:)=ds; 0063 end; 0064 sz=size(ds); 0065 dS=squeeze(dS); 0066 % if length(sz)==3; 0067 % dS=permute(dS,[2 1 3 4]); 0068 % elseif length(phi)>1 0069 % dS=permute(dS,[2 1 3]); 0070 % end; 0071 winmid=winstart+round(Nwin/2); 0072 t=winmid/Fs;