


Multi-taper derivative of the time-frequency spectrum - continuous process Usage: [dS,t,f]=mtdspecgramc(data,movingwin,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.


0001 function [dS,t,f]=mtdspecgramc(data,movingwin,tapers,phi,pad,Fs,fpass,trialave) 0002 % Multi-taper derivative of the time-frequency spectrum - continuous process 0003 % 0004 % Usage: 0005 % 0006 % [dS,t,f]=mtdspecgramc(data,movingwin,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 0013 % data (in form samples x channels/trials) -- required 0014 % movingwin (in the form [window winstep] i.e length of moving 0015 % window and step size. 0016 % Note that units here have 0017 % to be consistent with 0018 % units of Fs 0019 % tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0020 % specified, use [NW K]=[3 5] 0021 % phi (angle for evaluation of derivative) -- optional. 0022 % Default phi=[0,pi/2] giving the time and frequency 0023 % derivatives 0024 % pad (padding factor for the FFT) - optional. Defaults to 0. 0025 % e.g. For N = 500, if PAD = 0, we pad the FFT 0026 % to 512 points; if PAD = 2, we pad the FFT 0027 % to 2048 points, etc. 0028 % Fs (sampling frequency) - optional. Default 1. 0029 % fpass (frequency band to be used in the calculation in the form 0030 % [fmin fmax])- optional. 0031 % Default all frequencies between 0 and Fs/2 0032 % trialave (average over trials when 1, don't average when 0) - optional. Default 0 0033 % Output: 0034 % dS (spectrum in form angle x time x frequency x channels/trials) 0035 % t (times) 0036 % f (frequencies) 0037 0038 if nargin < 2; error('Need data and window parameters'); end; 0039 if nargin < 3; tapers=[3 5]; end; 0040 if nargin < 4; phi=[0 pi/2];end; 0041 if nargin < 5;pad=0;end; 0042 if nargin < 6; Fs=1; end; 0043 if nargin < 7; fpass=[0 Fs/2]; end; 0044 if nargin < 8; trialave=0; end; 0045 0046 N=size(data,1); 0047 Nwin=round(Fs*movingwin(1)); % number of samples in window 0048 Nstep=round(movingwin(2)*Fs); % number of samples to step through 0049 nfft=2^(nextpow2(Nwin)+pad); 0050 f=getfgrid(Fs,nfft,fpass); 0051 tapers=dpsschk(tapers,Nwin,Fs); % check tapers 0052 0053 winstart=1:Nstep:N-Nwin+1; 0054 nw=length(winstart); 0055 for n=1:nw; 0056 indx=winstart(n):winstart(n)+Nwin-1; 0057 datawin=data(indx,:); 0058 [ds,f]=mtdspectrumc(datawin,tapers,phi,pad,Fs,fpass,trialave); 0059 dS(n,:,:,:)=ds; 0060 end; 0061 sz=size(ds); 0062 if length(sz)==3; 0063 dS=permute(dS,[2 1 3 4]); 0064 else 0065 dS=permute(dS,[2 1 3]); 0066 end; 0067 winmid=winstart+round(Nwin/2); 0068 t=winmid/Fs;