Home > chronux_1_15 > continuous > fitlinesc.m

fitlinesc

PURPOSE ^

fits significant sine waves to data (continuous data).

SYNOPSIS ^

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

DESCRIPTION ^

 fits significant sine waves to data (continuous data).

 Usage: [datafit,Amps,freqs,Fval,sig]=fitlinesc(data,f0,params,p,plt)

  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.
       f0          a single frequency at which you want to remove the
                   lines - specify empty [] if you just want the program
                   to compute the significant lines
       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) - plots the
       Fratio at all frequencies if y


  Outputs: 
       datafit        (linear superposition of fitted sine waves)
       Amps           (amplitudes at significant frequencies)
       freqs          (significant frequencies)
       Fval           (Fstatistic at all frequencies)
       sig            (significance level for F distribution p value of p)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [datafit,Amps,freqs,Fval,sig]=fitlinesc(data,f0,params,p,plt)
0002 % fits significant sine waves to data (continuous data).
0003 %
0004 % Usage: [datafit,Amps,freqs,Fval,sig]=fitlinesc(data,f0,params,p,plt)
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 %       f0          a single frequency at which you want to remove the
0010 %                   lines - specify empty [] if you just want the program
0011 %                   to compute the significant lines
0012 %       params      structure containing parameters - params has the
0013 %       following fields: tapers, Fs, fpass, pad
0014 %            tapers         (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5]
0015 %            Fs             (sampling frequency) -- optional. Defaults to 1.
0016 %               fpass       (frequency band to be used in the calculation in the form
0017 %                                   [fmin fmax])- optional.
0018 %                                   Default all frequencies between 0 and Fs/2
0019 %            pad            (padding factor for the FFT) - optional. Defaults to 0.
0020 %                          e.g. For N = 500, if PAD = 0, we pad the FFT
0021 %                          to 512 points; if PAD = 2, we pad the FFT
0022 %                          to 2048 points, etc.
0023 %        p            (P-value to calculate error bars for) - optional. Defaults to 0.05/N where N is data length.
0024 %       plt         (y/n for plot and no plot respectively) - plots the
0025 %       Fratio at all frequencies if y
0026 %
0027 %
0028 %  Outputs:
0029 %       datafit        (linear superposition of fitted sine waves)
0030 %       Amps           (amplitudes at significant frequencies)
0031 %       freqs          (significant frequencies)
0032 %       Fval           (Fstatistic at all frequencies)
0033 %       sig            (significance level for F distribution p value of p)
0034 data=change_row_to_column(data);
0035 [N,C]=size(data);
0036 if nargin < 3 || isempty(params); params=[]; end;
0037 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0038 clear pad fpass err trialave
0039 if nargin<4;p=0.05/N;end;
0040 params.tapers=dpsschk(tapers,N,Fs); % calculate the tapers
0041 [Fval,A,f,sig] = ftestc(data,params,p,plt);
0042 if isempty(f0);
0043    fmax=findpeaks(Fval,sig);
0044    freqs=cell(1,C);
0045    Amps=cell(1,C);
0046    datafit=data;
0047    for ch=1:C;
0048         fsig=f(fmax(ch).loc);
0049         freqs{ch}=fsig;
0050         Amps{ch}=A(fmax(ch).loc,ch);
0051         Nf=length(fsig);
0052         fprintf('The significant lines for channel %d and the amplitudes are \n',ch);
0053         for nf=1:Nf;
0054             fprintf('%12.8f\n',fsig(nf));
0055             fprintf('%12.8f\n',real(A(fmax(ch).loc(nf),ch)));
0056             fprintf('%12.8f\n',imag(A(fmax(ch).loc(nf),ch))); 
0057             fprintf('\n');
0058         end;
0059         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));
0060    end;
0061 else;
0062     [fsig,indx]=min(abs(f-f0));
0063     fsig=f(indx);
0064     for ch=1:C;
0065         freqs{ch}=fsig;
0066         Amps{ch}=A(indx,ch);
0067         Nf=length(fsig);
0068         fprintf('For channel %d the amplitudes and the Fstatistic at f=%f are \n',ch,f0);
0069         fprintf('Fstatistic = %12.8f Fthreshold = %12.8f\n',Fval(indx),sig);
0070         fprintf('Real part of amplitude = %12.8f\n',real(A(indx,ch)));
0071         fprintf('Imaginary part of amplitude = %12.8f\n',imag(A(indx,ch))); 
0072         datafit(:,ch)=exp(i*2*pi*(0:N-1)'*fsig/Fs)*A(indx,ch)+exp(-i*2*pi*(0:N-1)'*fsig/Fs)*conj(A(indx,ch));
0073     end;
0074 end;
0075

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