Home > chronux_1_50 > pointtimes > mtspecgrampt.m

mtspecgrampt

PURPOSE ^

Multi-taper time-frequency spectrum - point process times

SYNOPSIS ^

function [S,t,f,R,Serr]=mtspecgrampt(data,movingwin,params,fscorr)

DESCRIPTION ^

 Multi-taper time-frequency spectrum - point process times

 Usage:

 [S,t,f,R,Serr]=mtspecgrampt(data,movingwin,params,fscorr)
 Input: 
       data        (structure array of spike times with dimension channels/trials; also accepts 1d array of spike times) -- required
       movingwin         (in the form [window,winstep] i.e length of moving
                                                 window and step size.
                                                 
       params: structure with fields tapers, pad, Fs, fpass, err, 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
           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/channels when 1, don't average when 0) - optional. Default 0
       fscorr   (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional
                (available only for spikes). Defaults 0.

 Output:
       S       (spectrogram with dimensions time x frequency x channels/trials if trialave=0; dimensions time x frequency if trialave=1)
       t       (times)
       f       (frequencies)

       Serr    (error bars) - only if err(1)>=1

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [S,t,f,R,Serr]=mtspecgrampt(data,movingwin,params,fscorr)
0002 % Multi-taper time-frequency spectrum - point process times
0003 %
0004 % Usage:
0005 %
0006 % [S,t,f,R,Serr]=mtspecgrampt(data,movingwin,params,fscorr)
0007 % Input:
0008 %       data        (structure array of spike times with dimension channels/trials; also accepts 1d array of spike times) -- required
0009 %       movingwin         (in the form [window,winstep] i.e length of moving
0010 %                                                 window and step size.
0011 %
0012 %       params: structure with fields tapers, pad, Fs, fpass, err, trialave
0013 %       - optional
0014 %           tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
0015 %                                                 specified, use [NW K]=[3 5]
0016 %            pad            (padding factor for the FFT) - optional (can take values -1,0,1,2...).
0017 %                    -1 corresponds to no padding, 0 corresponds to padding
0018 %                    to the next highest power of 2 etc.
0019 %                       e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
0020 %                       to 512 points, if pad=1, we pad to 1024 points etc.
0021 %                       Defaults to 0.
0022 %           Fs   (sampling frequency) - optional. Default 1.
0023 %           fpass    (frequency band to be used in the calculation in the form
0024 %                                   [fmin fmax])- optional.
0025 %                                   Default all frequencies between 0 and Fs/2
0026 %           err  (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
0027 %                                   [0 p] or 0 - no error bars) - optional. Default 0.
0028 %           trialave (average over trials/channels when 1, don't average when 0) - optional. Default 0
0029 %       fscorr   (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional
0030 %                (available only for spikes). Defaults 0.
0031 %
0032 % Output:
0033 %       S       (spectrogram with dimensions time x frequency x channels/trials if trialave=0; dimensions time x frequency if trialave=1)
0034 %       t       (times)
0035 %       f       (frequencies)
0036 %
0037 %       Serr    (error bars) - only if err(1)>=1
0038 
0039 if nargin < 2; error('Need data and window parameters'); end;
0040 if nargin < 3; params=[]; end;
0041 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0042 if isstruct(data); Ch=length(data); end;
0043 if nargin < 4 || isempty(fscorr); fscorr=0; end;
0044 if nargout > 4 && err(1)==0; error('Cannot compute errors with err(1)=0'); end;
0045 
0046 [mintime,maxtime]=minmaxsptimes(data);
0047 tn=(mintime+movingwin(1)/2:movingwin(2):maxtime-movingwin(1)/2);
0048 Nwin=round(Fs*movingwin(1)); % number of samples in window
0049 nfft=max(2^(nextpow2(Nwin)+pad),Nwin);
0050 f=getfgrid(Fs,nfft,fpass); Nf=length(f);
0051 params.tapers=dpsschk(tapers,Nwin,Fs); % check tapers
0052 nw=length(tn);
0053 
0054 if trialave
0055     S = zeros(nw,Nf);
0056     R = zeros(nw,1);
0057     if nargout==4; Serr=zeros(2,nw,Nf); end;
0058 else
0059     S = zeros(nw,Nf,Ch);
0060     R = zeros(nw,Ch);
0061     if nargout==4; Serr=zeros(2,nw,Nf,Ch); end;
0062 end
0063 
0064 for n=1:nw;
0065    t=linspace(tn(n)-movingwin(1)/2,tn(n)+movingwin(1)/2,Nwin);
0066    datawin=extractdatapt(data,[t(1) t(end)]);
0067    if nargout==5;
0068      [s,f,r,serr]=mtspectrumpt(datawin,params,fscorr,t);
0069      Serr(1,n,:,:)=squeeze(serr(1,:,:));
0070      Serr(2,n,:,:)=squeeze(serr(2,:,:));
0071    else
0072      [s,f,r]=mtspectrumpt(datawin,params,fscorr,t);
0073    end;
0074    S(n,:,:)=s;
0075    R(n,:)=r;
0076 end;
0077 t=tn;
0078 S=squeeze(S); R=squeeze(R); if nargout==5; Serr=squeeze(Serr);end

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003