function Rsq = corrcoef_pdf(X, Y, P_XY)
	% R^2 = corrcoef_pdf(X, Y, P_XY)
	%
	% calculate R^2 correlation coefficient
	% from joint PDF of two variables
	%
	% R^2 =     E[ (X - mu_x)(Y - mu_y) ]
	%      -----------------------------------
	%      (E[(X-mu_x)^2] E[(Y-mu_y)^2])^(1/2)

	mu_X	= trapz(X.^2/2, trapz(Y, P_XY, 2), 1);
	mu_Y	= trapz(X, trapz(Y.^2/2, P_XY, 2), 1);
	var_X = trapz(X.^3/3, trapz(Y, P_XY, 2), 1) - mu_X^2;
	var_Y = trapz(X, trapz(Y.^3/3, P_XY, 2), 1) - mu_Y^2;
	cov_XY= trapz((X-mu_X).^2/2, trapz((Y-mu_Y).^2/2, P_XY, 2), 1);
	
	Rsq	= cov_XY / sqrt(var_X * var_Y);
end