PDA

查看完整版本 : [MATLAB毕业设计] 求教!关于Hurst指数


doublee
2010-01-02, 13:38
我在论坛上搜到了求Hurst指数的代码,但是用的时候总是出现下面这个问题:
>> estimate_hurst_exponent(data0)
Warning: Polynomial is not unique; degree >= number of data points.
> In polyfit at 72
In estimate_hurst_exponent at 36

ans =

0
请高手不吝赐教!
我的数据:
0.9411
1.0931
1.1259
0.9026
0.9983
1.1045
1.0186
0.9405
1.0181
0.9603
1.0044
1.0253
0.8526
1.2328
1.0344
0.9079
1.0055
1.0472
1.0856
0.9161
1.0222
0.9894
1.0872
0.9087
0.9599
0.7679
1.4795
0.9754
1.0099
1.0674
Hurst指数的代码:
function [hurst] = estimate_hurst_exponent(data0) % data set

data=data0; % make a local copy

[M,npoints]=size(data0);

yvals=zeros(1,npoints);
xvals=zeros(1,npoints);
data2=zeros(1,npoints);

index=0;
binsize=1;

while npoints>4

y=std(data);
index=index+1;
xvals(index)=binsize;
yvals(index)=binsize*y;

npoints=fix(npoints/2);
binsize=binsize*2;
for ipoints=1:npoints % average adjacent points in pairs
data2(ipoints)=(data(2*ipoints)+data((2*ipoints)-1))*0.5;
end
data=data2(1:npoints);

end

xvals=xvals(1:index);
yvals=yvals(1:index);

logx=log(xvals);
logy=log(yvals);

p2=polyfit(logx,logy,1);
hurst=p2(1); % Hurst exponent is the slope of the linear fit of log-log plot

return;