%corrx_example3.m: 
% Assume that the ensemble is known, determine the ACF.
% x(t) = cos(t + theta), where theta is uniformly distributed.
% David Pan for EE 385

N = 10000;  % Number of sample functions in the ensemble
theta = random('Uniform', 0, 2*pi, 1, N);

sample_period = 0.001;
t = -10: sample_period: 10; 
M = length(t);  % Number of time indices
x0 = zeros(1, N);
xtau = zeros(1, N);
R = zeros(1, M);

x0 = cos(theta);
tau = -10: sample_period: 10;
for i = 1: M
    xtau = cos(tau(i) + theta);
    R(i) = mean(x0 .* xtau);
end 
plot(tau,R);
xlabel('LAG'); ylabel('RX'); grid;