% THis program generates time series and variance-time plots for a
% random-walk distribution. The distribution is generated as the
% integraql of an normal distribution.
%
clear all;
max = 1000000;
wander = .5;
rwilk = random('Normal', 0, wander, max, 1);
for i = 2:max
    rwilk(i) = rwilk(i - 1) + rwilk(i);
end
%
% Variance-time
%
x1 = linspace(1, length(rwilk) - 1, length(rwilk));
y1 = rwilk; i = 1; d = 1;
while length(y1) >= 100    
	z1(i) = var(y1);
	m1(i) = d;
    clf reset; h = newplot;
    set(h, 'FontSize', 12);
    set(h, 'Position', [.12 .15 .85 .8]);
    plot(x1 / 1000, y1, '-k')
    %axis([0 12 0 500]);
    lag = strcat('Time (ks) Interval=', num2str(d));
    xlabel(lag);
    ylabel('Delay (ms)');
    lag = strcat('rwalk_', num2str(d));
    print('-dtiff', '-r600', lag)
    x1 = (x1(2:2:length(x1)));
    y1 = (y1(2:2:length(y1)) + y1(1:2:length(y1) - 1)) / 2;
    i = i + 1; d = 2 * d;
end
e = m1 / m1(1);
e = 1 ./ e;
loglog(m1, z1, '-k', m1, e * z1(1))
%axis([1 1e5 1e-4 100]);
xlabel('Time Interval (s)');
ylabel('Variance (s^2)');
print -dtiff -r600 rwalk_var

