Home > chronux_1_0 > continuous > fitlinesc.m

fitlinesc

PURPOSE ^

fits significant sine waves to data (continuous data).

SYNOPSIS ^

function [datafit,Amps,freqs]=fitlinesc(data,params, p,plt)

DESCRIPTION ^

 fits significant sine waves to data (continuous data).

 Usage: [datafit,Amps,freqs]=fitlinesc(data,params, p)

  Inputs:  
 Note that units of Fs, fpass have to be consistent.
       data        (data in [N,C] i.e. time x channels/trials or a single vector) - required.
       params      structure containing parameters - params has the
       following fields: tapers, Fs, fpass, pad
            tapers         (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5]
            Fs             (sampling frequency) -- optional. Defaults to 1.
               fpass       (frequency band to be used in the calculation in the form
                                   [fmin fmax])- optional. 
                                   Default all frequencies between 0 and Fs/2
            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.
        p            (P-value to calculate error bars for) - optional. Defaults to 0.05/N where N is data length.
       plt         (y/n for plot and no plot respectively)


  Outputs: 
       datafit        (linear superposition of fitted sine waves)
       Amps           (amplitudes at significant frequencies)
       freqs          (significant frequencies)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [datafit,Amps,freqs]=fitlinesc(data,params, p,plt)
0002 % fits significant sine waves to data (continuous data).
0003 %
0004 % Usage: [datafit,Amps,freqs]=fitlinesc(data,params, p)
0005 %
0006 %  Inputs:
0007 % Note that units of Fs, fpass have to be consistent.
0008 %       data        (data in [N,C] i.e. time x channels/trials or a single vector) - required.
0009 %       params      structure containing parameters - params has the
0010 %       following fields: tapers, Fs, fpass, pad
0011 %            tapers         (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5]
0012 %            Fs             (sampling frequency) -- optional. Defaults to 1.
0013 %               fpass       (frequency band to be used in the calculation in the form
0014 %                                   [fmin fmax])- optional.
0015 %                                   Default all frequencies between 0 and Fs/2
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 %        p            (P-value to calculate error bars for) - optional. Defaults to 0.05/N where N is data length.
0021 %       plt         (y/n for plot and no plot respectively)
0022 %
0023 %
0024 %  Outputs:
0025 %       datafit        (linear superposition of fitted sine waves)
0026 %       Amps           (amplitudes at significant frequencies)
0027 %       freqs          (significant frequencies)
0028 %
0029 data=change_row_to_column(data);
0030 [N,C]=size(data);
0031 if nargin < 2 || isempty(params); params=[]; end;
0032 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0033 clear pad fpass err trialave
0034 if nargin<3;p=0.05/N;end;
0035 params.tapers=dpsschk(tapers,N,Fs); % calculate the tapers
0036 [Fval,A,f,sig] = ftestc(data,params,p,plt);
0037 fmax=findpeaks(Fval,sig);
0038 freqs=cell(1,C);
0039 Amps=cell(1,C);
0040 datafit=data;
0041 for ch=1:C;
0042     fsig=f(fmax(ch).loc);
0043     freqs{ch}=fsig;
0044     Amps{ch}=A(fmax(ch).loc,ch);
0045     Nf=length(fsig);
0046     fprintf('The significant lines for channel %d and the amplitudes are \n',ch);
0047     for nf=1:Nf;
0048         fprintf('%12.8f\n',fsig(nf));
0049         fprintf('%12.8f\n',real(A(fmax(ch).loc(nf),ch)));
0050         fprintf('%12.8f\n',imag(A(fmax(ch).loc(nf),ch))); 
0051         fprintf('\n');
0052     end;
0053     datafit(:,ch)=exp(i*2*pi*(0:N-1)'*fsig/Fs)*A(fmax(ch).loc,ch)+exp(-i*2*pi*(0:N-1)'*fsig/Fs)*conj(A(fmax(ch).loc,ch));
0054 end;

Generated on Fri 09-Jun-2006 23:38:05 by m2html © 2003