Trouble with Rescaled Range algorithm

Hello, everyone.
I'm trying to implement Rescaled Range algorithm from https://en.wikipedia.org/wiki/Rescaled_range and other sources, and using this generator https://uk.mathworks.com/matlabcentral/fileexchange/38935-fractional-brownian-motion-generator?s_tid=srchtitle to check how correct algorithm works. The problem is my algorithm doesn't work properly, Hurst estimation in the result is about source Hurst+0.5-0.9.
E.g. I set Hurst in fBm model = 0.1, alrogithm result is 0.59+. I tried to use several variations of code and still have same error
about Hurst+0.5-0.9. I ask you for help. Thank you a lot.
Here's the code of algorithm.
function [X,M,cumdev,rs,logRS,logN,H] = rsnew(x)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
idx = size(x,1)-1;
n = idx;
rows = floor(idx/n);
c = 0;
while rows <= idx/2
X = reshape(x(1:rows*n),rows,n); % если вернусь к N, заменить x на N
M = ones(rows,n).*mean(X,2);
demeaned = X - M;
cumdev = cumsum(demeaned,2);
rangeres = zeros(rows,n);
for i = 1:rows
for j = 1:n
rangeres(i,j) = max(cumdev(i,1:j)) - min(cumdev(i,1:j));
end
end
stdev = ones(rows,n).*std(X,1,2);
rs = rangeres./stdev;
averageRS(1,c+1) = mean(mean(rs,2));
logRS(1,c+1) = log(averageRS(1,c+1));
logN(1,c+1) = log(n);
c = c+1;
n = 2^(log2(n)-1);
rows = floor(idx/n);
end
H = logRS/logN;
p = polyfit(logN,logRS,9);
f = polyval(p,logN);
figure
plot(logN,logRS,'o')
hold on
plot(logN,f)
legend('logRS','f')
xlabel('log(number of test)'),ylabel('log(R/S)')
% axis([logN(1) logN(end) -inf +inf]),drawnow
end

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Mathematics and Optimization 的更多信息

产品

版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by