


Multi-taper frequency derivative of the spectrum - continuous process
Usage:
[dS,f]=mtdspectrumc(data,tapers,phi,pad,Fs,fpass,trialave)
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) -- required
tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
specified, use [NW K]=[3 5]7
phi (angle for evaluation of derivative) -- optional.
Default phi=[0,pi/2] giving the time and frequency derivatives
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
trialave (average over trials when 1, don't average when 0) - optional. Default 0
Output:
dS (spectrum in form angle x frequency x taper index x channels/trials)
f (frequencies)

0001 function [dS,f]=mtdspectrumc(data,tapers,phi,pad,Fs,fpass,trialave) 0002 % Multi-taper frequency derivative of the spectrum - continuous process 0003 % 0004 % Usage: 0005 % 0006 % [dS,f]=mtdspectrumc(data,tapers,phi,pad,Fs,fpass,trialave) 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) -- required 0013 % tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0014 % specified, use [NW K]=[3 5]7 0015 % phi (angle for evaluation of derivative) -- optional. 0016 % Default phi=[0,pi/2] giving the time and frequency derivatives 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 % trialave (average over trials when 1, don't average when 0) - optional. Default 0 0026 % Output: 0027 % dS (spectrum in form angle x frequency x taper index x channels/trials) 0028 % f (frequencies) 0029 0030 if nargin < 1; error('Need data'); end; 0031 if nargin < 2; tapers=[3 5]; end; 0032 if nargin < 3; phi=[0 pi/2];end; 0033 if nargin < 4;pad=0;end; 0034 if nargin < 5; Fs=1; end; 0035 if nargin < 6; fpass=[0 Fs/2]; end; 0036 if nargin < 7; trialave=0; end; 0037 0038 [N,C]=size(data); 0039 nfft=2^(nextpow2(N)+pad); 0040 [f,findx]=getfgrid(Fs,nfft,fpass); 0041 tapers=dpsschk(tapers,N)/sqrt(Fs); % check tapers 0042 K=size(tapers,2); 0043 J=mtfftc(data,tapers,nfft); 0044 J=J(findx,:,:); 0045 S=squeeze(mean(J(:,1:K-1,:).*conj(J(:,2:K,:)),2)); 0046 if trialave; S=squeeze(mean(S,2));end; 0047 nphi=length(phi); 0048 for p=1:nphi; 0049 dS(p,:,:)=real(exp(i*phi(p))*S); 0050 end; 0051 dS=squeeze(dS);