1function H = RS(sequence,isplot)
3%
'RS' estimate the hurst parameter of a given sequence with R/S method.
6% sequence: the input sequence
for estimate
7% isplot: whether display the plot. without a plot
if isplot equal to 0
9% H: the estimated hurst coeffeient of the input sequence
12% Version 1.0, 03/10/2008
22dsmall = max(10,log10(N)^2);
23D = floor(logspace(log10(dsmall),log10(dlarge),50));
36 matrix_sequence = reshape(sequence(1:d*m),d,m);
38 Z1 = cumsum(matrix_sequence);
39 Z2 = cumsum(repmat(mean(matrix_sequence),d,1));
40 R{i} = (max(Z1-Z2)-min(Z1-Z2));
41 S{i} = std(matrix_sequence);
43 if min(R{i})==0 || min(S{i}) ==0
48 y(i) = mean(log10(R{i}./S{i}));
51% fit a line with middle part of sequence
56cut_min = ceil(3*n2/10);
57cut_max = floor(9*n2/10);
59X = x(cut_min:cut_max);
60Y = y(cut_min:cut_max);
63H = (Yfit(end)-Yfit(1))/(X(end)-X(1));
67 bound = ceil(log10(N));
68 axis([0 bound 0 0.75*bound]);
73 plot(x(i),log10(R{index(i)}./S{index(i)}),
'b.');
76 x = linspace(0,bound,10);
79 h1 = plot(x,y1,
'b--',
'LineWidth',2);
80 h2 = plot(x,y2,
'b-.',
'LineWidth',2);
81 plot(X,Yfit,
'r-',
'LineWidth',3);
82 %legend([h1,h2],
'slope 1/2',
'slope 1',4)
83 xlabel('log10(blocks of size m)'),ylabel('log10(R/S)'),title('R/S Method');