


removes significant sine waves from data (continuous data).
Usage: data = rmlinesc(data,tapers,Fs,fpass,pad,p)
Inputs:
Note that units of Fs, fpass have to be consistent.
data (data in [N,C] i.e. time x channels/trials) - required.
tapers (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5]
Fs (sampling frequency) -- optional. Defaults to 1.
fpass (band of frequencies to be kept [fmin fmax]) - optional. Defaults to [0 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 (95% confidence).
Outputs:
data (data with significant lines removed)

0001 function data=rmlinesc(data,tapers, Fs, fpass, pad, p) 0002 % removes significant sine waves from data (continuous data). 0003 % 0004 % Usage: data = rmlinesc(data,tapers,Fs,fpass,pad,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) - required. 0009 % tapers (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5] 0010 % Fs (sampling frequency) -- optional. Defaults to 1. 0011 % fpass (band of frequencies to be kept [fmin fmax]) - optional. Defaults to [0 Fs/2] 0012 % pad (padding factor for the FFT) - optional. Defaults to 0. 0013 % e.g. For N = 500, if PAD = 0, we pad the FFT 0014 % to 512 points; if PAD = 2, we pad the FFT 0015 % to 2048 points, etc. 0016 % p (P-value to calculate error bars for) - optional. Defaults to 0.05 (95% confidence). 0017 % 0018 % 0019 % Outputs: 0020 % data (data with significant lines removed) 0021 % 0022 0023 [N,C]=size(data); 0024 if nargin<2; tapers=[3 5]; end; 0025 if nargin<3; Fs=1;end; 0026 if nargin<4;fpass=[0 Fs/2];end; 0027 if nargin<5;pad=0;end; 0028 if nargin<6;p=0.05;end; 0029 tapers=dpsschk(tapers,N); % calculate the tapers 0030 [Fval,A,f,sig,sd] = ftestc(data,tapers,Fs,fpass,pad,p); 0031 fmax=findpeaks(Fval,sig); 0032 for ch=1:C; 0033 fsig=f(fmax(ch).loc); 0034 Nf=length(fsig); 0035 fprintf('The significant lines for channel %d and the amplitudes are \n',ch); 0036 for nf=1:Nf; 0037 fprintf('%12.8f\n',fsig(nf)); 0038 fprintf('%12.8f\n',real(A(fmax(ch).loc,ch))); 0039 fprintf('%12.8f\n',imag(A(fmax(ch).loc,ch))); 0040 end; 0041 datasine(:,ch)=exp(i*2*pi*(1:N)'*fsig/Fs)*A(fmax(ch).loc,ch)+exp(-i*2*pi*(1:N)'*fsig/Fs)*conj(A(fmax(ch).loc,ch)); 0042 end; 0043 datan=data-datasine; 0044 if nargout==0; 0045 figure;subplot(211); plot(f,Fval); line(get(gca,'xlim'),[sig sig]); 0046 px1=pmtm(data(:,1)); 0047 px2=pmtm(datan(:,1)); 0048 subplot(212);plot(1:length(px1),10*log10(px1),1:length(px2),10*log10(px2)); 0049 end; 0050 data=datan;