LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
peng.m
1function H = peng(sequence,isplot)
2%
3% 'peng' estimate the hurst parameter of a given sequence with residuals
4% of regression method.
5%
6% Inputs:
7% sequence: the input sequence for estimate
8% isplot: whether display the plot. without a plot if isplot equal to 0
9% Outputs:
10% H: the estimated hurst coeffeient of the input sequence
11
12% Author: Chu Chen
13% Version 1.0, 03/10/2008
14% chen-chu@163.com
15%
16
17if nargin == 1
18 isplot = 0;
19end
20
21% Calculate aggregate level.
22N = length(sequence);
23FBM = cumsum(sequence);
24mlarge = floor(N/5);
25msmall = max(10,log10(N)^2);
26M = floor(logspace(log10(msmall),log10(mlarge),50));
27M = unique(M);
28n = length(M);
29cut_min = ceil(n/10);
30cut_max = floor(7*n/10);
31
32% Calculate residuals under different aggregate level.
33Goble_residuals = zeros(1,n);
34for i = 1:n
35 m = M(i);
36 k = floor(N/m);
37 matrix_FBM = reshape(FBM(1:m*k),m,k);
38 x = 1:m;
39 Local_residual = zeros(1,k);
40
41 for j = 1:k
42 y = matrix_FBM(:,j);
43 vv=[x' ones(length(x),1)];
44 p=vv\y;
45 norm_xx=norm(y-vv*p);
46 Local_residual(j) = norm_xx.^2/m;
47 end
48
49 Goble_residuals(i) = mean(Local_residual);
50end
51
52% Fit and calculate H.
53x = log10(M);
54y = log10(Goble_residuals);
55X = x(cut_min:cut_max);
56Y = y(cut_min:cut_max);
57p1 = polyfit(X,Y,1);
58Yfit = polyval(p1,X);
59yfit = polyval(p1,x);
60H = 0.5*(Yfit(end)-Yfit(1))/(X(end)-X(1));
61
62if isplot ~= 0
63 figure,hold on;
64 plot(x,y,'b*');
65 plot(X,Yfit,'r-','LineWidth',2);
66 plot(x(1:cut_min),yfit(1:cut_min),'r:','LineWidth',2);
67 plot(x(cut_max:end),yfit(cut_max:end),'r:','LineWidth',2);
68 xlabel('Log of Aggregate Level'),ylabel('Log of Residual Vaiance'),title('Peng Method');
69end