mtfftpt

PURPOSE ^

Multi-taper fourier transform for point process given as times

SYNOPSIS ^

function [J,Msp,Nsp]=mtfftpt(data,tapers,nfft,Fs,t,f,findx)

DESCRIPTION ^

 Multi-taper fourier transform for point process given as times

 Usage:
 [J,Msp,Nsp]=mtfftptt (data,tapers,nfft,Fs,t,f,findx) - all arguments required
 Input: 
       data        (structural array of times with dimension channels/trials; also takes in 1d array of spike times as a column vector) 
       tapers      (precalculated tapers from dpss) 
       nfft        (length of padded data) 
       Fs          (sampling frequency)
       t           (times over which tapers are calculated)
       f           (frequencies of evaluation)
       findx       (index corresponding to frequencies f) 
 Output:
       J (fft in form frequency index x taper index x channels/trials)
       Msp (number of spikes per sample in each channel)
       Nsp (number of spikes in each channel)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [J,Msp,Nsp]=mtfftpt(data,tapers,nfft,Fs,t,f,findx)
0002 % Multi-taper fourier transform for point process given as times
0003 %
0004 % Usage:
0005 % [J,Msp,Nsp]=mtfftptt (data,tapers,nfft,Fs,t,f,findx) - all arguments required
0006 % Input:
0007 %       data        (structural array of times with dimension channels/trials; also takes in 1d array of spike times as a column vector)
0008 %       tapers      (precalculated tapers from dpss)
0009 %       nfft        (length of padded data)
0010 %       Fs          (sampling frequency)
0011 %       t           (times over which tapers are calculated)
0012 %       f           (frequencies of evaluation)
0013 %       findx       (index corresponding to frequencies f)
0014 % Output:
0015 %       J (fft in form frequency index x taper index x channels/trials)
0016 %       Msp (number of spikes per sample in each channel)
0017 %       Nsp (number of spikes in each channel)
0018 if nargin < 7; error('Need all input arguments'); end;
0019 if isstruct(data); C=length(data); else; C=1; end% number of channels
0020 K=size(tapers,2); % number of tapers
0021 nfreq=length(f); % number of frequencies
0022 if nfreq~=length(findx); error('frequency information (last two arguments) inconsistent'); end;
0023 H=fft(tapers,nfft,1);  % fft of tapers
0024 H=H(findx,:); % restrict fft of tapers to required frequencies
0025 w=2*pi*f; % angular frequencies at which ft is to be evaluated
0026 for ch=1:C;
0027   if isstruct(data);
0028      fnames=fieldnames(data);
0029      eval(['dtmp=data(ch).' fnames{1} ';'])
0030      indx=find(dtmp>=min(t)&dtmp<=max(t));
0031      if ~isempty(indx); dtmp=dtmp(indx);end;
0032   else;
0033      dtmp=data;
0034      indx=find(dtmp>=min(t)&dtmp<=max(t));
0035      if ~isempty(indx); dtmp=dtmp(indx);end;
0036   end;
0037   Nsp(ch)=length(dtmp);
0038   Msp(ch)=Nsp(ch)/length(t);
0039   if Msp(ch)~=0;
0040       data_proj=interp1(t',tapers,dtmp);
0041       exponential=exp(-i*w'*(dtmp-t(1))');
0042       J(:,:,ch)=exponential*data_proj-H*Msp(ch);
0043   else;
0044       J(1:nfreq,1:K,ch)=0;
0045   end;
0046 end;

Generated on Fri 20-May-2005 13:10:28 by m2html © 2003