# locsmooth

## PURPOSE

Running line fit (using local linear regression) - 1d only, continuous

## SYNOPSIS

function data=locsmooth(data,Fs,Tw,Ts)

## DESCRIPTION

      Running line fit (using local linear regression) - 1d only, continuous
      processes
      Usage: data=locsmooth(data,Fs,Tw,Ts)
      Inputs:
     Note that units of Fs, movinwin have to be consistent.
      data  (single vector)
      Fs    (sampling frequency) - optional. Default 1
      Tw    (length of moving window) - optional.  Default. full length of data (global detrend)
      Ts    (step size) - optional. Default Tw/2.

     Output:
     data   (locally smoothed data).

## CROSS-REFERENCE INFORMATION

This function calls:

- runline Running line fit (local linear regression)
- runline Running line fit (local linear regression)
- change_row_to_column Helper routine to transform 1d arrays into column vectors that are needed

This function is called by:

- evoked Function to calculate the evoked response given continuous data in the
- sta Spike Triggered Average

## SOURCE CODE

    0001 function data=locsmooth(data,Fs,Tw,Ts)
    0002 %  Running line fit (using local linear regression) - 1d only, continuous
    0003 %  processes
    0004 %  Usage: data=locsmooth(data,Fs,Tw,Ts)
    0005 %  Inputs:
    0006 % Note that units of Fs, movinwin have to be consistent.
    0007 %  data  (single vector)
    0008 %  Fs    (sampling frequency) - optional. Default 1
    0009 %  Tw    (length of moving window) - optional.  Default. full length of data (global detrend)
    0010 %  Ts    (step size) - optional. Default Tw/2.
    0011 %
    0012 % Output:
    0013 % data   (locally smoothed data).
    0014 data=change_row_to_column(data);
    0015 N=size(data,1);
    0016 if nargin < 2; Fs=1; end;
    0017 if nargin < 3; Tw=N/Fs; end;
    0018 if nargin < 4; Ts=Tw/2; end;
    0019
    0020 n=round(Fs*Tw);
    0021 dn=round(Fs*Ts);
    0022 if ~isreal(data)
    0023   yr=real(data);
    0024   yi=imag(data);
    0025   tmp=runline(yr,n,dn);
    0026   yr=tmp';
    0027   tmp=runline(yi,n,dn);
    0028   yi=tmp';
    0029   data=yr+i*yi;
    0030 else
    0031   tmp=runline(data,n,dn);
    0032   data=tmp';
    0033 end