


Remove running line fit (using local linear regression)-continuous
processes
Usage: data=locdetrend(data,Fs,movingwin)
Inputs:
Note that units of Fs, movinwin have to be consistent.
data (data as a matrix times x channels)
Fs (sampling frequency) - optional. Default 1
movingwin (length of moving window, and stepsize) [window winstep] - optional.
Default. window=full length of data (global detrend).
winstep=window -- global detrend
Output:
data: (locally detrended data)

0001 function data=locdetrend(data,Fs,movingwin) 0002 % Remove running line fit (using local linear regression)-continuous 0003 % processes 0004 % Usage: data=locdetrend(data,Fs,movingwin) 0005 % Inputs: 0006 % Note that units of Fs, movinwin have to be consistent. 0007 % data (data as a matrix times x channels) 0008 % Fs (sampling frequency) - optional. Default 1 0009 % movingwin (length of moving window, and stepsize) [window winstep] - optional. 0010 % Default. window=full length of data (global detrend). 0011 % winstep=window -- global detrend 0012 % 0013 % Output: 0014 % data: (locally detrended data) 0015 0016 [N,C]=size(data); 0017 if nargin < 2; Fs=1; end; 0018 if nargin < 3; movingwin=[N/Fs N/Fs]; end; 0019 Tw=movingwin(1); Ts=movingwin(2); 0020 0021 n=round(Fs*Tw); 0022 dn=round(Fs*Ts); 0023 if ~isreal(data) 0024 yr=real(data); 0025 yi=imag(data); 0026 for ch=1:C 0027 tmp=runline(yr(:,ch),n,dn); 0028 yr=yr-tmp; 0029 tmp=runline(yi(:,ch),n,dn); 0030 yi=yi-tmp; 0031 tsr(:,ch)=yr+i*yi; 0032 end; 0033 else 0034 for ch=1:C; 0035 tmp=runline(data(:,ch),n,dn); 0036 data(:,ch)=data(:,ch)-tmp; 0037 end; 0038 end