Home > chronux_1_50 > continuous > rmlinesc.m

rmlinesc

PURPOSE ^

removes significant sine waves from data (continuous data).

SYNOPSIS ^

function data=rmlinesc(data,params,p,plt,f0)

DESCRIPTION ^

 removes significant sine waves from data (continuous data).

 Usage: data=rmlinesc(data,params,p,plt,f0)

  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 (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.
        p            (P-value for F-test) - optional. Defaults to 0.05/N
        where N is data length. This corresponds to a false detect
        probability of approximately 0.05

       plt         (y/n for plot and no plot respectively)
       f0          frequencies at which you want to remove the
                   lines - if unspecified the program uses the f statistic
                   to determine appropriate lines.

  Outputs: 
       data        (data with significant lines removed)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data=rmlinesc(data,params,p,plt,f0)
0002 % removes significant sine waves from data (continuous data).
0003 %
0004 % Usage: data=rmlinesc(data,params,p,plt,f0)
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 (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 %        p            (P-value for F-test) - optional. Defaults to 0.05/N
0023 %        where N is data length. This corresponds to a false detect
0024 %        probability of approximately 0.05
0025 %
0026 %       plt         (y/n for plot and no plot respectively)
0027 %       f0          frequencies at which you want to remove the
0028 %                   lines - if unspecified the program uses the f statistic
0029 %                   to determine appropriate lines.
0030 %
0031 %  Outputs:
0032 %       data        (data with significant lines removed)
0033 %
0034 data=change_row_to_column(data);
0035 [N,C]=size(data);
0036 if nargin < 2 || isempty(params); params=[]; end;
0037 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0038 clear pad fpass err trialave
0039 user_specified_pval=0;
0040 if nargin < 3 || isempty(p);p=0.05/N; else; user_specified_pval=1; end;
0041 if nargin < 4 || isempty(plt); plt='n'; end;
0042 if nargin < 5; f0=[]; end;
0043 if isempty(f0) && user_specified_pval==1; p=p/N; end;
0044 [datafit,Amps,freqs,Fval,sig]=fitlinesc(data,params,p,'n',f0);
0045 datan=data-datafit;
0046 %params.tapers=dpsschk(tapers,N,Fs); % calculate the tapers
0047 
0048 % [Fval,A,f,sig] = ftestc(data,params,p,'n');
0049 % fmax=findpeaks(Fval,sig);
0050 % datasine=data;
0051 % for ch=1:C;
0052 %     fsig=f(fmax(ch).loc);
0053 %     Nf=length(fsig);
0054 %     fprintf('The significant lines for channel %d and the amplitudes are \n',ch);
0055 %     for nf=1:Nf;
0056 %         fprintf('%12.8f\n',fsig(nf));
0057 %         fprintf('%12.8f\n',real(A(fmax(ch).loc(nf),ch)));
0058 %         fprintf('%12.8f\n',imag(A(fmax(ch).loc(nf),ch)));
0059 %         fprintf('\n');
0060 %     end;
0061 %     datasine(:,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));
0062 % end;
0063 % % subplot(211); plot(data); hold on; plot(datasine,'r');
0064 % datan=data-datasine;
0065 % subplot(212); plot(datan);
0066 if nargout==0 || strcmp(plt,'y'); 
0067    figure;
0068    [S1,f]=mtspectrumc(detrend(data),params);
0069    subplot(321); plot(f,10*log10(S1));xlabel('frequency Hz'); ylabel('Spectrum dB'); title('Original spectrum');
0070    subplot(323); plot(f,Fval); line(get(gca,'xlim'),[sig sig],'Color','r'); xlabel('frequency Hz');ylabel('F-statistic');
0071    [S2,f]=mtspectrumc(detrend(datan),params);
0072    subplot(325);plot(f,10*log10(S1),f,10*log10(S2));xlabel('frequency Hz'); ylabel('Spectrum dB'); title('Original and cleaned spectra');
0073    subplot(322); plot((1:size(data,1))/params.Fs,data); xlabel('time s');  title('Original data');
0074    subplot(324); plot((1:size(datan,1))/params.Fs,datan);xlabel('time s'); title('Cleaned data');
0075 end;
0076 data=datan;

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