Home > chronux_1_1 > continuous > mtspectrum_of_spectrumc.m

mtspectrum_of_spectrumc

PURPOSE ^

Multi-taper segmented, second spectrum (spectrum of the spectrum) for a continuous process

SYNOPSIS ^

function [SS,tau]=mtspectrum_of_spectrumc(data,win,tapers,params)

DESCRIPTION ^

 Multi-taper segmented, second spectrum (spectrum of the spectrum) for a continuous process
 This routine computes the second spectrum by explicitly evaluating the
 Fourier transform (since the spectrum is symmetric in frequency, it uses
 a cosine transform)

 Usage:

 [SS,tau]=mtspectrum_of_spectrumc(data,win,tapers,params)
 Input: 
 Note units have to be consistent. See chronux.m for more information.
       data (single channel) -- required
       win  (duration of the segments) - required. 
       tapers (tapers used for the spectrum of spectrum computation) -
       required in the form [TW K] - note that this is distinct from the
       the tapers argument in params. The latter is used to compute the
       spectrum itself.
       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
 Output:
       SS       (second spectrum in form frequency x segments x trials x channels 
                if segave=0; in the form frequency x trials x channels if segave=1)
       tau      (frequencies)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [SS,tau]=mtspectrum_of_spectrumc(data,win,tapers,params)
0002 % Multi-taper segmented, second spectrum (spectrum of the spectrum) for a continuous process
0003 % This routine computes the second spectrum by explicitly evaluating the
0004 % Fourier transform (since the spectrum is symmetric in frequency, it uses
0005 % a cosine transform)
0006 %
0007 % Usage:
0008 %
0009 % [SS,tau]=mtspectrum_of_spectrumc(data,win,tapers,params)
0010 % Input:
0011 % Note units have to be consistent. See chronux.m for more information.
0012 %       data (single channel) -- required
0013 %       win  (duration of the segments) - required.
0014 %       tapers (tapers used for the spectrum of spectrum computation) -
0015 %       required in the form [TW K] - note that this is distinct from the
0016 %       the tapers argument in params. The latter is used to compute the
0017 %       spectrum itself.
0018 %       params: structure with fields tapers, pad, Fs, fpass, err, trialave
0019 %       - optional
0020 %           tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
0021 %                                                 specified, use [NW K]=[3 5]
0022 %            pad            (padding factor for the FFT) - optional. Defaults to 0.
0023 %                       e.g. For N = 500, if PAD = 0, we pad the FFT
0024 %                       to 512 points; if PAD = 2, we pad the FFT
0025 %                       to 2048 points, etc.
0026 %           Fs   (sampling frequency) - optional. Default 1.
0027 %           fpass    (frequency band to be used in the calculation in the form
0028 %                                   [fmin fmax])- optional.
0029 %                                   Default all frequencies between 0 and
0030 %                                   Fs/2
0031 % Output:
0032 %       SS       (second spectrum in form frequency x segments x trials x channels
0033 %                if segave=0; in the form frequency x trials x channels if segave=1)
0034 %       tau      (frequencies)
0035 if nargin < 3; error('Need data,segment duration and taper information'); end;
0036 if nargin < 4 ; params=[]; end;
0037 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params); 
0038 [N,Ntr,NC]=size(data);
0039 if Ntr==1; error('cannot compute second spectrum with just one trial'); end;
0040 dt=1/Fs; % sampling interval
0041 T=N*dt; % length of data in seconds
0042 E=0:win:T-win; % fictitious event triggers
0043 datatmp=createdatamatc(data(:,1,1),E,Fs,[0 win]); % segmented data
0044 Ninseg=size(datatmp,1); % number of samples in segments
0045 nfft=2^(nextpow2(Ninseg)+pad);
0046 [f,findx]=getfgrid(Fs,nfft,fpass); 
0047 NF=length(findx);
0048 S=zeros(NF,Ntr,NC);
0049 for nc=1:NC;
0050     for ntr=1:Ntr;
0051         datatmp=change_row_to_column(data(:,ntr,nc));
0052         s=mtspectrumsegc(datatmp,win,params,1);
0053         S(:,ntr,nc)=s;
0054     end
0055 end;
0056 Sm=mean(S,2);
0057 tau=[0:NF-1]/max(f);
0058 cosinefunc=cos(2*pi*f'*tau);
0059 params.tapers=tapers;
0060 params.Fs=1/(f(2)-f(1));
0061 params.fpass=[0 params.Fs/2];
0062 for nc=1:NC;
0063     for ntr=1:Ntr;
0064         s=S(:,ntr,nc)./Sm(:,nc);
0065         s=log(s);
0066 %         sflip=flipdim(s,1);
0067 %         s=[sflip(1:NF-1);s];
0068 %         [ss,tau]=mtspectrumc(s,params);
0069 %         SS(:,ntr,nc)=ss;
0070         s=repmat(s,[1 NF]).*cosinefunc;
0071 %         subplot(221); plot(s(:,1));
0072 %         subplot(222); plot(s(:,10));
0073 %         subplot(223); plot(s(:,100));
0074 %         subplot(224); plot(s(:,120));
0075 %         pause
0076         s=trapz(f,s,1)';
0077         s=s.*conj(s);
0078 %         plot(tau,s)
0079 %         pause
0080         SS(:,ntr,nc)=s;
0081     end
0082 end;
0083 SS=mean(SS,2);

Generated on Sun 13-Aug-2006 11:49:44 by m2html © 2003