Home > chronux_1_15 > pointbinned > mtspecgrampb.m

mtspecgrampb

PURPOSE ^

Multi-taper time-frequency spectrum - binned point process

SYNOPSIS ^

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

DESCRIPTION ^

 Multi-taper time-frequency spectrum - binned point process

 Usage:

 [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,params,fscorr)
 Input: 
       data        (in form samples x channels/trials or single vector) -- 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. 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
           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/channnels 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       (spectrum in form time x frequency x channels/trials for trialave=0; or as a function of frequency if trialave=1)
       t       (times)
       f       (frequencies)
       R       (rate)
       Serr    (error bars) - only for err(1)>=1

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,params,fscorr)
0002 % Multi-taper time-frequency spectrum - binned point process
0003 %
0004 % Usage:
0005 %
0006 % [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,params,fscorr)
0007 % Input:
0008 %       data        (in form samples x channels/trials or single vector) -- 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. Defaults to 0.
0017 %                       e.g. For N = 500, if PAD = 0, we pad the FFT
0018 %                       to 512 points; if PAD = 2, we pad the FFT
0019 %                       to 2048 points, etc.
0020 %           Fs   (sampling frequency) - optional. Default 1.
0021 %           fpass    (frequency band to be used in the calculation in the form
0022 %                                   [fmin fmax])- optional.
0023 %                                   Default all frequencies between 0 and Fs/2
0024 %           err  (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
0025 %                                   [0 p] or 0 - no error bars) - optional. Default 0.
0026 %           trialave (average over trials/channnels when 1, don't average when 0) - optional. Default 0
0027 %       fscorr   (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional
0028 %                (available only for spikes). Defaults 0.
0029 % Output:
0030 %       S       (spectrum in form time x frequency x channels/trials for trialave=0; or as a function of frequency if trialave=1)
0031 %       t       (times)
0032 %       f       (frequencies)
0033 %       R       (rate)
0034 %       Serr    (error bars) - only for err(1)>=1
0035 
0036 if nargin < 2; error('Need data and window parameters'); end;
0037 if nargin < 3; params=[]; end;
0038 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0039 
0040 if nargin < 4 || isempty(fscorr); fscorr=0; end;
0041 if nargout > 4 && err(1)==0; 
0042 %    error('Cannot compute errors with err(1)=0');
0043      error('When Serr is desired, err(1) has to be non-zero.');
0044 end;
0045 data=change_row_to_column(data);
0046 [N,Ch]=size(data);
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); Nf=length(f);
0051 params.tapers=dpsschk(tapers,Nwin,Fs); % check tapers
0052 winstart=1:Nstep:N-Nwin+1;
0053 nw=length(winstart);
0054 if trialave
0055     S = zeros(nw,Nf);
0056     R = zeros(nw,Nwin);
0057     if nargout==4; Serr=zeros(2,nw,Nf); end;
0058 else
0059     S = zeros(nw,Nf,Ch);
0060     R = zeros(nw,Nwin,Ch);
0061     if nargout==4; Serr=zeros(2,nw,Nf,Ch); end;
0062 end
0063 
0064 for n=1:nw;
0065    indx=winstart(n):winstart(n)+Nwin-1;
0066    datawin=data(indx,:);
0067    if nargout==5;
0068      [s,f,r,serr]=mtspectrumpb(datawin,params,fscorr);
0069      Serr(1,n,:,:)=squeeze(serr(1,:,:));
0070      Serr(2,n,:,:)=squeeze(serr(2,:,:));
0071    else
0072      [s,f,r]=mtspectrumpb(datawin,params,fscorr);
0073    end;
0074    S(n,:,:)=s;
0075    R(n,:)=r';
0076 end;
0077 winmid=winstart+round(Nwin/2);
0078 t=winmid/Fs;
0079 S=squeeze(S); R=squeeze(R); if nargout==5; Serr=squeeze(Serr);end

Generated on Tue 15-Aug-2006 22:51:57 by m2html © 2003