Home > chronux_1_15 > continuous > rmlinesc.m

rmlinesc

PURPOSE ^

removes significant sine waves from data (continuous data).

SYNOPSIS ^

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

DESCRIPTION ^

 removes significant sine waves from data (continuous data).

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

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