Home > chronux_1_1 > continuous > rmlinesc.m

rmlinesc

PURPOSE ^

removes significant sine waves from data (continuous data).

SYNOPSIS ^

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

DESCRIPTION ^

 removes significant sine waves from data (continuous data).

 Usage: data=rmlinesc(data,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.
       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 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)

  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)
0002 % removes significant sine waves from data (continuous data).
0003 %
0004 % Usage: data=rmlinesc(data,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 %       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 for F-test) - optional. Defaults to 0.05/N
0021 %        where N is data length. This corresponds to a false detect
0022 %        probability of approximately 0.05
0023 %
0024 %       plt         (y/n for plot and no plot respectively)
0025 %
0026 %  Outputs:
0027 %       data        (data with significant lines removed)
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 || isempty(p);p=0.05/N;end;
0035 
0036 params.tapers=dpsschk(tapers,N,Fs); % calculate the tapers
0037 [Fval,A,f,sig] = ftestc(data,params,p,'n');
0038 fmax=findpeaks(Fval,sig);
0039 datasine=data;
0040 for ch=1:C;
0041     fsig=f(fmax(ch).loc);
0042     Nf=length(fsig);
0043     fprintf('The significant lines for channel %d and the amplitudes are \n',ch);
0044     for nf=1:Nf;
0045         fprintf('%12.8f\n',fsig(nf));
0046         fprintf('%12.8f\n',real(A(fmax(ch).loc(nf),ch)));
0047         fprintf('%12.8f\n',imag(A(fmax(ch).loc(nf),ch))); 
0048         fprintf('\n');
0049     end;
0050     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));
0051 end;
0052 % subplot(211); plot(data); hold on; plot(datasine,'r');
0053 datan=data-datasine;
0054 % subplot(212); plot(datan);
0055 if nargout==0 || strcmp(plt,'y'); 
0056    figure;
0057    [S1,f]=mtspectrumc(detrend(data),params);
0058    subplot(321); plot(f,10*log10(S1));xlabel('frequency Hz'); ylabel('Spectrum dB'); title('Original spectrum');
0059    subplot(323); plot(f,Fval); line(get(gca,'xlim'),[sig sig],'Color','r'); xlabel('frequency Hz');ylabel('F-statistic');
0060    [S2,f]=mtspectrumc(detrend(datan),params);
0061    subplot(325);plot(f,10*log10(S1),f,10*log10(S2));xlabel('frequency Hz'); ylabel('Spectrum dB'); title('Original and cleaned spectra');
0062    subplot(322); plot((1:size(data,1))/params.Fs,data); xlabel('time s'); ylabel('B fT'); title('Original data');
0063    subplot(324); plot((1:size(datan,1))/params.Fs,datan);xlabel('time s'); ylabel('B fT'); title('Cleaned data');
0064 end;
0065 data=datan;

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