locsmooth.m 858 B

123456789101112131415161718192021222324252627282930313233
  1. function data=locsmooth(data,Fs,Tw,Ts)
  2. % Running line fit (using local linear regression) - 1d only, continuous
  3. % processes
  4. % Usage: data=locsmooth(data,Fs,Tw,Ts)
  5. % Inputs:
  6. % Note that units of Fs, movinwin have to be consistent.
  7. % data (single vector)
  8. % Fs (sampling frequency) - optional. Default 1
  9. % Tw (length of moving window) - optional. Default. full length of data (global detrend)
  10. % Ts (step size) - optional. Default Tw/2.
  11. %
  12. % Output:
  13. % data (locally smoothed data).
  14. data=change_row_to_column(data);
  15. N=size(data,1);
  16. if nargin < 2; Fs=1; end;
  17. if nargin < 3; Tw=N/Fs; end;
  18. if nargin < 4; Ts=Tw/2; end;
  19. n=round(Fs*Tw);
  20. dn=round(Fs*Ts);
  21. if ~isreal(data)
  22. yr=real(data);
  23. yi=imag(data);
  24. tmp=runline(yr,n,dn);
  25. yr=tmp';
  26. tmp=runline(yi,n,dn);
  27. yi=tmp';
  28. data=yr+i*yi;
  29. else
  30. tmp=runline(data,n,dn);
  31. data=tmp';
  32. end