function Z = rndcn(m, n, mu, cq)
% RNDCN  random sample generation from unit variance complex normal distribution. 
% 
% INPUT 
%    m, n  size of the sample
%    mu    mean value (complex-valued) 
%    cq    circularity quotient (complex-valued). Since var = 1, cq is equal 
%          to the pseudo-variance parameter of the CN distribution
% OUTPUT 
%    Z     random sample of length m X n from CN(mu,var=1,pvar=cq) distribution
% 
% (c) Esa Ollila, contact: esollila AT wooster.hut.fi
%
% If you use this program, please cite 
%    E. Ollila, J. Eriksson, V. Koivunen, "Complex univariate elliptically symmetric distribution", 
%       submitted to IEEE Transactions on Signal Processing, Dec. 2009. 
%-------------------------------------------------------------------------------

if (abs(cq)>1)  
     error('Input parameter cq (circularity quotient) should have modulus <= 1')
end 


% STEP 1
cc  = abs(cq);    % circularity coefficient 
ang = angle(cq);  % circularity angle  

% STEP 2
Z0 = (1/sqrt(2))*(randn(m,n)+j*randn(m,n)); % random sample from CN(0,1) 

% STEP 3
a = sqrt(1+cc); 
b = sqrt(1-cc); 
Zp = (1/2)*(a+b)*Z0 + (1/2)*(a-b)*conj(Z0);

% STEP 4
Z = mu + exp(j*ang/2)*Zp; 


