cm_heuristic_hurst_exponent_20140302.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. % The Hurst exponent
  2. %--------------------------------------------------------------------------
  3. % This function does dispersional analysis on a data series, then does a
  4. % Matlab polyfit to a log-log plot to estimate the Hurst exponent of the
  5. % series.
  6. %
  7. % This algorithm is far faster than a full-blown implementation of Hurst's
  8. % algorithm. I got the idea from a 2000 PhD dissertation by Hendrik J
  9. % Blok, and I make no guarantees whatsoever about the rigor of this approach
  10. % or the accuracy of results. Use it at your own risk.
  11. %
  12. % Bill Davidson
  13. % 21 Oct 2003
  14. % THG 02.03.2014: algorithm downloaded together with the FASTER toolbox on
  15. % 02.03.2014
  16. function [hurst] = cm_heuristic_hurst_exponent_20140302(ts)
  17. %
  18. % input: ts = 1xN time series
  19. % output: hurst = hurst exponent of the input time series
  20. npoints = length(ts);
  21. yvals = zeros(1,npoints);
  22. xvals = zeros(1,npoints);
  23. ts2 = zeros(1,npoints);
  24. index = 0;
  25. binsize = 1;
  26. while npoints>4
  27. y=std(ts);
  28. index=index+1;
  29. xvals(index)=binsize;
  30. yvals(index)=binsize*y;
  31. npoints=fix(npoints/2);
  32. binsize=binsize*2;
  33. % average adjacent points in pairs
  34. for ipoints=1:npoints
  35. ts2(ipoints)=(ts(2*ipoints)+ts((2*ipoints)-1))*0.5;
  36. end
  37. ts=ts2(1:npoints);
  38. end
  39. xvals=xvals(1:index);
  40. yvals=yvals(1:index);
  41. logx=log(xvals);
  42. logy=log(yvals);
  43. p2=polyfit(logx,logy,1);
  44. % Hurst exponent is the slope of the linear fit of log-log plot
  45. hurst=p2(1);
  46. return;