LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
diffvar.m
1function H = diffvar(sequence,isplot)
2%
3% 'diffvar' estimate the hurst parameter of a given sequence with
4% difference variance method. The difference variance method can
5% distinguish a non-stationary sequence from a long-dependence
6% sequence. It's usually used with aggregate variance method.
7%
8% Inputs:
9% sequence: the input sequence for estimate
10% isplot: whether display the plot. without a plot if isplot equal to 0
11% Outputs:
12% H: the estimated hurst coeffeient of the input sequence
13
14% Author: Chu Chen
15% Version 1.0, 03/10/2008
16% chen-chu@163.com
17%
18
19if nargin == 1
20 isplot = 0;
21end
22
23N = length(sequence);
24mlarge = floor(N/5);
25M = [floor(logspace(0,log10(mlarge),50))];
26M = unique(M(M>1));
27n = length(M);
28
29V = zeros(1,n);
30for i = 1:n
31 m = M(i);
32 k = floor(N/m);
33 matrix_sequence = reshape(sequence(1:m*k),m,k);
34 V(i) = var(sum(matrix_sequence,1)/m);
35end
36
37Vdiff = -diff(V);
38index = (Vdiff>0);
39Mdiff = M(index);
40Vdiff = Vdiff(index);
41x = log10(Mdiff);
42y = log10(Vdiff);
43n2 = length(x);
44cut_min = ceil(n2/10);
45cut_max = floor(6*n2/10);
46X = x(cut_min:cut_max);
47Y = y(cut_min:cut_max);
48p1 = polyfit(X,Y,1);
49Yfit = polyval(p1,X);
50yfit = polyval(p1,x);
51beta = -(Yfit(end)-Yfit(1))/(X(end)-X(1));
52H = 1-beta/2;
53
54if isplot ~= 0
55 figure,hold on;
56 plot(x,y,'b*');
57 plot(X,Yfit,'r-','LineWidth',2);
58 plot(x(1:cut_min),yfit(1:cut_min),'r:','LineWidth',2);
59 plot(x(cut_max:end),yfit(cut_max:end),'r:','LineWidth',2);
60 xlabel('Log10(Aggreate Level)'), ylabel('Log10(Different Viance)'), title('Different Viance Method');
61end