Just to let anyone who might come across this post and is having the same issue.
I figured out the problem.
One cannot average the ρ as the output of the
corr
function, since this estimate is not an ergodic random variable.
I checked this by using the following code:
% Test on averaging the result of corr function
clear variables; close all;
% Parameters on correlation:
rho = 0.75;
L = 6;
% XA = randn(N, 1);
% XB = rho(iRho)*XA + sqrt(1-rho(iRho)^2)*randn(N, 1);
%% Monte Carlo simulation:
Ntrials = 1e3;
rhoexp = 0;
for k = 1:Ntrials
% Generate data:
h1 = randn(L, 1);
h2 = rho*h1 + sqrt(1-rho^2)*randn(L, 1);
%% Channel correlation
rhoexp = rhoexp + corr(h1, h2, 'type', 'Pearson');
end
rhoexp = rhoexp/Ntrials;
fprintf('Theoretical: %f \nExperimental: %f\n', rho, rhoexp)
%% Test with no averaging:
h1 = zeros(L, Ntrials);
h2 = zeros(L, Ntrials);
for k = 1:Ntrials
% Generate data:
h1(:, k) = randn(L, 1);
h2(:, k) = rho*h1(:, k) + sqrt(1-rho^2)*randn(L, 1);
end
h1 = h1(:);
h2 = h2(:);
%% Channel correlation
rhoexp = corr(h1, h2, 'type', 'Pearson');
fprintf('Theoretical: %f \nExperimental: %f\n', rho, rhoexp)
Therefore, the right way of computing the ρ value is to accumulate the channel values in a vector and, then, compute the correlation value after the trials loops.
